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

int dp[2010][2010] = {};

signed main(){
	int n,m,s[2010],t[2010];
	cin >> n >> m;
	for(int i = 0;i <= n;i++) dp[i][0] = 1;
	for(int i = 0;i <= m;i++) dp[0][i] = 1;
	for(int i = 0;i < n;i++) cin >> s[i];
	for(int i = 0;i < m;i++) cin >> t[i];
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + MOD) % MOD;
			if(s[i - 1] == t[j - 1]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
		}
	}
	cout << dp[n][m] << endl;
}

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

#define long long  ll

signed main(){
   int n; 
   int sum = 0;
   cin >> n; 
   bool flag = false;
   for (int i = 0; i < n; i += 1){
      string s;
      cin >> s;
      if (s == "A"){
         sum += 1;
      }
      else{
         sum -= 1;
      }
      if (sum < 0) {
         flag = true;
      }
   }
   if (flag or sum != 0){
      cout << "NO" << endl;
   }
   else{
      cout << "YES" << endl;
   }
}


Measured memory_bytes: 3156
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

#define mid ((l+r)>>1)

using namespace std;

const long long MOD=1e9+7;

long long qpow(long long a,int k)
{
	long long ans=1;
	while(k)
	{
		if(k&1)
		{
			ans=(ans*a)%MOD;
		}
		a=(a*a)%MOD;
		k>>=1;
	}
	return ans;
}

long long ans[1000009];

int main()
{
	int n;
	scanf("%d",&n);
	ans[1]=0;ans[2]=2;
	for(int i=3;i<=n;i++)
	{
		ans[i]=(((2*(qpow(10,i-1)-qpow(9,i-1)+MOD))%MOD)%MOD+(8*ans[i-1])%MOD)%MOD;
	}
	printf("%lld",ans[n]);
	return 0;
}

Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=1E5+5;

int main(){
    int n;
    cin>>n;
    cout<<((n/500)*1000+((n%500)/5)*5)<<endl;
    return 0;
}

Measured memory_bytes: 256
def i():
    return int(input())
def i2():
    return map(int,input().split())
def s():
    return str(input())
def l():
    return list(input())
def intl():
    return list(int(k) for k in input().split())

x=i()
a=100
cnt=0
while a < x:
	a=int(a*1.01)
	cnt+=1
print(cnt)

Measured memory_bytes: 9104
from fractions import gcd
n, m = map(int, input().split())

a = list(map(int, input().split()))

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        ans = 0
        break

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:
            ans = 0
            break
        else:
            num = format(a[i], 'b')[::-1].find('1')


