akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef long long  ll;

const int N = 100010;
int a[N], b[N];
char s[N];
map<pair<int, int> , int> myhash;
int ans;


int main() {
	int n, ans = 0, m;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	scanf("%d", &m);
	for (int i = 1; i <= n; i++) {
		char ch = s[i];
		int x;
		if (ch == 'a')
			x = 0;
		else
			x = 'z'- ch + 1;
		if (m >= x) {
			s[i] = 'a';
			m -= x;
		}
	}
	m %= 26;
	s[n] = s[n] + m;
	printf("%s\n", s + 1);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
    long x,a,b;
    scanf("%ld %ld %ld",&x,&a,&b);
    if(a>=b)
    {
        printf("delicious");
    }
    else if(a<b && a+x>=b)
    {
        printf("safe");
    }
    else
    {
        printf("dangerous");
    }
}


Measured memory_bytes: 128
#!/usr/bin/env python3
# GRL_5_B: Tree - Height of a Tree

import bisect


class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class WeightedEdge(Edge):
    __slots__ = ('v', 'w', 'weight')

    def __init__(self, v, w, weight):
        super().__init__(v, w)
        self.weight = weight


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


def heights(graph):
    def select_root():
        leaves = [v for v in range(graph.v) if len(graph.adj(v)) < 2]
        visited = [False] * graph.v
        while len(leaves) > 2:
            v, *leaves = leaves
            if not visited[v]:
                visited[v] = True
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        visited[w] = True
                        leaves.append(w)
        return leaves.pop()

    def dfs(s):
        visited = [False] * graph.v
        stack = [s]
        while stack:
            v = stack.pop()
            if not visited[v]:
                visited[v] = True
                stack.append(v)
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        edge_to[w] = e
                        stack.append(w)
            else:
                e = edge_to[v]
                if e is not None:
                    w = e.other(v)
                    bisect.insort(dists[w], (dists[v][-1][0] + e.weight, v))

    def _heights(s):
        hs = [0] * graph.v
        visited = [False] * graph.v
        stack = [s]
        while stack:
            v = stack.pop()
            if not visited[v]:
                visited[v] = True
                hs[v] = dists[v][-1][0]
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        for x, xv in reversed(dists[v]):
                            if xv != w:
                                bisect.insort(dists[w], (x + e.weight, v))
                                break
                        stack.append(w)
        return hs

    root = select_root()
    edge_to = [None] * graph.v
    dists = [[(0, i)] for i in range(graph.v)]
    dfs(root)
    return _heights(root)


def run():
    n = int(input())
    g = Graph(n)

    for _ in range(n-1):
        s, t, w = [int(i) for i in input().split()]
        g.add(WeightedEdge(s, t, w))

    for w in heights(g):
        print(w)


if __name__ == '__main__':
    run()



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

long long w[1<<20] = {0}, ans[1<<20];
vector<int> g[1<<20];

long long cur = 0;
void dfs(int u, int p) {
  cur += w[u];
  ans[u] = cur;
  for (int v : g[u]) if (v != p) {
    dfs(v, u);
  }
  cur -= w[u];
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, q; cin >> n >> q;
  for (int i = 1; i < n; ++i) {
    int a, b; cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  while (q--) {
    int p, x; cin >> p >> x;
    --p;
    w[p] += x;
  }
  dfs(0, 0);
  for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n - 1];
}


Measured memory_bytes: 46720
K, N = map(int, input().split())
A = list(map(int, input().split()))

distance = []
for i in range(1, N):
	distance.append(A[i] - A[i - 1])
distance.append((A[0] + K - (A[-1])))
most = max(distance)
output = K - most
print(output)

Measured memory_bytes: 26444
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]
    INF = 10**9


    N,M = LMIIS()
    keys = []
    for i in range(M):
        a,b = LMIIS()
        boxes = map(lambda x: int(x)-1, input().split())
        key = 0
        for b in boxes:
            key += 2**b
        keys.append((a,key))
        



    # 開けられる箱のパターン -> コスト
    dp = [INF] * 2 ** N
    dp[0] = 0

    for key_cost,key in keys:
        for box,cost in enumerate(dp):
            if cost != INF:
                dp[box|key] = min(dp[box|key], cost+key_cost)
    
    ans = dp[2**N-1]
    print(ans if ans != INF else -1)




    




if __name__ == '__main__':
    main()

