akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int n,m;
  cin >> n;
  m=3*n;
  int s[m],s2[m];
  for(int i=0 ; i<m ; i++ ){
    cin >> s[i];
    s2[i] = s[i];
  }


  for(int j=0 ; j<n ; j++){
    for(int i=0 ; i<(m-2) ; i+=3){
      if (s[3*j]==s[i] && 3*j != i){
        s2[3*j]=0;
      }
      if (s[3*j+1]==s[i+1] && 3*j != i){
        s2[3*j+1]=0;
      }
      if (s[3*j+2]==s[i+2] && 3*j != i){
        s2[3*j+2]=0;
      }
      }
    }
    for(int j=0 ; j<n ; j++){
      cout <<s2[3*j]+s2[3*j+1]+s2[3*j+2]<<endl;
    }
    }



Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main()
{
int a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
if(c<0)
{cout << "No" << endl;}
else if(d<0)
{cout << "No" << endl;}
else if((c+e)>a)
{cout << "No" << endl;}
else if((d+e)>b)
{cout << "No" << endl;}
else
{cout << "Yes" << endl;}
}


Measured memory_bytes: 3116
k=int(input())

s=7
cnt=1
m=0

while(1):

  t=s%k
  if m==0 and t!=s:
    m=t
  elif m==t:
    print("-1")
    break

  if t==0:
    print(cnt)
    break
  else:
    s=t*10 + 7

  cnt+=1


Measured memory_bytes: 63200
s = input()

#全体として回文になっているか
if s != s[::-1]:
    print("No")
    exit()

mae = s[:len(s)//2]#前半部分
ushiro = s[(len(s)+1)//2:]#後半部分

#前部分が回文になっているか
if mae != mae[::-1]:
    print("No")
    exit()

#後ろ部分が回文になっているか
if ushiro != ushiro[::-1]:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std ;
string s , t ;
long long sum = 0 ; 
vector<int>c[30] ;
int main () {
	cin >> s >> t ;
	int n = s.size() ;
	int m = t.size() ;
	for(int i = 0 ; i < s.size() ; i ++) {
		c[s[i]-'a'].push_back(i+1) ;
	}
	int x = t[0] - 'a' , j ;
	if(!c[x].size()) {
		puts("-1") ;
		return 0 ;
	}
	int k = c[x][0] ;
	sum += k ;
	for(int i = 1 ; i < m ; i ++) {
		x = t[i] - 'a' ;
		if(!c[x].size()) {
			puts("-1") ;
			return 0 ;
		}
		j = upper_bound(c[x].begin() ,c[x].end(),k) - c[x].begin() ;
		if(j == c[x].end()-c[x].begin() ) {
			sum += c[x][0] + n - k ;
			k = c[x][0] ;
		}else {
			sum += c[x][j] - k ;
			k = c[x][j] ;
		}
	}
	cout << sum <<endl ; 
	return 0 ;
}

Measured memory_bytes: 1216
N = int(input())

minimum = 0
headB = 0
lastA = 0
both = 0

strs = []
for _ in range(N):
    s = input()
    minimum += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        both += 1
    else:
        if s[0] == 'B':
            headB += 1
        if s[-1] == 'A':
            lastA += 1

combi = 0
combi += min(lastA, headB)
lastA -= combi
headB -= combi

extra = 0
if lastA > 0:
    extra = min(lastA, both)
    lastA -= extra
    both -= extra
elif headB > 0:
    extra = min(headB, both)
    headB -= extra
    both -= extra

bonus = 0
if both > 0:
    if combi > 0 or extra > 0:
        bonus = both
    else:
        bonus = both-1

result = minimum + combi + extra + bonus

print(result)


Measured memory_bytes: 3064
n = int(input())
v = list(map(int, input().split()))

Onum = {}
Enum = {}

for i in range(n):
    if i%2 == 1:
        if v[i] in Onum:
            Onum[v[i]] += 1
        else:
            Onum[v[i]] = 1
    else:
        if v[i] in Enum:
            Enum[v[i]] += 1
        else:
            Enum[v[i]] = 1

Onum = sorted(Onum.items(), key = lambda x:-x[1])
Enum = sorted(Enum.items(), key = lambda x:-x[1])


if Onum[0][0] != Enum[0][0]:
    ans = n - (Onum[0][1] + Enum[0][1])
elif Onum[0][1] == n // 2:
    ans = n // 2
else:
    ans = n - max(Onum[0][1] + Enum[1][1], Onum[1][1] + Enum[0][1])
print(ans)

Measured memory_bytes: 17652
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int n,a[101],cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i%2==1&&a[i]%2==1)
            cnt++;
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3592
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) < sum(b):
	print(-1)