if ans != 0:
    g = b[0]
    for i in range(1,n):

        g = (g*b[i]) // gcd(b[i],g)

    if g > m: ans = 0
    else:
        ans = (1 + (m-g)//(2*g))

print(ans)


Measured memory_bytes: 16280
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

int d[300];

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

	rep(i, s.size()){
		d[s[i]]++;
	}

	string v;
	while (1){
		string ta,t0;
		bool f = true;
		for (char c = 'a'; c <= 'z'; c++){
			if (d[c] && (ta.size() == 0 || ta[ta.size() - 1] == c - 1)){
				ta.push_back(c);
				d[c]--; f = false;
			}
		}
		for (char c = '0'; c <= '9'; c++){
			if (d[c] && (t0.size() == 0 || t0[t0.size() - 1] == c - 1)){
				t0.push_back(c);
				d[c]--; f = false;
			}
		}
		if (f)break;
		if (ta.size() >= 4){
			string t;
			t += ta[0];
			t += "-";
			t += ta[ta.size() - 1];
			ta = t;
		}
		if (t0.size() >= 4){
			string t;
			t += t0[0];
			t += "-";
			t += t0[t0.size() - 1];
			t0 = t;
		}
		v += ta;
		v += t0;
	}
	for (int i = 0; i < 300; i++){
		while (d[i]){
			v.push_back(i);
			d[i]--;
		}
	}

	cout << v.size() << endl;


	return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner

import scala.collection.mutable.ListBuffer

object Main {
  def main(args : Array[String]) = {
    val scanner = new Scanner(System.in)
    val inputs = ListBuffer.empty[Array[Int]]
    while(scanner.hasNextLine) {
      inputs += scanner.nextLine().split(" ").map(_.toInt)
    }


    inputs.foreach {
      input =>
      var divisor = 1 :: Nil
      var i = 2
      while (i <= input.min) {
        if (input(0) % i == 0 && input(1) % i == 0) {
          divisor = i :: divisor
          input(0) = input(0) / i
          input(1) = input(1) / i
          i = 2
        } else {
          i = i + 1
        }
      }

      val maxDivisor = divisor.product
      val minMultiple = maxDivisor * input.product

      println(s"$maxDivisor $minMultiple")
    }
  }
}

Measured memory_bytes: 45500
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, W;
	cin >> N >> W;

	vector<Int> w(N);
	vector<Int> v(N);

	for (Int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}

	vector<vector<Int>> dp(N + 1, vector<Int>(100000 + 1, INF));
	dp[0][0] = 0;

	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < 100001; j++) {
			//商品を選ぶ時
			if (j - v[i] >= 0) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			}
			//商品を選ばない時
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	Int ans = 0;
	for (Int j = 0; j < 100001; j++) {
		if (dp[N][j] <= W)ans = j;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 80256
c = [list(map(int,input().split())) for _ in range(3)]
a = [0]*3
b = [0]*3
ok = True

b = c[0]

a[1] = c[1][0]-b[0]
a[2] = c[2][0]-b[0]

for i in range(3):
    for j in range(3):
        if c[i][j]!=a[i]+b[j]:
            ok = False
        
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9204
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    a, b = i_map()

    if a == b:
        print('Draw')
    elif a == 1:
        print('Alice')
    elif b == 1:
        print('Bob')
    elif a > b:
        print('Alice')
    else:
        print('Bob')

if __name__ == '__main__':
    main()


Measured memory_bytes: 77096
N, W = map(int, input().split())
weight = []
value = []
for _ in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

dp = [[10**12]*(sum(value)+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(sum(value)+1 - value[i]):
        # 価値jの時の重みを最小化していく
        # i番目のitemを使わない時
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

        # i番目のitemを使うとき
        dp[i+1][j+value[i]] = min(dp[i+1][j+value[i]], dp[i][j]+weight[i])

# 重みがW以下で最大の価値を求める
ans = 0
for i in range(sum(value)+1):
    if dp[N][i] <= W:
        ans = i
print(ans)


Measured memory_bytes: 121068
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for _ in range(N):
        x, y = LI()
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx != 0 and gy != 0:  # merge
            if gx == gy:
                continue
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in g2xy.values():
        nx = sum(xy > 0 for xy in xys)
        ny = len(xys) - nx
        ans += nx * ny
    return ans

print(main())

Measured memory_bytes: 102488
n = int(input())
a = set(map(int,input().split()))
count = 0
while True:
    b = set()
    for i in a:
        if i%2 != 0:
            break
        b.add(i//2)
    else:
        a = b
        count += 1
        continue
    break
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
using namespace std;

int main() {
	int t = 1;
	while(true){
		int x;
		cin >> x;
		if(x == 0) break;
		cout << "Case " << t << ": " << x << endl;
		t++;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110000];
vector<ll> b;
int main(){
  ll n,cnt=1,ans=0,st=0;
  cin>>n;
  rep(i,0,n)cin>>a[i];
  sort(a,a+n);
  rep(i,0,n-1){
    if(a[i]==a[i+1])cnt++;
    else if(a[i]!=a[i+1]&&cnt>1){b.pb(cnt);cnt=1;}
    else if(a[i]!=a[i+1]&&cnt==1)continue;
  }
  if(cnt>1)b.pb(cnt);

  rep(i,0,b.size()){
    if(b[i]<2)continue;
    if(b[i]%2==0&&i+1+st<b.size()){
      if(b[i+1+st]>1)b[i+1+st]--;
      else {st++;b[i+1+st]--;}
    }
    ans+=(b[i]/2)*2;
  }
  cout<<n-ans<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
 
int main() {

    int x;
    cin >> x;
    if(x>=30) {
        cout<<"Yes"<<endl;
    }
    else    cout<<"No"<<endl;


 return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    ll N;
    cin>>N;
    vector<ll>A(N);
    ll ans=0;
    rep(i,N){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    ll cnt=0;
    rep(i,N){
        cnt++;
      	if(i!=N-1){
        if(A[i]!=A[i+1]){
            if(cnt%2==1){
                ans++;
            }
            cnt=0;
        }
        }
    }
    if(cnt%2==1){
        ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
 
//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std
 
Willy Indrayana Komara;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int s, w;
    cin >> s >> w;
    if (w >= s) puts("unsafe");
    else puts("safe");
}

Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
using namespace std;
struct point
{
	int a,b;
}p[200001];
bool cmp(const point& a,const point& b)
{
	return a.b<b.b;
}
int n,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d %d",&p[i].a,&p[i].b);
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		sum+=p[i].a;
		if(sum>p[i].b)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 1664
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

int H,W;
int c[1500][1500];
int dp[1500][1500];

int main(){
  cin>>H>>W;
  REP(i,H){
    REP(j,W){
      cin>>c[i][j];
    }
  }

  int ans=0;
  REP(i,H){
    dp[i][0]=(c[i][0]==0) ? 1:0;
    ans=max(ans,dp[i][0]);
  }

  REP(i,W){
    dp[0][i]=(c[0][i]==0) ? 1:0;
    ans=max(ans,dp[0][i]);
  }


  FOR(i,1,H){
    FOR(j,1,W){
      if(c[i][j]==1){
        dp[i][j]=0;
      }else{
        dp[i][j]=min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1]))+1;
        ans=max(ans,dp[i][j]);
      }
    }
  }
  cout<<ans*ans<<endl;
}



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

using namespace std;

const int N = 2e5+5;

string s , t;

int main(){
    cin >> s >> t;
    int bst = t.size();
    for(int i = 0; i+t.size() <= s.size(); i++){
        int cnt = 0;
        for(int j = 0; j < t.size(); j++){
            if(s[i + j] != t[j])
                cnt++;
        }
        bst = min(bst , cnt);
    }
    cout << bst << "\n";
}


Measured memory_bytes: 3632
L,R=map(int,input().split())
c=2019
z=0
for i in range(L,R+1):
    for j in range(i+1,R+1):
        a=i*j
        b=a%2019
        if c>b:
            c=b
        if c==0:
            z=1
            break
    if z==1:
        break
print(c)

Measured memory_bytes: 38896
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())

ans=0
for x in range(1,N+1):
    y=N//x
    ans+=(y+1)*y*x//2
print(ans)


Measured memory_bytes: 63392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Al dente
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringTokenizer st = new StringTokenizer(br.readLine());

		int N, T, E, minT, maxT;
		N = parseInt(st.nextToken());
		T = parseInt(st.nextToken());
		E = parseInt(st.nextToken());
		minT = T - E;
		maxT = T + E;

		st = new StringTokenizer(br.readLine());

		for (int i = 1; i <= N; i++) {

			int x, minX, maxX;
			x = parseInt(st.nextToken());
			minX = (T / x) * x;
			maxX = minX + x;

			if ((minT <= minX && minX <= maxT) || (minT <= maxX && maxX <= maxT)) {
				System.out.println(i);
				return;
			}
		}

		System.out.println(-1);
	}
}

Measured memory_bytes: 24316
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;
const int N=100010;

void solve(){
    ll a,b;
    cin>>a>>b;
    ll gc=__gcd(a,b);
    ll ans=(a*b)/gc;
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int A, B, C;

int main() {
	cin >> A >> B >> C;
	if (A < C&&C < B) cout << "Yes" << endl;
	else if (B < C && C < A) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long point[] = new long[5];
		for(int i = 0; i < 5; i ++) {
			point[i] = sc.nextLong();
		}
		System.out.println(point[4] - point[0] > sc.nextLong() ? ":(" : "Yay!");
	}
}

Measured memory_bytes: 21716
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  input.shift();
  input.splice(N,input.length);
  var X = input.map(i=>i.split(" ").map(i=>parseInt(i)));
  X.sort(function(a,b){return a[0]-b[0]});
  var ans =1;
  var xx=X[0][0]+X[0][1];
  for(var i=1;i<N;i++){
    if(xx>X[i][0]-X[i][1]){
      xx=Math.min(xx,X[i][0]+X[i][1]);
    }else{
      ans++;
      xx=X[i][0]+X[i][1];
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 52836
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

typedef struct {
    int c;
    int s;
    int f;
} Schedule;

signed main() {
    int n; cin >> n;
    vector<Schedule> v(n - 1);
    for (int i = 0; i < n - 1; i++) {
        int c, s, f;
        cin >> c >> s >> f;
        v[i] = Schedule{c, s, f};
    }

    for (int i = 0; i < n; i++) {
        int time = 0;
        for (int j = i; j < n - 1; j++) {
            if (time < v[j].s) {
                time = v[j].s;
            }
            else if (time % v[j].f == 0);
            else
                time += v[j].f - (time % v[j].f);
            time += v[j].c;
        }
        cout << time << "\n";
    }
}

Measured memory_bytes: 256
while True:
    i=int(input())
    if i==0:
        break
    s1=(1000-i)//500
    s2=(1000-i)%500//100
    s3=(1000-i)%500%100//50
    s4=(1000-i)%500%100%50//10
    s5=(1000-i)%500%100%50%10//5
    s6=(1000-i)%500%100%50%10%5//1
    print(s1+s2+s3+s4+s5+s6)


Measured memory_bytes: 5584
#include <iostream>
#include <stdio.h>

using namespace std;
int main(){
    int  n;
    cin >> n;
    
    for(int i = 1; i<= n ; i++){
        if( i % 3 == 0){
            cout << " " << i;
            continue;
        }
        
        for (int x = i; x > 0; x/=10){
           if( x % 10 == 3){
            cout << " " << i;
            break;
        } 
        }
    }
     cout << endl;
}


Measured memory_bytes: 3096
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func ch(a byte, R, S, P int) (byte, int) {
	var ret byte
	var pt int
	switch a {
	case 'r':
		ret = 'p'
		pt = P
	case 's':
		ret = 'r'
		pt = R
	case 'p':
		ret = 's'
		pt = S
	}
	return ret, pt
}

func choice(x, y byte) byte {
	var ret byte
	// out("chise", string(x), string(y))
	if x == 'p' {
		switch y {
		case 'r':
			ret = 's'
		case 's':
			ret = 'r'
		case 'p':
			ret = 'r'
		}
	}
	if x == 'r' {
		switch y {
		case 'r':
			ret = 's'
		case 's':
			ret = 'p'
		case 'p':
			ret = 's'
		}
	}
	if x == 's' {
		switch y {
		case 'r':
			ret = 'p'
		case 's':
			ret = 'r'
		case 'p':
			ret = 'r'
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, K := getInt(), getInt()
	R, S, P := getInt(), getInt(), getInt()
	T := getString()

	a := make([]byte, N)

	ans := 0
	for i := 0; i < K; i++ {
		x, pt := ch(T[i], R, S, P)
		a[i] = x
		ans += pt
	}
	for i := K; i < N; i++ {
		x, pt := ch(T[i], R, S, P)
		// out(string(a[i-K]), string(x))
		if a[i-K] != x {
			a[i] = x
			ans += pt
		} else {
			x := T[i]
			if i+K < N {
				x, _ = ch(T[i+K], R, S, P)
			}
			y := choice(x, T[i])
			// out("choise", string(y))
			a[i] = y
		}
	}

	//out(string(a))

	out(ans)

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<long> sub(N);
  for(int i = 0; i < N; i++)cin >> sub.at(i);
  vector<vector<long>> data(N, vector<long>(60));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 60; j++){
      data.at(i).at(j) = sub.at(i) % 2;
      sub.at(i) /= 2;
    }
  }
  for(int i = 0; i < N - 1; i++){
    for(int j = 0; j < 60; j++){
      data.at(i + 1).at(j) += data.at(i).at(j); 
    }
  }
  long ans = 0;
  for(int i = 0; i < N - 1; i++){
    for(int j = 0; j < 60; j++){
      if(data.at(i).at(j) == data.at(i + 1).at(j)){
        ans += (((long) pow(2, j)) % 1000000007) * data.at(i).at(j);
        ans %= 1000000007;
      } else {
        ans += (((long) pow(2, j)) % 1000000007) * (i + 1 - data.at(i).at(j));
        ans %= 1000000007;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n ;
    cin >> n ;
    map<int,int> m ;
    for(int i=0;i<n;i++){
        int x ;
        cin >> x ;
        m[x]++;
    }
    int ans = 0 ;
    for(auto &p : m){
        if ( p.second > p.first ) ans += (p.second - p.first);
        else if ( p.second < p.first ) ans += p.second ;
    }
    cout << ans << endl;

    return 0 ;
}


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

typedef long long ll;

int main()
{
	int t;
	ll n, m, a, b;
	scanf("%d", &t);
	while (t--) {
		scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
		printf("%lld\n", floor_sum(n, m, a, b));
	}
}

Measured memory_bytes: 3800
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#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;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(long long(a), long long(b), long long(c)) {
	return max(max(a,b), c);
}
int Min(long long(a), long long(b), long long(c)) {
	return min(min(a, b), c);
}

int cnt(ll N) {
	int digits = 0;

	while (N > 0) {
		N /= 10;
		digits++;
	}

	return digits;
}



int main() {
	
	ll N;
	cin >> N ;
	int an = cnt(N);
	ll B=0;
	for (ll A = 1; A * A <= N; A++) {
		if (N % A == 0) {
			ll B = N / A;
			an = min(an, cnt(B));
		}
		
	}
	
	cout << an << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
char x[maxn];

int main()
{
    scanf("%s", x);
    ll ans = 0;
    ll cur = 0;
    int len = strlen(x);
    for (int i = 0; i < len; i++) {
        if (x[i] == 'B')
            cur++;
        else
            ans += cur;
    }
    printf("%lld", ans);
}

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

int main(){
  int A,B;
  cin >> A >> B;
  int ans=0;
  for(int i=1;i<=1250;i++){
    if(i*8/100 == A && i/10 == B){
      ans=i;
      break;
    }
  }
  if(ans==0) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.next();

            Console.WriteLine(string.Join("",n.Select(c => c=='9'?'1':'9')));
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11348
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		a: f64,
		b: f64,
	}

	println!("{}", ((a + b) / 2.0 + 0.5) as usize);
}



Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vector<ll> a;
vector<ll> b;
int cc;

int col[100001];
vi adj[100001];
bool dfs(int u, int c)
{
	col[u]=c;
	cc++;
	bool pos=1;
	for(int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i];
		if(col[v]==-1)
		{
			pos&=dfs(v,c^1);
		}
		else if((c^1)!=col[v])
		{
			pos=false;
		}
	}
	return pos;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int u,v; cin>>u>>v;
		u--; v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	memset(col,-1,sizeof(col));
	for(int i=0;i<n;i++)
	{
		if(col[i]==-1)
		{
			cc=0;
			bool tmp = dfs(i,0);
			if(tmp)
			{
				a.pb(cc);
			}
			else
			{
				b.pb(cc);
			}
		}
	}
	//a = bipartite
	//b = non-bipartite
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	ll cnt1 = 0;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]==1) cnt1++;
	}
	ll ans=0;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]==1) ans++;
		else ans+=2;
	}
	for(int i=0;i<b.size();i++)
	{
		ans++;
	}
	for(int i=0;i<a.size();i++)
	{
		if(a[i]!=1) ans+=cnt1*a[i]*2;
	}
	for(int i=0;i<b.size();i++)
	{
		ans+=cnt1*b[i]*2;
	}
	ans+=cnt1*(cnt1-1);
	ans+=(int(a.size())-cnt1)*ll(b.size())*2;
	ans+=ll(b.size())*(ll(b.size())-1);
	ans+=(ll(a.size())-cnt1)*(ll(a.size())-cnt1-1)*2;
	cout<<ans<<'\n';
}


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

