akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 200100;
ld A[mxn];
ll B[mxn];

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

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

	for(int i=0; i<n; i++) {
		B[i] = llround(A[i]*1e9);
		//cout << B[i] << '\n';
	}

	map<pair<int, int>, int> f;

	for(int i=0; i<n; i++) {
		int cnt2 = 0; while(B[i]%2==0) B[i]/=2, cnt2++;
		int cnt5 = 0; while(B[i]%5==0) B[i]/=5, cnt5++;
		cnt2-=9; cnt5-=9;
		f[make_pair(cnt2, cnt5)]++;
	}
	ll ans = 0;
	for(auto it = f.begin(); it!=f.end(); it++) {
		for(auto it2 = it; it2!=f.end(); it2++) {
			if(it2==it) {
				if(it->first.first>=0 and it->first.second>=0) {
					ans+=1ll*(it->second-1)*it->second/2;
				}
				continue;
			}
			if(it->first.first+it2->first.first>=0 and it->first.second+it2->first.second>=0)
				ans+=1ll*it->second*it2->second;
		}
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 7860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n, m,a,sum=0,p;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        cin>>a;
        sum+=a;
    }
    p=n-sum;
    if(p>0)
        cout<<p<<endl;
    else if(p==0)
        cout<<0<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	printf("%d %d %.5f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;



int main()
{
    int n,r=0;
    cin>>n; int v[n];int c[n];
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=0;i<n;i++)
        cin>>c[i];
    for(int i=0;i<n;i++)
        if ((v[i]-c[i])>0)
            r+=(v[i]-c[i]);
    cout<<r;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
#include <assert.h>
using namespace std;

const unsigned long long MOD = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

int main()
{
    int n;
    cin >> n;
    int diff = 0;
    FROM_0(i, n)
    {
        int x;
        cin >> x;
        diff += x == i + 1 ? 0 : 1;
    }
    cout << (diff == 0 || diff == 2 ? "YES" : "NO") << endl;
    return 0;
}


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

int main(){
    int a, b, k;
    cin >> a >> b;
 
    k = a + (b - a) / 2;
    if ((b - a) % 2 != 0){
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << k;
    }
    return 0;
}

Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000
#define MOD 1000000007

string fun(long long n) {
	if (n == 0) {
		return "0";
	}	
	if (n == 1) {
		return "1";
	}
	else if(n == 2) {
		return "11";
	}
	else if(n == 3) {
		return "00";
	}
	else if(n == 4) {
		return "100";
	}

	long long p = log2(n);
	long long leastpow = pow(2,p);

	if((n - leastpow) % 2 == 1) {
		string s = "0";
		string t = fun(n - leastpow);

		for (int i = 0; i < p - t.size(); ++i) {
			s += "0";
		}
		
		return s + t;
	}
	else {
		string s = "1";
		string t = fun(n - leastpow);

		for (int i = 0; i < p - t.size(); ++i) {
			s += "0";
		}
		
		return s + t;
	}
}

long long XOR(string a, string b) {
	string s = "", t = "";

	for (int i = 0; i < a.size() - b.size(); ++i) {
		t += "0";
	}
	
	b = t + b;


	for (int i = 0; i < a.size(); ++i) {
		if (a[i] != b[i]) {
			s += "1";
		}
		else {
			s += "0";
		}
	}
	
	long long num = 0;

	for (int i = s.size() - 1; i >= 0; --i) {
		if(s[i] == '1') {
			num += pow(2,s.size() - 1 - i);
		}
	}

	return num;
}

int main() {
	long long a, b;

	cin >> a >> b;

	if (a > 1) {
		cout <<	XOR(fun(b), fun(a - 1));
	}
	else {
		cout << XOR(fun(b),"0");
	}
	return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000001000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<pair<int, int>> G[SIZE];
bool visited[SIZE];
bool diff[SIZE];
vector<int> ans;

bool dfs(int now, int e = -1) {
  if (visited[now]) return false;
  visited[now] = true;

  bool f = diff[now];

  for (auto p : G[now]) {
    f ^= dfs(p.first, p.second);
  }

  if (e >= 0 && f) ans.push_back(e);

  debug(now);
  debug(diff[now]);
  debug(e);
  debug(f);

  return f;
}

int main() {
  int N, M;
  pair<int, int> bombs[SIZE], codes[SIZE];
  vector<pair<int, int>> vec;
  int groups[SIZE];

  scanf("%d%d", &N, &M);

  for (int i = 0; i < N; i++) {
    int A, B;
    scanf("%d%d", &A, &B);
    bombs[i] = {A, B};
  }

  sort(bombs, bombs + N);
  bombs[N] = {INF, 0};

  for (int i = 0; i < M; i++) {
    int L, R;
    scanf("%d%d", &L, &R);
    R++;
    codes[i] = {L, R};
    vec.push_back({L, i});
    vec.push_back({R, i});
  }

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

  int t = 0;
  bool prev = false;

  for (int i = 0; i < M; i++) groups[i] = -1;

  for (int i = 0; i <= N; i++) {
    while (t < M * 2 && vec[t].first <= bombs[i].first) {
      int idx = vec[t].second;
      debug(idx + 1);
      if (groups[idx] == -1) {
        groups[idx] = i;
      } else {
        G[groups[idx]].push_back({i, idx});
        G[i].push_back({groups[idx], idx});
      }
      t++;
    }
    diff[i] = prev != !!bombs[i].second;
    prev = bombs[i].second;

    debug(diff[i]);
    debug("---");
  }

  for (int i = 0; i < N; i++) {
    bool res = dfs(i);

    if (res) {
      cout << "-1" << endl;
      return 0;
    }
  }

  printf("%d\n", (int)ans.size());

  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d", ans[i] + 1);
    if (ans.size() != i + 1) printf(" ");
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 20972
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))

    ans = a[0]

    for i in range(1, n):
        ans = gcd(ans, a[i])

    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
	int a[5];
	rep(i,5) cin >> a[i];
	int dmax = 0;
	int idmax = 4;
	rep(i,5){
		int d = 10*ceil(0.1*a[i]) - a[i];
		if (d>dmax) {
			dmax = d;
			idmax = i;
		}
	}
	int tmp = a[idmax];
	a[idmax] = a[4];
	a[4] = tmp;

	int ans = 0;
	rep(i,4) {
		ans = 10*ceil((ans+a[i])/10.0);
	}
	ans += a[4];
	cout << ans << endl;

		return 0;
}


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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n; cin >> n;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];
	reverse(all(v));
	rep(i, n) {
		cout << v[i];
		if (i < n - 1)cout << " ";
		else cout << endl;
	}
}


