akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[101010];
ll y[101010];
ll a[201010];
ll b[101010];
ll c[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;


int main() {
	string s;
	cin>>s;
	string num="2019/04/30";
	if(s<=num){
		cout<<"Heisei"<<endl;
	}else{
		cout<<"TBD"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t MAXH = 1010, MOD = 1000000007;
int64_t H, W;
vector<vector<bool>> Grid(MAXH, vector<bool>(MAXH, false));
vector<vector<int64_t>> DP(MAXH, vector<int64_t>(MAXH, -1));

int64_t dfs(int64_t y, int64_t x)
{
  if (y < 0 || y >= H || x < 0 || x >= W)
    return 0;
  if (!Grid.at(y).at(x))
    return 0;
  if (DP.at(y).at(x) != -1)
    return DP.at(y).at(x);
  int64_t ret = 0;
  ret += dfs(y + 1, x) % MOD;
  ret += dfs(y, x + 1) % MOD;
  DP.at(y).at(x) = ret % MOD;
  return ret % MOD;
}

int main()
{
  cin >> H >> W;
  char c;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> c;
      if (c == '.')
        Grid.at(i).at(j) = true;
    }
  }
  // そのグリッドからH, Wにたどり着くまでのパターン数
  DP.at(H - 1).at(W - 1) = 1;
  int64_t ans = dfs(0, 0) % MOD;
  cout << ans << endl;
}


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

int main(){
	int k,s;
	cin >> k >> s;
	int ans = 0;
	for(int x = 0; x <= k ; ++x){
		for(int y = 0; y <= k; ++y){
			int z = s - x - y;
			if(0<=z && z<=k) ++ans;
		}
	}
	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) {
        println(s);
    }
    else {
        println("red")
    }
    return 0;
}

Measured memory_bytes: 3580
import Data.List

main = do

    [n, h] <- take 2 . map read . words <$> getLine
    sords <- sequence $ replicate n (map read . words <$> getLine) :: IO [[Int]]

    let [atks, thrs] = transpose sords
        maxDps = maximum atks
        needThrowSords = takeWhile (maxDps <) . sortBy (flip compare) $ thrs
        attackCount
            | h <= sum needThrowSords = (+1) . length . takeWhile (h >) . scanl1 (+) $ needThrowSords
            | otherwise               = 1 + length needThrowSords + div (h - 1 - sum needThrowSords) maxDps
        in
            print attackCount

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

signed main() {
	int a[20][20][20];
	int n;
	cin >> n;
	int b, f, r, v;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		a[b][f][r] += v;
	}

	for (int i = 1; i <= 4; i++) {
		for (int j = 1; j <= 3; j++) {
			for (int k = 1; k <= 10; k++) {
				cout << ' ' << a[i][j][k];
			}
			cout << endl;
		}
		if (i != 4) cout << "####################" << endl;
	}
}





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

using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
int h, w, ch, cw, dh, dw;
// int ans = INF;

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

vector<P> wdxdy;

int bfs(vector<string> s) {
  vector<vector<int> > dist(h, vector<int>(w, INF));
  priority_queue<pair<int, P> , vector< pair<int, P> >, greater< pair<int, P> > > que;
  que.push(pair<int, P>(0, P(ch, cw)));
  dist[ch][cw] = 0;
  while (!que.empty()) {
    P cur = que.top().second;
    int d = que.top().first; que.pop();
    int cy = cur.first, cx = cur.second;

    if (dist[cy][cx] < d) continue;
    int cnt = 0;
    for (int i = 0; i < 4; ++i) {
      int ny = cy + dy[i];
      int nx = cx + dx[i];
      if (ny >= 0 && ny < h && nx >= 0 && nx < w && s[ny][nx] == '.' && dist[ny][nx] > dist[cy][cx]) {
	cnt++;
	que.push(pair<int, P>(dist[cy][cx], P(ny, nx)));
	dist[ny][nx] = dist[cy][cx];
      }
    }
    if (cnt < 4) {
      for (int i = 0; i < wdxdy.size(); ++i) {
	int ny = cur.first + wdxdy[i].first;
	int nx = cur.second + wdxdy[i].second;
	if (ny >= 0 && ny < h && nx >= 0 && nx < w && s[ny][nx] == '.' && dist[ny][nx] > dist[cy][cx] + 1) {
	  que.push(pair<int, P>(dist[cy][cx] + 1, P(ny, nx)));
	  dist[ny][nx] = dist[cy][cx] + 1;
	}
      }
    }
  }
  return dist[dh][dw];
}