using namespace std;

int main()
{
    string S;
    cin >> S;
    string T1 = S, T2 = S;
    int count1 = 0, count2 = 0;
    for(int i=0;i<S.size();i++){
        if(i%2){
            T1[i] = '0';
            T2[i] = '1';
        }
        else{
            T1[i] = '1';
            T2[i] = '0';
        }
    }

    for(int i=0;i<S.size();i++){
        if(S[i] != T1[i]) ++count1;
        if(S[i] != T2[i]) ++count2;
    }
    cout << min(count1, count2) << endl;    
}

Measured memory_bytes: 512
def reflect(x, y, w, h, dx, dy, board)
  c = 0
  loop do
    x += dx; y += dy
    break if 0 > x || x >= w || 0 > y || y >= h
    if board[y][x] == 1
      return c
    elsif board[y][x] == 3
      return -1
    end
    c += 1
  end
end

loop do
  w, h = gets.split.map(&:to_i)
  break if w == 0 && h == 0
  sx, sy = 0, 0
  board = h.times.map{ |y|
    row = gets.split(' ').map(&:to_i)
    if x = row.index(2) then sx, sy = x, y end
    row
  }
  pos = []
  pos << [sx, sy, 1, board]
  ans = -1
  until pos.empty?
    x, y, i, b = pos.shift
    [[-1, 0], [0, 1], [1, 0], [0, -1]].each do |dx, dy|
      if len = reflect(x, y, w, h, dx, dy, b)
        if len == -1 # goal
          ans = i
          break
        elsif i < 10 && len != 0
          xx = len * dx + x; yy = len * dy + y
          nb = b.map(&:dup)
          nb[yy + dy][xx + dx] = 0
          pos << [xx, yy, i + 1, nb]
        end
      end
    end
    break if ans != -1
  end
  puts ans
