akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 dy[]={0, 0, 1, -1};                                 // 4方向近傍
int dx[]={1, -1, 0, 0};                                 // 4方向近傍


/*
   upll : (a<b)なら-1, (a=b)なら0, (a>b)なら1
 downll : (a<b)なら1, (a=b)なら0, (a>b)なら-1

 const void* a : 型を縛らずにconstをつける(=変数aが読み込み専用の変数であることを明示する)
        (ll*)a : 変数aがconst long long *型であると明示する
*/
// int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
// int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
// void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
// void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

int main(){
    ll n;
    cin >> n;
    rep(i,1,10){
        rep(j,1,10){
            if(n == i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int dp[5001][5001],a[5001],n,ans=2;
unordered_map<int,int>M;

int main(){
  cin>>n;
  r(i,n)cin>>a[i];
  sort(a,a+n);
  r(i,n)M[a[i]]=i;

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

      dp[i][j] = max( dp[i][j] , 2 );
      ans = max( ans , dp[i][j] );
      int nex = a[j]+(a[j]-a[i]);

      if(M.count(nex)){
        int idx = M[nex];
        dp[j][idx] = max( dp[j][idx] , dp[i][j]+1 );
      }
    }
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 70156
#include <iostream>
#define N1 35
using namespace std;
void Dice(int,int,int,int);
pair<int,int> data[N1][N1];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int dice[6][4]={{2,3,5,4},{1,4,6,3},{1,2,6,5},{1,5,6,2},{1,3,6,4},{2,4,5,3}};
int main(){
  int n,t,f,d,i,j,cnt[6];
  d=N1/2;
  while(1){
    for(i=0;i<N1;i++){
      for(j=0;j<N1;j++){
	data[i][j].first=data[i][j].second=0;
      }
    }
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> t >> f;
      Dice(t,f,d,d);
    }
    for(i=0;i<6;i++) cnt[i]=0;
    for(i=0;i<N1;i++){
      for(j=0;j<N1;j++){
	if(data[i][j].first!=0) cnt[data[i][j].first-1]++;
      }
    }
    for(i=0;i<6;i++){
      if(i!=5) cout << cnt[i] << ' ';
      else cout << cnt[i];
    }
    cout << endl;
  }
}
void Dice(int t,int f,int y,int x){
  int s,max=3,a,r;
  for(int i=0;i<4;i++){
    if(dice[t-1][i]==f) s=i;
  }
  for(int i=0;i<4;i++){
    if(max<dice[t-1][(s+i)%4]&&data[y][x].second>data[y+dy[i]][x+dx[i]].second){
      max=dice[t-1][(s+i)%4];
      r=i;
    }
  }
  if(max!=3){
    if(r==1||r==3) a=f;
    else if(r==2) a=7-t;
    else a=t;
    Dice(7-max,a,y+dy[r],x+dx[r]);
  }else{
    data[y][x].first=t;
    data[y][x].second++;
  }
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s;
  cin >> s;

  int ans = 0;
  if(s == "hi") ans = 1;
  if(s == "hihi") ans = 1;
  if(s == "hihihi") ans = 1;
  if(s == "hihihihi") ans = 1;
  if(s == "hihihihihi") ans = 1;
  if(s == "hihihihihihi") ans = 1;
  if(s == "hihihihihihihi") ans = 1;
  if(s == "hihihihihihihihi") ans = 1;

  if(ans) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        l: [(i32, i32); n],
    }

    let num = l.iter().fold(0, |sum, &(a,  b)| sum + (b - a + 1));

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



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define vi vector<int>
#define Vi vector<vector<int>>
#define ll long long
#define P pair<int,int>
#define vp  vector<P>
#define mod 1000000009
using namespace std;
int main(){
	string S;
	cin>>S;
	if((S[0]=='A' || S[1]=='A' || S[2]=='A') && (S[0]=='B' || S[1]=='B' || S[2]=='B'))
		cout<<"Yes\n";
	else
		cout<<"No\n"; 
	return 0;
}

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

int x, n;

int main() {
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  rep (i, n) {
    cin >> p[i];
  }
  rep (i, 55) {
    bool is_included = false;
    rep (j, n) {
      if (p[j] == x - i) is_included = true;
    }
    if (!is_included) {
      cout << x - i << endl;
      return 0;
    }
    is_included = false;
    rep (j, n) {
      if (p[j] == x + i) is_included = true;
    }
    if (!is_included) {
      cout << x + i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#define N 3030
using namespace std;

int matrice[N][N];char nr[N];
char a[N],b[N];
int main()
{
    int n,j,i,m;
    string x,y;
    cin >> x >> y;
    n = x.size();
    m = y.size();
    for(i = 1;i <= n;i++){
        a[i] = x[i - 1];
    }
    for(i = 1;i <= m;i++){
       b[i] = y[i - 1];
    }
    for(i = 1;i <= n;i++){
        for(j = 1;j <= m;j++){
            if(a[i] == b[j]){
                matrice[i][j] = matrice[i-1][j-1] + 1;
            }else{
                matrice[i][j] = max(matrice[i-1][j],matrice[i][j-1]);
            }
        }
    }
    i = n;
    j = m;
    int varf = 0;
    while(i > 0 &&  j > 0){
        if(a[i] == b[j])
        {
            nr[++varf] = a[i];
            i--;
            j--;
        }else if(matrice[i][j] == matrice[i-1][j])
        {
            i--;
        }else{
            j--;
        }
    }
    for(i = varf;i > 0;i--){
        cout << nr[i];
    }
    return 0;
}


Measured memory_bytes: 35840
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_COL_CNT		2										// 列数
#define D_CANDLE_MAX	100000									// 最大ろうそく数

// 内部変数
static FILE *szpFpI;											// 入力
static int si2Candle[D_COL_CNT][D_CANDLE_MAX];					// ろうそく
static int si1CCnt[D_COL_CNT];									// ろうそく数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// ソート関数 - int昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// 昇順
	if (*lipVal1 > *lipVal2) {
		return(1);
	}
	else if (*lipVal1 < *lipVal2) {
		return(-1);
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化
	memset(si1CCnt, 0, sizeof(si1CCnt));						// ろうそく数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// ろうそく数・着火数 - 取得
	int liCCnt, liFCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &liCCnt, &liFCnt);

	// ろうそく - 取得
	int liVal;
	for (i = 0; i < liCCnt; i++) {
		fscanf(szpFpI, "%d", &liVal);

		if (liVal > 0) {								// １列目に追加
			si2Candle[0][si1CCnt[0]] = liVal;
			si1CCnt[0]++;
		}
		else if (liVal < 0) {							// ２列目に追加
			si2Candle[1][si1CCnt[1]] = -liVal;
			si1CCnt[1]++;
		}
		else {											// 着火数デクリメント
			liFCnt--;
		}
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// ２列目 - ソート
	if (si1CCnt[1] > 1) {
		qsort(si2Candle[1], si1CCnt[1], sizeof(int), fSortFnc);
	}

	// １列目の最大着火数
	int liCnt1;
	if (liFCnt < si1CCnt[0]) {
		liCnt1 = liFCnt;
	}
	else {
		liCnt1 = si1CCnt[0];
	}

	// 最小時間 - 算出
	int liMin = INT_MAX;
	for (i = liCnt1; i >= 0; i--) {

		// １列目の着火数
		int liVal1 = 0;
		if (i > 0) {
			liVal1 = si2Candle[0][i - 1];
		}

		// ２列目の着火数
		int liCnt2 = liFCnt - i;
		if (liCnt2 > si1CCnt[1]) {
			break;
		}
		int liVal2 = 0;
		if (liCnt2 > 0) {
			liVal2 = si2Candle[1][liCnt2 - 1];
		}

		// 短い距離を往復
		if (liVal1 < liVal2) {
			liVal1 *= 2;
		}
		else {
			liVal2 *= 2;
		}

		// 合計
		int liSum = liVal1 + liVal2;

		// 最小時間 - 更新
		if (liMin > liSum) {
			liMin = liSum;
		}
	}

	// 結果 - セット
	sprintf(lc1Out, "%d\n", liMin);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

int main(){
  int n,m;
  cin >> n >> m;
  int h[n+1];
  for(int i=1; i<=n; i++){
    cin >> h[i];
  }
  int a,b;
  int good[n];
  for(int i=1; i<=n; i++){
    good[i] = 0;
  }
  for(int j=0; j<m; j++){
    cin >> a >> b;
    if(h[a] >= h[b])good[b]++;
    if(h[a] <= h[b])good[a]++;
  }
  int ans=0;
  for(int i=1; i<=n; i++){
    if(good[i] == 0)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[1<<10][1<<10];
signed main(){
  Int n;
  while(cin>>n,n){
    string s;
    cin>>s;
    memset(dp,0,sizeof(dp));
    vector<vector<Int> > sp(1<<10);
    dp[0][0]=1;
    sp[0].emplace_back(0);
    bool flg=0;
    for(Int i=0;i<n;i++){
      if(s[i]=='u') continue;
      Int b=0;
      while(s[i+1]!='u'){
	b|=1<<(s[i]-'0');
	Int ne=1<<(s[i+1]-'0');
	if(b&ne) flg=1;
	if(flg) break;
	for(Int x=(1<<10)-1;x>=0;x--){
	  if(x&b) continue;
	  if(sp[x].empty()) continue;
	  
	  //using BS = bitset<10>;
	  
	  for(Int y:sp[x]){
	    //cout<<BS(x)<<" "<<BS(y)<<":"<<BS(b)<<" "<<BS(ne)<<endl;
	    //if((x&ne)&&((y|b)==b)) cout<<x<<" "<<y<<endl;
	    
	    if((x&ne)&&((y|b)==b)) flg=1;
	    int nx=x|b,ny=y|ne;
	    if((y&b)==b) ny^=b;
	    if(!dp[nx][ny]){
	      dp[nx][ny]=1;
	      sp[nx].emplace_back(ny);
	    }
	    if(flg) break;
	  }
	  if(flg) break;
	}
	i++;
      }
      Int ne=1<<(s[i]-'0');
      if(b&ne) flg=1;
      if(flg) break;
    }
    cout<<(flg?"UNSAFE":"SAFE")<<endl;
  }
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T>
struct SegmentTree {
  using F = function<T(T, T)>;
  vector<T> v;
  F f;
  T e;
  int n;
  SegmentTree(int size, F f, T e) : f(f), e(e) {
    n = 1;
    while (n < size) n <<= 1;
    v.resize(n * 2, e);
  }
  void set(int k, T x) {
    v[k + n] = x;
  }
  void build() {
    for (int i = n - 1; i > 0; i--) {
      v[i] = f(v[i * 2 + 0], v[i * 2 + 1]);
    }
  }
  void update(int k, T x) {
    v[k += n] = x;
    while (k >>= 1) v[k] = f(v[k * 2 + 0], v[k * 2 + 1]);
  }
  T query(int a, int b) {
    T l = e, r = e;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) l = f(l, v[a++]);
      if (b & 1) r = f(v[--b], r);
    }
    return f(l, r);
  }
};

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  SegmentTree<int> st(n, [](int a, int b) { return (int) gcd(a, b); }, 0);
  rep(i, n) st.set(i, a[i]);
  st.build();
  int ans = 0;
  rep(i, n) {
    int a = st.query(0, i);
    int b = st.query(i + 1, n);
    amax(ans, (int) gcd(a, b));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1664
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]
cond t f c = if c then t else f

gcdlcm [a, b] = [gcd, lcm] <*> [a] <*> [b]

main = map (map read . words) . lines <$> getContents >>= mapM_ (putStrLn . unwords . map show . gcdlcm)

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

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

double n , mx;

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  cin >> n >> mx;
  double x , y;
  int cnt = 0;
  for(int i = 0 ; i < n ; ++i){
    cin >> x >> y;
    double ans = sqrt((x*x) + (y*y));
    if(ans <= mx)
      cnt++;
  }
  cout << cnt << "\n";


  return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;

struct much
{
    int x,v;
};

vector <much> G[100001];
int f[100001],d[100001];

void dfs(int i,int k)
{
    f[i]=1;
    d[i]=k;
    for(auto it : G[i])
        if(!f[it.x])
            dfs(it.x,k+it.v);
}

int main()
{
    int i,n,x,y,u;
    scanf("%d",&n);
    for(i=1; i<n; i++)
    {
        scanf("%d%d%d",&x,&y,&u);
        G[x].push_back({y,u%2});
        G[y].push_back({x,u%2});
    }
    dfs(1,0);
    for(i=1; i<=n; i++)
    printf("%d\n",d[i]%2);

    return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q; cin >> n >> q;
    string s; cin >> s;
    vector<int> l(q),r(q);
    for(int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
    }
    vector<int> cnt(n+1);
    int tmp = 0;
    cnt[0] = 0;
    for(int i = 0; i < n - 1; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'C')
        {
            tmp++;
        }
        cnt[i+1] = tmp;
    }
    cnt[n] = tmp;
    for(int i = 0; i < q; i++)
    {
        cout << cnt[r[i]-1] - cnt[l[i]-1] << endl;
    }
}

Measured memory_bytes: 2176
# ABC100D - Patisserie ABC
from itertools import product


def calc(func: "func") -> int:
    cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)]
    cakes.sort(reverse=1)
    return max(sum(cakes[:M]), -sum(cakes[-M:]))


def main():
    global M, XYZ
    N, M, *XYZ = map(int, open(0).read().split())
    if M == 0:
        print(0)
        return
    ans = 0
    for sign1, sign2 in product(("+", "-"), repeat=2):
        func = lambda x, y, z: eval("x {} y {} z".format(sign1, sign2))
        ans = max(ans, calc(func))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  int n,m;cin>>n>>m;
  int kekka[m];
  for(int i = 0; m > i; i++)kekka[i] = 0;
  rep(i,n){
    int leng;cin>>leng;
    rep(j,leng){
      int tmp;cin>>tmp;tmp-=1;
      kekka[tmp]++;
    }
  }
  int ret = 0;
  rep(i,m){
    if(kekka[i] == n)ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
XY=[tuple(map(int, input().split()))for _ in range(M)]
C=[1]*N
R=[False]*N
R[0]=True
for x,y in XY:
    x-=1
    y-=1
    if R[x]:
        R[y]=True
        if C[x]==1:
            R[x]=False
    C[x]-=1
    C[y]+=1
print(sum(R))

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

using namespace std;

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

  long long x, y, a, b, c; cin >> x >> y >> a >> b >> c;
  priority_queue<pair<long long, long long> > events;
  for(long long i = 0; i<a; ++i) {
    long long val; cin >> val;
    events.push(make_pair(val, 0));
  }
  for(long long i = 0; i<b; ++i) {
    long long val; cin >> val;
    events.push(make_pair(val, 1));
  }
  for(long long i = 0; i<c; ++i) {
    long long val; cin >> val;
    events.push(make_pair(val, 2));
  }
  long long ret = 0;
  long long taken = 0;
  long long r = 0, g = 0;
  while(taken < x+y) {
    pair<long long, long long> curr = events.top(); events.pop();
    if(curr.second == 2) {
      taken++;
      ret += curr.first;
    }
    if(curr.second == 1) {
      if(g < y) {
        taken++;
        ret += curr.first;
        g++;
      }
    }
    if(curr.second == 0) {
      if(r < x) {
        taken++;
        ret += curr.first;
        r++;
      }
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 10476
import math

def cmb(n, r):
  if r == 0: return 1
  if r == 1: return n
  if n < r: return 0
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k = map(int,input().split())
blue = k
red = n-k

print(red+1)
for i in range(2,blue+1):
  print((cmb(red+1,i)%(10**9+7)) * (cmb(blue-1,i-1)%(10**9+7))% (10**9+7))


Measured memory_bytes: 70616
import sys
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def size(self, x):
        return -self.root[self.find_root(x)]


def main():
    N = int(input())
    x_list = []
    y_list = []
    x_app = x_list.append
    y_app = y_list.append
    for i in range(N):
        x, y = map(int, input().split())
        x_app([x, i])
        y_app([y, i])

    x_list.sort()
    y_list.sort()
    adj = []
    adj_app = adj.append
    for i in range(N-1):
        adj_app([x_list[i + 1][0] - x_list[i][0], x_list[i + 1][1], x_list[i][1]])
        adj_app([y_list[i + 1][0] - y_list[i][0], y_list[i + 1][1], y_list[i][1]])

    adj.sort(key=lambda x: x[0])
    uf = UnionFind(N)
    ans = 0
    for edge in adj:
        if not uf.isSameGroup(edge[1], edge[2]):
            ans += edge[0]
            uf.unite(edge[1], edge[2])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 136028
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

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

void solve_A(){
    int n;
    cin >> n;
    if(n%2 == 0) cout << n/2;
    else cout << n/2 + 1;
}

int main(void){
    solve_A();
    
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
        G[a - 1].append((i, b - 1))
        G[b - 1].append((i, a - 1))

    queue = deque([0])
    seen = [False] * N
    seen[0] = True
    color = [0] * (N - 1)
    color_parent = [-1] * N

    while queue:
        v = queue.popleft()
        c = 1
        for i, nv in G[v]:
            if seen[nv]:
                continue
            if c == color_parent[v]:
                c += 1
            color_parent[nv] = c
            color[i] = c
            queue.append(nv)
            seen[nv] = True
            c += 1

    print(max(color))
    print(*color, sep='\n')
    return


if __name__ == '__main__':
    main()


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

int N;
int D[110];
int G[110][110];
int F[110];
int t = 1;
void dfs(int cur){
	D[cur] = t;
	t++;
	for(int i=0;i<N;i++){
		if(G[cur][i] && D[i]==0){
			dfs(i);
		}
	}
	F[cur] = t;
	t++;
}


int main(){
	while(cin >> N && N>0){
		vector<vector<int> > g(110,vector<int>(110,0));
		int u,k;
		for(int i=0;i<N;i++){
			cin >> u >> k;
			for(int j=0;j<k;j++){
				int a;
				cin >> a;
				g[u-1].push_back(a); 
			}
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<g[i].size();j++){
				int f = g[i][j];
				G[i][f-1] = 1;
			}
		}
		dfs(0);
		for(int i=0;i<N;i++){
			if(D[i]==0){
				dfs(i);
			}
		}
		for(int i=0;i<N;i++){
			cout << i+1 << " " << D[i]  << " " << F[i] << endl;
		}
	}
}



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

int main() {
  int S;
  cin >> S;
  int s = S % 60;
  S /= 60;
  int m = S % 60;
  S /= 60;
  int h = S % 60;
  cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const ll mod = 1e9+7;
const ll nax = 1e3+7;
const ll INF = 1e18;

ll dp[nax][nax],n,m;
char a[nax][nax];

int main(){
//	freopen("input.inp","r",stdin);
//	freopen("output.out","w",stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>n>>m;
	
	for (ll i=1;i<=n;++i){
		for (ll j=1;j<=m;++j) cin>>a[i][j];
	}
	
	dp[1][1]=1;
	
	for (ll i=1;i<=n;++i){
		for (ll j=1;j<=m;++j){
			if (a[i][j]=='#'||(i==1&&j==1)) continue;
			
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	
	cout<<dp[n][m]<<"\n";
}

Measured memory_bytes: 12468
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,A,B=pin()
    C=A+B
    n=N%C
    m=N//C
    ans=A*m
    if n<=A:
        ans+=n
    else:
        ans+=A
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 38384
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fromIntegral . fst . fromJust . BS.readInteger

getInt = readInt <$> BS.getLine

play :: Int -> Int -> Int
play 1 k = k
play h k = k + play (h `div` 2) (2 * k)

main = do
  h <- getInt
  print $ play h 1

Measured memory_bytes: 380
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;

            var YP = new Dictionary<int,int>();
            for(var i=0; i<M; i++)
            {
                var P = cin.ReadInt;
                var Y = cin.ReadInt;
                YP.Add(Y, P);
            }

            var sortedYP = YP.OrderBy((x) => x.Key);
            var cityCnt = new int[N];
            var YcityCnt = new Dictionary<int, int>();
            foreach (var tmp in sortedYP)
            {
                YcityCnt[tmp.Key] = ++cityCnt[tmp.Value-1];
            }

            foreach(var tmp in YP)
            {
                WriteLine("{0:d6}{1:d6}", tmp.Value, YcityCnt[tmp.Key]);
            }
        }

        static long GcdArray(long[] array)
        {
            var ans = array[0];
            for(var i=1; i<array.Length; i++)
            {
                ans = Gcd(ans, array[i]);
            }
            return ans;
        }

        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];
        }

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int A,B;
  cin >> A >> B;
  if(A == 1) A=20;
  if(B == 1) B=20;

  cout << ((A>B) ? "Alice" : ((A<B) ?"Bob":"Draw")) << endl;
	return 0;
}


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

int main (void)
{
    int n,m,ok = 0;
    int i,j;
    long long d[250000] = {0},t[250000] = {0};
    int cheek[250000] = {0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&d[i]);
    }
    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%lld",&t[i]);
    }

    sort(d,d+n);
    sort(t,t+m);

    for(i=0;i<m;i++){
        while(1){
            if(d[j] == t[i] && cheek[j] == 0){
                cheek[j]++;
                //printf("%lld\n",d[j]);
                break;
            }
            if(j == n-1){
                ok++;
                break;
            }
            j++;
        }
        if(ok != 0){
            break;
        }
    }
    if(ok == 0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }


    return 0;
    
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	int i;
	cin>>n;
	m=1;
	for(i=1;i<=n;++i)
	 {
	 	m=m*i%1000000007;
	 }
    cout<<m<<endl;
	return 0;	 
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          String O = sc.nextLine();
          String E = sc.nextLine();
          for (int i = 0; i < O.length() + E.length() ; i++) {
            if (i % 2 == 0) System.out.print(O.charAt(i/2));
              else System.out.print(E.charAt(i/2));
          }
     }
}

Measured memory_bytes: 23508
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int res[8];
double r[8];

void f(double t,int n){
	if(t<r[6]){
		r[7]=r[6];
		res[7]=res[6];
		r[6]=t;
		res[6]=n;
	}else if(t<r[7]){
		r[7]=t;
		res[7]=n;
	}
}

int main() {
	int num;
	double time;
	int i;
	for(i=0;i<8;i++)r[i]=1000000;
	for(i=0;i<8;i++){
		cin>>num>>time;
		if(time<r[0]){
			f(r[1],res[1]);
			r[1]=r[0];
			res[1]=res[0];
			r[0]=time;
			res[0]=num;
		}else if(time<r[1]){
			f(r[1],res[1]);
			r[1]=time;
			res[1]=num;
		}else{
			f(time,num);
		}
//for(int j=0;j<8;j++)cout<<res[j]<<" "<<r[j]<<endl;
	}
	for(i=0;i<8;i++){
		cin>>num>>time;
		if(time<r[2]){
			f(r[3],res[3]);
			r[3]=r[2];
			res[3]=res[2];
			r[2]=time;
			res[2]=num;
		}else if(time<r[3]){
			f(r[3],res[3]);
			r[3]=time;
			res[3]=num;
		}else{
			f(time,num);
		}
//for(int j=0;j<8;j++)cout<<res[j]<<" "<<r[j]<<endl;
	}
	for(i=0;i<8;i++){
		cin>>num>>time;
		if(time<r[4]){
			f(r[5],res[5]);
			r[5]=r[4];
			res[5]=res[4];
			r[4]=time;
			res[4]=num;
		}else if(time<r[5]){
			f(r[5],res[5]);
			r[5]=time;
			res[5]=num;
		}else{
			f(time,num);
		}
//for(int j=0;j<8;j++)cout<<res[j]<<" "<<r[j]<<endl;
	}
	for(i=0;i<8;i++){
		printf("%d %2.2f\n",res[i],r[i]);
	}
	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (h % 2 == 0 || w % 2 == 0) {
        cout << h * w / 2 << endl;
    } else {
        cout << h * w / 2 + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3596
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i) 
const int N = 2e5 + 5, M = N , mo = 1e9 + 7 ;
const ll inf = 1e17 ;
using namespace std ;

struct poi {
    int l, r, ans ;
} a[N], b[N] ;
multiset <int> S ;
int n, bit[N] ;

bool cmpl(poi a, poi b) {
    return a.l < b.l ;
}

bool cmpr(poi a, poi b) {
    return a.r < b.r ;
}

int solve() {
    rep(i, 0, M - 5) bit[i] = 0 ;
    rep(i, 1, n) ++ bit[a[i].l], -- bit[a[i].r] ;
    rep(i, 1, M - 5) bit[i] += bit[i - 1] ;
    int res = 0 ;
    rep(i, 0, M - 5) res = max(res, bit[i]) ;
    return res ;
}

void put(int x) {
    for ( ; x <= M - 5 ; x += x & (- x)) bit[x] ++ ;
}

int get(int x) {
    int res = 0 ;
    for ( ; x ; x -= x & (- x)) res += bit[x] ;
    return res ;
}

int l[N],r[N];

int SOLVE() {
	for (int i=1;i<=n;i++) {
		l[a[i].l]++; r[a[i].r]++;
	}
	for (int i=1;i<=200000;i++) l[i]+=l[i-1],r[i]+=r[i-1];
    int res = 0 ;
	rep(i,1,n) res=max(res,l[a[i].r-1]-r[a[i].l]);
    return res ;
}

int main() {
    scanf("%d", &n) ;
    rep(i, 1, n) scanf("%d%d", &a[i].l, &a[i].r) ;
    int r=solve();
    printf("%d %d\n", SOLVE(), r) ;
    return 0 ;
}


Measured memory_bytes: 7884
object Main {
  def main(args: Array[String]): Unit = {
    val score = scala.io.StdIn.readInt
    var rate  = 0
    if( 400 <= score && score < 600 )         rate = 8
    else if( 600 <= score && score < 800 )    rate = 7
    else if( 800 <= score && score < 1000 )   rate = 6
    else if( 1000 <= score && score < 1200 )  rate = 5
    else if( 1200 <= score && score < 1400 )  rate = 4
    else if( 1400 <= score && score < 1600 )  rate = 3
    else if( 1600 <= score && score < 1800 )  rate = 2
    else if( 1800 <= score && score < 2000 )  rate = 1

    println( rate )
  }
}

Measured memory_bytes: 54608
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 51;

int a[102];

int main(){
  int N; cin >> N;
  rep(i,N) cin >> a[i];
  sort(a,a+N);
  reverse(a,a+N);
  int ans = 0;
  rep(i,N){
    if(i%2==0) ans += a[i];
    else ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> b(N,K-Q);
  vector<int> A(Q);
  for (int i=0;i<Q;i++){
  cin >> A.at(i);
  b.at(A.at(i)-1)++;
  }
  for (int i=0;i<N;i++){
  if (b.at(i)>0){
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
  }
  
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int
typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  itn n;
  cin >> n;
  vector<int> v(n, 0);
  map<int, int> mp;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    mp[v[i]]++;
    mp[v[i]+1]++;
    mp[v[i]-1]++;
  }

  int maxv = -1;
  int res = -1;
  for(auto a : mp)
  {
    if (a.second >= maxv)
    {
      maxv = a.second;
      res = a.first;
    }
  }
  cout << maxv << endl;

}

Measured memory_bytes: 5120
# 最短距離を全白マス数から引く

import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
grid = [None] * H
white = 0
for i in range(H):
  grid[i] = readline().rstrip()
  white += grid[i].count(".")

from collections import deque
q = deque()
# y,x,距離
q.append([0,0,1])
visited = set()
cases = ((0,1),(0,-1),(1,0),(-1,0))
while q:
  y,x,dist = q.popleft()
  if grid[y][x] == "#":
    continue
  if (y,x) in visited:
    continue
  visited.add((y,x))
  if y == H - 1 and x == W - 1:
    print(white - dist)
    break
  for c in cases:
    if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
      q.append([y + c[0],x + c[1],dist + 1])
else:
  print(-1)

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

int main() {
  int N;
  int K;
  cin >> N >> K;
  double a=0;
  for(int i=1;i<=N;i++){
    double b = 1.0/N;
    int score = i;
    while(score<K){
      score*=2;
      b/=2;
    }
    a+=b;
  }
  printf("%.12f\n",a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

bool solve(){
    int h;
    cin>>h;
    if(h==0)return true;
    int grid[h+1][5]={};
    for(int i=0;i<h;i++){
        for(int j=0;j<5;j++){
            cin>>grid[i+1][j];
        }
    }
    int ans=0;
    bool update=true;
    while(update){
        int fall[h+1][5]={};
        update=false;
        for(int i=1;i<=h;i++){
            int left=17320508,right=-141421356;
            for(int le=0;le<5;le++){
                int val=grid[i][le];
                for(int ri=le+2;ri<5;ri++){
                    bool flag=true;
                    for(int j=le;j<=ri;j++){
                        if(val!=grid[i][j]||grid[i][j]==0)flag=false;
                    }
                    if(flag){
                        left=min(left,le);
                        right=max(right,ri);
                    }
                }
            }
            for(int k=left;k<=right;k++){
                ans+=grid[i][k];
                grid[i][k]=0;
                for(int j=i-1;j>=0;j--)fall[j][k]++;
            }
        }
        for(int i=h;i>=0;i--){
            for(int j=0;j<5;j++){
                if(fall[i][j]>0){
                    update=true;
                    grid[i+fall[i][j]][j]=grid[i][j];
                    grid[i][j]=0;
                    fall[i][j]=0;
                }
            }
        }
    }
    cout<<ans<<endl;
    return false;
}

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

    while(!solve());
}


Measured memory_bytes: 3016
#include<iostream>
#include<cstdio>
#include<string>
#define fo(i,n) for(int i=1;i<=n;i++)
#define for(i,n) for(int i=0;i<n;i++)
#define ll long long 
using namespace std;
string s[10];
int cnt;
int n,m,k,res;
int main()
{
	cin>>n>>m>>k;
	for(i,n)
	{
		for(j,m)
		{
			cin>>s[i][j];
			if(s[i][j]=='#')cnt++;
		}
	}
	int t=0;
	for(i,1<<n)
	{
		for(j,1<<m)
		{
			t=0;
			for(x,n)
			{
				for(y,m)
				{
					if((i>>x&1)&&(j>>y&1)&&s[x][y]=='#')
					t++;
				}
			}
			if(t==k)res++;
		}
	 } 
	cout<<res<<"\n";
	return 0;
 } 

Measured memory_bytes: 3124
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	int n;
	int max=0;
	int count=0;
	string S;
	cin >> n;
	cin >> S;
	REP(i,n)
	{
		if (S.at(i) == 'I')
		{
			count++;
		}
		else if (S.at(i) == 'D')
		{
			count--;
		}
		if (max <= count)max = count;
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
//by sdfzchy
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int inf=(1<<30),N=100010;
int n,m;
deque<PII> q;
inline int in()
{
    char ch=getchar();
    int f=1,tmp=0;
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {tmp=(tmp<<1)+(tmp<<3)+(ch-'0');ch=getchar();}
    return tmp*f;
}
bool vis[N];
int main()
{
    n=in();
    q.push_front(make_pair(1,1));
    while(!q.empty())
    {
        PII x=q.front();
        q.pop_front();
        int fir=x.first,sec=x.second;
        if(vis[fir]) continue;
        vis[fir]=1;
        if(fir==0) {printf("%d\n",sec);return 0;}
        q.push_front(make_pair(fir*10%n,sec));
        q.push_back(make_pair((fir+1)%n,sec+1));
    }
    return 0;
}


Measured memory_bytes: 1152
h,w=map(int,input().split())
s=["."*(w+2)]
for i in range(h):
	s.append("."+input()+".")
s.append("."*(w+2))
for i in range(1,h+1):
	p=""
	for j in range(1,w+1):
		if s[i][j]==".":
			x=s[i-1][j-1:j+2]+s[i][j-1:j+2]+s[i+1][j-1:j+2]
			p+=str(x.count("#"))
		else:
			p+="#"
	print(p)


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;
const int Maxn=2*1e5+5;
int N,A[Maxn],f[Maxn],B[Maxn],Mx;
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
int main(){
	N=read();
	for(int i=1;i<=N;i++)A[i]=read(),B[A[i]]=i;
	for(int i=1;i<=N;i++){
		if(B[i]>B[i-1])f[i]=f[i-1]+1;
			else f[i]=1;
		}
		for(int i=1;i<=N;i++)Mx=max(Mx,f[i]);
	printf("%d",N-Mx);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
    //write code  here
    int N;
    cin >> N;
    vector<int>a(N);

    int sum=0;

    for (int i = 0; i < N; ++i) {
        cin >> a.at(i);
        sum += a.at(i);

    }
    float var = (float)sum / (float)N;
    vector<float>disFromSum(N);
    float minDis = (float) N;
    int flame = N;
    for (int i = 0; i < N; ++i) {
        disFromSum.at(i) = var - a.at(i);//差を計算
        if (disFromSum.at(i) < 0) disFromSum.at(i) *= -1;//絶対値
        if (disFromSum.at(i) < minDis){
            minDis = disFromSum.at(i);//最小値を更新
            flame = i;//フレームを選択
        }
    }
    cout << flame << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

n  = STDIN.gets.chomp.to_i
a  = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i }

z = Array.new(n, 0)

a.each do |i|
	z[i - 1] += 1
end

all = 0
z.each do |i|
	all += i * (i - 1) / 2
end

a.each do |i|
	puts all - (z[i - 1] - 1)
end



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

string S;
int main()
{
    cin >> S;
    int count = 0;
    for(int i = 0;i < 3;i++)
    {
        if(S[i] == '1') count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b;
  if((a+b)%2==0){
    c=(a+b)/2;
  }
  else{
  	c=(a+b)/2+1;
  }
  cout << c << endl;
}

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

using std::pair;
using std::make_pair;
typedef pair<int, int> Pair;

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

const int N = 100;

int a[N], n;

void run(int case_id = 0) {
  std::priority_queue<double, std::vector<double>, std::greater<double> > heap;
  std::cin >> n;
  for (int i = 1; i <= n; ++ i) {
    std::cin >> a[i];
    heap.push(a[i]);
  }

  double answer = 0;
  while (!heap.empty()) {
    double x = heap.top();
    heap.pop();
    if (heap.empty()) {
      answer = x;
      break;
    }
    double y = heap.top();
    heap.pop();
    heap.push((x + y) / 2);
  }
  std::cout << std::setprecision(9) << std::fixed;
  std::cout << answer << std::endl;
}

void multi_cases_main() {
  int num_tests;
  std::cin >> num_tests;
  for (int t = 1; t <= num_tests; ++ t) {
    run(t);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


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

int main() {
  vector<int> d(5);
  for (int i = 0; i < 5; i++)
    cin >> d.at(i);

  int index, min = 9;
  for (int i = 0; i < 5; i++) {
    if (d.at(i) % 10 != 0 && d.at(i) % 10 < min) {
      min = d.at(i) % 10;
      index = i;
    }
  }
  int sum = 0;
  for (int i = 0; i < 5; i++) {
    if (i == index) {
      sum += d.at(i);
    }
    else {
      sum += (d.at(i) + 9) / 10 * 10;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256