akhauriyash/Code-Regression huggingface dataset:
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

const int mod = 998244353;

int binpow(int a, int b, int m) {
	int res = 1;
	a = a % m;
	while (b) {
		if (b & 1)
			res = (res * a) % m;
		a = (a * a) % m;
		b /= 2;
	}

	return res;
}

void solve() {
	int n, sum;
	cin >> n >> sum;

	vi arr(n);
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}

	int dp[n + 1][sum + 1];

	for (int i = 0; i < n + 1; ++i) {
		for (int j = 0; j < sum + 1; ++j) {
			if (i == 0 and j == 0)
				dp[i][j] = binpow(2, n, mod);
			else if (i == 0)
				dp[i][j] = 0;
			else if (arr[i - 1] <= j)
				dp[i][j] = ((dp[i - 1][j - arr[i - 1]] % mod * binpow(2, mod - 2, mod)) % mod  + dp[i - 1][j]) % mod;
			else
				dp[i][j] = dp[i - 1][j];

			// cout << dp[i][j] << " ";
		}

		// cout << endl;
	}

	cout << dp[n][sum] << endl;
}

signed main() {
	crap;

	solve();

	return 0;
}

Measured memory_bytes: 74028
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.next
    sc.close()

    val s1 = s.splitAt(2)._1.toInt
    val s2 = s.splitAt(2)._2.toInt

    val result = (under12(s1), under12(s2)) match {
      case (true, true) => "AMBIGUOUS"
      case (false, true) => "YYMM"
      case (true, false) => "MMYY"
      case _ => "NA"
    }
    println(result)
  }

  def under12(v: Int): Boolean = 0 < v && v <= 12
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	string s, t; cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<int>());
	rep(i, min(s.size(), t.size())) {
		if (s[i] < t[i]) {
			cout << "Yes" << endl;
			return 0;
		}
		else if (s[i] > t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (s.size() >= t.size())cout << "No";
	else cout << "Yes";
}



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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll N;
string S;

int main() {
    cin >> N;
    vector<int> res;
    FOR(i, 1, N) {
        if (i * (i + 1) / 2 >= N) {
            for (int k = i; k > 0; k--) {
                if (k <= N){
                    res.push_back(k);
                    N -= k;
                }
            }
            break;
        }
    }
    REP(i, res.size()) {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 384
//                             In The Name Of Allah                                           
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
const int N = 1e6 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
string s, t = "";
int n, p;

bool check(int k) {
	string g = t;
	p = 9 * k;
	int st = 0;
	while(p) {
		if((int)g.size() <= st)
			g += '0';
		p += (int)(g[st] - '0');
		g[st] = (int)((p % 10) + '0');
		st++;
		p /= 10;
	}
	int cnt = 0;
	for(auto u : g) 
		cnt += (int)(u - '0');
	return (cnt <= 9 * k);
}

int32_t main() {
	use_fast;
	cin >> s;
	n = (int)s.size();
	for(int i = (int)s.size() - 1; i >= 0; i--) {
		p += (int)(s[i] - '0') * 9;
		t += (char)((p % 10) + '0');
		p /= 10;
	}
	while(p) {
		t += (char)((p % 10) + '0');
		p /= 10;
	}
	int l = 0, r = n + 1;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 5228
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
dir = ((-1, 0), (1, 0), (0, -1), (0, 1))
def main():
    h, w = map(int, readline().split())
    grid = []
    for _ in range(h):
        grid.append(readline().rstrip().decode())

    INF = int(1e9)
    mx = 0
    for si in range(h):
        for sj in range(w):
            if grid[si][sj] == '#':
                continue            
            dq = deque()
            dq.append((si, sj))
            dist = [[-1 for _ in range(w)] for _ in range(h)]
            dist[si][sj] = 0
            while len(dq) > 0:
                ni, nj = dq.popleft()
                for d in dir:
                    x, y = ni+d[0], nj+d[1]
                    if (x < 0) or (y < 0) or (x >= h) or (y >= w):
                        continue
                    if grid[x][y] == '#':
                        continue
                    if dist[x][y] != -1:
                        continue 
                    dist[x][y] = dist[ni][nj]+1 
                    dq.append((x, y))

            for i in range(h):
                for j in range(w):
                    if dist[i][j] == -1: 
                        continue
                    mx = max(mx, dist[i][j])
    print(mx)
if __name__ == '__main__':
    main()

Measured memory_bytes: 45404
n = int(input())
s = input()
match = []
for i in range(1,len(s)):
    s1 = list(s[:i])
    s2 = list(s[i:])
    cnts = []
    for j in s1:
        if j in s2:
            if j not in cnts:
                cnts.append(j)
    match.append(len(cnts))
print(max(match))

Measured memory_bytes: 9180
n = int(input())
yakusu = [0]*105
for num in range(1,n+1):
    for i in range(2,n+1):
        while(num%i==0):
            yakusu[i] += 1
            num//=i
        if num == 1:
            break

over = [0]*100
for i in range(1,n+1):
    if(yakusu[i] >= 2):
        over[2]+=1
    if(yakusu[i] >= 4):
        over[4]+=1
    if(yakusu[i] >= 14):
        over[14]+=1
    if(yakusu[i] >= 24):
        over[24]+=1
    if(yakusu[i] >= 74):
        over[74]+=1

ans = over[74]+over[14]*(over[4]-1) + over[24]*(over[2]-1) + over[4]*(over[4]-1)*(over[2]-2)//2
print(ans)

Measured memory_bytes: 3064
Q = int(input())

import heapq
import sys
input = sys.stdin.readline

INF = 10**18
L = []
R = []
heapq.heappush(L,INF)
heapq.heappush(R,INF)
L_size = 0
R_size = 0
sum_b = 0
sum_L = 0
sum_R = 0

def f1(a,b):
  global sum_b,L_size,R_size,sum_L,sum_R
  sum_b += b
  L_max = -heapq.heappop(L)
  R_min = heapq.heappop(R)
  sum_L -= L_max
  sum_R -= R_min
  X = sorted([L_max,a,R_min])
  if L_size == R_size:
    heapq.heappush(L,-X[0])
    heapq.heappush(L,-X[1])
    heapq.heappush(R,X[2])
    L_size += 1
    sum_L += X[0] + X[1]
    sum_R += X[2]
  else:
    heapq.heappush(L,-X[0])
    heapq.heappush(R,X[1])
    heapq.heappush(R,X[2])
    R_size += 1
    sum_L += X[0]
    sum_R += X[1] + X[2]
  return

def f2():
  min_value = sum_b
  min_x = -L[0]
  if L_size == R_size:
    min_value += sum_R - sum_L
  else:
    min_value += sum_R - sum_L + min_x
  print(min_x,min_value)

for _ in range(Q):
  q = [int(x) for x in input().split()]
  if q[0]&1:
    f1(q[1],q[2])
  else:
    f2()


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

int main() {
  int n, m;
  cin >> n >> m;
  int a[50], b[50];
  // initialize
  for(int i=0; i<50; i++) {
    a[i] = 0;
    b[i] = 0;
  }
  for(int i=0; i<m; i++) {
    cin >> a[i] >> b[i];
  }

  int r[50];
  // initialize
  for(int i=0; i<50; i++)
    r[i] = 0;
  // a と b をつなぐ道路は一本とは限らない
  for(int i=0; i<m; i++) {
    r[a[i]-1]++;
    r[b[i]-1]++;
  }

  for(int i=0; i<n; i++)
    cout << r[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
vector<int> G[MAX_N];
bool visited[MAX_N];
int ans[MAX_N];
queue<P> Q;

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,M)
	{
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	Q.push(P(0,0));
	while(!Q.empty())
	{
		P p = Q.front();
		Q.pop();
		int v = p.first, u = p.second;
		if (visited[v]) continue;
		visited[v] = true;
		ans[v] = u;
		rep(i,G[v].size())
		{
			Q.push(P(G[v][i],v));
		}
	}
	cout << "Yes" << endl;
	rep(i,N-1)
	{
		cout << ans[i+1]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 12300
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <utility>
#include <queue>
#include <stdio.h>
#include <string>
#include <map>
#include <stack>
#include <complex>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 1000000000007
#define ESP 1e-11
using namespace std;
typedef long long int ll;


vector<ll> a(2000005,0);

ll flag = 1;

void push(ll x){
    ll i = flag++;
    while (i > 1) {
        ll p = i/2;
        if(a[p]>=x)break;
        a[i]=a[p];
        i = p;
    }
    a[i]= x;
}

ll pop(){
    ll ans = a[1];
    ll hoge = a[--flag];
    ll i = 1;
    while (i*2 <= flag) {
        ll l =2*i;
        ll r =2*i+1;
        if(l < flag and a[l] < a[r]){
            l =r;
        }
        if(a[l]<=hoge)break;
        a[i]=a[l];
        i =l;
    }
    a[i] = hoge;
    return ans;
}

int main(){
    string s;
    while (cin >> s) {
        if(s == "end")break;
        if (s == "extract") {
            cout << pop() << endl;
        }else{
            ll n;
            cin >> n;
            push(n);
        }
    }
}

Measured memory_bytes: 16704
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
int n , a[3][N];

template<class T>
struct Fenwick{
#define lb(x) ((x)&-(x))
    int n;T a[N];
    void ini(int _n){ fill_n(a+1,n=_n,0);}
    void Pre(){ for(int i=1,j=i+lb(i);i<=n;++i,j=i+lb(i)) if(j<=n) a[j]+=a[i];}
    void add(int x,T d){ for(;x<=n;x+=lb(x)) a[x]+=d;}
    T sum(int x){ T r=0;for(;x>=1;x^=lb(x)) r+=a[x];return r;}
};
Fenwick<int> f[2];

int main(){
    scanf("%d",&n);
    rep(i,0,3) rep(j,1,n+1) scanf("%d",&a[i][j]);
    int invA = 0 , invB = 0 , flipA = 0 , flipB = 0;
    rep(i,0,2) f[i].ini(n);
    rep(i,1,n+1){
        vi v;rep(j,0,3) v.pb(a[j][i]);
        sort(all(v));
        if(v[2] - v[0] != 2 || v[2] % 3 != 0) return puts("No") , 0;
        int x = v[2] / 3;
        if((x&1) != (i&1)) return puts("No") , 0;
        (i&1 ? invA : invB) ^= f[i&1].sum(n + 1 - x)&1;
        f[i&1].add(n + 1 - x , 1);
        vi nv;rep(j,0,3) nv.pb(a[j][i]);
        if(nv == v) continue;
        else{
            reverse(all(nv));
            if(nv == v) (i&1 ? flipA : flipB) ^= 1;
            else return puts("No") , 0;
        }
    }
    bool ok = (invA == flipB) && (invB == flipA);
    puts(ok ? "Yes" : "No");
    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  
  int n; cin >> n;
  vi a(n), b(n), c(n);
  rep(i,0,n) {
    cin >> a[i] >> b[i] >> c[i];
  }
  vi A(n), B(n), C(n);
  A[0] = a[0],  B[0] = b[0], C[0] = c[0];

  rep(i,1,n) {
    A[i] = a[i] + max(B[i - 1], C[i - 1]);
    B[i] = b[i] + max(A[i - 1], C[i - 1]);
    C[i] = c[i] + max(A[i - 1], B[i - 1]);
  }
  int res = max(A[n - 1], max(B[n - 1], C[n - 1]));
  cout << res;
}

Measured memory_bytes: 5556
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

bool f(int a, int b, int c) {

    return (a < b and b < c) or (c < b and b < a);

}

int main() {

    int N;
    cin >> N;
    vector<int> ds;

    int d;
    for (int i = 0; i < N; ++i) {
        cin >> d;
        ds.push_back(d);
    }

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

    cout << ds[(ds.size() / 2)] - ds[(ds.size() / 2) - 1] << endl;

    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
using namespace std;
string s[310];
int a[310][310] = {};
int main(){
	int i,j,l,h,w,k;
	cin >> h >> w >> k;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	int cnt = 0;
	for(j=0;j<w;j++){
		int mn = 0;
		for(i=0;i<h;i++){
			if(s[i][j]=='#'){
				cnt++;
				int cnt1 = 0;
				for(l=mn;l<h;l++){
					if(s[l][j]=='#'){
						cnt1++;
						if(cnt1==2){
							mn = l;
							break;
						}
					}
					a[l][j] = cnt;
				}
			}
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(a[i][j]==0){
				for(l=j;l<w;l++){
					if(a[i][l]!=0){
						a[i][j] = a[i][l];
						break;
					}
				}
				for(l=j;l>=0;l--){
					if(a[i][l]!=0){
						a[i][j] = a[i][l];
						break;
					}
				}
			}
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cout << a[i][j] << " " ;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back
#define SIZE 100005

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;

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

    int n;
    cin >> n;
    int a[2][105];
    for( int i = 0; i < 2; ++i ) {
        for( int j = 0; j < n; ++j ) cin >> a[i][j];

    }
    int ans[2][105] = {};
    for( int i = 0; i < 2; ++i ) {
        for( int j = 0; j < n; ++j ) {
            if( !i || !j ) {
                if( !i && !j ) ans[i][j] = a[i][j];
                else if( j ) ans[i][j]  = ans[i][j - 1] + a[i][j];
                else if( i ) ans[i][j] = ans[i - 1][j] + a[i][j];

            } else {
                ans[i][j] = a[i][j] + max( ans[i - 1][j], ans[i][j - 1] );

            }
        }
    }

    cout << ans[1][n - 1] << endl;

    return 0;
}



Measured memory_bytes: 256
from scipy.sparse import *
from scipy.sparse.csgraph import *
N = int(input())
T = [[n]+list(map(int,input().split())) for n in range(N)]
P = set()

for i in [1,2]:
  T.sort(key=lambda a: a[i])
  for j in range(1,N):
    i0,x0,y0 =  T[j-1]
    i1,x1,y1 =  T[j]
    P.add((min(abs(x1-x0),abs(y1-y0)),i0,i1))

d,i,j = zip(*P)
G = csr_matrix((d,(i,j)),shape=(N,N))
print(int(minimum_spanning_tree(G).sum()))

Measured memory_bytes: 101872
R, G, B, N = map(int, input().split())
cnt = 0
rindex = 0
while R * rindex <= N:
	gindex = 0
	while R * rindex + G * gindex <= N:
		if (N - R * rindex - G * gindex) % B == 0:
			cnt += 1
		gindex += 1
	rindex += 1
print(cnt)

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

typedef long long   ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    cout << min(b / a, c) << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define ALL(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    string s; cin >> s;
    int ans = 0;
    rep(i,sz(s)-1){
        if(s[i] != s[i+1]) ++ans;
    }
    cout << ans << endl;    

    return 0;

    return 0;
}

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


Measured memory_bytes: 512
import heapq

N, M = map(int, input().split())
jobs = [[] for i in range(M)]
for i in range(N):
    a, b = map(int, input().split())
    if a > M: continue
    jobs[M-a].append(b)

q = []
ans = 0
for i in range(M-1, -1, -1):
    for b in jobs[i]:
        heapq.heappush(q, b*(-1))
    if len(q) > 0:
        ans += heapq.heappop(q)*(-1)

print(ans)


Measured memory_bytes: 18620
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
LL inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =1000000000000000000;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define F first
#define S second
class MagicNumberThree
{

    public:
int countSubsequences(string s)
{

}

};

int C[55][100005]={};
int cnt[100005]={};
int main()
{
    int a,b;
    while(cin>>a>>b){
            int ans=0;
        for(int i=0;i<a;i++){
            int l,r,z;
            cin>>l>>r>>z;
            for(int j=l;j<=r;j++){
                if(!C[z][j]){
                    C[z][j]=1;
                    cnt[j]++;
                    ans=max(ans,cnt[j] );
                }
            }
        }
        cout<<ans<<endl;
        
        
        
        
        
        
        
    }
 
    return 0;
}


Measured memory_bytes: 14208
import sys
import bisect as bi
import math
from collections import defaultdict as dd
input=sys.stdin.readline
##sys.setrecursionlimit(10**7)
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
for _ in range(1):
    x,k,d=cin()
    x=abs(x)
    jumps=x//d
    des1=x%d
    if(k<=jumps):
        ans=x-k*d
    else:
        if((k-jumps)%2==0):
            ans=des1
        else:
            ans=d-des1
    print(ans)
        
            
    
    
    
    
        
        


Measured memory_bytes: 9480
#include<bits/stdc++.h>
using namespace std;
char a[3][3];
int main()
{
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
            scanf("%c",&a[i][j]);
        getchar();
    }
    printf("%c%c%c\n",a[0][0],a[1][1],a[2][2]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
set <int> st[MAXN];
int n, m, p[MAXN], f[MAXN];
int F(int x) {
	if (f[x] == x) return x;
	else return f[x] = F(f[x]);
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		read(p[i]), f[i] = i;
	for (int i = 1; i <= m; i++) {
		int x, y;
		read(x), read(y);
		f[F(x)] = F(y);
	}
	for (int i = 1; i <= n; i++)
		st[F(i)].insert(p[i]);
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += st[F(i)].count(i);
	writeln(ans);
	return 0;
}

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

int main() {
  int a;
  cin >> a;
  if (a / 1000 * 1110 == a / 10 * 10 || (a % 1000) / 100 * 111 == a % 1000)
  {
    cout << "Yes"  << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

 int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && y-r >= 0 && x+r <=w && y+r <=h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3116
object Main extends App {
  import java.{ util => ju }
  import scala.annotation._
  import scala.collection._
  import scala.collection.{ mutable => mu }
  import scala.collection.JavaConverters._
  import scala.math._
  import scala.io.StdIn.readLine

  val sc = new ju.Scanner(System.in)

  val n = sc.nextInt()
  var nums = Array.fill(n)(sc.nextInt())

  var swapCount = 0
  for (i <- 0 until n) {
    var min = i
    for (j <- i to n - 1) {
      if (nums(j) < nums(min)) {
        min = j
      }
    }
    if (min != i) {
      val bigger = nums(min)
      nums(min) = nums(i)
      nums(i) = bigger
      swapCount += 1
    }
  }

  printArray(nums)
  println(swapCount)

  def printArray(nums: Array[Int]) {
    for (i <- 0 until nums.length - 1) print(nums(i) + " ")
    println(nums.last)
  }
}

Measured memory_bytes: 45420
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

void print(int base,int k,int m){
	for(int i=0;i<(1<<(m-1));i++){
		if((i+base) != k) printf("%d ",(i+base));
	}
	cout<<k<<" ";
	for(int i=(1<<(m-1))-1;i>=0;i--){
		if((i+base) != k) printf("%d ",(i+base));
	}
}

int main(){
	int m,k;cin>>m>>k;
	if(m == 0){
		if(k == 0){
			cout<<"0 0"<<endl;
			return 0;
		}
	}
	if(k >= (1<<m)){
		cout<<"-1"<<endl;
	} else {
		if(m == 1){
			if(k == 0){
				cout<<"0 0 1 1"<<endl;
			}
			if(k == 1){
				cout<<"-1"<<endl;
			}
			return 0;
		}
		print(0,k,m);
		print((1<<(m-1)),k,m);
		cout<<endl;
	}
	return 0;

}

Measured memory_bytes: 1792
n = int(input())
val = [1 for _ in range(n)]
ans = 1
for i in range(2, n+1):
    for j in range(2, i+1):
        while i%j == 0:
            val[j-1] += 1
            i //= j
    if i != 1:
        val[i-1] += 1

for i in val:
    ans *= i
    ans %= 10**9+7
print(ans)


Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 入力受け取り
		Scanner in = new Scanner(System.in);
		double N = in.nextDouble();
		double K = in.nextDouble();

		double y = 1;
		double sum = 0;

		// サイコロの目：１～Nで場合分け
		for ( int die = 1; die <= N; die++, y = 1.0 ) {

			// K以上になるまでコインを振る
			while ( die * y < K ) {
				y *= 2;
			}
			// 表が出続ける確率*サイコロのその目が出る確率
			sum += (1 / y) * (1 / N);
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 22996
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	string s,t;
	cin>>s>>t;
	if(s[0]<t[0]) cout<<'<';
	else if(s[0]==t[0]) cout<<'=';
	else cout<<'>';
	return 0;
}


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

int main() {
    int h,a;
    cin >> h >> a;

    int count = 0;
    while (h>0) {
        h -= a;
        count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b,x,c;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(x%4==0)a++;
		else if(x&1)b++;
		else c++;
	}
	if(!c)b--;
	if(a>=b)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	string s;
	cin>>s;
	ll ans = s.size()*(s.size()-1)/2+1;
	map<char,ll> cha;
	rep(i,s.size()){
		cha[s[i]]++;
	}
	for(auto x: cha){
		ll t = x.second;
		ans -= t*(t-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=111;i<=999;i++){
		ll now=i;
		bool ch=true;
		for(ll j=0;j<3;j++){
			if(now%10>n||now%10==0){
				ch=false;
			}
			now/=10;
		}
		if(ch){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
# 2019/02/24
# AtCoder Beginner Contest 119 - B

# Input
n = int(input())
sum = [0, 0]

# Calc
for i in range(n):
    x, u = input().split()
    if u == "JPY":
        sum[0] += float(x)
    else:
        sum[1] += float(x)

# Output
print(sum[0] + sum[1] * 380000.0)


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,M;

signed main(){
    while(scanf("%lld%lld",&N,&M),N||M){
        vector<tuple<int,int,int>>es;
        rep(i,M){
            int a,b,c;
            scanf("%lld%lld%lld",&a,&b,&c);
            a--;b--;
            es.push_back(make_tuple(c,a,b));
        }
        sort(all(es));
        int mi=LLONG_MAX;
        for(int i=0;i<M;i++){
            UF uf;uf.init(N);
            int c0=get<0>(es[i]);
            for(int j=i;j<M;j++){
                int a,b,c;
                tie(c,a,b)=es[j];
                uf.unite(a,b);
                if(uf.size(0)==N){
                    chmin(mi,c-c0);
                    break;
                }
            }
        }
        if(mi==LLONG_MAX)mi=-1;
        printf("%lld\n",mi);
    }
    return 0;
}

Measured memory_bytes: 3320
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_M 100001
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n, m;
int p[MAX_M], y[MAX_M];
vector<int> yd[MAX_N];

signed main(){
	cin >> n >> m;
	REP(i, m){
		cin >> p[i] >> y[i];
		yd[p[i]].pb(y[i]);
	}
	REP(i, n){
		sort(yd[i+1].begin(), yd[i+1].end());
	}
	REP(i, m){
		cout << setfill('0') << setw(6) << right << p[i];
		cout << setfill('0') << setw(6) << right << int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin()) + 1;
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 7808
#include<stdio.h>

int main(void){
	int t, n, s, f;
	
	while(1){
	int total = 0;
	scanf("%d", &t);
	if(t == 0) return 0;
	scanf("%d", &n);
	
	while(n > 0){
		scanf("%d %d", &s, &f);
		total = total + (f - s);
		n--;
	}
	
	if(total >= t){
		printf("OK\n");
	}
	
	if(total <t){
		printf("%d\n",t - total);
	}
	}
	
	return 0;
}

Measured memory_bytes: 612
#include <stdio.h>

int main(void){
  int W, a, b, d;
  scanf("%d %d %d", &W, &a, &b);
  if(a < b){
    d = b - (a + W);
  }
  else{
    d = a -(b + W);
  }
  if(d < 0){
    d = 0;
  }
  printf("%d\n", d);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String[]po=new String[n];
        Map<String,Integer>map=new HashMap<>();
        for(int i=0;i<n;i++){
            char po2[]=sc.next().toCharArray();
            Arrays.sort(po2);
            po[i]=String.valueOf(po2);
            if(map.containsKey(po[i])){
                map.put(po[i],map.get(po[i])+1);
            }
            else 
                map.put(po[i],0);
        }
        Arrays.sort(po);
        long ans=0;
        for(String key:map.keySet()){
            ans+=(long)(map.get(key))*(map.get(key)+1)/2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 53760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define lepb(i,s,t) for(int i=(s);i>=(t);--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 998244353;

ll C[4001][4001],two[4001];

ll cal(int x,int y,int z)
{
//	dd(y-1+x);de(z+y-1);
	if(y-1+x>=0&&z+y-1>=0)return C[z+y-1][y+x-1];
	return 0;
}

ll f(int x,int y,int z)
{
//	cout<<x<<" "<<y<<" "<<z<<endl;
	ll s=0;
	repb(i,0,min(x,z))
		(s+=(C[x][i]*two[i]%mod)*cal(i,y,z)%mod)%=mod;
//	de(s);
	return s;
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	repb(i,0,4000)C[i][0]=C[i][i]=1;
	repb(i,1,4000)repb(j,1,i-1)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	two[0]=1;repb(i,1,4000)two[i]=two[i-1]*2%mod;

	int k,n,x,y,o;ll a=0;
	cin>>k>>n;
	repb(t,2,2*k)
	{
		x=0;y=max(0,k-t+1);o=0;
		repb(z,1,t/2)
		{
			if(t-z<=k&&z<=k)
			{
				if(t-z==z)o=1;
				else x+=1;
			}
			else y+=1;
		}
	//	dd(x);de(y);
		if(!o)a=(f(x,y,n))%mod;
		else a=(f(x,y,n)+f(x,y,n-1))%mod;
		cout<<a<<endl;
	}
}

Measured memory_bytes: 123648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
int const INF = 1001001001;


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

int K; cin >> K;
queue<ll> que;
rrep(i,9) que.push(i);

rep(i,K) {
    ll d = que.front();
    if(i == K-1) cout << d << endl;
    que.pop();
    string s = to_string(d);
    int cur = s[SZ(s)-1] - '0';
    if(cur != 0) que.push(10*d + cur - 1);
    que.push(10*d + cur);
    if(cur != 9) que.push(10*d + cur + 1);
}

return 0;
}

Measured memory_bytes: 1792
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""

t=ii()
ans=0
for i in range(1,t+1):
    if(i%3!=0 and i%5!=0):
        ans+=i
print(ans)        

Measured memory_bytes: 68056
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N, A, B; cin >> N >> A >> B;
	ll ans = 0;
	if ((A < B && N>1) || (A == B && N >= 1)) {
		ans = (ll)B * (N - 1) + A - (B + (ll)A * (N - 1)) + 1;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3652
import sys
from collections import deque

H, W = map(int, sys.stdin.readline().split())
cy, cx = map(int, sys.stdin.readline().split())
gy, gx = map(int, sys.stdin.readline().split())

cy -= 1
cx -= 1
gy -= 1
gx -= 1

grid = []
for _ in range(H):
    grid.append(sys.stdin.readline().strip())

q = deque()
# x, y, 累積移動距離, ブロック通過数, ワープ利用数
q.append((cx, cy, 0))
visited_d = {}
visited_e = {}
ans = float("inf")
while q:
    x, y, e = q.popleft()
    if (x, y) in visited_e and visited_e[(x, y)] <= e:
        continue
    visited_e[(x, y)] = e
    # print(x, y, c, d, e)
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < W and 0 <= ny < H and grid[ny][nx] != "#":
            if nx == gx and ny == gy:
                ans = min(ans, e)
                continue
            if (nx, ny) not in visited_e:
                q.appendleft((nx, ny, e))
    for dx in range(-2, 3):
        for dy in range(-2, 3):
            if abs(dx) == 1 and dy == 0 or abs(dy) == 1 and dx == 0:
                continue
            nx = x + dx
            ny = y + dy
            # print("warp", dx, dy)
            if 0 <= nx < W and 0 <= ny < H and grid[ny][nx] != "#":
                if nx == gx and ny == gy:
                    ans = min(ans, e+1)
                    continue
                # print("warp append")
                if (nx, ny) not in visited_e:
                    q.append((nx, ny, e+1))

print(-1 if ans == float("inf") else ans)

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

typedef struct LIST{
	char c;
	struct LIST* next_ptr;
} list;

//リストの要素を削除する
void Del(list* NotD, list* D){
	(NotD -> next_ptr) = (D -> next_ptr);
	free(D);
}

int main(void){
	int N;
	int i;
	int count = 0;
	char* str;
	list* first_ptr;
	list* cullent_element;
	int a;
	
	scanf("%d", &N);
	str = malloc(N + 1);
	scanf("%s", str);
	
	cullent_element = (list*)malloc(sizeof(list));
	first_ptr = cullent_element;	
	//スライム列(リスト)を作る
	for(i = 0; i < N; i++){
		list* next_element;
		//終端のnextにはNULLを詰める
		if(i == N - 1){
			cullent_element -> next_ptr = NULL;
		}
		else{
			next_element = (list*)malloc(sizeof(list));
			(cullent_element -> next_ptr) = next_element;
		}
		cullent_element -> c = str[i];
		cullent_element = cullent_element -> next_ptr;
	}
	
	cullent_element = first_ptr;
	//隣接するスライムの色が一緒なら融合させる
	while(cullent_element -> next_ptr != NULL){
		list* next = cullent_element -> next_ptr;
		if((cullent_element -> c) == (next -> c)){
			Del(cullent_element, next);
		}
		else{
			cullent_element = next;
		}
	}
	
	//最終的に何匹になったかを求める
	cullent_element = first_ptr;
	while(cullent_element != NULL){
		count++;
		cullent_element = cullent_element -> next_ptr;
	}
	printf("%d", count);
	
	//メモリ解放
	cullent_element = first_ptr;
	while(cullent_element -> next_ptr != NULL){
		Del(cullent_element, cullent_element -> next_ptr);
	}
	free(first_ptr);
	return 0;
}

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

double n,m,sumv,ans=0;
double a[100005];

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		sumv+=a[i];
	}
	double num=sumv*(1.00/(4.00*m));
	
	for (int i=1;i<=n;i++)
	{
		if (a[i]>=num)  ans++;
	}
	if (ans>=m)  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)

N,K = map(int,input().split())

store = [pow(2,i+1)-1 for i in range(51)]

def maisu(n):
  return pow(2,n+2)-3

def burger(n,k): #n層でk枚
  if k == maisu(n):
    return store[n]
  elif k <= 1:
    return 0
  elif (maisu(n)-3)//2 +1 >= k:
    return burger(n-1,k-1)
  else:
    #print(k-(2+maisu(n-1)),maisu(n-1))
    return burger(n-1,k-(2+maisu(n-1)))+burger(n-1,maisu(n-1))+1
  
ans = burger(N,K)    
print(ans)

Measured memory_bytes: 9048
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    string s="";
    for(ll i=0;i<n;i++)
        s.pb('.');
    ll flag=0;
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        if(s[a]!='.' && b+'0'!=s[a])
        {
            flag=1;
            break;
        }
        s[a]=b+'0';
    }
    if(flag)
        cout<<-1;
    else if(n>1 && s[0]=='0')
        cout<<-1;
    else
    {
        ll ans=0;
        for(ll i=0;i<n;i++)
        {
            if(n==1 && s[0]=='.')
                s[0]='0';
            else if(s[i]=='.' && i>0)
                s[i]='0';
            else if(s[i]=='.' && i==0)
                s[i]='1';
            ans=ans*10+s[i]-'0';
        }
        cout<<ans;
    }
}


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

int main( void ) {
    int n;
    cin >> n;
    vector<int> a;
    while( n-- ) {
        int l, r;
        cin >> l;
        if( l == 2 ) {
            a.pop_back();
            continue;
        }
        cin >> r;
        if( l == 0 ) {
            a.push_back( r );
        } else if( l == 1 ) {
            cout << a.at( r ) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
char s[N];int f[N][3];
signed main(){
	cin>>(s+1);
	int n=strlen(s+1);
	if(n==1) return puts("1"),0;
	f[1][1]=1;
	f[2][1]=(s[1]==s[2])?0:2;
	f[2][2]=1;
	for(int i=3;i<=n;++i){
		if(s[i]!=s[i-1]) f[i][1]=max(f[i-1][1],f[i-1][2])+1;
		else f[i][1]=f[i-1][2]+1;
		string tmp1="",tmp2="";
		tmp1+=s[i-1];tmp1+=s[i];
		tmp2+=s[i-3];tmp2+=s[i-2];
		if(tmp1==tmp2) f[i][2]=max(f[i-2][1],f[i-2][2])+1;
		else f[i][2]=f[i-2][1]+1;
//		cout<<f[i][1]<<" "<<f[i][2]<<endl;
	}
	cout<<max(f[n][1],f[n][2]);
	return 0;
}

Measured memory_bytes: 6112
#include<map>
#include<vector>
#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;

typedef pair<int,int> P;

vector<int> G[10000];

int main(void) {
    int v,e;
    scanf("%d%d",&v,&e);

    vector<int> res;
    vector<int> in(v);

    for(int i=0; i<e; i++) {
        int s,t;
        scanf("%d%d",&s,&t);
        G[s].push_back(t);
        in[t]++;
    }
    
    queue<int> q;
    for(int i=0; i<v; i++)
        if(in[i] == 0)
            q.push(i);
    while(q.size()) {
        int i = q.front(); q.pop();
        res.push_back(i);
        for(auto &j : G[i])
            if(--in[j] == 0)
                q.push(j);
    }
    for(auto &r : res)
        cout << r << endl;

    return 0;
}

Measured memory_bytes: 3912
N=int(input())
dp=[[0]*9 for _ in range(9)]
for i in range(N):
  a=int(str(i+1)[0])
  b=int(str(i+1)[-1])
  if 1<=a<=9 and 1<=b<=9:
    dp[a-1][b-1]+=1

ans=0
for i in range(9):
  for j in range(9):
    ans+=dp[i][j]*dp[j][i]
print(ans)

Measured memory_bytes: 3064
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
string s;
long long m,a,r,c,h,n,ans;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>s;
		if (s[0]=='M') m++;
		if (s[0]=='A') a++;
		if (s[0]=='R') r++;
		if (s[0]=='C') c++;
		if (s[0]=='H') h++;
	}
	ans+=m*a*r+m*a*c+m*a*h;
	ans+=m*r*c+m*r*h+m*c*h;
	ans+=a*r*c+a*r*h+a*c*h+r*c*h;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a + b + c;
	cout << ((sum >= 22)?"bust":"win") << endl;



	return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll n; cin >> n;
    map<ll, ll> a;
    ll sum = 0;
    REP(i, n) {
        ll tmp; cin >> tmp;
        sum += tmp;
        a[tmp]++;
    }

    ll q; cin >> q;
    vector<ll> b(q), c(q);
    REP(i, q) cin >> b[i] >> c[i];

    REP(i, q) {
        if (a.find(b[i]) != a.end()) {
            sum += a[b[i]] * (c[i] - b[i]);
            a[c[i]] += a[b[i]];
            a[b[i]] = 0;
            cout << sum << '\n';
        } else {
            cout << sum << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 9924
import sys
s = raw_input()

for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		print i + 1, i + 2
		sys.exit()

if len(s) >= 2:
	for i in range(len(s) - 2):
		if s[i] == s[i + 2]:
			print i + 1, i + 3
			sys.exit()

print -1, -1

Measured memory_bytes: 5892