end

Measured memory_bytes: 64684
#include<iostream>

using namespace std;

int main(void)

{
    string s, s1, s2;
    cin>>s>>s1;
    for(int i = 0; i < s1.size()-1; i++){
        s2 += s1[i];
    }
    if(s2 == s)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3128
#include<stdio.h>


int main()
{
	int n5 = 0, n7 = 0, i, A[4];
	scanf("%d %d %d", &A[1], &A[2], &A[3]);
	for (i = 1; i < 4; i++)
	{
		if (A[i] == 5)n5++;
		if (A[i] == 7)n7++;
	}
	if (n5 == 2 && n7 == 1)printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const int INF = 10000000;
int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> v( N ), w( N );
    REP( i, N )
    {
        cin >> v[ i ] >> w[ i ];
    }
    vector<vector<int>> dp( N + 1, vector<int>( 100001, -INF ) );
    dp[ 0 ][ 0 ] = 0;
    for( int i = 1; i <= N; ++i )
    {
        for( int j = 0; j <= W; ++j )
        {
            dp[ i ][ j ] = max( dp[ i - 1 ][ j ], dp[ i - 1 ][ j ] );
            if( j >=w[ i - 1 ] )
            {
                dp[ i ][ j ] = max( dp[ i - 1 ][ j - w[ i - 1 ] ] + v[ i - 1 ], dp[ i ][ j ] );
                dp[ i ][ j ] = max( dp[ i ][ j ], dp[ i ][ j - 1 ] );
            }
        }
    }
    cout << dp[ N ][ W ] << endl;
    return 0;
}


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

using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

template <class T>
i64 mod_pow(i64 a, i64 n, T mod) {
    mod = (i64)mod;
    i64 res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

template <int mod>
struct ModInt {
    using i64 = int64_t;
    i64 x;
    ModInt() : x(0) {}
    ModInt(i64 y) : x(y >= 0 ? y % mod : ((mod - (-y) % mod) % mod)) {}
    constexpr ModInt &operator+=(const ModInt &rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &rhs) {
        x = x * rhs.x % mod;
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt &rhs) {
        *this *= rhs.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }
    constexpr ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }
    constexpr ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }
    constexpr ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }
    constexpr ModInt operator==(const ModInt &rhs) const { return x == rhs.x; }
    constexpr ModInt operator!=(const ModInt &rhs) const { return x != rhs.x; }
    friend ostream &operator<<(ostream &os, const ModInt &rhs) {
        return os << rhs.x;
    }
    friend istream &operator>>(istream &is, ModInt &rhs) {
        i64 t;
        is >> t;
        rhs = ModInt<mod>(t);
        return (is);
    }

   private:
    ModInt inverse() const {
        i64 a = x, u = 1LL, v = 0LL, t, b = (i64)mod;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
};
using mint = ModInt<1000000007>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    i64 n, a, b;
    cin >> n >> a >> b;
    mint ans = (mod_pow(2, n, MOD) - 1) % MOD;
    mint nca = 1;
    rep(k, a) { nca *= (n - k); }
    rep(k, a) { nca /= (k + 1); }
    mint ncb = 1;
    rep(k, b) { ncb *= (n - k); }
    rep(k, b) { ncb /= (k + 1); }

    ans -= nca;
    ans -= ncb;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define w(e) int e ; cin >> e ; while (e--)  
