akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    double x;
    cin >> x;
    cout << setprecision(10) << 2 * M_PI * x << endl;

    return 0;
}


Measured memory_bytes: 3796
fun main(){
    val (a, b, c, n) = readLine()!!.split(" ").map { it.toInt() }
    if(n <= a){
        println(n)
    }else if(a < n && n <= a + b){
        println(a)
    }else if(a + b < n){
        println(a - (n - (a + b)))
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> B(N-1);
  for (int i = 0; i < N - 1; i++)
    cin >> B.at(i);
  
  int maxsum = B.at(0) + B.at(N - 2);
  for (int i = 0; i < N - 2; i++)
    maxsum += min(B.at(i), B.at(i + 1));
  
  cout << maxsum << endl;
}


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

int main() {
	int a[4] = {}, b[4] = {};
	std::cin >> a[0] >> a[1] >> a[2] >> a[3];
	std::cin >> b[0] >> b[1] >> b[2] >> b[3];
	std::cout << std::max({ a[0] + a[1] + a[2] + a[3], b[0] + b[1] + b[2] + b[3] }) << std::endl;
	return 0;
}

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

int main() {
  vector<string> a(200);
  int b = 0, c, d, e;
  for (cin >> c; c--; cin >> a.at(c));
  for (cin >> c; cin >> a.at(99 + c--););
  for (c = 100; c; c--) {
    d = 0;
    for (e = 200; e; e--) {
      if (a.at(c - 1) != "" && a.at(c - 1) == a.at(e - 1)) {
        if (e > 100) d--;
        else d++;
      }
    }
    if (d > b) b = d;
  }
  cout << b;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	vl ans(n);
	ll tmp=0;
	rep(i,n){
		if(s[i]=='R')tmp=i;
		else{
			ans[tmp+((i-tmp)%2)]++;
		}
	}
	tmp=n-1;
	rrep(i,n){
		if(s[i]=='L')tmp=i;
		else{
			ans[tmp-((tmp-i)%2)]++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2256
#include <bits/stdc++.h>
using namespace std;
int num[50];
int fun(int k)
{
    if(num[k]) return num[k];
    if(k==0||k==1) return num[k]=1;
    return num[k]=fun(k-1)+fun(k-2);
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",fun(n));
    return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define mkp make_pair
#define pb push_back
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0)
const ll INF=4e18;
const ll MAX=1e5+5;
const ll MOD=1e9+7;
//}}}
int n;
int main(){
	IOS;
	cin>>n;
	set<int> st; st.clear();
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(st.find(a)==st.end())
			st.insert(a);
		else
			st.erase(a);
	}
	cout<<SZ(st)<< '\n';
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    double t,x;
    cin >> t>>x;
    cout << t/x << endl;
}

Measured memory_bytes: 256
import numpy as np
import itertools
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])

def f(H, W, S):
  for i, j in itertools.product(range(H), range(W)):
    if S[i, j] == '#':
      if np.sum(np.concatenate([S[i-1:i, j], S[i, j-1:j], S[i+1:i+2, j], S[i, j+1:j+2]]) == '#') == 0:
        return False
  return True

if f(H, W, S):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 12488
#include <bits/stdc++.h>
#define pb push_back
#define vii vector<int>
#define task "ABC"
#define pll pair<ll, ll>
#define pii pair< ll, pair< ll, ll > >
#define fi first
#define se second

using ll = long long;
using ld = long double;
using ull = unsigned long long;
const ll mod = 1e9 + 7;
using namespace std;
const int N = 2e5+5;
ll tong, m, n, k, t, T, ntest, ans, u, v, b[N], P[N][20], lab[N], sum[N];
string s;
ll a[N], d[N][53];
vector<pii> kq;
vector<pll> adj[N], adt[N];
bool check;
inline void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        a[i] = a[i] % mod;
    }
    b[n+1] = 0;
    for(int i = n; i > 0; i --)b[i] = (b[i+1] + a[i]) % mod;
    for(int i = 1; i < n; i ++)
    {
        ans = (ans + a[i] * b[i+1]) % mod;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();

}