Measured memory_bytes: 75364
#include "bits/stdc++.h"
using namespace std;
typedef long long int LL;
template<typename T> using V = vector<T>;
#define fi first
#define se second
#define pb push_back
#define fo(i, n) for (int i = 0; i < (int)(n); ++i)
#define fr(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ro(i, a, b)		for (int i = (a); i <= (int)(b); ++i)
#define all(x) (x).begin(), (x).end()
#define	SZ(x)	(int)x.size()
#define ii	pair< int, int >
#define iii pair< int, ii >
#define ret return 0;
const int INF = 1e9 + 5;
const int MOD = (int)1e9 + 7;
const int maxn = 1e5 + 5;
int modE(int n, int x){int res=1;while(x){if(x&1)res=(1ll*res*n)%MOD;n=(1ll*n*n)%MOD;x>>=1;}return res;}

int N, t;
V<int> a, b, c;

int main() {
// ios::sync_with_stdio(false), cin.tie(0);
cin >> N;
fo(i, N){
	cin >> t;
	a.pb(t);
}
fo(i, N){
	cin >> t;
	b.pb(t);
}
fo(i, N){
	cin >> t;
	c.pb(t);
}
sort(all(a)), sort(all(b)), sort(all(c));

LL ans = 0, aa, cc;
fo(i, N){
	int mid = b[i];
	aa = upper_bound(all(a), mid - 1) - a.begin();
	cc = upper_bound(all(c), mid) - c.begin();
	// cout << aa << ' ' << cc << endl;
	cc = N - cc;
	ans += 1ll * aa * cc;
}
cout << ans;

}

Measured memory_bytes: 1784
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

#kigen
x = int(arr_data[0][0])

#buy
a = int(arr_data[0][1])

#eat
b = int(arr_data[0][2])


if(a>=b):
    
    print("delicious")

elif(x+a>=b):
    
    print("safe")
    
else:
    
    print("dangerous")



Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define MAXN 100100
using namespace std;

deque<int>dq;
int ok[MAXN],n;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)ok[i]=INF;
	ok[1]=1;
	dq.push_back(1);
	while (!dq.empty())
	{
		int x=dq.front();dq.pop_front();
		if(ok[x]+1<ok[(x+1)%n])
		{
			ok[(x+1)%n]=ok[x]+1;
			dq.push_back((x+1)%n);
		}
		if(ok[x]<ok[(x*10)%n])
		{
			ok[(x*10)%n]= ok[x];
			dq.push_front((x*10%n));
		}
	}
	
	printf("%d\n",ok[0]);
	

	return 0;	
} 

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

int main(){
 
  int N;
  cin>>N;
  vector<string> S;
  string a;
  
  for(int i=0;i<N;i++){
    cin>>a;
    S.push_back(a);
  }
  
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  cout<<S.size()<<endl;
  
  return 0;
}

Measured memory_bytes: 11660
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC179D
//ABC179C
//ABC179B
int main(void) {
  int n, k, i, cou=0, tmp=0;
  scanf("%d", &n);
  int d1[n], d2[n];
  for(i=0; i<n; i++){
    scanf("%d %d", &d1[i], &d2[i]);
    if(d1[i]==d2[i]) cou++;
    else cou=0;
    if(cou==3){
     tmp=1;
    }
  }
  if(tmp==1)printf("Yes");
  else  printf("No");
  return 0;
}