Measured memory_bytes: 3136
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
money = 0
num = 0
for i in range(n):
    if num + ab[i][1] > m:
        break
    money += ab[i][0] * ab[i][1]
    num += ab[i][1]
print(money + (m-num) * ab[i][0])

Measured memory_bytes: 27348
"""
author : halo2halo
date : 10, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a = int(readline().decode('utf8'))
s = read().decode('utf8').rstrip()
print('red' if a < 3200 else s)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const ll inf = (ll) 1e18;

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

  int n;
  cin >> n;
  vector<int> d(n);
  for (auto &x: d) cin >> x;

  ll score = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      score += d[i] * d[j];
    }
  }

  cout << score << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2020;
int a[N];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  ordered_set<pair<int, int>> os;
  //order_of_key returns index of this element if it was inserted.
  int n;
  cin >> n;
  for (int i=1; i<=n; ++i) {
    cin >> a[i];
    os.insert({a[i], i});
  }
  ll ans = 0;
  for (int i=1; i<=n; ++i) {
    for (int j=i+1; j<=n; ++j) {
      int u = a[i];
      int v = a[j];
      int lo = abs(u-v);
      int hi = u+v;
      int beg = os.order_of_key({lo, 1e9});
      int fin = os.order_of_key({hi-1, 1e9});
      if (lo >= u) {
        beg--;
      }
      if (lo >= v) {
        beg--;
      }
      if (hi > u) {
        fin--;
      }
      if (hi > v) {
        fin--;
      }
      if (fin < beg) {
        continue;
      }
      ans +=fin-beg;
    }
  }
  assert(ans%3 == 0);
  cout << ans/3 << endl;
  return 0;
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

string s;
signed main() {
  cin>>s;
  cout<<s.substr(0,4)<<" "<<s.substr(4,8)<<endl;
}


Measured memory_bytes: 256
N,A,B,C,D = map(int,input().split())
S = input()

def test(x,y):
  # xからyへ行ける
  substr = S[x:y-1]
  return substr.find('##') == -1

bl = test(A,C) and test(B,D)
if C > D:
  # 追い越す必要がある
  # 道の存在は保証されているので、局所的に詰まないようにBを配置できればよい
  can_swap = False
  for b in range(B-1,D):
    if S[b] == '#':
      continue
    if S[b-1] == '.' and S[b+1] == '.':
      can_swap = True
      break
  bl = bl and can_swap
answer = 'Yes' if bl else 'No'
print(answer)


Measured memory_bytes: 3636
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
 
using namespace std;
 
 
#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

char ch[10][10];
int h ,w ;
int main(){
        scanf("%d%d",&h, &w);
        for(int i=0;i<h;i++){
                scanf("%s",ch[i]);
        }
        bool ans = true;
        int last_idx= 0;
        for(int i=0;i<h;i++){
                int maxidx=-1;
                for(int j=0;j<w;j++){
                        if(ch[i][j]=='#'){
                                //cout<< i <<" "<<j <<" "<<last_idx<<endl;
                                if(j<last_idx) ans = false;
                                if(maxidx>=0 and j-maxidx!=1) ans =false;
                                maxidx=max(maxidx,j);
                        }
                }
                last_idx=maxidx;
        }
        if(ans){
                printf("Possible\n");
        }else{
                printf("Impossible\n");
        }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        
        int b = scan.nextInt();
        
        System.out.print(a * b);
        
        System.out.print(" ");

        System.out.println(2 * (a + b));
    }
}


Measured memory_bytes: 26032
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  ll ans = 0;
  ll cnt;

  rep2(i, 1, N + 1){
    if(i % 2 == 0) continue;

    cnt = 0;

    rep2(j, 1, i + 1){
      if(i % j == 0) cnt++;
    }

    if(cnt == 8) ans++;
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
cnt1=0
cnt2=0
for i in range(n):
  if arr[i]%4==0:
    cnt1+=1
  elif arr[i]%2==0:
    cnt2+=1
if cnt1*2>=n-1:
  print('Yes')
else:
  n-=(cnt1*2)
  if cnt2>=n:
    print('Yes')
  else:
    print('No')

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
using vi  = vector<int>;
using vvi = vector<vi>;
constexpr int inf = 1<<30;
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;}

vvi f;

int calc_min(int x, int y, int h, int w){
  int minv = inf;
  FOR(i,x,x+h+2){
    chmin(minv, f[i][y]);
    chmin(minv, f[i][y+w+1]);
  }
  FOR(j,y,y+w+2){
    chmin(minv, f[x][j]);
    chmin(minv, f[x+h+1][j]);
  }
  return minv;
}
int calc_max(int x, int y, int h, int w){
  int maxv = -inf;
  FOR(i,x+1,x+h+1) FOR(j,y+1,y+w+1)
    chmax(maxv, f[i][j]);
  return maxv;
}
int calc_cap(int x, int y, int h, int w, int minv){
  int ans = 0;
  FOR(i,x+1,x+h+1) FOR(j,y+1,y+w+1)
    ans += minv - f[i][j];
  return ans;
}

int main(){
  int a, b;
  while(cin >> a >> b, a){
    f.clear();
    f.resize(a, vi(b,0));
    rep(i,a) rep(j,b) cin >> f[i][j];

    int ans = 0;
    FOR(x,0,a-1) FOR(y,0,b-1){ // 枠の左上の点
      FOR(h,1,a-x-1) FOR(w,1,b-y-1){ // 水の幅
	int minv = calc_min(x,y,h,w);
	if(minv <= calc_max(x,y,h,w)) continue;
	chmax(ans, calc_cap(x,y,h,w,minv));
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3072
from collections import Counter,OrderedDict
n=int(input())
s=[ input() for idd in range(n)]
alf=list("abcdefghijklmnopqrstuvwxyz")
ans=OrderedDict()
for idd in alf:
  ans[idd]=1000
for idd in s:
  sl=list(idd)
  sl=OrderedDict(Counter(sl))
  for jdd in alf:
    if not (jdd in sl):
      ans[jdd]=0
    elif ans[jdd]>sl[jdd]:
      ans[jdd]=sl[jdd]
s=""
for idd in ans:
  if ans[idd]!=0:
    s+=str((idd*int(ans[idd])))
print(s)

Measured memory_bytes: 3316
def getInts():
    return [ int(x) for x in input().split() ]

[N,M] = getInts()
H = getInts()
G = {}
for i in range(1,N+1):
    G[i] = set()
As = []
Bs = []
for i in range(M):
    [A,B] = getInts()
    G[A].add(B)
    G[B].add(A)

goodCount = 0
for i in range(1,N+1):
    if all([ H[nei-1] < H[i-1] for nei in G[i] ]):
        goodCount += 1
print(goodCount)


Measured memory_bytes: 54176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define dloop(i,a,b) for(ll i=a;i>=b;--i)
#define all(a) a.begin(),a.end()
#define lar 1000000007
#define pq priority_queue
#define pll pair<ll,ll>
#define ss second
#define ff first
#define pb push_back
#define ppb pop_back
#define umap unordered_map
#define ub upper_bound
#define lb lower_bound
#define br "\n"
#define sp " "

void solve(){
   ll n;
   cin>>n;
   cout<<!n<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int h, m, H, M, k;
  cin >> h >> m >> H >> M >> k;

  int ans = (H - h) * 60 + (M - m) - k;

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
xs = 'keyence'.split('')
c = 0
ARGF.each { |l|
  if l =~ /^keyence$/ or l =~ /^k.*eyence$/ or l =~ /^ke.*yence$/ or l =~ /^key.*ence$/ or l =~ /^keye.*nce$/ or l =~ /^keyen.*ce$/ or l =~ /^keyenc.*e$/ or l =~ /^keyence.*$/
    puts 'YES'
    exit
  end
}
puts 'NO'


Measured memory_bytes: 1788
#include<stdio.h>
#include<iostream> 
#include<string>
#include<sstream>
#include<fstream>
#include<vector>
using namespace std;

int main(){
 int N,M,C,X=0,a=0;
 cin>>N;
 cin>>M;
 cin>>C;

 int B[M],A[N][M];
 
 for(int i=0;i<M;i++){
 	 cin>>B[i];
 }
 
 for(int i=0;i<N;i++){
 	 X=C;
 	 for(int j=0;j<M;j++){
 	 	 cin>>A[i][j];
 	 	 X += A[i][j]*B[j];
 	 }
	if(X>0){a++;}
 }
 
 printf("%d",a);




}


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

int main() {
string s; 
  cin>>s;
  
  int st1=0;
  int st0=0;
  for(int i=1;i<=s.size();i++){
    if(i%2==1){
      if(s[i-1]=='0'){st1++;}
      else st0++;
    }
     if(i%2==0){
      if(s[i-1]=='1'){st1++;}
      else st0++;
     }
  }
  cout<<min(st1,st0)<<endl;

  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_V 100000

struct edge { int to; ll cost; };

int V;//頂点数
vector<edge> G[MAX_V];//辺の張り方 : G[from].push_back((edge){to, cost});
ll d[MAX_V];
bool seen[MAX_V];

void DFS(int now, ll cost){
    d[now] = cost;
    seen[now] = true;
    for(int i = 0; i < G[now].size(); i++){
        if(seen[G[now][i].to] == false){
            DFS(G[now][i].to, cost + G[now][i].cost);
        }
    }
    return;
}

signed main(){
    cin >> V;
    int a,b;
    ll c;
    REP(i,V - 1){
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back((edge){b, c});
        G[b].push_back((edge){a, c});
    }
    int q,k;
    cin >> q >> k;
    k--;
    DFS(k, 0);
    int x[q],y[q];
    REP(i,q){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    REP(i,q){
        cout << d[x[i]] + d[y[i]] << endl;        
    }
}

Measured memory_bytes: 14592
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;

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

	int left[100002],right[100002];
	memset(left,0,sizeof(left));
	memset(right,0,sizeof(right));

	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		left[a]++;right[b]++;
	}

	int before=left[2];
	int ans=0;
	if(left[2]>=1) ans=1;

	for(int num=3;num<=N+1;num++){
		int now=before+left[num]-right[num-1];
		if(now>=num-1) ans=max(ans,num-1);
		before=now;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1612
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a == c) cout << 0 << endl;
    else cout << 1 << endl;
}

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

const int inf = 1000000;

int main()
{
	int n, e, t;
	vector<int> w;
	vector<pair<int, vector<int> > > gcs;

	scanf("%d%d%d", &n, &e, &t);
	t -= 1;
	w.resize(n);
	gcs.resize(e);
	for(int i = 0; i < n; ++i)
		scanf("%d", &w[i]);
	for(int i = 0; i < e; ++i) {
		int size;
		scanf("%d%d", &gcs[i].first, &size);
		gcs[i].first -= 1;
		gcs[i].second.resize(size);
		for(int j = 0; j < size; ++j) {
			scanf("%d", &gcs[i].second[j]);
			gcs[i].second[j] -= 1;
		}
	}

	vector<int> mini(n);

	for(int i = 0; i < n; ++i)
		mini[i] = w[i] == 0 ? inf : 1;

	while(true) {

		bool update = false;

		for(auto &law : gcs) {

			int dest = law.first;
			vector<int> &src = law.second;

			bool ok = true;
			for(auto k : src)
				ok = ok && mini[k] < inf;
			if(!ok)
				continue;

			int ca = 1;
			static vector<int> count(n + 1);

			fill(count.begin(), count.end(), 0);
			for(auto k : src)
				count[mini[k]] += 1;
			for(int i = n; i > 0; --i)
				count[i - 1] += count[i];

			for(auto k : src)
				ca = max(ca, count[mini[k]] - 1 + mini[k]);

			if(mini[dest] > ca) {
				mini[dest] = ca;
				update = true;
			}
		}

		if(!update)
			break;
	}

	int ans = mini[t] < inf ? mini[t] : -1;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1092
#include <stdio.h>

int main(){

	int a,b;

	scanf("%d",&a);
	scanf("%d",&b);

	if(a>9){
		printf("-1");
	}else if(b>9){
		printf("-1");
	}else{
		printf("%d",a*b);
	}
	
	return 0;

}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n, m := uint64(nextInt()), uint64(nextInt())
	if n == 1 && m == 1 {
		fmt.Println(1)
		return
	} else if n == 1 || m == 1 {
		fmt.Println(max(int(n), int(m)) - 2)
		return
	}

	outer := (n-2)*2 + m*2
	inner := n*m - outer
	fmt.Println(inner)

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a

}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>

bool c2(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}
int main()
{
    ll res=0,N,W,w1,sum1[101],sum2[101],sum3[101],sum4[101];
    pair<ll,ll> wv[101];
    vector<ll> g1,g2,g3,g4;
    cin >> N >> W;
    rep(i,N)cin >> wv[i].first >> wv[i].second;
    w1 = wv[0].first;
    rep(i,N){
        if(wv[i].first -w1 == 0){
            g1.push_back(wv[i].second);
        }else if(wv[i].first - w1 == 1){
            g2.push_back(wv[i].second);
        }else if(wv[i].first - w1 == 2){
            g3.push_back(wv[i].second);
        }else
            g4.push_back(wv[i].second);
    }
    sort(g1.rbegin(),g1.rend());
    sort(g2.rbegin(),g2.rend());
    sort(g3.rbegin(),g3.rend());
    sort(g4.rbegin(),g4.rend());

    sum1[0] = 0;sum2[0] = 0;sum3[0] = 0;sum4[0] = 0;
    rep(i,g4.size()){sum4[i+1] = sum4[i] + g4[i];}
    rep(i,g3.size()){sum3[i+1] = sum3[i] + g3[i];}
    rep(i,g2.size()){sum2[i+1] = sum2[i] + g2[i];}
    rep(i,g1.size()){sum1[i+1] = sum1[i] + g1[i];}

    rep(i,g4.size()+1){
        rep(j,g3.size()+1){
            rep(k,g2.size()+1){
                rep(l,g1.size()+1){
                    if((w1)*(l)+(w1+1)*(k)+(w1+2)*(j)+(w1+3)*(i) <= W){
                        res = max(res,sum1[l]+sum2[k]+sum3[j]+sum4[i]);

                    }

                }
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
const int N = 100010;
int h[N];
struct edge{
	int v;
	int next;
}e[2*N];
int p[N],eid;
void init(){
	memset(p,-1,sizeof(p));
	eid=0;
}
void insert(int u,int v){
	e[eid].v=v;
	e[eid].next=p[u];
	p[u]=eid++;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	init();
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		insert(u,v);
		insert(v,u);
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		int maxn=-1;
		for(int j=p[i];j!=-1;j=e[j].next){
			int v=e[j].v;
			maxn=max(maxn,h[v]);
		}
		if(h[i]>maxn){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 5956
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n;
  int a[100001];
  scanf("%d",&n);
  for(int i =0;i<n;i++){
    scanf("%d\n",&a[i]);
  }

  int allmoney=0;
  int temp=0;
  for(int i=0;i<n;i++){
    allmoney+=abs(a[i]-temp);
    temp=a[i];
  }
  allmoney+=abs(0-a[n-1]);

  for(int i=0;i<n;i++){
    if(i==0){
      int ans=allmoney+abs(a[1])-abs(a[0])-abs(a[1]-a[0]);
      printf("%d\n", ans);
    }
    else if(i==n-1){
      int ans=allmoney+abs(a[n-2])-abs(a[n-2]-a[n-1])-abs(a[n-1]);
      printf("%d\n", ans);
    }
    else{
          int ans=allmoney+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i+1]-a[i]);
          printf("%d\n", ans);
        }
  }

  return 0;
}

Measured memory_bytes: 1536
import sys
import numpy as np


def main():
    s = input()
    snotx = s.replace('x', '')
    if snotx != snotx[::-1]:
        print(-1)
        sys.exit()
    ans = 0
    ileft = 0
    iright = len(s) - 1
    while ileft < iright:
        if s[ileft] != s[iright]:
            if s[ileft] == 'x':
                ans += 1
                ileft += 1
            elif s[iright] == 'x':
                ans += 1
                iright -= 1
            else:
                print("Error!")
                sys.exit()
        else:
            ileft += 1
            iright -= 1
    print(ans)



main()


Measured memory_bytes: 12508
#include <iostream>
using namespace std;
int main(void){
    int n, left = 0, ans[100000];
    string s;
    cin >> s;
    n = s.length();
    fill(ans, ans+n, 0);
    for(int i=0;i<n-1;i++){
        if(s[i] == 'R' && s[i+1] == 'L'){
            int right = i+1, t;
            while(right < n-1 && s[right+1] == 'L'){
                right++;
            }
            t = i - left + 1;
            ans[i] += (t+1)/2;
            ans[i+1] += t/2;
            t = right - i;
            ans[i] += t/2;
            ans[i+1] += (t+1)/2;
            left = right+1;
            i = right;
        }
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <math.h>

using namespace std;

int main()
{
  long long N, A, B;
  cin >> N >> A >> B;

  long long div = N / (A + B);
  long long rest = N % (A + B);
  long long rest_bule = rest > A ? A : rest;

  cout << div * A + rest_bule << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
pair<ll,P> p[100000];
int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i].second.first >> p[i].second.second;
    p[i].first=p[i].second.first+p[i].second.second;
  }
  sort(p,p+n);
  ll tsum=0,asum=0;
  for(int i=0;n-2*i-2>=0;i++){
    int a=p[n-2*i-1].second.first;
    int b=p[n-2*i-2].second.second;
    tsum+=a;
    asum+=b;
  }
  if(n%2==1) tsum+=p[0].second.first;
  cout << tsum-asum << "\n";
  return 0;
}


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

using namespace std;

typedef long long int ll;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	
	int r, d, x;
	
	cin >> r >> d >> x;
	
	for(int i = 2000; i < 2010; i++){
		cout << r * x - d << endl;
		x = r * x - d;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> a(n), b(n);
    map<int, int> mp;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]] = i%2;
        b[i] = a[i];
    }

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

    int ans = 0;
    rep(i, n) {
        if(mp[b[i]] != i%2) {
            ans++;
        }
    }

    if(ans%2 == 0) {
        ans /= 2;
    }   
    /*else {
        ans /= 2;
        ans++;
    }*/

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
import bisect

def PRIME(N):
    LIM = int(N**0.5)+2
    for i in range(2, LIM):
        if N%i == 0:
            return False
    return True

q = int(input())
prime, ans = {2:True}, []
for i in range(3, 100001):
    if i%2 == 0:
        prime[i] = False
        continue
    a = PRIME(i)
    prime[i] = a
    if a:
        if prime[(i+1)//2]:
            ans.append(i)

for _ in range(q):
    l, r = map(int, input().split())
    L = bisect.bisect_left(ans, l)
    R = bisect.bisect_right(ans, r)
    print(R-L)

Measured memory_bytes: 15128
def solve():
    N, W = map(int, input().split())
    weight = []
    value = []
    for i in range(N):
        tmpw, tmpv = map(int, input().split())
        weight.append(tmpw)
        value.append(tmpv)
    
    dp = [[0] * (W+1) for i in range(N+1)]
    for i in range(N):
        for w_i in range(W+1):
            if w_i - weight[i] >= 0:
                dp[i+1][w_i] = max(dp[i+1][w_i], dp[i][w_i - weight[i]] + value[i])
            
            dp[i+1][w_i] = max(dp[i+1][w_i], dp[i][w_i])

    print(dp[N][W])
if __name__ == '__main__':
    solve()


Measured memory_bytes: 118896
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int H, W;
    int h, w;
 
    while (1) {
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0) break;
        for (h = 0; h < H; h++) {
            for (w = 0; w < W; w++) putchar('#');
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s, t;
    cin >> s >> t;
    int length = s.length();
    int l = t.length();
    int ans=0;
    int mini = 10000;
    for (int i = 0; i <= length-l; ++i){
        for (int j = 0; j < l; ++j){
            if(s[j+i] != t[j]){
                ++ans;
            }
        }
        mini = min(ans, mini);
        ans = 0;
    }
    
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 3612
import scala.util.control.Breaks._
object Main extends App {
  val Array(a, b) = io.StdIn.readLine().split(' ').map(_.toInt)
  var answer = -1
  breakable {
    for (n <- 1 to 1000) {
      val (ta, tb) = ((n * 0.08).toInt, (n * 0.1).toInt)
      if (ta == a && tb == b) {answer = n; break()}
      if (ta > a || tb > b) break()
    }
  }
  println(answer)
}

Measured memory_bytes: 27332
#include <iostream>
using namespace std;
string s;
int cloud[100],h,w;
int main(){
	cin  >> h>>w;
	
	for(int i=0;i<h;i++){
		cin >>s;
		for(int i=0;i<w;i++){
			cloud[i]=-1;
		}
		for(int j=0;j<w;j++){
			if(s[j]=='c'){
				for(int k=j;k<w;k++){
					cloud[k]=k-j;
				}
			}
			if(j!=w-1)cout <<cloud[j] <<" ";
		}
		cout << cloud[w-1]<<endl;
	}
	
	return 0;
}

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

#define MAX_N 100001

vector<pair<int, int> > adj[MAX_N];
int64_t dis[MAX_N];
bool vis[MAX_N];

void dfs(int v)
{
    vis[v] = true;
    for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].first;
        int w = adj[v][i].second;
        if (!vis[u]) {
            dis[u] = dis[v] + w;
            dfs(u);
        }
    }
}

int main()
{
    int n, k, q;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        adj[a].push_back(make_pair(b, c));
        adj[b].push_back(make_pair(a, c));
    }
    scanf("%d%d", &q, &k);
    dfs(k);
    while (q--) {
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%lld\n", dis[x] + dis[y]);
    }
    return 0;
}

Measured memory_bytes: 12800
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
    long N, Y;
    cin >> N >> Y;
    long k, sum, a, b, c;
    bool finished = false;
    for (long i = 0; i < N + 1; i++) {
        for (long j = 0; j < N - i + 1; j++) {
            k = N - i - j;
            sum = 10000 * i + 5000 * j + 1000 * k;
            if (sum == Y) {
                finished = true;
                a = i;
                b = j;
                c = k;
                break;
            }
            if (Y < i + j) {
                break;
            }
        }
        if (finished) {
            break;
        }
    }
    if (!finished) {
        a = -1;
        b = -1;
        c = -1;
    }
    cout << a  << " " << b  << " " << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < (int)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int four = 0, two = 0;
    int n;
    cin >> n;

    rep(i, n) {
        int a;
        cin >> a;
        if (a % 4 == 0) four++;
        else if (a % 2 == 0) two++;
    }

    if (two > 0) Yes(two + four * 2 >= n);
    else Yes(four * 2 + 1 >= n);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define in(e,l) (std::find(l.begin(), l.end(), e) != l.end())
#define asort(l) (std::sort(l.begin(), l.end()))
#define dsort(l) (std::sort(l.rbegin(), l.rend()))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;

int main() {
  ll N, M;
  cin >> N >> M;
  v(ll) H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  vector<set<ll>> h(N);
  for (int i = 0; i < M; ++i) {
    ll j, k;
    cin >> j >> k;
    h[j-1].insert(H[k-1]);
    h[k-1].insert(H[j-1]);
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    if (h[i].size() == 0) {
      ++ans;
      continue;
    }
    auto itr = h[i].end();
    --itr;
    ll t = *itr;
    if (t != H[i] && max(t, H[i]) == H[i]) ++ans;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 18040
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <complex>
#include <string>
#include <sstream>
#include <iomanip>
#include <climits>
#include <functional>
#include <bitset>
#include <tuple>

using namespace std;

typedef long long ll;

int H;
const int W = 5;

int Dfs(int y, int x, int c, vector<vector<int>> &board) {
    if (x >= W || board[y][x] != c)
        return 0;
    return Dfs(y, x + 1, c, board) + 1;
}

int main()
{
    while (cin >> H, H) {
        vector<vector<int>> board(H, vector<int>(W, 0));

        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                cin >> board[i][j];

        int ans = 0;
        bool change = true;

        while (change) {
            change = false;

            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if (board[i][j] == 0)
                        continue;
                    int cnt = Dfs(i, j, board[i][j], board);
                    if (cnt >= 3) {
                        ans += cnt * board[i][j];
                        for (int k = 0; k < cnt; ++k)
                            board[i][j + k] = 0;
                        change = true;
                    }
                }
            }

            if (!change)
                break;

            for (int j = 0; j < W; ++j) {
                for (int i = H - 1; i >= 0; --i) {
                    if (board[i][j] == 0) {
                        int k = i - 1;
                        while (k >= 0 && board[k][j] == 0)
                            --k;
                        if (k < 0)
                            break;
                        swap(board[i][j], board[k][j]);
                    }
                }
            }
        }

        cout << ans << endl;
    }


    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;


    
int main(){
    int K, N;
    cin >> N >> K;
    vi A(N);
    REP(i,N){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    A.push_back(0);
    vi num;
    int count = 1;
    
    REPS(i,N){
        if(A[i]==A[i-1]) count++;
        else {
            num.push_back(count);
            count = 1;
        }
    }
    
    sort(num.begin(),num.end());
    reverse(num.begin(),num.end());
    int k = num.size();
    if(k<=K) cout << 0 << endl;
    else{
        int sum = 0;
        REP(i,K){
            sum += num[i];
        }
        
        cout << N-sum << endl;
    }
    
}


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

int main()
{
  int h, w;
  cin >> h >> w;
  int MX = 80 * (h + w);
  vector<vector<int>> a(h, vector<int>(w)), b(h, vector<int>(w));
  rep(i, h)
    rep(j, w)
      cin >> a[i][j];
  rep(i, h)
    rep(j, w)
      cin >> b[i][j];
  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(MX, false)));
  rep(i, h)
    rep(j, w)
    {
      int d = abs(a[i][j] - b[i][j]);
      if (i == 0 && j == 0)
        dp[i][j][d] = true;
      if (i != 0)
        rep(k, MX)
          if (dp[i-1][j][k])
          {
            dp[i][j][k+d] = true;
            dp[i][j][abs(k-d)] = true;
          }
      if (j != 0)
        rep(k, MX)
          if (dp[i][j-1][k])
          {
            dp[i][j][k+d] = true;
            dp[i][j][abs(k-d)] = true;
          }
    }
  rep(i, MX)
    if (dp[h-1][w-1][i])
    {
      printf("%d\n", i);
      return 0;
    }
  return 0;
}

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

using namespace std;

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

int64_t comb(int64_t n, int64_t k)
{
  int64_t p = 1, q = 1;
  N_TIMES(i, k) {
    p *= (n - i);
    q *= (i + 1);
  }
  return p / q;
}

int64_t power(int64_t x, int64_t y)
{
  if (y <= 1) { return (y == 0) ? 1 : x; }

  int64_t w = power(x, y >> 1);
  int64_t z = w * w;
  if ((y & 1) == 1) { z *= x; }

  return z;
}

int64_t dfs(const vector<int64_t> &N, int64_t K, int64_t L, int64_t i, int64_t k)
{
  if (k < 0) { return 0; }

  if (i == L) { return (k == 0) ? 1 : 0; }

  int64_t sum = 0;

  if (N[i] == 0) {
    sum += dfs(N, K, L, i + 1, k);
  } else if (N[i] == 1) {
    sum += dfs(N, K, L, i + 1, k - 1);

    int64_t remain_len = (L - 1) - i;
    if (remain_len >= k) {
      sum += comb(remain_len, k) * power(9, k);
    }
  } else {
    sum += dfs(N, K, L, i + 1, k - 1);

    int64_t remain_len = (L - 1) - i;
    int64_t p = N[i] - 1;

    if (k >= 1 && remain_len >= k - 1) {
      sum += p * comb(remain_len, (k - 1)) * power(9, k - 1);
    }

    if (k >= 0 && remain_len >= k) {
      sum += comb(remain_len, k) * power(9, k);
    }
  }
  
  return sum;
}

int main()
{
  string S;
  cin >> S;
  
  int64_t L = S.size();

  vector<int64_t> N(L);
  N_TIMES(i, L) { N[i] = S[i] - '0'; }

  int64_t K;
  cin >> K;

  int64_t ans = dfs(N, K, L, 0, K);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
typedef long long ll;

using namespace std;

int main(void)
{
    int a;
    cin >> a;

    int cnt = 0;

    while(1) {
        a = a-2;
        cnt++;
        if (a <= 0) {
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(self.n+1) # 1-indexed

    def init(self, init_val):
        for i, v in enumerate(init_val):
            self.add(i, v)

    def add(self, i, x):
        # i: 0-indexed
        i += 1 # to 1-indexed
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)

    def sum(self, i, j):
        # return sum of [i, j)
        # i, j: 0-indexed
        return self._sum(j) - self._sum(i)

    def _sum(self, i):
        # return sum of [0, i)
        # i: 0-indexed
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & (-i)
        return res

class RangeAddBIT:
    def __init__(self, n):
        self.n = n
        self.bit1 = BIT(n)
        self.bit2 = BIT(n)

    def init(self, init_val):
        self.bit2.init(init_val)

    def add(self, l, r, x):
        # add x to [l, r)
        # l, r: 0-indexed
        self.bit1.add(l, x)
        self.bit1.add(r, -x)
        self.bit2.add(l, -x*l)
        self.bit2.add(r, x*r)

    def sum(self, l, r):
        # return sum of [l, r)
        # l, r: 0-indexed
        return self._sum(r) - self._sum(l)

    def _sum(self, i):
        # return sum of [0, i)
        # i: 0-indexed
        return self.bit1._sum(i)*i + self.bit2._sum(i)

import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, d, a = map(int, input().split())
XH = []
for i in range(n):
    x, h = map(int, input().split())
    XH.append((x-d, h))
XH.sort()
X = []
H = []
for x, h in XH:
    X.append(x)
    H.append(h)

bit = RangeAddBIT(n+1)
bit.init(H)
import bisect
ans = 0
for i in range(n):
    h = bit.sum(i, i+1)
    if h > 0:
        q = (h+a-1)//a
        ans += q
        j = bisect.bisect_right(X, X[i]+2*d)
        bit.add(i, j, -q*a)
print(ans)


Measured memory_bytes: 120708
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int a,b;
  cin >> a >> b;
  int c = 1;
  int fa = a,fb = b;

  REP(i,pow(10,5)){
    if(a < i + 1 || b < i + 1){
      continue;
    }
    if(a % (i + 1)  == 0 && b % (i+1)  == 0){
      c *= i+1;
      a /= i+1;
      b /= i+1;
      i = 0;
    }
  }

  cout << c * a * b << endl;

  return 0;
}

Measured memory_bytes: 256