akhauriyash/Code-Regression huggingface dataset:
### constant

MAX_P = 10 ** 6
MAX_X = MAX_Y = 1003

DXYS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### subroutines

def gen_primes(max_p)
  primes = (max_p + 1).times.map{true}
  primes[0] = primes[1] = false

  s_max_p = Math.sqrt(max_p + 0.5).to_i

  for p in (2..s_max_p)
    if primes[p]
      (p * p).step(max_p, p).each{|q| primes[q] = false}
    end
  end

  primes
end

### main

primes = gen_primes(MAX_P)

cvs = MAX_Y.times.map{MAX_X.times.map{0}}
x = MAX_X / 2
y = MAX_Y / 2
cvs[x][y] = 1
drc = 3
drc0 = 0

for k in (2..MAX_P)
  x0 = x + DXYS[drc0][0]
  y0 = y + DXYS[drc0][1]
  if cvs[y0][x0] == 0
    drc = drc0
    drc0 = (drc0 + 1) % 4
  end
  x += DXYS[drc][0]
  y += DXYS[drc][1]
  cvs[y][x] = k
end
#cvs.each{|cv| puts cv.map{|c| "%3d" % c}.join(' ')}; exit

loop do
  m, n = gets.split.map(&:to_i)
  break if (m | n) == 0

  pnums = MAX_Y.times.map{MAX_X.times.map{0}}
  maxps = MAX_Y.times.map{MAX_X.times.map{0}}

  (MAX_Y - 1).downto(0).each do |y|
    for x in (0...MAX_X)
      cv = cvs[y][x]
      if cv > 0 && cv <= m
        max_pnum = maxp = 0
        y0 = y + 1
        if y0 < MAX_Y
          for x0 in ((x - 1)..(x + 1))
            next if x0 < 0 || x0 >= MAX_X
            pn0 = pnums[y0][x0]
            maxp0 = maxps[y0][x0]

            if max_pnum < pn0
              max_pnum = pn0
              maxp = maxp0
            elsif max_pnum == pn0 && maxp < maxp0
              maxp = maxp0
            end
          end
        end

        if primes[cv]
          max_pnum += 1
          maxp = cv if maxp == 0
        end

        pnums[y][x] = max_pnum
        maxps[y][x] = maxp
      end

      if cv == n
        puts [pnums[y][x], maxps[y][x]].join(' ')
        break
      end
    end
    break if cv == n
  end
end