Measured memory_bytes: 1732
N=int(input())
A=list(map(int,input().split()))
ans=[0 for i in range(0,N)]
for i in range(0,N):
    ans[N-1-i]=(A[N-1-i]-sum(ans[k*(N-i)-1] for k in range(1,N//(N-i)+1)))%2
print(sum(ans))
data=[i+1 for i in range(0,N) if ans[i]==1]
print(*data)


Measured memory_bytes: 80604
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans;
  string s;
  cin>>s;
  rep(i,s.size()){
    if(i&1){
      if(s[i]!='i')break;
    }else{
      if(s[i]!='h')break;
    }
  }
  if(i==s.size()&&s.size()%2==0)printyes;
  else printno;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int  main() {
  int n, i;
  long input;
  long minv;
  long maxv;

  scanf("%d", &n);
  
  scanf("%ld", &input);
  minv = input;
  
  for (i = 1; i < n; i++) {
    scanf("%ld", &input);

    if (i == 1) maxv = input - minv;
    
    maxv = (maxv > input - minv) ? maxv : input - minv;
    minv = (minv < input) ? minv : input;

  }
  printf("%d\n", maxv);
  
  return 0;
}


Measured memory_bytes: 2104
import sys
s = input()
k = int(input())

chrs = []
for ch in s:
  if int(ch) in {2,3,4,5,6,7,8,9}:
    chrs.append( (ch, 'Inf') )
  else:
    chrs.append( (ch, None) )

#print(chrs)

#で実数値がでるとき
#print( all(chrs[k2][1] is None for k2 in range(0,k)) )
if all(chrs[k2][1] is None for k2 in range(0,k)):
  print(1)
  sys.exit()
ret = None
for chr in chrs:
  if chr[1] == 'Inf':
    ret = chr[0]
    break

print(ret)

Measured memory_bytes: 3064
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
struct edge { int to; ll cost; };
struct state { int pos; ll cost; };
bool operator<(const state& s1, const state& s2) { return s1.cost > s2.cost; }
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
int H, W, A, B, C, N, x[100009], y[100009], xl[100009], xr[100009], yl[100009], yr[100009], ds[509][509]; vector<vector<edge> > g;
void add_edge(int v1, int v2, ll c) {
	g[v1].push_back(edge{ v2, c });
}
void add_edge2(int v1, int v2, ll c) {
	add_edge(v1, v2, c);
	add_edge(v2, v1, c);
}
ll shortest_path(int start, int goal) {
	vector<ll> dist(g.size(), 1LL << 60); dist[start] = 0;
	priority_queue<state> que; que.push(state{ start, 0 });
	while (!que.empty()) {
		int u = que.top().pos; que.pop();
		for (edge e : g[u]) {
			ll nd = dist[u] + e.cost;
			if (dist[e.to] > nd) {
				dist[e.to] = nd;
				que.push(state{ e.to, nd });
			}
		}
	}
	return dist[goal];
}
int main() {
	ios::sync_with_stdio(false);
	cin >> H >> W >> A >> B >> C >> N; H++; W++;
	g.resize(3 * H * W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (j >= 1) {
				add_edge2(i * W + j, i * W + j - 1, C);
				add_edge2(H * W + i * W + j, H * W + i * W + j - 1, A);
			}
			if (i >= 1) {
				add_edge2(i * W + j, i * W + j - W, C);
				add_edge2(2 * H * W + i * W + j, 2 * H * W + i * W + j - W, A);
			}
			add_edge(i * W + j, H * W + i * W + j, B);
			add_edge(i * W + j, 2 * H * W + i * W + j, B);
			ds[i][j] = -1;
		}
	}
	fill(xl, xl + H, W + 1);
	fill(xr, xr + H, -1);
	fill(yl, yl + W, H + 1);
	fill(yr, yr + W, -1);
	queue<pair<int, int> > qs;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		xl[x[i]] = min(xl[x[i]], y[i]);
		xr[x[i]] = max(xr[x[i]], y[i]);
		yl[y[i]] = min(yl[y[i]], x[i]);
		yr[y[i]] = max(yr[y[i]], x[i]);
		ds[x[i]][y[i]] = 0;
		add_edge(H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
		add_edge(2 * H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
		qs.push(make_pair(x[i], y[i]));
	}
	while (!qs.empty()) {
		pair<int, int> u = qs.front(); qs.pop();
		for (int i = 0; i < 4; i++) {
			int px = u.first + dx[i], py = u.second + dy[i];
			if (0 <= px && px < H && 0 <= py && py < W && ds[px][py] == -1) {
				ds[px][py] = ds[u.first][u.second] + 1;
				add_edge(H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
				add_edge(2 * H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
				qs.push(make_pair(px, py));
			}
		}
	}
	cout << shortest_path(x[0] * W + y[0], x[N - 1] * W + y[N - 1]) << '\n';
	return 0;
}

Measured memory_bytes: 115452
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#define N 100010
#define M 500010
#define ls i << 1
#define rs i << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
#define int long long
#define XRZ 20031223
#define debug() puts("XRZ TXDY");
#define n_ ((n >> 1) + 1)
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
// const int dx[10] = {1, -1, 0, 0};
// const int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
int n, k, Ans;
signed main() { n = read(), k = read();
    while(n) {
        if(n < k) break;
        n /= k; inc(Ans);
    } printf("%lld", Ans + 1);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define emp emplace 
#define pb push_back
#define mp make_pair
#define mem(arr,val) memset(arr,val,sizeof arr)
// int val = stoi(str1);// converts string to integer 
using lli = long long int;
#define nl(n) for(i=0;i<n;i++)
#define in(a,n) lli a[n];for(i=0;i<n;i++)cin>>a[i];
#define pi 3.141592653589793238
#define rev(v) reverse(v.begin(),v.end())
#define sort(v) sort(v.begin(),v.end())
#define gsort(v) sort(v.begin(),v.end(),greater<ll>())
#define bc __builtin_popcountll  // number of bits set in a number or no of 1's in a no 
//#define bc2 _mm_popcnt_u64

#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);
#define upper(a) transform(a.begin(),a.end(),a.begin(),::toupper);
// if( (num & 1)>=1) to check if a number is odd  
//  initialise a vector with 0 values ,vector<int> a(26,0); 
//inline ll pwr(ll base, ll n, ll m) {ll ans = 1;while( n > 0 ) {if ( n % 2 == 1 )ans = (ans * base) % m; base = (base * base) % m;n/=2;}return ans;}

// accumulate(a.begin(),a.end(),0) sum in a range ,here 0 is the initial sum
#define mod 1000000007
// upper1 = std::upper_bound(v.begin(), v.end(), 35);   

// lower1 = std::lower_bound(v.begin(), v.end(), 35); index of same upper element in log time  
//It returns an iterator to the first element which is not less than k. 

//s.order_of_key(6) : Count of elements strictly smaller than 6 is 2.
//order_of_key: The number of items in a set that are strictly smaller than k
//find_by_order: It returns an iterator to the ith largest element(counting from zero)
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// part of policy based data structure not a part of c++ library but of g++ library...


// typeid(x).name() for type of variable it return i for integers, d for doubles, Pi for the pointer to integer
//using namespace __gnu_pbds;
using namespace std;

int days[36] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30,
        31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31,
        30, 31 };

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli T,i,j,k,ans,con,val,n,num,len,m;
   cin>>n>>m;
    cout<<n+m/2;
    return 0;}

Measured memory_bytes: 256
local n, m = io.read("*n", "*n", "*l")
local a, b = {}, {}
for i = 1, n do
  local s = io.read()
  for j = 1, n do
    table.insert(a, s:sub(j, j))
  end
end
for i = 1, m do
  local s = io.read()
  for j = 1, m do
    table.insert(b, s:sub(j, j))
  end
end

local function check(x, y)
  for i = 1, m do
    for j = 1, m do
      local i_b = (i - 1) * m + j
      local i_a = (x + i - 2) * n + y + j - 1
      if b[i_b] ~= a[i_a] then return false end
    end
  end
  return true
end

local f = false
for i = 1, n + 1 - m do
  for j = 1, n + 1 - m do
    if check(i, j) then f = true break end
  end
  if f then break end
end
print(f and "Yes" or "No")


Measured memory_bytes: 760
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Main solution = new Main();
    
    System.out.println(solution.solve(N));
  }
  
  int solve(int N) {
    int ret = 0;
    for(int i=1; i<=N; i++) {
      if(i%2==0) continue;
      int count=0;
      for(int j=1; j<=i; j++) {
        if(i%j==0) count++;
      }
      if(count==8) ret++;
    }
    return ret;
  }
}


Measured memory_bytes: 23764
#include<iostream>

#define endl '\n'

using namespace std;

const int MAXN=403;
long long dp[MAXN][MAXN],prefix[MAXN];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        for(int i2=0;i2<n;++i2){
            dp[i][i2]=1e17;
        }
    }
    for(int i=0;i<n;++i){
        long long slime;
        cin>>slime;
        dp[i][i]=0;
        prefix[i+1]=prefix[i]+slime;
    }
    for(int range=1;range<n;++range){
        for(int l=0;l+range<n;++l){
            int r=l+range;
            for(int mid=l;mid<r;++mid){
                dp[l][r]=min(dp[l][r],dp[l][mid]+dp[mid+1][r]+prefix[r+1]-prefix[l]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
return 0;
}

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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> l(n);
	for(int i = 0; i < n; i++)
		cin >> l[i];
	sort(l.begin(),l.end());
	int ans = 0;
	for(int i = n-k; i < n; i++)
		ans += l[i];

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
A =  [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(A[k-1])

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(void)
{
    int X, A,B;
    cin >> X >> A >> B; 

    if(A >= B)
        cout << "delicious" << endl;
    else if((A + X) >= B)
        cout << "safe" << endl;
    else if(B > (A + X))
        cout << "dangerous" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b, c;
    cin >> a >> b >> c;
    rep(i, a * b)
    {
        if ((a * i) % b == c)
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}


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

    #define ll long long
    #define pb push_back
    #define mod 1000000007

    int main() {

      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      
      ll n,i,ans=0;
      cin>>n;
      string a;
      map<string,ll> m;
      for(i=0;i<n;i++){cin>>a; sort(a.begin(),a.end());m[a]++; }
      // int count[26];
      for(auto val: m){
        ll s=val.second;
        ans+=(s*(s-1)/2);
      }
      cout<<ans;

      return 0;
      
      }


    

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define int long long
using namespace std;

template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF = 1e18;
const int MAX_D = 365;
int n,dp[400][400];

void solve(){
	using P = pair<int,int>;
	vector<P> dat[400];
	for(int i = 0;i < n;i++){
		int l,r,w;
		cin >> l >> r >> w;
		dat[r].emplace_back(l - 1,w);
	}
	for(int i = 0;i <= MAX_D;i++){
		for(int j = 0;j <= MAX_D;j++){
			dp[i][j] = -INF;
		}
	}
	dp[0][0] = 0;
	for(int i = 0;i <= MAX_D;i++){
		for(int j = 0;j <= MAX_D;j++){
			if(i) chmax(dp[i][j],dp[i - 1][j]);
			if(j) chmax(dp[i][j],dp[i][j - 1]);
			if(i > j){
				for(P p : dat[i]){
					chmax(dp[i][j],dp[p.first][j] + p.second);
				}
			}else if(i < j){
				for(P p : dat[j]){
					chmax(dp[i][j],dp[i][p.first] + p.second);
				}
			}else{
				for(int k = 0;k < dat[i].size();k++){
					for(int l = k + 1;l < dat[i].size();l++){
						chmax(dp[i][j],dp[dat[i][k].first][dat[i][l].first] + dat[i][k].second + dat[i][l] .second);
					}
				}
			}
		}
	}
	/*for(int i = 0;i <= MAX_D;i++){
		for(int j = 0;j <= MAX_D;j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << dp[MAX_D][MAX_D] << endl;
}

signed main(){
	while(cin >> n,n) solve();
}


Measured memory_bytes: 4204
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 


int main() {
    int n, r;
    cin >> n >> r; 
    if (n < 10) r += 100*(10-n);
    cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iterator>
#include <deque>
#include <bitset>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <fstream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <bitset>
#include <queue>

using namespace std;

int main() {
	int a, b, s, c=0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> b >> s;
		if (b == s) {
			c++;
		}
		else
			c = 0;
		if (c >= 3) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}



Measured memory_bytes: 3560
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
   
int main(){
   string s,t;
   cin >> s >> t;
   int n=s.size();
   int m=t.size();
   int ans=0;
   rep(i,n-m+1){
         int ans1=0;
      for(int j=0;j<m;j++){
         if(s.at(i+j)==t.at(j)){
            ans1++;
         }
      }
      ans=max(ans,ans1);
   }
   cout << m-ans << endl;
} 

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

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

  vector<int> a(n);
  for (auto&& e : a)
    cin >> e;

  int ans = 0;
  vector<int> dp(s + 1);
  for (int i = 0; i < n; i++) {
    dp[0] = i + 1;
    for (int j = s; j >= a[i]; j--) {
      dp[j] += dp[j - a[i]];
      dp[j] %= 998244353;
    }
    ans += dp[s];
    ans %= 998244353;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    bill_count, total_yen = list(map(int, input().split()))

    # See:https://beta.atcoder.jp/contests/abc085/submissions/1967109
    for i in range(bill_count + 1):
        for j in range(bill_count - i + 1):
            if (10 * i + 5 * j + (bill_count - i - j)) == total_yen // 1000:
                print(i, j, bill_count - i - j)
                exit()
    else:
        print('-1 -1 -1')


Measured memory_bytes: 3064
//config = {stdin: 'tmp', newline: '\r\n'}; // win
config = {stdin: '/dev/stdin', newline: '\n'}; // linux

line = require('fs').readFileSync(config.stdin, 'ascii')
	.trim()
	.split(config.newline)
	.map(Number);
line.sort(function (a, b) { return b - a; });

console.log(line.slice(0, 3).join('\n'));

Measured memory_bytes: 15556
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         1000000007 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,t;
    cin>>a>>b>>t;
    t=t/a;
    t=t*b;
    cout<<t;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define rg register

using namespace std;

inline LL read() {
    LL x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

LL n, m, ans1, ans2;

int main() {
    n = read(); m = sqrt(n);
    if(n == 1) {cout << 1 << endl; return 0;}
    if(n == 2) {cout << 1 << endl; return 0;}
    for(rg LL i = 2; i <= m; ++i) {
        LL now = n;
        if(!(now % i)) {
            while(!(now % i)) now /= i;
            if(!((now - 1) % i)) ++ans1;
        }
        else if(!((now - 1) % i)) {
            if(i * i == now - 1) ++ans2;
            else ans2 += 2;
        }
    }
    printf("%lld\n", ans1 + ans2 + 2);
    return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int[][] z = new int[N][2];
		int[] x = new int[N];
		int[] y = new int[N];
		for (int i = 0; i < N; i++) {
			z[i][0] = Integer.parseInt(sc.next());
			z[i][1] = Integer.parseInt(sc.next());
			x[i] = z[i][0];
			y[i] = z[i][1];
		}
		Arrays.sort(x);
		Arrays.sort(y);
		long ans = Long.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				for (int k = 0; k < N; k++) {
					for (int l = k + 1; l < N; l++) {
						int count = 0;
						int left = x[i];
						int right = x[j];
						int down = y[k];
						int up = y[l];
						for (int c = 0; c < N; c++) {
							if (left <= z[c][0] && z[c][0] <= right && down <= z[c][1] && z[c][1] <= up)
								count++;
						}
						if (count >= K)
							ans = Math.min(ans, (long)(right - left) * (up - down));
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

ll a, b, k[2005], ans;
int main() {
	cin >> a >> b;
	for (int i = 0; i < a; ++i) { cin >> k[i]; }

	for (int i = 0; i < a; ++i) {
		for (int j = i + 1; j < a; ++j) {
			if (k[i] > k[j]) { ans += b * (b + 1) / 2; }
			else if (k[i] < k[j]) { ans += b * (b - 1) / 2; }
			ans %= MOD;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N >> M;
  ;
}
void solve() {
  ;
  cout << (N - 1) * (M - 1) << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	double a,b,c,d,e,f,x,y;
	while(scan.hasNext())
	    {
		a=scan.nextDouble();
		b=scan.nextDouble();
		c=scan.nextDouble();
		d=scan.nextDouble();
		e=scan.nextDouble();
		f=scan.nextDouble();
		x=(c*e-b*f)/(a*e-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(x==0)x=0;
		if(y==0)y=0;
					System.out.printf("%.3f %.3f\n",x,y);
				    
			    
		    
	    }
    }
}

Measured memory_bytes: 20544
h, w = map(int, input().split())
ans1 = [['.'] * w for _ in range(h)]
ans2 = [['.'] * w for _ in range(h)]
for i in range(h):
    ans1[i][0] = '#'
    ans2[i][-1] = '#'
    if i % 2:
        for j in range(w - 1):
            ans1[i][j] = '#'
    else:
        for j in range(1, w):
            ans2[i][j] = '#'
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '#':
            ans1[i][j] = '#'
            ans2[i][j] = '#'
for row in ans1:
    print(''.join(row))
print()
for row in ans2:
    print(''.join(row))


Measured memory_bytes: 47596
from collections import defaultdict
d = defaultdict(int)


N = int(input())
A = list(map(int,input().split()))
Q = int(input())


for i in range(N):
    d[A[i]] += 1
    

SUM = sum(A)


for i in range(Q):
    B,C = map(int,input().split())
    
    plus = d[B] * (C-B)
    d[C] += d[B]
    d[B] = 0
    
    SUM += plus
    print(SUM)

Measured memory_bytes: 24176
#include <stdio.h>
int main()
{
  char a[300];
  scanf("%s", a);
  int i;
  for (i = 0; i < 30000; i++) {
    if (a[i] == '\0')
      break;
    if (a[i] == '\'') {
      continue;
    }
    if (a[i] == ',') {
      putchar(' ');
      continue;
    }

    putchar(a[i]);
  }
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int gi()
{
	char c=getchar(); int x=0;
	for(;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
	return x;
}
const int N=1e5+5,M=5e5+5,inf=1<<30;
int head[N],cur[N],nxt[M],to[M],wei[M],lev[N],tot=1,s,t,n,p[N],q[N],cp[N],cq[N],tid,ans;
void addedge(int u, int v, int w=1)
{
	nxt[++tot]=head[u], head[u]=tot, to[tot]=v, wei[tot]=w;
	nxt[++tot]=head[v], head[v]=tot, to[tot]=u, wei[tot]=0;
}
bool bfs()
{
	memset(lev,-1,sizeof(lev));
	queue<int> q;
	q.push(s),lev[s]=1;
	memcpy(cur,head,sizeof(head));
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(int e=head[u];e;e=nxt[e])
			if(lev[to[e]]==-1&&wei[e])
			{
				lev[to[e]]=lev[u]+1,q.push(to[e]);
				if(to[e]==t) return true;
			}
	}
	return false;
}
int dfs(int u, int mx)
{
	if(u==t) return mx;
	int l=mx;
	for(int& e=cur[u];l&&e;e=nxt[e])
		if(wei[e]&&lev[to[e]]==lev[u]+1)
		{
			int f=dfs(to[e],min(l,wei[e]));
			if(!f) --lev[to[e]];
			l-=f,wei[e]-=f,wei[e^1]+=f;
		}
	return mx-l;
}
int main()
{
	n=ans=gi();
	for(int i=1;i<=n;++i) p[i]=gi()+1;
	for(int i=1;i<=n;++i) q[i]=gi()+1;
	for(int i=1;i<=n;++i) if(!cp[i])
	{
		cp[i]=++tid;
		for(int j=p[i];!cp[j];j=p[j]) cp[j]=tid;
	}
	for(int i=1;i<=n;++i) if(!cq[i])
	{
		cq[i]=++tid;
		for(int j=q[i];!cq[j];j=q[j]) cq[j]=tid;
	}
	s=tid+1,t=s+1;
	for(int i=1;i<=n;++i)
	{
		if(p[i]==q[i]&&p[i]==i)--ans;
		else if(p[i]==i) addedge(cq[i],t);
		else if(q[i]==i) addedge(s,cp[i]);
		else if(p[i]!=q[i]) addedge(cq[i],cp[i]);
		else addedge(cp[i],cq[i]),addedge(cq[i],cp[i]);
	}
	while(bfs()) ans-=dfs(s,inf);
	printf("%d",ans);
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(all(a)); sort(all(b));
    ll l, r;
    if(n % 2 == 0) {
        l = a[n/2-1] + a[n/2];
        r = b[n/2-1] + b[n/2];
    }
    else {
        l = a[(n+1)/2-1];
        r = b[(n+1)/2-1];
    }
    cout << r - l + 1<< endl;
}


Measured memory_bytes: 6332
n = int(input())
s_l = [ input() for _ in range(n) ]

d = {}
for s in s_l:
    try:
        d[s] += 1
    except:
        d[s] = 1

max_c = max([ v for _,v in d.items() ])
ans = [ i for i, v in d.items() if v == max_c ]

for i in sorted(ans):
    print(i)

Measured memory_bytes: 38588
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();

        int count = 1;
        for (int ans = 0;; ans++)
        {
            if (count >= b)
            {
                Console.WriteLine(ans);
                return;
            }

            count--;
            count += a;
        }

    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

/*================================================
	Disjoint Set
================================================*/
class DisjointSet {
private:
	vector<int> rank, p, num;
	ll connect, all;

	ll nC2(ll n) { return n * (n - 1) / 2; }
	void link(int x, int y) {
		int num_x = num[x];
		int num_y = num[y];
		int sum = num_x + num_y;

		connect += nC2(sum) - nC2(num_x) - nC2(num_y);
		num[x] = num[y] = sum;

		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (rank[x] == rank[y]) rank[y]++;
		}
	}
	int findSet(int x) {
		if (x != p[x]) p[x] = findSet(p[x]);
		return p[x];
	}

public:
	DisjointSet(): connect(0), all(0){}
	DisjointSet(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		num.resize(size, 1);
		connect = 0;
		all = (ll)size * ((ll)size - 1) / 2;
		rep(i, size) makeSet(i);
	}
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}
	void unite(int x, int y) {
		if (!same(x, y)) link(findSet(x), findSet(y));
	}
	ll inconvinience() {
		return all - connect;
	}
};

int A[100000];
int B[100000];
ll ans[100000];

int main()
{
	int N, M;

	cin >> N >> M;
	rep(i, M) cin >> A[i] >> B[i];

	DisjointSet DS(N);

	rrep(i, M) {
		if (i == M - 1) ans[i] = DS.inconvinience();
		else {
			DS.unite(A[i + 1] - 1, B[i + 1] - 1);
			ans[i] = DS.inconvinience();
		}
	}

	rep(i, M) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 4096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int grid[10][5];
int tmp_col[10];
/*
void show(int H){
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++){
      cout << grid[i][j];
    }
    cout << endl;
  }
  return;
}
*/
int main(void){
  while(true){
    int H;
    cin >> H;
    if(H == 0){
      break;
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++){
        cin >> grid[H - i - 1][j];
      }
    }
    int score = 0;
    while(true){
      bool updated = false;
      for(int i = 0; i < H; i++){
        int range_begin = -1;
        int range_color = -1;
        for(int j = 0; j < 5; j++){
          if(range_color != grid[i][j]){
            if(j - range_begin >= 3 && range_color > 0){
              updated = true;
              for(int k = range_begin; k < j; k++){
                score += grid[i][k];
                grid[i][k] = 0;
              }
            }
            range_begin = j;
            range_color = grid[i][j];
          }
        }
        if(5 - range_begin >= 3 && range_color > 0){
          updated = true;
          for(int k = range_begin; k < 5; k++){
            score += grid[i][k];
            grid[i][k] = 0;
          }
        }
      }
      if(!updated){
        break;
      }

      for(int i = 0; i < 5; i++){
        int real_height = 0;
        for(int j = 0; j < H; j++){
          if(grid[j][i] != 0){
            tmp_col[real_height] = grid[j][i];
            real_height ++;
          }
        }
        for(int j = 0; j < H; j++){
          grid[j][i] = 0;
        }
        for(int j = 0; j < real_height; j++){
          grid[j][i] = tmp_col[j];
        }
      }
    }
    cout << score << endl;
  }
  return 0;
}



Measured memory_bytes: 3068
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

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

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

//#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
#define WFA(d,v) REP(i,v)REP(j,v)REP(k,v)d[j][k]=min(d[j][k],d[j][i]+d[i][k])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  CIN(n,num);
  V s(n);V t(n);V c(n);
  REP(i,n){cin>>s[i]>>t[i]>>c[i];c[i]--;} // 10^5
  vector<vector<P>> v(num);
  REP(i,n)v[c[i]].pb(mp(s[i],t[i])); // 10^5

  vector<V> cou(num);
  REP(i,num){cou[i]=V(v[i].size());REP(j,v[i].size())cou[i][j]=j;}

  REP(i,num){
    if(v[i].empty())continue;
    sort(ALL(v[i]));
    REP(j,v[i].size()-1){
      if(v[i][j].second == v[i][j+1].first){// 10^5
        v[i][cou[i][j]].second = v[i][j+1].second;
        cou[i][j+1]=cou[i][j];
        // v[i].erase(v[i].begin() + j+1);
        //j--;
      }
    }
  }
  vector<P> jobs;
  REP(i,num){
    REP(j,v[i].size()){
      if(cou[i][j]==j)jobs.pb(v[i][j]);
    }
    // FOREACH(xx,v[i])jobs.pb(xx); // 10^5
  }
  sort(ALL(jobs)); // 10^5

  V imos(1e5+9,0);

  REP(i,jobs.size()){imos[jobs[i].first]++;imos[jobs[i].second+1]--;} // 10^5

  int max_=0;int val=0;
  REP(i,imos.size()){val+=imos[i];max_=max(max_,val);} // 10^5
  COUT(max_);

  return 0;
}


Measured memory_bytes: 4232
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define eb emplace_back
#define ep emplace
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

main(){
    int x=in();
    vec prime(x*2,1);
    prime[0]=prime[1]=0;
    rep2(i,2,x*2-1){
        if(prime[i]){
            for(int j=i*2;j<x*2;j+=i)prime[j]=0;
        }
    }
    rep2(i,x,x*2-1){
        if(prime[i]){
            cout<<i;return 0;
        }
    }
}

Measured memory_bytes: 1024