else:
	excess = []
	needed_num = 0
	needed_score = 0
	for i in range(n):
		if a[i] > b[i]:
			excess.append(a[i]-b[i])
		elif a[i] < b[i]:
			needed_num += 1
			needed_score += b[i]-a[i]

	if needed_num == 0:
		print(0)
	else:
		excess.sort(reverse=True)
		e_sum = [excess[0]]
		for i in range(1, len(excess)):
			e_sum.append(e_sum[-1]+excess[i])
		ind = bisect_left(e_sum, needed_score)
		print(needed_num + ind+1)

Measured memory_bytes: 82224
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int dp[11][1001]={};
	dp[0][0]=1;
	for(int i=0;i<=100;i++){
        for(int j=8;j>=0;j--){
            for(int k=0;k<1000;k++){
                if(k+i>1000) continue;
                dp[j+1][k+i] += dp[j][k];
            }
        }
    }
    int n,s;
    while(1){
		cin>>n>>s;
		if(!n&&!s)break;
		cout<<dp[n][s]<<endl;
	}
}
	

Measured memory_bytes: 1252
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,K; cin>>N>>K;
  ll ans=0;
  vector<ll> A(N),B(N); rep(i,N) cin>>A[i]>>B[i];
  rep(i,31){
    ll sK;
    ll sans=0;
    sK=((K>>i)<<i)-(i==0?0:1); if(sK<0) break;
    //cout<<sK<<endl;
    rep(j,N){
      if(!(A[j]&(~sK))) sans+=B[j];
    }
    chmax(ans,sans);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e18+7;

int main() {
    ios::sync_with_stdio(false);   
    Int n;
    cin >> n;
    vector<Int> h(n);
    for (Int i = 0; i < n; i++) cin >> h[i];
    Int ma = 0;
    Int res = 0;
    for (Int i = 0; i < n; i++) {
        if (ma <= h[i]) {
            res++;
            ma = h[i];
        }
    }
    dump(res);
    return 0;
}

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

int main(void){
    int n, m;
    string bl[110], re[110];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> bl[i];
    }
    cin >> m;
    for(int i=0;i<m;++i){
        cin >> re[i];
    }
    int max = 0;
    for(int i=0;i<n;++i){
        int cnt = 0;
        for(int j=0;j<n;++j) if(bl[j]==bl[i]) ++cnt;
        for(int j=0;j<m;++j) if(re[j]==bl[i]) --cnt;
        if(max < cnt) max = cnt;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
import numpy as np

rawRounds = input()
rawDistances = input()

mizuumiRound = int(rawRounds.split()[0])
houseNumber = int(rawRounds.split()[1])
distances = [int(n) for n in rawDistances.split()]

sortedDistances = sorted(distances)

betweens = list(sortedDistances)
for i in range(len(betweens)-1) :
    betweens[i+1] -= sortedDistances[i]

betweens[0] = mizuumiRound - sortedDistances[len(sortedDistances)-1] + sortedDistances[0]

startPoint = betweens.index(max(betweens))

routeLen = sum(betweens) - betweens[startPoint]

print(routeLen)

Measured memory_bytes: 36520
lim = 10 ** 5

primes = [True] * (lim + 1)
primes[0], primes[1] = False, False
for i in range(2, int(lim ** 0.5) + 1):
    if primes[i]:
        for j in range(i * 2, lim, i):
            primes[j] = False

like = [False] * (lim + 1)
for i in range(1, lim + 1):
    if primes[i] and primes[(i + 1) // 2]:
        like[i] = True

cumsum = [0] * (lim + 1)
for i in range(1, lim + 1):
    if like[i]:
        cumsum[i] = cumsum[i - 1] + 1
    else:
        cumsum[i] = cumsum[i - 1]

n = int(input())
q = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    l, r = q[i]
    ans = cumsum[r] - cumsum[l - 1]
    print(ans)

Measured memory_bytes: 30592
#include <vector>
#include <cassert>
#include <functional>

/*
last-updated: 2020/08/15

# 仕様
BinaryIndexedTree2D(size_type h, size_type w) :
	h \times w の表を構築

void add(size_type i, size_type j, const_reference x) :
	時間計算量: Θ(log h log w)
	点 (i, j) に値 x を加算

value_type sum(size_type i, size_type j) const :
	時間計算量: Θ(log h log w)
	[0, i) \times [0, j) の合計を返す

	// [i1, i2) x [j1, j2)
value_type sum(size_type i1, size_type j1, size_type i2, size_type j2) const :
	時間計算量: Θ(log h log w)
	[i1, i2) \times [j1, j2) の合計を返す

# 参考
https://algo-logic.info/binary-indexed-tree/, 2020/08/15
*/

template<typename T>
struct BinaryIndexedTree2D {
	using value_type = T;
	using const_reference = const value_type &;
	using size_type = std::size_t;
	
	BinaryIndexedTree2D(size_type h, size_type w) : h(h), w(w) {
		node.resize(h + 1, std::vector<value_type>(w + 1));
	}
	
	void add(size_type i, size_type j, const_reference x) {
		assert(i < h);
		assert(j < w);
		++i; ++j;
		for (; i <= h; i += i & -i) {
			for (size_type k = j; k <= w; k += k & -k) {
				node[i][k] += x;
			}
		}
	}
	
	// [0, i) x [0, j)
	value_type sum(size_type i, size_type j) const {
		assert(i <= h);
		assert(j <= w);
		value_type res = 0;
		for (; i > 0; i -= i & -i) {
			for (size_type k = j; k > 0; k -= k & -k) {
				res += node[i][k];
			}
		}
		return res;
	}
	
	// [i1, i2) x [j1, j2)
	value_type sum(size_type i1, size_type j1, size_type i2, size_type j2) const {
		assert(i1 < i2);
		assert(j1 < j2);
		assert(i2 <= h);
		assert(j2 <= w);
		return sum(i2, j2) - sum(i2, j1) - sum(i1, j2) + sum(i1, j1);
	}
	
private:
	size_type h, w;
	std::vector<std::vector<value_type>> node;
};

#include <cstdio>
#include <vector>
#include <queue>
#include <utility>

int main() {
	int H, W, T, Q;
	scanf("%d %d %d %d", &H, &W, &T, &Q);
	std::vector<int> t(Q), c(Q), h1(Q), w1(Q), h2(Q), w2(Q);
	
	using pii = std::pair<int, int>;
	
	std::queue<pii> que; // 焼き上がりの時刻, イベントID
	BinaryIndexedTree2D<int> bit1(H, W), bit2(H, W); // bit1: 焼き上がった, bit2: まだ焼き上がっていない
	
	for (int i = 0; i < Q; ++i) {
		scanf("%d %d %d %d", &t[i], &c[i], &h1[i], &w1[i]);
		--h1[i]; --w1[i];
		
		while (!que.empty() && que.front().first <= t[i]) {
			int idx = que.front().second; que.pop();
			bit2.add(h1[idx], w1[idx], -1);
			bit1.add(h1[idx], w1[idx], 1);
		}
		
		if (c[i] == 0) { // セット
			bit2.add(h1[i], w1[i], 1);
			que.emplace(t[i] + T, i);
		}
		else if (c[i] == 1) { // つまみ食い
			if (bit1.sum(h1[i], w1[i], h1[i] + 1, w1[i] + 1) == 1) bit1.add(h1[i], w1[i], -1);
		}
		else { // カウント
			scanf("%d %d", &h2[i], &w2[i]);
			printf("%d %d\n", bit1.sum(h1[i], w1[i], h2[i], w2[i]), bit2.sum(h1[i], w1[i], h2[i], w2[i]));
		}
	}
	
	return 0;
}


Measured memory_bytes: 36872
N = int(input())
counter_val = ['AC', 'WA', 'TLE', 'RE']
counter = [0, 0, 0, 0]  # [AC, WA, TLE, RE]
LenOfCounter = 4

for _ in range(N):
    S = input()
    for i in range(LenOfCounter):
        if counter_val[i] == S:
            counter[i] += 1

for i in range(LenOfCounter):
    print('{} x {}'.format(counter_val[i], counter[i]))


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

using namespace std;
long long a[200010];
long long b[200010];
int main(){
    int c;
    cin>>c;
    long long s=0;
    for(int i=0;i<c;i++){
        cin>>a[i];
        if(i==0)
            b[i]=a[i];
        else
            b[i]=b[i-1]+a[i];
        s=s+a[i];
    }
    long long m;
    if(b[0]>s-b[0])
        m=b[0]+b[0]-s;
    else
        m=s-b[0]-b[0];
    for(int i=1;i<(c-1);i++){
        if(m>abs(s-b[i]-b[i]))
        m=abs(s-b[i]-b[i]);
    }
    cout<<m<<endl;
    return 0;
} 

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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    vector<string> S(H);
    for (int i=0;i<H;++i) cin >> S[i];
    UnionFind uf(H*W);
    const int dx[2]={1,0};
    const int dy[2]={0,1};
    for (int i=0;i<H;++i){
        for (int j=0;j<W;++j){
            for (int k=0;k<2;++k){
                int nh=i+dx[k],nw=j+dy[k];
                if (H<=nh||W<=nw) continue;
                if (S[nh][nw]!=S[i][j]) uf.merge(i*W+j,nh*W+nw);
            }
        }
    }
    vector<vector<ll>> cnt(2,vector<ll>(H*W,0));
    for (int i=0;i<H;++i){
        for (int j=0;j<W;++j){
            if (S[i][j]=='#') ++cnt[0][uf.root(i*W+j)];
            else ++cnt[1][uf.root(i*W+j)];
        }
    }
    ll ans=0;
    for (int i=0;i<H*W;++i)
        ans+=cnt[0][i]*cnt[1][i];
    cout << ans << '\n';
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll n;
ll a[110];
ll dp[101010];

double rec(ll x){
	if(dp[x]!=-1) return dp[x];
	ll ret=0;
	REP(i,n) if(x-a[i]>=0 && rec(x-a[i])==1) ret=1;//1こでも勝てるルートがあったら勝ち
	return dp[x]=!ret;
}

void solve(){
	ll k;
	cin>>n>>k;
	REP(i,n) cin>>a[i];
	memset(dp,-1,sizeof(dp));

	cout<<(rec(k)==0? "First":"Second")<<en;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      }
      aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

using fp = modint<(i64)(1e9 + 7)>;

int main() {
  i64 n, m;
  cin >> n >> m;
  vector<i64> a(m);
  rep(i,0,m) cin >> a[i];
  
  vector<bool> bro(n + 1);
  for(auto x: a) bro[x] = 1;
  vector<fp> dp(n + 1);
  dp[0] = fp(1);
  rep(i,1,n + 1) {
    if(bro[i]) continue;
    else {
      if(i - 1 >= 0) dp[i] += dp[i - 1];
      if(i - 2 >= 0) dp[i] += dp[i - 2];
    }
  }
  cout << dp[n].value() << endl;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, q;
	cin >> n;
	VI a(n); rep(i, n)cin >> a[i];
	a.erase(unique(a.begin(), a.end()), a.end());
	rep(i, sz(a)) {
		cout << a[i];
		printf(i == sz(a) - 1 ? "\n" : " ");
	}
}


Measured memory_bytes: 3428
N,M,X = map(int,input().split())
C = [0]*N
A = [[0] for _ in range(N)]
for i in range(N):
    tmp = list(map(int,input().split()))
    C[i] = tmp[0]
    A[i] = tmp[1:M+1]
f = False
money_min = 100000000000
for i in range(1,2**N):
    use = format(i,"0{}b".format(N))
    money = 0
    understand = [0]*M
    for j in range(N):
        if use[j] == "1":
            money += C[j]
            for k in range(M):
                understand[k] += A[j][k]
    if min(understand) >= X and money < money_min:
        money_min = money
        f = True

if f:
    print(money_min)
else:
    print(-1)









Measured memory_bytes: 68648
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    H, W = LI()
    g = []
    for _ in range(H):
        g.append(S())
    dp = [[inf for _ in range(W)] for __ in range(H)]

    if g[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0

    for r in range(H):
        for c in range(W):
            if r != H-1:
                if g[r][c] == '.' and g[r+1][c] == '#':
                    dp[r+1][c] = min(dp[r+1][c], dp[r][c] + 1)
                else:
                    dp[r+1][c] = min(dp[r+1][c], dp[r][c])
            if c != W-1:
                if g[r][c] == '.' and g[r][c+1] == '#':
                    dp[r][c+1] = min(dp[r][c+1], dp[r][c] + 1)
                else:
                    dp[r][c+1] = min(dp[r][c+1], dp[r][c])
    print(dp[-1][-1])
main()



Measured memory_bytes: 68588
#include<bits/stdc++.h>
using namespace std;
int main()
{
   // ifstream cin("input.in");
   // ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long long N;
    cin>>N;
    long long P=sqrt(1+8*N);
    P-=1;
    P/=2;
    long long F=P;
    P*=(P+1);
    P/=2;
    cout<<F+(N!=P);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class APalindromicNumber {
public:
	void solve(istream& in, ostream& out) {
        string s; in >> s;
        if(s[0] == s[2]) out << "Yes" << endl;
        else out << "No" << endl;
	}
};

int main() {
	APalindromicNumber solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
struct ant { int loc; char dir; };
ant a[20]; int n, l; int memo;
void move() {
	bool f = true;
	rep(i, n) {
		if (a[i].loc == 1) {
			memo = i; f = false;
		}
		else if (a[i].loc == l - 1 && f) {
			memo = i;
		}
	}
	rep(i, n) {
		if (a[i].loc == 0 || a[i].loc == l)continue;
		if (a[i].dir == 'R')a[i].loc++;
		else a[i].loc--;
	}
	rep(i, n) {
		if (a[i].loc == 0 || a[i].loc == l)continue;
		Rep(j, i + 1, n) {
			if (a[i].loc == a[j].loc)swap(a[i].dir, a[j].dir);
		}
	}
	return;
}
bool antfall() {
	rep(i, n) {
		if (a[i].loc != 0 && a[i].loc != l)return false;
	}
	return true;
}
int main() {
	while (cin >> n >> l, n) {
		char d; int p;
		rep(i, n) {
			cin >> d >> p;
			a[i] = { p,d };
		}
		int turn;
		for (turn = 1; turn < 105; turn++) {
			move();
			if (antfall())break;
		}
		cout << turn << " " << memo+1 << endl;
	}
	return 0;
}


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

int main(){
	int n,m;	cin>>n>>m;
	int sum=0;
	vector<int> item(n);
	for(int i=0;i<n;i++){
		cin>>item[i];
		sum+=item[i];
	}

	int cnt=0;
	for(int i=0;i<n;i++){
		if(!( sum>(item[i]*m*4) ))++cnt;
	}

	if(cnt>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();
		sc.close();

		if ((d + s - 1) / s <= t) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35760
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; 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 out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int a,b; cin >> a >> b;
    int c = GCD(a,b);
    auto d = divisor(c);
    int ans = 1;
    for(auto x:d) if(isPrime(x)) ans++;
    out(ans);

    return 0;
}


Measured memory_bytes: 384
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<string> ss(n);
    for(auto &x:ss)cin>>x;
    sort(all(ss));
    for(auto x:ss)cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
using ll = long long;

const int INF = 1001001001;

int main()
{
	ll h, num(1), ans(1);
	cin>>h;
	if(h==1)cout<<ans<<endl;
	else{
	    while(true){
	        ans*=2;
	        if(ans>h)break;
    	}
    	ans-=1;
    	cout<<ans<<endl;
	}
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int& x : xs) {
        cin >> x;
    }
    multiset<int> current(xs.begin(), xs.end());
    for (int x : xs) {
        current.erase(current.find(x));
        cout << *current.rbegin() << "\n";
        current.insert(x);
    }
    return 0;
}


Measured memory_bytes: 11776
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
#define int ll
P2 mk_P(ll a,ll b,ll c){
  return P2(a,P(b,c));
}
struct uftree{
private:
  vector<ll> par,val,rnk;
public:
  uftree(ll n){
    par.resize(n+5);
    val.resize(n+5);
    rnk.resize(n+5);
    for(int i=0;i<=n;i++){
      par[i]=i;
      val[i]=0;
      rnk[i]=0;
    }
  }
  ll find(ll pos){
    if(par[pos]==pos) return pos;
    else return par[pos]=find(par[pos]);
  }
  void set_val(ll pos,ll x){
    val[pos]=x;
  }
  bool same(ll a,ll b){
    return find(a)==find(b);
  }
  ll sum(ll pos){
    return val[find(pos)];
  }
  void unite(ll a,ll b){
    a=find(a);
    b=find(b);
    if(same(a,b)) return;
    if(rnk[a]<rnk[b]){
      par[a]=b;
      val[b]+=val[a];
    }
    else{
      par[b]=a;
      val[a]+=val[b];
      if(rnk[a]==rnk[b]) rnk[a]++;
    }
  }
};
bool kans[100005],ans[100005];
vector<P2> node[100005];
void dfs(ll pos,ll border){
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first,cos=node[pos][i].second.first;
    ll idx=node[pos][i].second.second;
    if(!ans[idx]&&cos<=border){
      ans[idx]=true;
      dfs(to,border);
    }
  }
}
signed main(){
  ll n,m;
  cin>>n>>m;
  uftree uf(n+5);
  for(int i=1;i<=n;i++){
    ll a;
    cin>>a;
    uf.set_val(i,a);
  }
  vector<P2> vec;
  for(int i=0;i<m;i++){
    kans[i]=false;
    ll a,b,c;
    cin>>a>>b>>c;
    vec.push_back(mk_P(c,a,b));
    node[a].push_back(mk_P(b,c,i));
    node[b].push_back(mk_P(a,c,i));
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<m;i++){
    ans[i]=false;
    ll s=vec[i].second.first,t=vec[i].second.second;
    ll cos=vec[i].first;
    uf.unite(s,t);
    if(uf.sum(s)>=cos) {
      kans[i]=true;
    }
  }
  for(int i=m-1;i>=0;i--){
    if(kans[i]){
      dfs(vec[i].second.first,vec[i].first);
    }
  }
  ll cnt=0;
  for(int i=0;i<m;i++) {
    if(!ans[i]) {
      cnt++;
      //cout<<i<<endl;
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 20272
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	int p = a * 100 + b * 10 + c;
	if (p % 4 == 0)puts("YES");
	else puts("NO");
	ggr
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [val - 1 for val in A]
# print(A)
route = [0]
seen = set()
here = 0
for _ in range(N + 100):
    here = A[here]
    route.append(here)

if len(route) >= K:
    print(route[K] + 1)
else:
    for i in range(len(route)):
        if route[i] in seen:
            start = route.index(route[i])
            period = i - start
            # print(period)
            r = (K - start + 1) % period
            if r == 0:
                idx = period + start - 1
            else:
                idx = r + start - 1
            print(route[idx] + 1)
            break
        seen.add(route[i])



Measured memory_bytes: 130156
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
 
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
 
T lread(T = long)()
{
    return readln.chomp.to!T();
}
 
T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}
 
void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

long disit_sum(long a)
{
    long sum,disit_num;
    foreach(disit;0 .. 9)
    {
        disit_num = a / pow(10, disit);
        sum += disit_num % 10;
    }
    return sum;
}


void main()
{
    long n = lread();
    string s = sread();
    foreach(e;s)
    {
        if(e == 'Y')
        {
            writeln("Four");
            return;
        }
    }
    writeln("Three");
}

Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

a, b, x = MAP()
if x <= a**2*b/2:
    ans = degrees(atan(a*b**2/2/x))
else:
    ans = degrees(atan(2*b/a-2*x/a**3))
print(ans)

Measured memory_bytes: 10120
// Aizu Vol-3 0338: New Town
// 2017.8.25

#include <stdio.h>

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int main()
{
	int W, H, C, k;
	scanf("%d%d%d", &W, &H, &C);
	k = gcd(W, H);
	printf("%d\n", W/k * H/k * C);
	return 0;
}

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

using namespace std;

int n;
const int MAXN = 310000;
string S;
int se[MAXN], sw[MAXN];
int fe[MAXN], fw[MAXN];
int e, w;

int main() {
	cin >> n >> S;
	for (int i = 0; i < n; ++i) {
		se[i] = se[i - 1];
		sw[i] = sw[i - 1];
		if (S[i] == 'E') {
			++se[i];
		}
		else ++sw[i];
	}
	e = se[n - 1];
	w = sw[n - 1];
	for (int i = n - 1; i >= 0; --i) {
		fe[i] = e - se[i];
		fw[i] = w - sw[i];
	}
	int ans = fe[1];
	for (int i = 1; i <= n; ++i) {
		ans = min(ans, sw[i - 1] + fe[i]);
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int main(void){
  string str;
  
  cin >> str;
  
  int month = (str[5] - '0') * 10 + (str[6] - '0');
  
  if(month <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cap, rev;
};

vector<vector<edge>> r;
vector<int> used;

void add_edge(int f, int t) {
  r[f].push_back(edge{t, 1, r[t].size()});
  r[t].push_back(edge{f, 0, r[f].size() - 1});
}

int dfs(int f, int t, int fl) {
  if(f == t) return fl;
  used[f] = 1;
  for(int i = 0; i < r[f].size(); i++) {
    if(r[f][i].cap > 0 && !used[r[f][i].to]) {
      auto &e = r[f][i];
      int d = dfs(e.to, t, min(fl, e.cap));
      if(d > 0) {
        e.cap -= d;
        r[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int main() {
  int h, w, s, t;
  scanf("%d %d", &h, &w);
  vector<vector<int>> V(w), H(h);
  char a;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> a;
      if(a == 'S') s = w * i + j;
      if(a == 'T') t = w * i + j;
      if(a != '.') H[i].push_back(j), V[j].push_back(i);
    }
  }
  if(s / w == t / w || s % w == t % w) {
    printf("-1\n");
    return 0;
  }
  r = vector<vector<edge>>(h * w * 2);
  for(int i = 0; i < h * w; i++) {
    add_edge(i, i + h * w);
    add_edge(i + h * w, i);
  }
  for(int i = 0; i < h; i++)
    for(int j = 0; j < H[i].size(); j++)
      for(int k = 0; k < H[i].size(); k++)
        if(j != k) add_edge(w * i + H[i][j] + h * w, w * i + H[i][k]);
  for(int i = 0; i < w; i++)
    for(int j = 0; j < V[i].size(); j++)
      for(int k = 0; k < V[i].size(); k++)
        if(j != k) add_edge(w * V[i][j] + i + h * w, w * V[i][k] + i);
  int flow = 0, f;
  used = vector<int>(h * w * 2);
  do {
    fill(used.begin(), used.end(), 0);
    f = dfs(s + h * w, t, INT_MAX);
    flow += f;
  } while(f);
  printf("%d\n", flow);
}

Measured memory_bytes: 62976
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll N,A[100007];

int main(){
    ll A,B,C,X,Y,N,M;
    string S,T;
    cin >> N >> S;
    if(N%2==1){
        cNo;
        return 0;
    }
    else{
        rep(i,N/2){
            if(S[i]!=S[i+N/2]){
                cNo;
                 return 0;
            }
        }
    }
    cYes;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] suki = new int[m];
		for(int i = 0; i < n; i ++) {
			int k = sc.nextInt();
			for(int j = 0; j < k; j ++) {
				suki[sc.nextInt() - 1] ++;
			}
		}
		sc.close();
		int count = 0;
		for(int i=0; i < m; i ++) {
			if(suki[i] == n) {
				count ++;
			}
		}
		System.out.println(count);

	}
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, T;
  cin >> N >> T;
  map<ll, ll> num;
  map<ll, ll> v;
  
  rep(i, N){
    ll t;cin >> t;
    if(num.size()>0){
      auto inum1 = num.begin();
      auto inum = *inum1;
      v[t - inum.first]+=1;
    }
    num[t]++;
  }

  auto iv = v.rbegin();
  cout << (*iv).second;
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=201;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

int main(){
  boost;
  ll a,b,c;
  cin>>a>>b>>c;
  int d=a%2+b%2+c%2;
  if(d==3)cout<<min(a*b,min(b*c,a*c));
  else cout<<0;
}


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

using namespace std;
typedef long long ll;

const int M = 6;
char a[M][M];

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int r = 0; r < (1 << h); r++) {
        for (int c = 0; c < (1 << w); c++) {
            int cur = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (((1 << i) & r) || ((1 << j) & c)) continue;
                    if (a[i][j] == '#') cur++;
                }
            }
            if (cur == k) ans++;
        }
    }
    cout << ans << "\n";
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

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

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

int main() {
    ll x, y;
    cin >> x >> y;
    ll tmp = lcm(x, y);
    ll a = (1e18/x - 1e18/tmp);
    if (a == 0LL) {
        cout << -1 << endl;
    }
    else {
        ll tmp2 = tmp/x;
        if (tmp2 > 2) tmp2--;
        else tmp2++;
        cout << x*tmp2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256