Measured memory_bytes: 60624
#include<stdio.h>
int main(void){
	int i,j,k,H[300],W[300];
	for(i=0;;i++){
		scanf("%d %d",&H[i],&W[i]);
		if(H[i]==0&&W[i]==0){
			break;
		}
	}
	for(i=0;H[i]!=0||W[i]!=0;i++){
		for(j=0;j<H[i];j++){
			for(k=0;k<W[i];k++){
				if(j%2==k%2){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;

  for(int i=min(a, b), cnt=0; ; i--){
    if(a % i == 0 && b % i == 0) cnt++;
    if(cnt == k){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
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 (b<a) {a=b; return 1;} return 0;}

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i, h) cin >> field[i];
    
    const int dy[4] = {1, 0, -1, 0};
    const int dx[4] = {0, 1, 0, -1};
    
    int ans = 0;

    rep(y, h) {
        rep(x, w) {
            if (field[y][x] == '.') {
                int sy = y, sx = x;
                queue<int> qy, qx;
                vector<vector<int>> dist(h, vector<int>(w, -1));
                qy.push(sy); qx.push(sx);
                dist[sy][sx] = 0;
                while (!qy.empty()) {
                    int vy = qy.front(), vx = qx.front();
                    qy.pop(); qx.pop();
                    for (int i = 0; i < 4; ++i) {
                        int ny = vy + dy[i], nx = vx + dx[i];
                        if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
                        if (dist[ny][nx] >= 0) continue;
                        if (field[ny][nx] == '#') continue;
                        qy.push(ny); qx.push(nx);
                        dist[ny][nx] = dist[vy][vx] + 1;
                    }
                }

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

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
    }
    let x = 800 * n;
    let y = 200 * (n / 15);
    println!("{}", x - y);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()
const long double PI = 3.141592653589793238462643383279502884197169399375105820974;

int main() {
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    ld rad = 2*PI*( (ld)h/12.0 + ((ld)m/60.0)/12.0 - (ld)m/60.0);
    ld ans= (ld)(a*a + b*b) - (ld)2.0*a*b*cosl(rad);
    ans = sqrtl(ans);
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 4164
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int k; cin >> k;
    ll ans = 0;
    for(int a = 1; a <= k; ++a){
        for(int b = 1; b <= k; ++b){
            for(int c = 1; c <= k; ++c){
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << '\n';
    
    
    
    return 0;
}


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

int main()
{
    int t;
    cin >> t;
    while (t-- > 0){
        int n;
        cin >> n;
        int h[n];
        for (int i = 0; i < n; i++) cin >> h[i];
        int d[n - 1];
        for (int i = 0; i < n - 1; i++) d[i] = h[i + 1] - h[i];
        sort(d, d + n - 1);
        cout << max(0, d[n - 2]) << " " << max(0, -d[0]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
using namespace std;
int main()
{
	char a[4];
	scanf("%s",a);
	if(a[0]==a[2])
	{
		printf("Yes"); 
	}
	else
	{
		printf("No");
	} 
	return 0;
}



Measured memory_bytes: 256
from random import *
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(365)]
for i in range(365):
    cand=0
    for j in range(26):
        if s[i][cand]<s[i][j]:
            cand=j
    print(cand+1)
    #print(randrange(1,26))

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

int main(){
  int n , k;
  cin >> n;
  k = n;
  int x = 0;
  
  while(n>0){
    x += n%10;
    n /= 10;
  }
  
  if(k % x == 0)
    cout << "Yes"<< endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
int b[100000];

bool IsTriNum() {
    if ( b[0] != 1 ) return false;
    for ( int i=1; i<n; ++i ) {
	if ( b[i] != b[i-1]+1 ) return false;
    }
    return true;
}

int main() {

    while ( cin >> n && n != 0 ) {

	for ( int i=0; i<n; ++i ) cin >> b[i];

	int cnt = 0;
	while ( !IsTriNum() && cnt <= 10000 ) {
	
	    int new_column = 0;
	    for ( int i=0; i<n; ++i ) {
		if ( b[i] >= 1 ) {
		    --b[i];
		    ++new_column;
		}
	    }

	    //0の列の分はつめる
	    int m = 0, k = 0;
	    for ( int i=0; i<n; ++i ) {

		while ( b[k] == 0 && k < n ) ++k;

		if ( k == n ) break;
		else {
		    b[i] = b[k];
		    ++m;
		    ++k;
		}
	    }

	    b[m] = new_column;

	    n = m + 1;
	    ++cnt;
	}

	if ( cnt > 10000 ) cout << -1 << endl;
	else cout << cnt << endl;
    }

    return 0;
}



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

typedef long long ll;
typedef pair<int,int> pint;
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());
signed main(void){
  int n,k,q;cin >> n >> k >> q;
  vint a(q);vin(a);
  vint b(n,0);
  rep(i,q) b[a[i]-1]++;
  rep(i,n){
    if(k-(q-b[i])<=0)cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def calc_comb(zeros, ones, length):
    return (pow(2,ones,MOD) * pow(3,(length - ones - zeros),MOD)) % MOD

def main():
    # L = int('0b'+SI(), 0)
    L = SI()

    count_one = 0
    count_zero = 0
    comb = 0
    for char in L:
        if char == '0':
            count_zero += 1
        elif char == '1':
            count_one += 1
            comb += calc_comb(count_zero + 1, count_one -1, len(L))
            comb %= MOD

    comb += calc_comb(count_zero, count_one, len(L))  # Lの最後が0だったとしても1だったとしても、a+b = L の場合が計算されていない。
    comb %= MOD

    print(comb)

main()

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;


signed main() {
  double a,b,x,o=2.0;
  cin>>a>>b>>x;
  if(2*x<a*a*b){
  //  cerr<<b/((2*x)/(a*b));
    cout << std::setprecision(20)<<atan(b/((2*x)/(a*b)))*180/M_PI;
  }else{
   // cerr<<(b-((2*x)/(a*a)-b))/a;
    cout << std::setprecision(20)<<atan((b-((2*x)/(a*a)-b))/a)*180/M_PI;
  }

}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
	while (x->left != NIL) x = x->left;
	return x;
}

Node *find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}

	return u;
}

Node* treeSuccessor(Node *x) {
	if (x->right != NIL) return treeMinimum(x->right);
	Node *y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}

	return y;
}

void treeDelete(Node *z) {
	Node *y;
	Node *x;

	if (z->left == NIL || z->right == NIL) y = z;
	else y = treeSuccessor(z);

	if (y->left != NIL) {
		x = y->left;
	}
	else {
		x = y->right;
	}

	if (x != NIL) {
		x->parent = y->parent;
	}

	if (y->parent == NIL) {
		root = x;
	}
	else {
		if (y == y->parent->left) {
			y->parent->left = x;
		}
		else {
			y->parent->right = x;
		}
	}

	if (y != z) {
		z->key = y->key;
	}

	free(y);
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node*)malloc(sizeof(Node));
	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;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'f') {
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com == "delete") {
			scanf("%d", &x);
			treeDelete(find(root, x));
		}
	}

	return 0;
}


Measured memory_bytes: 22064
def main():
    N = int(input())

    def sum_num(num):
        div = N // num
        
        ret = num * int(div * ((1 + div) / 2))
        
        return (ret)

    ans = 0

    for i in range(1, N + 1):
        ans += sum_num(i)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 64440
main = readLn >>= print . digits

isqrt :: Integral a => a -> a 
isqrt = floor . sqrt . (fromIntegral :: Integral a => a -> Double) 

digits :: Int -> Int
digits n = max (length (show dmax)) (length (show (div n dmax)))
  where
    dmax = maximum $ filter (\d -> mod n d == 0) cands
    cands = [1 .. isqrt n]

Measured memory_bytes: 508
#include <stdio.h>

#define N 1200

int main(void){

    char c;
    int count[26];
    int i;
    for(i=0; i<26; i++){
        count[i] = 0;
    }
    
    while(scanf("%c", &c)!=EOF){
        if('A'<=c && c<='Z'){
            c += ('a'-'A') ; 
        }
        if('a'<=c && c<='z'){
            count[c-'a'] ++;
        }
    }
    for(i=0; i<26; i++){
        printf("%c : %d\n", i+'a', count[i]);
    }
    return 0;
}


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

int nxt[100010][26];

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

	string s, t;
	cin >> s >> t;

	for (char alp = 'a'; alp <= 'z'; ++alp) {
		int pos = -1;
		for (int i = s.size(); i >= 0; --i) {
			nxt[i][alp - 'a'] = pos;
			if (i != 0 && s[i - 1] == alp) pos = i;
		}
	}

	long long ans = 0;
	for (int i = 0; i < t.size();) {
		int now = 0;
		if (nxt[0][t[i] - 'a'] == -1) {
			cout << -1;
			return 0;
		}
		while (i < t.size() && nxt[now][t[i] - 'a'] != -1) {
			now = nxt[now][t[i] - 'a'];
			i++;
		}
		if (i == t.size()) ans += now;
		else ans += s.size();
	}

	cout << ans;
}

Measured memory_bytes: 10704
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define vec vector
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false 
using namespace std;

ll bmm(ll a, ll b) {
	if (b == 0) return a;
	else return bmm(b, a%b);
}
ll kmm(ll a, ll b) {
	return(a*b) / bmm(a, b);
}


const ll mod = 1e9 + 7;
const ll MAXN = 1e3+5;

ll n;
ss s;
int main() {
	isc;
	cin >> n >> s;
	if(n%2!=0)
		cout << "No";
	else{
		n/=2;
		ss t;
		rep(i,0,n){
			t+=s[i];
		}
		s.erase(0,n);
		if(t==s)
			cout << "Yes";
		else
			cout << "No";
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(void) {
  int H, W, whites = 0;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, 1, 0, -1};
  queue<P> q;
  cin >> H >> W;
  char map[W][H];
  int d[W][H];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> map[j][i];
      d[j][i] = INF;
      if (map[j][i] == '.') whites++;
    }
  }

  q.push(P(0, 0));
  d[0][0] = 0;
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    if (p.first == W - 1 && p.second == H - 1) break;

    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];

      if (0 <= nx && nx < W && 0 <= ny && ny < H && map[nx][ny] == '.' &&
          d[nx][ny] == INF) {
        q.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }

  if (d[W - 1][H - 1] == INF)
    cout << -1 << endl;
  else
    cout << whites - (d[W - 1][H - 1] + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
using namespace std;

int N, T, A;

int fitness(int x)
{
	return abs(1000*T - 6*x - 1000*A); 
}

int main(void)
{
	cin >> N >> T >> A;

	vector<int> H(N);
	for(int i=0; i<N; i++)
		cin >> H[i];

	int ret = -1;
	int mf = INT_MAX;
	for(int i=0; i<N; i++){
		int f = fitness(H[i]);

		if(f < mf){
			ret = i;
			mf = f;
		}
	}

	cout << ret + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll; 
 
using namespace std;
 
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i,n,k;
    ll t(0);
    cin>>n;
    ll arr[n]{0},sr[n+1]{0};
    for(i=0;i<n;i++){
        cin>>arr[i];
        sr[arr[i]]++;
    }
    for(i=1;i<=n;i++){
        t+=((sr[i]*(sr[i]-1))/2);
    }
    for(i=0;i<n;i++){
        cout<<t-sr[arr[i]]+1<<"\n";
    }


    



 
 
return 0;
} 

Measured memory_bytes: 5760
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
  int N;
  ll A,B,X[110000],dis,ans=0;
  cin>>N>>A>>B;

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

  for(int i=1;i<N;i++){
    dis=X[i]-X[i-1];
    ans+=min(A*dis,B);
  }
  cout<<ans<<endl;
}


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

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

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

int main(){
    
    int A;
    int B;
    int T;
    
    cin >> A;
    cin >> B;
    cin >> T;
    
    int remainder = T % A;
    
    cout << ( T - remainder ) * B / A << endl;
    
    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nl = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string[] s = new string[nl[0]];
            for (int i = 0; i < nl[0]; i++)
            {
                s[i] = Console.ReadLine();
            }
            Array.Sort(s);
            Console.WriteLine(String.Join("", s));
        }
    }
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
const int N=105;
ll a[N],val[N];
vi v[4],v2[4];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,c;
  cin>>n>>c;
  rep(i,1,n+1) cin>>a[i]>>val[i],v[a[i]-a[1]].pb(val[i]);
  rep(i,0,4) sort(all(v[i])),reverse(all(v[i]));
  rep(i,0,4)
    {
      v2[i].resize(sz(v[i])+1);
      v2[i][0]=0;
      rep(j,0,sz(v[i]))
	v2[i][j+1]=v2[i][j]+v[i][j];
    }
  int ans=0;
  rep(i,0,sz(v[0])+1)
    rep(j,0,sz(v[1])+1)
    rep(k,0,sz(v[2])+1)
    {
      ll done=(ll)(i+j+k)*a[1]+j+2*k;
      if(done>c) continue;
      int take=(c-done)/(a[1]+3);
      ans=max(ans,v2[0][i]+v2[1][j]+v2[2][k]+v2[3][take]);
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include<stdio.h>

int count(int n){
  if(n!=0){
    int sc;
    scanf("%d",&sc);
    return sc+count(n-1);
  }
  else{
    return 0;
  }
}

void doit(){
  int score=count(10);
  printf("%d\n",score);
}

int main(){
  doit();
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  bool ok = true;
  for(int i=0;i<S.length();i+=2){
    if(S[i]!='h' || S[i+1] != 'i')ok =false;
  }
  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input().ToInt();
		for(int i = 0; i < n; i++)
		{
			if(a[i] % 2 == 0 && !(a[i]%3 == 0 || a[i]%5==0))
			{
				Console.WriteLine("DENIED");
				return;
			}
		}
		Console.WriteLine("APPROVED");
		
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	 }
}

class HeapQueue<T> 
{
	private List<T> _buffer;
	private Comparison<T> _comparer;
	
	public HeapQueue()
	{
		_buffer = new List<T>();
	}
	
	public HeapQueue(int capacity, Comparison<T> comparer = null)
	{
		_buffer = new List<T>(capacity);

		_comparer = comparer;
	}
	
	public void Push(T el)
	{
		List<T> array = _buffer;
		int n = array.Count;
		array.Add(el);
		
		while (n != 0)
		{
			int i = (n - 1) / 2;
			if (Compare(array[n], array[i]) > 0)
			{
				T tmp = array[n]; array[n] = array[i]; array[i] = tmp;
			}
			n = i;
		}
	}
	
	public T Pop()
	{
		T el = _buffer[0];
		
		List<T> array = _buffer;
		
		int n = array.Count - 1;
		array[0] = array[n];
		array.RemoveAt(n);

		for (int i = 0, j; (j = 2 * i + 1) < n; )
		{
			if ((j != n - 1) && (Compare(array[j], array[j + 1]) < 0))
				j++;
			if (Compare(array[i], array[j]) < 0)
			{
				T tmp = array[j]; array[j] = array[i]; array[i] = tmp;
			}
			i = j;
		}
		return el;
	}
	
	public T Peep()
	{
		if(_buffer.Count <= 0)
			return default(T);

		return _buffer[0];
	}
	
	public bool Contains(T t)
	{
		return _buffer.Contains(t);
	}
	
	private int Compare(T left, T right)
	{
		return _comparer(left, right);
	}
	
	public int Count
	{
		get{ return _buffer.Count; }
	}
	
}


Measured memory_bytes: 13140
// Problem : A - November 30
// Contest : AtCoder - Sumitomo Mitsui Trust Bank Programming Contest 2019
// URL : https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m2 == m1+1) cout<<1<<endl;
    else cout<<0<<endl;
    
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
main :: IO ()
main = do
    l1 <- getLine
    let n = read l1
    l2 <- getLine
    let d = map read $ words l2 :: [Int]

    print $ sum $ map (f (*) d) [0..n - 1]

f g l i = sum $ map (g (l !! i)) (drop (i + 1) l)

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

const ll INF = 1LL << 60;

ll N, Q;
vector<ll> a, b, p, x;
vector<ll> g[500100];
vector<ll> ans;

map<ll, ll> mp;

void dfs(ll cur, ll par, ll score) {
    ans[cur] = score;
    for (ll i = 0; i < g[cur].size(); i++) {
        ll to = g[cur][i];
        if (to == par) continue;
        // if (to < cur) continue;

        dfs(to, cur, score + mp[to]);
    }
}

int main() {
    cin >> N >> Q;
    a.resize(N); 
    b.resize(N);
    rep(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    ans.resize(N);
    p.resize(Q);
    x.resize(Q);

    rep(i, Q) {
        cin >> p[i] >> x[i];
        p[i]--;
        mp[p[i]] += x[i];
    }

    dfs(0, -1, mp[0]);

    rep(i, N) {
        cout << ans[i] << endl;
    }
}


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

int main()
{
    int n;
    cin >> n;
    int p[10];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    int s[10];
    for(int i = 0; i < n; i++) s[i] = i;
    int a = 0;
    do{
        a++;
        bool f = true;
        for(int i = 0; i < n; i++){
            if(s[i] != p[i]) f = false;
        }
        if(f) break;
    }while(next_permutation(s, s + n));
    int q[10];
    for(int i = 0; i < n; i++){
        cin >> q[i];
        q[i]--;
    }
    for(int i = 0; i < n; i++) s[i] = i;
    int b = 0;
    do{
        b++;
        bool f = true;
        for(int i = 0; i < n; i++){
            if(s[i] != q[i]) f = false;
        }
        if(f) break;
    }while(next_permutation(s, s + n));
    cout << abs(a - b) << endl;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 1e9 + 7;

bool check(ll n, ll k) {
    while (n % k == 0) n /= k;
    return (n % k == 1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    int ans = 1;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        if (check(n, i)) ans++;
        if (i * i != n && check(n, n / i)) ans++;
    }
    if (n > 2) ans++;
    n--;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        if (i * i == n) ans++;
        else ans += 2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n';
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll h;
    cin >> h;
    ll c = 0;
    ll ans = 1;
    while (h > 1) {
        h /= 2;
        c++;
        ans += pow(2, c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
# coding: utf-8
import sys
input = sys.stdin.readline

MOD = int(1e9 + 7)

def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD)

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(f(n, m, s, t))


Measured memory_bytes: 159472
//abc166_d.cpp
//Sun May  3 20:54:16 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

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

	vector<ll> gojyo;
	unordered_map<ll,int> mp;
	for (ll i=0;i<=6208;i++){
		ll tmp = i*i*i*i*i;
		gojyo.push_back(tmp);
		mp[tmp] = i;
		mp[tmp*(-1)] = i*(-1);
//		tmp = -1*tmp;
//		gojyo.push_back(tmp);
	}

	sort(gojyo.begin(),gojyo.end());

	for (ll i=0;i<=gojyo.size();i++){
		ll tmp = gojyo[i]-x;
		int flag = 1;
		if (tmp<=0){
			tmp = tmp*(-1);
			flag = 0;
		}
		auto itr = lower_bound(gojyo.begin(),gojyo.end(),tmp);
		if (*itr == tmp){
			if (flag){
				cout << mp[gojyo[i]] << " " << mp[tmp] << endl;
			}else {
				cout << mp[gojyo[i]] << " " << mp[(-1)*tmp] << endl;
			}
			return 0;
		}

	}

}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, A, B, C; cin >> N >> A >> B >> C;
        vector<int> L(N); cin >> L;
        vector<int> ABC = {A, B, C};
        function<int(int, vector<int>&)> dfs = [&] (int now, vector<int> &choice) {
            int res = INF;
            if(now == N) {
                res = 0;
                vector<int> abc(3);
                rep(i, choice.size()) {
                    if(choice[i] < 3) {
                        res += abc[choice[i]] > 0 ? 10 : 0;
                        abc[choice[i]] += L[i];
                    }
                }
                rep(i, 3) if(abc[i] == 0 and ABC[i] > 0) return INF;
                rep(i, 3) res += abs(abc[i] - ABC[i]);
                return res;
            }
            rep(i, 4) {
                choice.push_back(i);
                set_min(res, dfs(now + 1, choice));
                choice.pop_back();
            }
            return res;
        };
        vector<int> tmp;
        cout << dfs(0, tmp) << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

bool check(string s) {
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != s[s.length() - i - 1]) {
      return false;
    }
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  string sub1 = S.substr(0, (S.length() - 1) / 2);
  string sub2 = S.substr((S.length() + 3) / 2 - 1,
                         S.length() - ((S.length() + 3) / 2) + 1);
  string ans = "No";
  if (check(S) && check(sub1) && check(sub2)) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize
    };

    let mut switch_v: Vec<Vec<usize>> = Vec::new();

    for _ in 0..m {
        input! {
            k: usize,
            s: [usize; k]
        };
        let s: Vec<usize> = s;

        switch_v.push(s.iter().map(|&x| x - 1).collect());
    }

    input! {p: [usize; m]};
    let p: Vec<usize> = p;
    let mut result = 0;

    for i in 0..(1 << n) {
        let mut flag = true;
        for (switches, p_i) in switch_v.iter().zip(p.iter()) {
            let mut count = 0;
            for switch in switches.iter() {
                if (i >> switch) & 1 == 1 {
                    count += 1;
                }
            }
            if count % 2 != *p_i {
                flag = false;
                break;
            }
        }

        if flag {
            result += 1;
        }
    }

    println!("{}", result);
}


Measured memory_bytes: 2212
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  rep(i, n) {
    int numx, numy, numa;
    cin >> numx >> numy >> numa;
    x.at(i) = numx;
    y.at(i) = numy;
    a.at(i) = numa;
  }
  vector<vector<int>> data(h, vector<int>(w, 1));
  rep(i, n) {
    if (a.at(i) == 1) {
      rep(j, x.at(i)) {
        rep(k, h) {
          data.at(k).at(j) = 0;
        }
      }
    }
    if (a.at(i) == 2) {
      for (int j = x.at(i); j < w; j++) {
        rep(k, h) {
          data.at(k).at(j) = 0;
        }
      }
    }
    if (a.at(i) == 3) {
      rep(j, y.at(i)) {
        rep(k, w) {
          data.at(j).at(k) = 0;
        }
      }
    }
    if (a.at(i) == 4) {
      for (int j = y.at(i); j < h; j++) {
        rep(k, w) {
          data.at(j).at(k) = 0;
        }
      }
    }
  }
  int count = 0;
  rep(i, h) {
    rep(j, w) {
      //cout << data.at(i).at(j);
      if (data.at(i).at(j) == 1) {
        count++;
      }
    //cout << endl;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3504
/*
  AOJ 2589
  Title:North West
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
char s[101];

main()
{
  int i,ret1,ret2,len,f;
  char c;
  while(scanf("%s",s) && s[0] != '#')
  {
    ret1=0;
    ret2=1;
    len=strlen(s);
    for(i=len-1,f=0;i>=0;i--)
      {
	c=s[i];
	
	if(c=='n' || c=='w')
	  {
	    if(c=='w')
	      ret1++;
	    else if(f==1)
	      ret1--;
	    f=1;
	    ret2 <<=1;
	    ret1 <<=1;
	  }
      }
    ret1*=45;
    ret2>>=1;

    if((ret1 & 1)==0 && ret2 >1)
      ret1/=2,ret2/=2;

    if(ret2>1)
      printf("%d/%d\n",ret1,ret2);
    else
      printf("%d\n",ret1/ret2);
  }
  return(0);
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int n;
int arr[4] = {0};

double dp[305][305][305];


double expect(int a, int b, int c, int tab){
    double s = a+b+c;
    if(s == 0) return 0;

    if(dp[a][b][c] == -1){
        dp[a][b][c] = (double)n/s;
        if(a > 0) dp[a][b][c] += ((double)a/s)*expect(a-1, b, c, tab+1);
        if(b > 0) dp[a][b][c] += ((double)b/s)*expect(a+1, b-1, c, tab+1);
        if(c > 0) dp[a][b][c] += ((double)c/s)*expect(a, b+1, c-1, tab+1);
    }
    return dp[a][b][c];
}


int32_t main(){
    cin >> n;
    int temp;
    for(int i = 0; i < 305; i++)
        for(int j = 0; j < 305; j++)
            for(int k = 0; k < 305; k++)
                dp[i][j][k] = -1;

    loop(n) {
        cin >> temp;
        arr[temp]++;
    }
    cout << setprecision(12);
    cout << expect(arr[1], arr[2], arr[3], 0) << endl;
}

Measured memory_bytes: 225468
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>
 
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
 
const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;
 
/** Problem2000 : Misterious Gems **/
int main()
{
    P now;
    map<P, bool> gems;
    int N, M, got;
     
    while (cin>>N, N) {
        now = P(10, 10);
        got=0;
        gems.clear();
        rep(i, N) {
            int x, y;
            cin >> x >> y;
            gems[P(x, y)] = true;
        }
        cin >> M;
        rep(i, M) {
            char d; int a, dx=0, dy=0;
            cin >> d >> a;
            switch (d) {
                case 'N': dy=1; break;
                case 'E': dx=1; break;
                case 'S': dy=-1; break;
                case 'W': dx=-1; break;
            }
            rep(j, a) {
                now.first += dx;
                now.second += dy;
                 
                if (gems[P(now.first, now.second)]) {
                    got++;
                    gems[P(now.first, now.second)] = false;
                }
            }
        }
        if (got==N)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
map<lli, lli> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli N;
    cin >> N;
    REP(i, N)
    {
        lli p;
        cin >> p;
        v[p]++;
    }
    if (v.size() == 1 && v.begin()->first == 0)
    {
        cout << "Yes" << endl;
    }
    else if (v.size() == 3 && N % 3 == 0)
    {
        bool flg = true;
        vector<lli> x;
        for (auto itr = v.begin(); itr != v.end(); ++itr)
        {
            //     cout << itr->first << " " << itr->second << endl;
            if (itr->second != N / 3)
            {
                flg = false;
                //break;
            }
            x.push_back(itr->first);
        }
        //        cout << (2 ^ 7) << endl;
        if (flg && !(((x[0] ^ x[1]) == x[2]) && ((x[1] ^ x[2]) == x[0]) && ((x[2] ^ x[0]) == x[1])))
        {
            flg = false;
        }
        if (flg)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else if (v.size() == 2 && N % 3 == 0)
    {
        vector<pair<lli, lli>> x;
        for (auto itr = v.begin(); itr != v.end(); ++itr)
        {
            x.emplace_back(itr->first, itr->second);
        }
        if (x[0].first == 0 && x[0].second == N / 3)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int F(long long a, long long b){
    int cnta = 0;
    int cntb = 0;
    while(a>0){
        cnta++;
        a/=10;
    }

    while(b>0){
        cntb++;
        b/=10;
    }

    return max(cnta, cntb);

}

int main()
{
    long long N;
    cin >>N;

    int minval = INT_MAX;
    for (long long i = 1; i*i<= N; i++){
        if(N%i==0){
            long long b = N/i;
            int val = F(i, b);
            //cout << i<< " " << b << " "  << val<< endl;
            minval = min(minval, val);
        }
    }

    cout << minval << endl;


   return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b, q;
  cin >> a >> b >> q;
  vector<long long> s(a), t(b);
  for (int i = 0; i < a; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> t[i];
  }
  while (q--) {
    long long x;
    cin >> x;
    long long slo = LLONG_MAX / 2, shi = LLONG_MAX / 2;
    long long tlo = LLONG_MAX / 2, thi = LLONG_MAX / 2;
    auto sx = lower_bound(s.begin(), s.end(), x);
    if (sx == s.begin()) shi = *sx;
    else if (sx == s.end()) slo = *--sx;
    else shi = *sx, sx--, slo = *sx;
    auto tx = lower_bound(t.begin(), t.end(), x);
    if (tx == t.begin()) thi = *tx;
    else if (tx == t.end()) tlo = *--tx;
    else thi = *tx, tx--, tlo = *tx;
    long long ans = LLONG_MAX;
    ans = min(ans, abs(min(shi, thi) - x) + abs(shi - thi));
    ans = min(ans, abs(x - max(slo, tlo)) + abs(slo - tlo));
    ans = min(ans, abs(x - slo) + abs(thi - slo));
    ans = min(ans, abs(thi - x) + abs(thi - slo));
    ans = min(ans, abs(shi - x) + abs(shi - tlo));
    ans = min(ans, abs(x - tlo) + abs(shi - tlo));
    cout << ans << endl;
  }
	return 0;	 
}

Measured memory_bytes: 2944