#define ll long long 
#define endl "\n"
#define mod  10000000007
#define pi 3.1415926535897932384626433
#define setbit(x) __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)  
/*
*/
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n ; cin >> n; int sum=0;
    for (int i=1; i<=n ;i++ )
    {
    	if (i%3==0 || i%5==0)
    	{
    		continue ;
    	}
    	else 
    	{
    		sum+=i;
    	}
    }
    cout << sum <<endl;
	return  0;
}

Measured memory_bytes: 3664
n, k = gets.chomp.split.map(&:to_i)
HP = gets.chomp.split.map(&:to_i)

HP.sort!.reverse!
if n <= k then
  puts 0
else
  sum = 0
  HP.slice(k, HP.size).each do |i|
    sum += i
  end
  puts sum
end


Measured memory_bytes: 19824
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    ll ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            ll sm=a[i]+a[j];
            ll cnt=lower_bound(a.begin(),a.end(),sm)-a.begin()-(j+1);
            //cout<<cnt<<" ";
            ans+=cnt;
        }
    }
    cout<<ans<<endl;
}



















































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

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string S;
	int K;


	cin >> K >> S;

	if (S.size() > K) {
		cout << S.substr(0, K) << "..." << endl;
	}
	else {
		cout << S << endl;
	}


	return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int parent[600],sum[600],l[600],r[600],n[600];