Measured memory_bytes: 16072
x,y=input().split()
x=int(x)
y=int(y)
k=(y-2*x)%2
if((k==0)and(((y-2*x)/2)>=0)):
  if((x-((y-2*x)/2))>=0):
    print("Yes")
  else:
    print("No")
else:
  print("No")
  

Measured memory_bytes: 9056
n = gets.to_i
list = {}
prev_last = nil
ok = true
for i in 0...n do
  w = gets.chomp
  if list.include?(w) || (!prev_last.nil? && w[0] != prev_last)
    ok = false
  end
  list[w] = true
  prev_last = w[-1]
end
puts ok ? "Yes" : "No"


Measured memory_bytes: 1788
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>
#include<iomanip>
#include <set>
#define INT_MINs -2000000000
#define INT_MAXs 1000000001
#define mod 1000000007
#define MID mid=(l+r)/2
#define REP1(i,x,y) for(int i=x;i<y;i++)
#define REP2(i,x,y) for(int i=x;i<=y;i++)
#define ls (2*k)
#define lr (2*k+1)
#define lson l,mid,2*k
#define lron mid+1,r,2*k+1
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0);
#define pb(a) push_back(a)
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { 1,0,-1,0,-1,1,-1,1};
int num[10000005];
int main()
{
    char str1[200005],str2[200005];
    scanf("%s%s",str1,str2);
    int ans=0;
    int len=strlen(str1);
    for(int i=0;i<len;i++)
        if(str1[i]!=str2[i])
        ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3616
n = int(input())
a = [int(input()) for i in range(n)]
a = a[::-1]

ans = 0
num = 1

while a:
    if a[-1] < num:
        del a[-1]
    elif a[-1] == num:
        num += 1
    elif a[-1] > num:
        if a[-1] % num == 0:
            ans += a[-1] // num - 1
            a[-1] = 1
        else:
            ans += a[-1] // num
            a[-1] = 1

print(ans)

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

#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = 1'000'000'000LL + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string S,T; cin >> S >> T;
    int ans = 12345678;
    for(int i = 0; i < S.size(); ++i) {
        if(i+T.size() > S.size()) continue;
        auto U = S.substr(i,T.size());
        int cnt=0;
        for(int j = 0; j < T.size(); ++j) {
            cnt += U[j]!=T[j];
        }
        chmin(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
string s,t;
int p;
signed main(){
	cin>>s>>t;
	int ls=s.size(),lt=t.size();
	FOR(i,0,lt-1){
		p=s.find(t[i]);
		if(p==-1){
			cout<<-1;return 0;
		}
	}
	int last=-1,ans=0;
	FOR(i,0,lt-1){
		p=s.find(t[i],last+1);
		if(p==-1){
			ans+=ls;p=s.find(t[i]);
		}
		last=p;
	}
	ans+=last+1;
	cout<<ans;
	RE 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>qq;
const ll maxn=1e6+5;
int main()
{
    string x;
    cin>>x;
    if(x.size()!=6)
        cout<<"No";
    else
    {
        if(x[0]!=x[1]&&x[2]==x[3]&&x[4]==x[5])
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}
/*
10 6
8 3 7 8 2 9 3 8 2 4


20 20
*/


Measured memory_bytes: 256
import java.io.PrintWriter
import kotlin.math.roundToLong
import kotlin.math.sqrt

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextLong()
    val NN = sqrt(N.toDouble()).roundToLong()
    for (A in NN downTo 1) {
        val B = N / A
        if (A * B == N) {
            println(A + B - 2)
            return
        }
    }
}

Measured memory_bytes: 34576
s = input()

fa = (s[0] == 'A')

cntC = 0
fc = True
for i in range(2, len(s)-1):
    if s[i] == 'C':
        cntC += 1
    elif s[i].isupper():
        fc = False
if s[1].isupper() or s[-1].isupper():
    fc = False

fb = (cntC == 1)

if fa and fb and fc:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define ALL(obj)		obj.begin(), obj.end()
using namespace std;

int main() {
	int n, l, min, minabs, a;
	cin >> n >> l;

	int sum = 0;
	minabs = abs(l);
	min = l;
	FOR(n) {
		a = l + i;
		sum += a;
		if (minabs > abs(a))
		{
			minabs = abs(a);
			min = a;
		}
	}
	cout << sum - min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> vec;
    int n, k; cin>>n>>k;
    vec.reserve(n);
    while(n--){
        int a; cin>>a;
        vec.emplace_back(a);
    }
    sort(vec.begin(),vec.end());
    cout<<(long long int)accumulate(vec.begin(),vec.begin()+k,0);
}

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

int main(){
  long X;cin>>X;
  long b=X%100;
  long a=(X-b)/100;
  long c=b/5;
  long d=b-5*c;
  long t=105*c+(d==0?0:100+d);
  if(t<=X)cout<<1;
  else cout<<0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(num) scanf("%d",&num)
#define sff(num1,num2) scanf("%d %d",&num1,&num2)
#define sfff(num1,num2,num3) scanf("%d %d %d",&num1,&num2,&num3)
#define sl(num) scanf("%lld",&num)
#define sll(num1,num2) scanf("%lld %lld",&num1,&num2)
#define slll(num1,num2,num3) scanf("%lld %lld %lld",&num1,&num2,&num3)
#define rep(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define pb push_back
#define mpp make_pair
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
#define TIME cerr<<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<"s\n";
typedef long long int ll;
using namespace std;
int dp[N],ara[N];
int main()
{
    int i,n;
    sf(n);
    rep0(i,n)
    {
        sf(ara[i]);
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    dp[1]=abs(ara[1]-ara[0]);
    for(i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(ara[i]-ara[i-1]),dp[i-2]+abs(ara[i]-ara[i-2]));
    pf("%d",dp[n-1]);
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n,d=MI()
	d=d**2

	ans=0

	for _ in range(n):
		x,y=MI()
		if x**2+y**2<=d:
			ans+=1

	print(ans)





if __name__ == "__main__":
	main()


Measured memory_bytes: 68416
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,x;
  cin>>a>>b>>x;
  x-=a;
   if(b>=x && x>=0){
    cout<<"YES"<<"\n";
  }
  else{
    cout<<"NO"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3588
#define _[2<<17]
n,i;A _,B _,T _,F _;long M,D _,P _,R _;s(u,p,i,I){D[u]=1;for(i=F[u];I=B[i];i=T[i])I-p?s(I,u),D[u]=D[u]*-~D[I]%M:0;}S(u,x,p,i,I){for(m(i=F[u],p);I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}m(i,p){i?m(T[i],p),R[i]=R[T[i]]*(B[i]-p?-~D[B[i]]:1)%M:0;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,0);S(1,1);for(;i++<n;)printf("%d ",P[i]);}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("YES\n")
#define outn printf("NO\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100100
/*------------------------------------------------------------*/
map<int ,int >a;
int main(){
	int n;
	in(n);
	FOR(i,1,n){
		int c;
		in(c);
		a[c]++;
	}
	int m;
	in(m);
	while(m--){
		int c;
		in(c);
		if(a[c])a[c]--;
		 else{
		 	outn;
		 	return 0;
		 }
	}	
	outy;
}

Measured memory_bytes: 9600
#include <iostream>
#include <limits.h>
using namespace std;

typedef long long ll;
#define INF LONG_MAX

int main() {
    int N; cin >> N;
    ll arr[N];
    for (int i=0; i<N; i++) scanf("%lld", arr+i);

    ll ans[N][N];
    ll leftover[N][N];

    // initialize:
    for (int i=0; i<N; i++){
        ans[i][i] = 0;
        leftover[i][i] = arr[i];
    }

    for (int len=2; len<=N; len++) {
        for (int st=0; st+len<=N; st++) {
            int en = st+len-1;
            ans[st][en] = INF;
            // cout << "calculating " << st << " " << en << endl;
            
            for (int last=st; last<en; last++) {
                ll cur_score = ans[st][last] + ans[last+1][en] + leftover[st][last] + leftover[last+1][en];
                // printf("score for [%d %d] [%d %d] = %lld %lld for [%d %d] = %lld\n", st, last, last+1, en, ans[st][last], ans[last+1][en], st, en, cur_score);
                if (cur_score < ans[st][en]) {
                    ans[st][en] = cur_score;
                    leftover[st][en] = leftover[st][last] + leftover[last+1][en];
                }
            }
        }
    }

    cout << ans[0][N-1] << endl;
    return 0;
}

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

int X, Y, E, x, y;
bool D[110][110] = {};

int PY[110];
bool V[110];
bool match(int x) {
	if (x<0) return true;
	if (V[x]) return false;
	V[x] = true;
	for (int y = 0; y<Y; ++y) {
		if (!D[x][y]) continue;
		if (match(PY[y])) {
			PY[y] = x;
			return true;

		}
	}
	return false;
}


int main() {
	cin >> X >> Y >> E;
	for (int i = 0; i<E; ++i) {
		cin >> x >> y;
		D[x][y] = true;
	}
	fill(PY, PY + Y, -1);
	int count = 0;
	for (int x = 0; x<X; ++x) { 
		fill(V, V + X, false);
		if (match(x)) ++count;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3132
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

s=input()
a,b,c=s.split(",")
print(a,b,c)

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  vector<int> cnt(B);
  int i = 1;
  while(1){
    cnt.at(((A%B)*i)%B) ++;
    if(((A%B)*i)%B == C){
      cout << "YES" << endl;
      return 0;
    }
    if(cnt.at(((A%B)*i)%B) > 1){
      cout << "NO" << endl;
      return 0;
    }
    i++;
  }
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> Ais, Bis, Cis;
    for (ll i = 0; i < N; i++) {
        ll Ai;
        cin >> Ai;
        Ai--;
        Ais.push_back(Ai);
    }
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
        ll Bi;
        cin >> Bi;
        Bis.push_back(Bi);
        sum += Bi;
    }
    for (ll i = 0; i < N-1; i++) {
        ll Ci;
        cin >> Ci;
        Cis.push_back(Ci);
    }
    ll add = 0;
    for (ll i = 0; i < N-1; i++) {
        if (Ais[i+1] == Ais[i] + 1) {
            add += Cis[Ais[i]];
        }
    }
    cout << add + sum << endl;
    
    // asan
}



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

using namespace std;

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

	string res = "";

	for (int i = 0; i < N; i++)
	{
		res += S[i];
		res += T[i];
	}

	cout << res << endl;
}



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

#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
using namespace atcoder;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n, K;
    scanf("%d%d", &n, &K);
    lint a[n][n];
    rep(i, n) rep(j, n) scanf("%lld", &a[i][j]);

    mcf_graph<lint, lint> gr(2 * n + 2);
    int source = 2 * n, sink = 2 * n + 1;
    rep(i, n) {
        gr.add_edge(source, i, K, 0);
        gr.add_edge(n + i, sink, K, 0);
    }
    rep(i, n) rep(j, n) { gr.add_edge(i, n + j, 1, mod - a[i][j]); }
    gr.add_edge(source, sink, n * K, mod);

    auto [cap, cost] = gr.flow(source, sink, n * K);
    printf("%lld\n", mod * n * K - cost);
    char c[n][n];
    rep(i, n) rep(j, n) c[i][j] = '.';
    auto es = gr.edges();
    for (auto &e : es)
        if (e.flow > 0 && e.from != source && e.to != sink) {
            c[e.from][e.to - n] = 'X';
        }
    rep(i, n) {
        rep(j, n) printf("%c", c[i][j]);
        printf("\n");
    }
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int Q;
    cin >> Q;
    vector<int> l(Q);
    vector<int> r(Q);
    rep(i,Q){
        cin >> l[i] >> r[i];
    }
    vector<bool> isPrime(100005,true);
    isPrime[1] = false;
    for (int i = 2; i <= 100000; i++){
        if (isPrime[i]){
            for (int j = 2; j * i <= 100000; j++){
                isPrime[i * j] = false;
            }
        }
    }
    vector<int> like2017(100005, 0);
    for (int i = 3; i <= 99999; i += 2){
        if (isPrime[i] && isPrime[(i + 1) / 2]){
            like2017[i]++;
        }
    }
    for (int i = 1; i <= 100000; i++){
        like2017[i + 1] += like2017[i];
    }
    rep(i,Q){
        cout << like2017[r[i]] - like2017[l[i] - 1] << endl;
    }
}

Measured memory_bytes: 4572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a1 = scanner.nextInt();
        int a2 = scanner.nextInt();
        int a3 = scanner.nextInt();
      if(a1 + a2 + a3 >= 22){
        System.out.println("bust");
      } else {
              System.out.println("win");
      }
    }
}


Measured memory_bytes: 23252
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int LL;
typedef long long int ll;
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include<stack>

const int maxn=1010;
const long long INF=1LL<<50;;
long long dist[maxn];
int a[maxn*2],b[maxn*2];
long long c[maxn*2];
bool vis[maxn];

int main()
{
#ifdef LOCAL
    freopen("data.h", "r", stdin);
    //freopen("1.h","w",stdout);
#endif
    //cout<<INF<<endl;
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) dist[i]=INF;
    for(int i=0;i<m;i++) cin>>a[i]>>b[i]>>c[i];
    for(int i=0;i<m;i++) c[i]=-c[i];
    for(int i=0;i<n;i++) vis[i]=false;
    dist[0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(dist[a[j]-1]==INF) continue;
            if(dist[b[j]-1]>dist[a[j]-1]+c[j])
                dist[b[j]-1]=dist[a[j]-1]+c[j];
        }
    }
    ll ans=-dist[n-1];
    for(int loop=0;loop<n;++loop){
        for(int i=0;i<m;i++){
            if(dist[a[i]-1]==INF) continue;
            if(dist[b[i]-1]>dist[a[i]-1]+c[i]){
                vis[b[i]-1]=true;
                dist[b[i]-1]=dist[a[i]-1]+c[i];
            }
            if(vis[a[i]-1]==true)
                vis[b[i]-1]=true;
        }
    }
    if(vis[n-1]==true) puts("inf");
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let (n, tt): (usize, usize) = parse_line().unwrap();
    let t: Vec<usize> = parse_line().unwrap();
    let mut x = tt;

    for i in 1..n {
        x += (t[i] - t[i - 1]).min(tt);
    }
    println!("{}", x);
}


Measured memory_bytes: 5660
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long int
int32_t main()
{
	int n;
	cin>>n;
	int answer=0;
	int j;
	for(j=0;j<n;j++)
	{
		int x;
		cin>>x;
		while(x%2==0)
		{
			answer++;
			x/=2;
		}
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = (1 << 30);
const int N = 100005;
struct Card
{
	char suit;
	int value;
} card[N], t[N], temp;
Card L[N / 2 + 1], R[N / 2 + 1];

void _merge(Card a[], int l, int m, int r)	//[l, r)
{
	int i, j, k;
	int n1 = m - l;
	int n2 = r - m;
	for (i = 0; i < n1; ++i)
		L[i] = a[l + i];
	for (i = 0; i < n2; ++i)
		R[i] = a[m + i];
	L[n1].value = R[n2].value = INF;
	i = j = 0;
	for (k = l; k < r; ++k)
	{
		if (L[i].value <= R[j].value)
			a[k] = L[i++];
		else
			a[k] = R[j++];
	}
}

void _merge_sort(Card arr[], int l, int r)
{
	if (l + 1 >= r)
		return;
	int m = (l + r) >> 1;
	_merge_sort(arr, l, m);
	_merge_sort(arr, m, r);
	_merge(arr, l, m, r);
}

int partition(Card arr[], int p, int r)	//[p, r)????????????,????????????pivot??????
{
	int pivot = arr[r - 1].value;
	int i = p;
	for (int j = p; j < r - 1; ++j)
	{
		if (arr[j].value <= pivot)
		{
			temp = arr[i];
			arr[i++] = arr[j];
			arr[j] = temp;
		}
	}
	temp = arr[i];
	arr[i] = arr[r - 1];
	arr[r - 1] = temp;
	return i;
}

void q_sort(Card arr[], int l, int r)
{
	if (l + 1 < r)
	{
		int t = partition(arr, l, r);
		q_sort(arr, l, t);
		q_sort(arr, t, r);
	}
}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> card[i].suit >> card[i].value;
		t[i] = card[i];
	}
	q_sort(card, 0, n);
	_merge_sort(t, 0, n);
	bool flag = true;
	for (int i = 0; i < n; ++i)
	{
		if (card[i].suit != t[i].suit)
		{
			flag = false;
			break;
		}
	}
	if (flag)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	for (int i = 0; i < n; ++i)
		cout << card[i].suit << ' ' << card[i].value << endl;

	return 0;
}

Measured memory_bytes: 5400
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string>
#include<set>
#include<limits.h>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<functional>
#include<stack>
#include<deque>
#include<queue>
using namespace std;

vector<int>V;
signed main() {
	int n, h; cin >> n >> h;
	int MAX = 0;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		MAX = max(MAX, a);
		V.push_back(b);
	}
	sort(V.begin(), V.end(), greater<int>());
	int sum = 0;
	for (int i = 0; i < V.size(); i++) {
		if (V[i] < MAX)break;
		sum++;
		h -= V[i];
		if (h <= 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << sum + (h - 1) / MAX + 1 << endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

int main()
{
    int n,m;
    scanf(" %d %d", &n, &m);
    vector<ll> x(n),y(m);
    rep(i,n) scanf(" %lld", &x[i]);
    rep(i,m) scanf(" %lld", &y[i]);

    ll X=0,Y=0;

    ll sum=0;
    rep(i,n) (sum+=x[i])%=mod;
    rep(i,n)
    {
        sum-=x[i];
        if(sum<0) sum+=mod;

        (X+=sum)%=mod;
        (X+=(mod-x[i])%mod*(n-1-i))%=mod;
    }

    sum=0;
    rep(i,m) (sum+=y[i])%=mod;
    rep(i,m)
    {
        sum-=y[i];
        if(sum<0) sum+=mod;

        (Y+=sum)%=mod;
        (Y+=(mod-y[i])%mod*(m-1-i))%=mod;
    }

    printf("%lld\n", (X*Y)%mod);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(void) {
    int n,m,x;
    string s;
    cin >> n >> s;
    m = x = 0;
    REP(i,n){
        if(s[i]=='I'){
            x++;
            if (x > m) m = x;
        } else {
            x--;
        }
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int h,w=5;
int v[15][5];

int disappearance(){

  int ret=0;
  int i,j;
  /*
消えるとき
1 2 3 4 5
1 2 3 4
1 2 3
2 3 4
2 3 4 5
3 4 5
   */

  rep(i,h){
    if(v[i][0]==v[i][1] && v[i][1]==v[i][2] && v[i][2]==v[i][3] && v[i][3]==v[i][4]
       && v[i][0]!=-1){
      ret+=v[i][0]*5;
      rep(j,5)v[i][j]=-1;
    }
    if(v[i][0]==v[i][1] && v[i][1]==v[i][2] && v[i][2]==v[i][3] && v[i][3]!=v[i][4]
       && v[i][0]!=-1){
      ret+=v[i][0]*4;
      rep(j,4)v[i][j]=-1;
    }
    if(v[i][0]==v[i][1] && v[i][1]==v[i][2] && v[i][0]!=v[i][3]
       && v[i][0]!=-1){
      ret+=v[i][0]*3;
      rep(j,3)v[i][j]=-1;
    }
    if(v[i][0]!=v[i][1] && v[i][1]==v[i][2] && v[i][2]==v[i][3] && v[i][3]==v[i][4]
       && v[i][1]!=-1){
      ret+=v[i][1]*4;
      loop(j,1,5)v[i][j]=-1;
    }
    if(v[i][0]!=v[i][1] && v[i][1]==v[i][2] && v[i][2]==v[i][3] && v[i][3]!=v[i][4]
       && v[i][1]!=-1){
      ret+=v[i][1]*3;
      loop(j,1,4)v[i][j]=-1;
    }
    if(v[i][1]!=v[i][4] && v[i][2]==v[i][4] && v[i][3]==v[i][4]
       && v[i][4]!=-1){
      ret+=v[i][2]*3;
      loop(j,2,5)v[i][j]=-1;
    }
  }

  return ret;
}

void drop(){
  int i,j;
  loop(i,1,h)rep(j,w)if(v[i][j]>0){
    int k=i-1;
    while(k>=0){
      if(v[k][j]!=-1)break;
      k--;
    }
    if(k+1!=i){
      v[k+1][j]=v[i][j];
      v[i][j]=-1;
    }
  }
}


int main(void) {
  int i,j;
  while(1){
    cin>>h;
    if(h==0)break;
    rep(i,15)rep(j,5)v[i][j]=-1;
    rep(i,h)rep(j,w)cin>>v[h-1-i][j];

    int ans=0;

    while(1){

      int t=disappearance();

      if(t==0)break;

      ans+=t;
      
      drop();

    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3084
// D.

#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long LL;

static const LL MOD = 1000000007;
static const size_t MAX_N = 100030;

struct modll {
	long long x;
	modll() { }
	modll(long long _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(const modll &r) { return (x + r.x) % MOD; }
	modll operator+=(const modll &r) { return x = (x + r.x) % MOD; }
	modll operator-(const modll &r) { return (x + MOD - r.x) % MOD; }
	modll operator-=(const modll &r) { return x = (x + MOD - r.x) % MOD; }
	modll operator*(const modll &r) { return (x * r.x) % MOD; }
	modll operator*(int r) { return (x * r) % MOD; }
	modll operator*=(const modll &r) { return x = (x * r.x) % MOD; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

int main(int argc, char *argv[])
{
	int n, m;
	cin >> n >> m;
	int mx = sqrt(m);
	vector<int> b;
	for (int i = 2; i <= mx; ++i) {
		if ((m % i) == 0) {
			int cnt = 0;
			while ((m % i) == 0) {
				++cnt;
				m /= i;
			}
			b.push_back(cnt);
		}
	}
	if (m > 1) {
		b.push_back(1);
	}
	modll ans = 1;
	for (int x : b) {
		ans *= combination(x + n - 1, x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+10;
const double inf=1000;
typedef long long ll;
typedef pair<int,int>pr;
const int mod=1000000007;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a;
        a=a*a;
        b>>=1;
    }
    return ans;
}
ll gcd(ll a,ll b){
    if(!b) return a;
    else return gcd(b,a%b);
}


int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin>>t;
  int s1=0,s2=0,s3=0,s4=0;
  while(t--){
    string s;
    cin>>s;
    if(s=="AC") s1++;
    else if(s=="WA") s2++;
    else if(s=="TLE") s3++;
    else s4++;
  }
  cout<<"AC x "<<s1<<endl<<"WA x "<<s2<<endl<<"TLE x "<<s3<<endl<<"RE x "<<s4<<endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,d,i,j,k,wa,x,kotae=0;
  cin>>n>>d;
  int a[n][d];
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      cin>>a[i][j];
    }
  }
  for(i=0;i<n-1;i++){
    for(k=i+1;k<n;k++){
      wa=0;
      for(j=0;j<d;j++){
        wa+=(a[i][j]-a[k][j])*(a[i][j]-a[k][j]);
      }
      x = (int)sqrt((double)wa); /* Nの平方根を求めint型に格納することで小数部分を捨てる。 */
if (x*x == wa) { /* a^2 と nが等しければ平方数と判断する */
kotae++;
}
    }
  }
  cout<<kotae;
}
  


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

using namespace std;
const int N = 200100;
int dp[N],n;
const int Mod = 998244353;
pair < int , int > a[N];

int Add_self(int &x , int y){
    x = (x + y)%Mod;
}

int Next[N];

int Rec(int i){

    if(i >= n)  return 1;

    if(dp[i] != -1)  return dp[i];

    int Res = 0;

    Add_self(Res , Rec(i + 1) + Rec(Next[i]));

    return dp[i] = Res;
}

int x[200100],Seg[N * 4];

void Update(int i , int v , int p = 1, int L = 1, int R = N)
{
    if (i < L || i > R) return;
    if (L == R)
    {
        Seg[p] = v;
        return;
    }
    int mid = (L + R)/2;
    Update(i , v , p * 2, L, mid);
    Update(i , v , p * 2 + 1, mid + 1, R);

    Seg[p] = max(Seg[p * 2] , Seg[p * 2 + 1]);
}

int Query(int i, int j, int p = 1, int L = 1, int R = N)
{
    if (L > j || R < i) return 0;
    if (L >= i && R <= j)
        return Seg[p];

    int mid = (L + R)/2;
    return max(Query(i, j, p * 2, L, mid) , Query(i, j, p * 2 + 1, mid + 1, R));
}


int main()
{
    memset(dp , -1 , sizeof(dp));
    cin >> n;
    for(int i = 0;i<n;i++)  cin >> a[i].first >> a[i].second;
    sort(a , a + n);
    for(int i = 0;i<n;i++)  x[i] = a[i].first;
    for(int i = n - 1;i>=0;i--){
        int y = lower_bound(x + i , x + n , a[i].first + a[i].second) - &x[0];
        if(y == n){
            Next[i] = n;
        }
        else {
            if(x[y] == a[i].first + a[i].second){
                Next[i] = max(y , Query(i + 2, y));
            }
            else {
                Next[i] = max(i + 1 ,  Query(i + 2, y));
            }
        }
        if(i < n - 1) Update(i + 1, Next[i]);
    }
    cout << Rec(0);
    return 0;
}


Measured memory_bytes: 13568
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for _ in range(n):
    a = list(map(int, input().split()))
    t = 0
    for i in range(m):
        t += a[i]*b[i]
    if (t + c) > 0:
        ans += 1
print(ans)


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

int main(){
    long long int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0;i<=n;i++){
        for(int j = 0;j<=m;j++){
            long long int temp = i * m + j * n - i * j * 2;
            if(temp == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main () {
  string cards;
  int m, h;
  int i;

  while (1) {
    cin >> cards;
    if (cards == "-") break;
    cin >> m;
    rep(i,m) {
      cin >> h;
      cards = cards.substr(h,cards.length()) + cards.substr(0,h);
    }
    cout << cards << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N, D; cin >> N >> D;
    int X[15][15];
    rep(i, N) {
        rep(j, D) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N ; j++) {
            double dist = 0;
            rep(k, D) {
                dist += (double)(X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            dist = sqrt(dist);
            if(ceil(dist) == floor(dist)) ans ++;
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll MAX = 1e7 + 20;
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              "\n"

template< class T > T gcd(T a, T b)
{
    return (b != 0 ? gcd<T>(b, a%b) : a);
}
template< class T > T lcm(T a, T b)
{
    return (a / gcd<T>(a, b) * b);
}

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b,c,d;
    cin>>a;
    cout<<a*a<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n], b=0;
	rep(i, n){
		cin>>a[i];
		if(a[i]%2==0){
			if(a[i]%6!=0 && a[i]%10!=0){
				b=1;
			}
		}
	}
	if(b==1)
		cout<<"DENIED"<<endl;
	else
		cout<<"APPROVED"<<endl;
	return 0;
}


Measured memory_bytes: 256