int main() {
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) cin >> s[i];

  for (int i = -2; i <= 2; ++i) {
    for (int j = -2; j <= 2; ++j) {
      if (i == 0 && j == 0) continue;
      wdxdy.push_back(P(i, j));
    }
  }
  // for (int i = 0; i < 4; ++i) {
  // }
  // dfs(s, P(ch, cw), 0);
  int ans = bfs(s);
  if (ans == INF) puts("-1");
  else cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 10424
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 500000
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|
    
void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}
    
bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}
   
    
void TREE_INSERT(int z){
  int y = NIL;
  int x = root;
    
  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }
    
}
    
void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}
    
void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}
    
    
int main(){
  int val;
  string op;
  long long zr;                   
    
    
  scanf("%d",&n);
  Init();
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;       
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
    printf("yes\n");
      }else{
    printf("no\n");
      }
          
    
    }
  }
    
  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;
   
  return 0;
}


Measured memory_bytes: 10740
#include<stdio.h>
#include<stdlib.h>//NILを使う為                                                 
struct Node{
  int key;
  struct Node *right, *left, *parent;//                                         
};
struct Node *root , *NIL;//                                                     
struct Node*find(struct Node *u, int k);
void insert(int);
void inorder(struct Node*);
void preorder(struct Node*);
int main(){
  int n,i,x;
  char c[10];
 struct  Node*t;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&x);
      insert(x);//挿入関数                                                      
    }else if(c[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else{
      scanf("%d",&x);
      t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}
void insert(int k){
  struct Node *y=NIL,*x=root,*z;//                                              
  z=(struct Node *)malloc(sizeof(struct Node));//mallocを使って格納             
  z->key=k;//                                                                   
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
struct Node*find(struct Node *u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}
void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

  



Measured memory_bytes: 20552
import sys

from functools import lru_cache

N = int(sys.stdin.readline().rstrip())
K = int(sys.stdin.readline().rstrip())


@lru_cache(None)
def F(N, K):
    """(0以上）N以下で、0でないものがちょうどK個"""

    assert N >= 0  # Nが非負であることを保証する

    if N < 10:  # N が一桁
        if K == 0:  # 使える 0 以外の数がない場合
            return 1  #
        if K == 1:
            return N  # 1,2,...,N までのどれか
        return 0  # それ以上 K が余っていたら作れない

    q, r = divmod(N, 10)  # N = 10*q + r と置く

    ret = 0
    if K >= 1:
        # 1の位(r)が nonzero
        ret += F(q, K - 1) * r  #
        ret += F(q - 1, K - 1) * (9 - r)

    # 1の位(r)が zero
    ret += F(q, K)
    return ret


print(F(N, K))


Measured memory_bytes: 9704
# 解説動画から累積和ポイント。 
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N,Q = map(int,input().split())
ABList = [list(map(int,list(input().split()))) for i in range(N-1)]  
PXList = [list(map(int,list(input().split()))) for i in range(Q)]  
 
# N+1 にしているのは、dfs関数でparentsを使う時に合わせるため 
graph=[[] for _ in range(N+1)]
values=[0]*(N+1)
 
for a,b in ABList:
    graph[a].append(b)
    graph[b].append(a)
    # aとbを入れ替えて
    # graphは例１の時、[[], [2], [1, 3, 4], [2], [2]] になる
    # 頂点がどことつながっているか 
for p,x in PXList:
    values[p]+=x
    # p をキーにしているのでNの昇順ｘにしている
    # 例１であれば[0, 100, 10, 1, 0]　累積和する前の値をもつ
 
def dfs(x,parent,add):
    # 累積和をvaluesに計算していく
    values[x]+=add
    for i in graph[x]:
        # continueはループの残りを飛ばして次の反復へ
        # 親と子判定
        if i==parent:
            continue
        dfs(i,x,values[x])
 
dfs(1,0,0)
 
print(' '.join(map(str,values[1:])))
# 難しい。graph[x]の使い方の理解がまだまだ

Measured memory_bytes: 301404
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
//cout << fixed << setprecision(8) << a << endl;
//cout << "Case " << ca << ": " << ans << endl;
#define Fast_Input ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define MX 100001
#define infinity 20000000
#define pb push_back
#define ll long long int
int arr[MX];
int tree[MX*3];
int sum;
void init(int node,int b,int e)
{
    if(b==e)
    {
        tree[node]=arr[b];
        return;
    }

    int left=2*node;
    int right=(2*node)+1;
    int mid=(b+e)/2;
    init(left,b,mid);
    init(right,mid+1,e);
    tree[node]=tree[left]+tree[right];
}

int query(int node,int b,int e,int i,int j)
{
    if(j<b || i>e)
    {
        return 0;
    }

    if(b>=i && e<=j)
    {
        sum=tree[node];
        tree[node]=0;
        return sum;
    }

    int left=2*node;
    int right=(2*node)+1;
    int mid=(b+e)/2;
    long long int p=query(left,b,mid,i,j);
    long long int q=query(right,mid+1,e,i,j);

    tree[node]=tree[left]+tree[right];
    return p+q;
}
int query1(int node,int b,int e,int r,int j)
{
    if(j<b || r>e)
    {
        return 0;
    }

    if(b>=r && e<=j)
    {
        return tree[node];
    }

    int left=2*node;
    int right=(2*node)+1;
    int mid=(b+e)/2;
    int p1=query1(left,b,mid,r,j);
    int p2=query1(right,mid+1,e,r,j);

    return p1+p2;
}

void update(int node,int b,int e,int j,int value)
{
    if(j<b || j>e)
    {
        return;
    }

    if(b>=j && e<=j)
    {
        tree[node]=tree[node]+value;
        return;
    }

    int left=2*node;
    int right=(2*node)+1;
    int mid=(b+e)/2;
    update(left,b,mid,j,value);
    update(right,mid+1,e,j,value);
    tree[node]=tree[left]+tree[right];
}
int main()
{
    int n;
    cin >> n;
    int i,maxi=-1;
    map < string ,int>m;
    for(i=1;i<=n;i++)
    {
        string s;
        cin >> s;
        m[s]++;
        if(m[s]>maxi)
            maxi=m[s];
    }
    set < string > s;
    for(auto x: m)
    {
        if(x.second==maxi)
            s.insert(x.first);
    }

    for(auto x: s)
        cout << x << endl;
    return 0;
}


Measured memory_bytes: 34560
#include<bits/stdc++.h>
using namespace std;
int n,a[111111];
bool chk(int cat,int color){
	if(color <= 0)return false;
	return cat >= 2 * color;
}
int main(){
	scanf("%d",&n);
	int S = n+1, E = -1;
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		S = min(S,a[i]);
		E = max(E,a[i]);
	}
	if(E - S >= 2){
		puts("No");
		return 0;
	}
	if(E == S){
		if(E == 1 || E == n-1 || E * 2 <= n)
			puts("Yes");
		else
			puts("No");
		return 0;
	}
	int cnt = 0;
	for(int i=1; i<=n; i++)
		if(a[i] == S)
			cnt++;
	puts(chk(n-cnt,E-cnt)?"Yes":"No");
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;



int main(){
	string s; cin >> s;
	reverse(all(s));
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  string S;
  set<char> st = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
                  'o','p','q','r','s','t','u','v','w','x','y','z'};
  cin >> S;
  for (const char &x : S) st.erase(x);

  if (0 == st.size())
    cout << "None" << "\n";
  else
    cout << *st.begin() << "\n";
  return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int n,a,b ;
   int min,cost;
   cin>>n>>a>>b;
  int cost1=n*a;
   if(cost1>b)
   {
       cost=b;
   }
   else
   {
       cost=cost1;
   }
   
   cout<<cost;
    
    return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    int n;
    cin >> n;
    vector<ll> a;
    vector<ll> a4; //x*4
    int flg2 = 0;
    rep(i, n)
    {
        int b;
        cin >> b;
        if (b % 4 == 0)
            a4.push_back(b);
        else
        {
            if (b % 2 != 0)
                a.push_back(b);
            else
                flg2 = 1;
        }
    }
    int div = a4.size() - (a.size() + flg2);
    if (div >= -1)
    {
        c("Yes");
    }
    else
    {
        c("No");
    }
    return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
#define MAX 100001

int main(){
  int i,n,H[MAX];

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d",&H[i]);
  }

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ",i,H[i]);
    if(i/2 >= 1){
      printf("parent key = %d, ",H[i/2]);
    }
    if(2*i <= n){
      printf("left key = %d, ",H[2*i]);
    }
    if(2*i+1 <= n){
      printf("right key = %d, ",H[2*i+1]);
    }
    printf("\n");
  }

  return 0;
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

struct custom_hash {    // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map;
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//


void solve()
{
    int n;
    cin>>n;
    int ac = 0, wa = 0, tle=0,re=0;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")
        ac++;
        else if(s=="WA")
        wa++;
        else if(s=="TLE")
        tle++;
        else
        re++;
    }
    cout<<"AC x "<<ac<<"\nWA x "<<wa<<"\nTLE x "<<tle<<"\nRE x "<<re<<endl;
}

int main()
{
	fastio;
    // int T;
    // cin>>T;
    // while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 3648
a, b = map(int, input().strip().split())


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


factors_a = factorize(a)
factors_b = factorize(b)

factors_a = {f[0] for f in factors_a}
factors_b = {f[0] for f in factors_b}

commons = factors_a & factors_b

print(len(commons) + 1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long; //10^19 < 9223372036854775807
#define REP(i,n) for(ll i=0;i<ll(n);i++)

int main(void)
{
    ll N,M;
    cin >> N >> M;

    cout << N*(N-1)/2+M*(M-1)/2 << endl;

    return 0;
}


Measured memory_bytes: 3596
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
import numpy
C=numpy.cumsum(B)
cnt=1
for i in range(N-1):
  if C[-2-i]*2>=B[-1-i]:
    cnt+=1
  else:
    print(cnt)
    exit()
print(cnt)

Measured memory_bytes: 18800
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  2000007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main() {
    int n, k;
    I2(n, k);
    

    if(k % 2 == 0){
        ll ans = PW((ll)(n/k), 3ll);
        ll rem = k/2;
        ll val = n/k;
        if(n % k >= rem)val++;
        ans += PW(val, 3ll);
        cout<<ans<<endl;
    }
    else {
        ll ans = PW((ll)(n/k), 3ll);
        cout<<ans<<Endl;
    }

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=100005;
int val[2*nmax],sum[2*nmax];
int a[nmax];
int n,i,j,zr;
void update(int poz,int value)
{
    val[poz]+=value;
    sum[poz]=sum[poz-1]+val[poz];
}
int compute(int poz)
{
    return sum[poz];
}
long long check(int value)
{
    long long ret=0;
    int summ=0;
    update(zr,1);
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=value) summ++;
        if(a[i]>value) summ--;
        ret+=1LL*compute(summ+zr-1);
        update(summ+zr,1);
    }
    for(i=1;i<=2*n+1;i++)
        val[i]=sum[i]=0;
    return ret;
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    int ans=0;zr=n+1;
    long long c=(1LL*n*(n+1)/2)/2+1;
    for(int p=30;p>=0;p--)
        if(check(ans+(1<<p))<c)
              ans+=(1<<p);
    ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2176
import collections

n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Measured memory_bytes: 69352
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[2][105];
int ans[105];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<2;i++)
    {
        int j;
        for (j=0;j<n;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    int sum=0;
    for (i=0;i<n;i++)
    {
        sum+=a[0][i];
        ans[i]+=sum;
    }
    sum=0;
    for (i=n-1;i>=0;i--)
    {
        sum+=a[1][i];
        ans[i]+=sum;
    }
    int final_ans=0;
    for (i=0;i<n;i++)
    {
        final_ans=max(final_ans,ans[i]);
    }
    cout<<final_ans<<endl;
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int prec[200001][2];
int A[200000];
int32_t main(){
	int n;
	cin >> n;
	prec[0][0] = 0;
	prec[n][1] = 0;
	for(int i = 0; i < n; i++){
		cin >> A[i];
		prec[i + 1][0] = prec[i][0] + A[i];
	}
	for(int i = n - 1; i >= 0; i--){
		prec[i][1] = prec[i + 1][1] + A[i];
	}
	int ans = (1LL << 60);
	for(int i = 0; i <= n; i++){
		ans = min(abs(prec[i][0] - prec[i][1]), ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  char c;
  cin >> c;
  if(isupper(c))cout << 'A' << endl;
  else cout << 'a' << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
    char s[201],p[101],copy[101];
    scanf("%s %s",s,p);
    strcpy(copy,s);
    strcat(s,copy);
    if(strstr(s,p)== NULL) printf("No\n");
    else printf("Yes\n");
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (count(s.begin(), s.end(), s[i]) > 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  int flag = 1;
  for (int i = 0; i < n-1; i++) {
    if (s[i].back() != s[i+1].front()) {
      flag = 0;
      break;
    }
  }
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k,m,a,ans,an[1000];
int main() 
{
  cin>>n>>k;
  for(int i=0;i<k;i++)
  {
      cin>>m;
      for(int j=0;j<m;j++)
      {
          cin>>a;
          an[a]=1;
      }
  }
  for(int i=1;i<=n;i++)
  {
      if(an[i]==0)
      {
          ans++;
      }
  }
  cout<<ans;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mod 1000000007
#define endl "\n"

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

int main()
{
    fastio
    char c ;

    cin >> c ;

    if(c>='A' && c<='Z')
        cout << 'A';
    else
        cout << 'a';

    return 0;
}

Measured memory_bytes: 3644
h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

dp=[10**8+1 for i in range(h+1)]
dp[0]=0

for i in range(h+1):
 for a,b in l:
  j=min(i+a,h)
  dp[j]=min(dp[j],dp[i]+b)

print(dp[-1])

Measured memory_bytes: 42220
#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 n;
    cin >> n;
    map<string, int> mp;
    rep(i, n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mcnt = 0;
    for (auto cnt : mp)
    {
        mcnt = max(mcnt, cnt.second);
    }
    for (auto ans : mp)
    {
        if (mcnt == ans.second)
            cout << ans.first << endl;
    }
    return 0;
}

Measured memory_bytes: 19204
import itertools


s = input()
p = input()

n = len(p)

ans = "No"
for i in range(len(s)):
    ring = itertools.cycle(s)
    for j in range(i):
        next(ring)
    chars = [next(ring) for _ in range(n)]
    if "".join(chars) == p:
        ans = "Yes"
print(ans)



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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  string s, t;  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  int ans = INT_MAX;
  for (int i = 0; i+m-1 < n; ++i){
    int cnt = 0;
    for (int j = 0; j < m; ++j){
      if(s[i+j]!=t[j])  cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n * n * n << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    A1 = [i + a for i, a in enumerate(A)]
    A2 = [i - a for i, a in enumerate(A)]
    c1 = Counter(A1)
    c2 = Counter(A2)
    c2_keys = c2.keys()
    ans = 0
    for key, val in c1.items():
        if key in c2_keys:
            ans += val * c2[key]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 63504
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<queue>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

int n,a[10];
map<int,int>k;
bool b[10],ans=false;

int main() {
	for(int i=0;i<9;i++){
		cin>>a[i];
		k[a[i]]=i;
		b[i]=false;
	}
	cin>>n;
	for(int i=0;i<n;i++){
		int c;
		cin>>c;
		if(k.count(c))b[k[c]]=true;
	}
	ans=((b[0]&&b[4]&&b[8])||(b[6]&&b[4]&&b[2]));
	for(int i=0;i<3;i++){
		if(b[i*3]&&b[i*3+1]&&b[i*3+2])ans=true;
		if(b[i]&&b[i+3]&&b[i+6])ans=true;
	}
	cout<<(ans?"Yes":"No")<<endl;

	return 0;
}



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

int n;
ll a[200005], b[200005];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%lld", a + i);
    ll x = 0;
    for (int i = 1; i < n; ++i)
        if (i % 2) x -= a[i];
        else x += a[i];
    b[1] = a[n] - x;
    for (int i = 2; i <= n; ++i)
        b[i] = a[i - 1] * 2 - b[i - 1];
    for (int i = 1; i <= n; ++i)
        printf("%lld ", b[i]);
    return 0;
}


Measured memory_bytes: 2944
Q=int(input())

def isPrime(x):
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  else:
    return True

plist=[False]*(10**5+3)
for i in range(3,10**5+3,2):
  if isPrime(i) and isPrime((i+1)//2):
    plist[i]=True
#print(plist[:10])

slist=[0]*(10**5+3)
for i in range(3,10**5+3):
  if plist[i]:
    slist[i]=slist[i-1]+1
  else:
    slist[i]=slist[i-1]
#print(slist[:10])
  
for i in range(Q):
  l,r=map(int,input().split())
  print(slist[r]-slist[l-1])

Measured memory_bytes: 4980
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
        int N,k;
        cin >> N >> k;
        bool dislike[10]={false};
        for(int i=0 ; i<k ; i++ ){
                int x;cin >> x;
                dislike[x]=true;
        }
        for(int i=N ; true ; i++ ){
                stringstream ss;
                ss << i;
                string str=ss.str();
                bool sign=true;
                for(int l=0 ; l<str.size() ; l++ ){
                        string tmp="";tmp+=str[l];
                        istringstream iss(tmp);
                        int x;iss >>x;
                        if(dislike[x]){
                                sign=false;
                                break;
                        }
                }
                if(sign){
                        cout << i << endl;
                        return 0;
                }
        }
        return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N, K;

signed main() {
  cin >> N >> K;

  double ans = 0;
  for (int i = 1; i <= N; i++) {
    double tmp = 1.0 / N;
    int num = i;
    while (1) {
      if (num >= K) break;
      num *= 2;
      tmp *= 0.5;
    }
    ans += tmp;
  }

  printf("%.10f\n", ans);

  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  cin >> s;

  ll ans = 0;
  ll cnt = 0;
  for (auto c : s) {
    if (c == 'B') {
      cnt++;
    } else {
      ans += cnt;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 720
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  std::string s, t;
  std::cin >> s;
  std::cin >> t;
  std::sort(s.begin(), s.end());
  std::sort(t.begin(), t.end());
  std::reverse(t.begin(), t.end());
  if (s < t)
    std::cout << "Yes";
  else
    std::cout << "No";
}


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

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++)
		{
			cin >> x[i][j];
		}
	}

	int count = 0;
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			int length = 0;
			for (int k = 0; k < d; k++)
			{
				length += (x[j][k] - x[i][k]) * (x[j][k] - x[i][k]);
			}
			for (int k = 1; k <= sqrt(length); k++)
			{
				if (k * k == length)
				{
					count++;
				}
			}
		}
	}

	cout << count << endl;
}

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

using namespace std;

int x,y,i,j;
char s[8005];
vector <int> a[2];
bool dp[16005];

int main(){
	scanf("%s", s);
	scanf("%d%d", &x, &y);
	
	int l = strlen(s);
	
	int cnt = 0;
	bool ok = 0;
	bool first = 0;
	
	for(i = 0; i < l; i++){
		if(s[i] == 'T'){
			first = 1;
			cnt ^= 1;
			ok = 0;
		}
		else{
			if(!first){
				x--;
			}
			else if(!ok){
				a[cnt].push_back(1);
				ok = 1;
			}
			else
			a[cnt].back()++;
		}
	}
	
	int xsum = 0;
	int ysum = 0;
	
	for(i = 0; i < a[0].size(); i++)
	xsum += a[0][i];
	
	for(i = 0; i < a[1].size(); i++)
	ysum += a[1][i];
	
	if(xsum < abs(x) || ysum < abs(y))
	return 0 * printf("No\n");
	
	x += xsum;
	y += ysum;
	
	dp[0] = 1;
	
	for(i = 0; i < a[0].size(); i++){
		for(j = x; j >= 2 * a[0][i]; j--)
		dp[j] |= dp[j - 2 * a[0][i]];
	}
	
	bool res = 1;
	res &= dp[x];
	
	memset(dp, 0, sizeof(dp));
	
	dp[0] = 1;
	
	for(i = 0; i < a[1].size(); i++){
		for(j = y; j >= 2 * a[1][i]; j--)
		dp[j] |= dp[j - 2 * a[1][i]];
	}
	
	res &= dp[y];
	
	if(res)
	printf("Yes\n");
	else
	printf("No\n");
}


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

#define mod 1000000007
ll H, W, A, B, fact[200000], inv[200000], factinv[200000];

ll ncr(int n, int r) {
  return (n - r >= 0 && r >= 0)
             ? 1LL * fact[n] * factinv[r] % mod * factinv[n - r] % mod
             : 0;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < 200000; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i < 200000; i++)
    inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
  factinv[0] = 1;
  for (int i = 1; i < 200000; i++)
    factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;
  cin >> H >> W >> A >> B;
  ll sum = 0;
  for (int i = 0; i < H - A; i++) {
    sum += ncr(B + i - 1, B - 1) * ncr((W - B - 1) + (H - i - 1), W - B - 1);
    sum %= mod;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<pll> vplll;

int main(){
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
	// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    s[k-1]=(char)((int)s[k-1]+32);
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
d, g = gets.split.map(&:to_i)
pcs = []
d.times do
  pcs << gets.split.map(&:to_i)
end

ans = 10 ** 20
score = 0
(1..2**d).each do |x|
  score = 0
  nonselected = nil
  t_ans = 0
  (0..d-1).each do |i|
    if (x & (1<<i)) != 0
      p, c = pcs[i]
      score += c
      score += (i+1) * 100 * p
      t_ans += p
    else
      nonselected = [pcs[i][0], i]
    end
  end
  p, i = nonselected
  if p
    (0..p).each do |pp|
      if score >= g
        break
      end
      score += (i+1) * 100 * 1
      t_ans += 1
    end
  end
  if score >= g
    ans = [ans, t_ans].min
  end
end

puts ans


Measured memory_bytes: 1788
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>
#include<stack>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

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

int w,h;
char a[51][51],b[51][51];
	
void dfs(int x,int y,char c){
	rep(i,4)if(x+dx[i]>=0&&x+dx[i]<h&&y+dy[i]>=0&&y+dy[i]<w){
		if(a[x+dx[i]][y+dy[i]]=='.' && (b[x+dx[i]][y+dy[i]]&c)!=c){
			b[x+dx[i]][y+dy[i]]|=c;
			dfs(x+dx[i],y+dy[i],c);
		}
	}
}
int main(){
	do{
		scanf("%d%d",&w,&h);
		if(!w)break;
		rep(i,h)scanf("%s",a[i]);
		int bl=0,wi=0;
		memset(b,0,sizeof(b));
		rep(i,h)rep(j,w){
			if(a[i][j]!='.')dfs(i,j,a[i][j]=='B'?2:1);
		}
		rep(i,h)rep(j,w){
			bl+=b[i][j]==2;
			wi+=b[i][j]==1;
		}
		printf("%d %d\n",bl,wi,0);
	}while(1);
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    long double ans = 0.0;
    for (int i = 1; i <= N; i++) {
        int t = 0;
        long double p = 1;
        int n = i;
        while (n < K) {
            n *= 2;
            p /= 2.0;
            t++;
        }
        if (t == 0) {
            ans += 1.0 / (long double)N;
        } else {
            ans += 1.0 * (long double)p / (long double)N;
        }
    }
    cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int d,t,s;cin >> d >> t >> s;
	if(s*t >= d)cout << "Yes" << endl;
	else cout <<"No" << endl;
	return 0;
}

Measured memory_bytes: 3628
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    r, g, b = i_map()

    print('YES' if (r*100+g*10+b)%4 == 0 else 'NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 77080
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    string s;
    cin >> s;
    cout << s.at(0) << s.at(1) << s.at(2) << endl;
    return 0;
}

Measured memory_bytes: 3600