int Find(int x){
    if(parent[x] != x) parent[x] = Find(parent[x]);
    return parent[x];
}

void Union(int x, int y){
    x = Find(x); y = Find(y);
    
    if(x != y){
        parent[x] = y;
        
        sum[y] += sum[x];
        
        if(l[x] != -1){
            if(l[y] == -1){
                l[y] = l[x];
                r[y] = r[x];
            }else{
                l[y] = min(l[y],l[x]);
                r[y] = max(r[y],r[x]);
            }
        }
    }
}

int main(){
    int w,h;
    char M[60][11];
    bool done[600][600];
    int dr[] = {-1,1,0,0};
    int dc[] = {0,0,-1,1};
    
    while(true){
        scanf("%d %d",&w,&h);
        
        if(w == 0) break;
        
        for(int i = 0;i < h;++i)
            scanf("%s",M[i]);
        
        int N = w * h;
        int cont = 0;
        
        for(int i = 0;i < N;++i){
            int y = i / w,x = i % w;
            
            parent[i] = i;
            sum[i] = 2*x + 1;
            l[i] = r[i] = -1;
            n[i] = 1;
            
            if(M[y][x] != '.') ++cont;
            
            if(y == h - 1 || (M[y + 1][x] != '.' && M[y + 1][x] != M[y][x])){
                l[i] = 2*x;
                r[i] = 2*x + 2;
            }
        }
        
        for(int i = 0;i < h;++i){
            for(int j = 0;j < w;++j){
                if(M[i][j] != '.'){
                    for(int k = 0;k < 4;++k){
                        int y = i + dr[k];
                        int x = j + dc[k];
                        
                        if(y >= 0 && y < h && x >= 0 && x < w && M[y][x] == M[i][j])
                            Union(i*w + j,y*w + x);
                    }
                }
            }
        }
        
        memset(done,0,sizeof done);
        
        for(int i = 0;i + 1 < h;++i){
            for(int j = 0;j < w;++j){
                if(M[i][j] != '.' && M[i + 1][j] != '.' && M[i + 1][j] != M[i][j]){
                    int x = i * w + j,y = (i + 1) * w + j;
                    x = Find(x); y = Find(y);
                    
                    if(x != y && !done[x][y]){
                        done[x][y] = 1;
                        sum[y] += sum[x];
                        n[y] += n[x];
                    }
                }
            }
        }
        
        bool ok = true;
        
        for(int i = 0;i < h;++i)
            for(int j = 0;j < w;++j)
                if(M[i][j] != '.' && parent[i*w + j] == i*w + j)
                    if(sum[i*w + j] <= 4 * n[i * w + j] * l[i*w + j] || sum[i*w + j] >= 4 * n[i * w + j] * r[i*w + j])
                        ok = false;
        
        puts(ok? "STABLE" : "UNSTABLE");
    }
    
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

struct Shop {
	long long price;
	long long stock;

	bool operator<(const Shop& rhs) const {
		return price < rhs.price;
	}
};

int main (int argc, char* argv[]) {
	long long n, m;
	cin >> n >> m;

	vector<Shop> shops(n);
	for (long long i = 0; i < n; i++) {
		long long price, stock;
		cin >> price >> stock;
		shops.emplace_back(Shop { price, stock });
	}

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

	long long shop_idx = 0;
	long long cost = 0;
	while (m > 0) {
		auto consume_amount = min(m, shops[shop_idx].stock);
		cost += consume_amount * shops[shop_idx].price;
		shop_idx++;
		m -= consume_amount;
	}
	cout << cost << endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

string s, t;
map<char,int> tem;
map<char, vector<int> > pos;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> s >> t;
  
  for(int i=0;i<sz(s);i++){
    tem[s[i]] = 1;
    pos[s[i]].push_back(i+1);
  }

  lli ans = 0, ult = 0;

  for(auto i : t){
    if(!tem[i]){
      cout << -1 << endl;
      return 0;
    }
  }

  for(int j=0;j<sz(t);j++){
    char i = t[j];
    auto atual = upper_bound(pos[i].begin(), pos[i].end(), ult);
    // cout << i << " - " << *atual << endl;
    if(atual == pos[i].end()){
      ans += sz(s) - ult;
      ult = *pos[i].begin();
      ans += ult;
    } else {
      ans += *atual - ult;
      ult = *atual;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int bit = 0;
		for(int i=0; i<N; i++) {
			bit |= scan.nextInt();
		}
		System.out.println(Integer.numberOfTrailingZeros(bit));
	}

}


Measured memory_bytes: 22740
#include <iostream>
 
using namespace std;
 
int main(){
    int h, w;
    while (cin >> h >> w && h) {
        for (int j=0; j<w; j++) cout << '#';
        cout << endl;
        for (int i=0; i<h-2; i++) {
            cout << '#';
            for (int j=0; j<w-2; j++) cout <<'.';
            cout << '#' << endl;
        }
        for (int j=0; j<w; j++) cout << '#';
        cout << endl << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N, D,ans=0,x=0;
	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	rep(i, N) {
		rep(j, D)
			cin >> X[i][j];
	}
	rep(i, N) {
		rep(j, N) {
			rep(k, D) {
				x += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			if (SQRTOR(x))
				ans++;
			x = 0;
		}
	}
	cout << (ans-N)/2;
}

Measured memory_bytes: 256