akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N = int(input())
A = input().split()

nowTall = int(A[0])
ans = 0

for i in range(N):
    if i == 0:
        continue

    if int(A[i]) < nowTall:
        ans+= nowTall - int(A[i])

    nowTall = max(nowTall, int(A[i]))

print(ans)

Measured memory_bytes: 25136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_E = (int)4e5 + 5;

class UNION_FIND{
public:
	vector<int> a;
	UNION_FIND(int n){
		a.clear();
		a.resize(n, -1);
	}

	~UNION_FIND(){
		a.clear();
	}

	int find(int x){
		if (a[x] < 0){
			return x;
		}else{
			return (a[x] = find(a[x]));
		} // end if
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if (x != y){
			a[x] += a[y];
			a[y] = x;
		} // end if
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}

	int size(int x){
		return -a[find(x)];
	} // end if
};

struct edge{
	int u, v, cost;
};

bool cmp(const edge & e1, const edge & e2){
	return e1.cost < e2.cost;
}

vector<edge> es;
int V, E;			// 頂点数と辺数

ll kruskal(void){
	sort (ALL(es), cmp);	// edge.cost が小さい順にソートする
	UNION_FIND uf(V);	// Union-Find の初期化
	ll res = 0LL;
	for (int i = 0; i < E; ++i){
		edge e = es[i];
		if (!uf.same (e.u, e.v)){
			uf.unite (e.u, e.v);
			res += (ll)e.cost;
		} // end if
	} // end rep

	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> x(N, 0), y(N, 0);
	rep (i, N){
		cin >> x[i] >> y[i];
	} // end rep

	vector<P> xi(N), yi(N);
	rep (i, N){
		xi[i].first = x[i];
		yi[i].first = y[i];
		xi[i].second = i;
		yi[i].second = i;
	} // end rep

	sort(ALL(xi));
	sort(ALL(yi));

	es.clear();
	set<P> same; same.clear();
	rep (i, N - 1){
		set<int> uni; uni.clear();
		rep (j, 2){
			uni.insert(xi[i+j].second);
			uni.insert(yi[i+j].second);
		} // end rep
		vector<int> pi; pi.clear();
		set<int>::iterator it = uni.begin();
		for (; it != uni.end(); ++it){
			int p = (*it);
			pi.push_back(p);
		} // end for

		rep (j, (int)pi.size()){
			int u = pi[j];
			for (int k = j + 1; k < (int)pi.size(); ++k){
				int v = pi[k];
				if (same.count(P(u,v))){
					continue;
				} // end if
				same.insert(P(u,v));
				int cost = min(abs(x[u] - x[v]), abs(y[u] - y[v]));
				es.push_back((edge){u,v,cost});
			} // end for
		} // end rep
	} // end rep
					
	V = N;
	E = (int)es.size();

	ll res = kruskal();
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 32556
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, K;
	cin >> N >> K;
	vector<int> X(N);
	for(int i = 0; i < N; i++) cin >> X[i];
	int ans = (X[N-1] - X[0]) * 2;
	for(int i = 0; i <= N-K; i++) {
		int l = X[i], r = X[i+K-1];
		ans = min(ans, r-l + min(abs(l), abs(r)));
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 640
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
INF = 10**12
MOD = 10**9+7

arr = [[1, INF] for _ in range(n)]
cur_max = -1
for i in range(n):
    cur = t[i]
    if cur > cur_max:
        arr[i][0] = max(cur, arr[i][0])
        arr[i][1] = min(cur, arr[i][1])
        cur_max = cur
    else:
        arr[i][1] = min(cur, arr[i][1])

cur_max = -1
for i in reversed(range(n)):
    cur = a[i]
    if cur > cur_max:
        arr[i][0] = max(cur, arr[i][0])
        arr[i][1] = min(cur, arr[i][1])
        cur_max = cur
    else:
        arr[i][1] = min(cur, arr[i][1])

for i in range(n):
    if arr[i][0] > arr[i][1]:
        print(0)
        exit()

ans = 1
for i in range(n):
    ans *= arr[i][1] - arr[i][0] + 1
    ans %= MOD
print(ans)


Measured memory_bytes: 95588
#include <stdio.h>

int main(){
  int n, x, i, j, k, c = 0;
  while(scanf("%d%d", &n, &x)){
    if(n == 0 && x == 0) break;
    for(i = 1;i < n - 1;i++)
      for(j = i + 1;j < n;j++)
        for(k = j + 1;k < n + 1;k++)
          if((i + j + k) == x) c++;
    printf("%d\n", c);
    c = 0;
  }
  return 0;
}



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

int main(){
    int n, count=1;
    cin >> n;
    int *a = new int[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int dif = 0, tmp;
    for(int i=0;i<n-2;i++){
        tmp = a[i+1] - a[i];
        if(tmp!=0){
            dif = tmp;
        }
        if(dif>0){
            if(a[i+2]-a[i+1]<0){
                count++;
                i++;
                dif = 0;
            }
        }else{
            if(dif<0&&a[i+2]-a[i+1]>0){
                count++;
                i++;
                dif = 0;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;

	int ans = 0;
	char past[n];
	rep(i, n) past[i] = 'A';
	rep(i, n) {
		if(i - k < 0) {
			if(t[i] == 'r') {
				ans += p;
				past[i] = 'p';
			}
			if(t[i] == 's') {
				ans += r;
				past[i] = 'r';
			}
			if(t[i] == 'p') {
				ans += s;
				past[i] = 's';
			}
			continue;
		} else {
			if(t[i] == 'r' && past[i-k] != 'p') {
				ans += p;
				past[i] = 'p';
			}
			if(t[i] == 's' && past[i-k] != 'r') {
				ans += r;
				past[i] = 'r';
			}
			if(t[i] == 'p' && past[i-k] != 's') {
				ans += s;
				past[i] = 's';
			}
		}
		//cout << i << " " << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=max(a)
p=a[0]
for i in range(1,n):
    p=gcd(a[0],a[i])
print("POSSIBLE" if k%p==0 and k<=c else "IMPOSSIBLE")

Measured memory_bytes: 16280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AIZU {
	class Program {
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }

		static bool[] compose = new bool[200000];

		static void Main(string[] args) {
			Filt();
			var Prime = Enumerable.Range(1, 200000).
				Where(i=>!compose[i-1]);
			int x;
			while (true) {
				x = cin();
				if (x == 0)
					break;
				int res = Prime.Take(x).Sum();
				print(res);
			}
		}

		static void Filt() {
			compose[0] = true;
			for (int i = 2; i <= 500; i++) {
				if (compose[i-1])
					continue;
				for (int j = 2; j * i < 200000; j++) 
					compose[j * i - 1] = true;
			}
		}

	}
}

Measured memory_bytes: 9444
n1, n2, n3 = [int(i) for i in input().split()]

if n1 >= n3:
    n1 -= n3
elif n1 + n2 >= n3:
    n2 -= (n3 - n1)
    n1 = 0
else:
    n1 = 0
    n2 = 0

print(str(n1) + " " + str(n2))

Measured memory_bytes: 3060
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

S=one_str()

count=0
list_S = list(S)
old = list_S[0]
for i in range(1,len(list_S)):
    if old != list_S[i]:
        count+=1
    old = list_S[i]

print(count)

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

using namespace std;

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

    int r;

    cin >> r;
    if (r < 1200) cout << "ABC\n";
    else if (r < 2800) cout << "ARC\n";
    else cout << "AGC\n";

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;


int main()
{
  ll N;
  cin >> N;
  ll a[N];
  FOR(i,0,N) cin >> a[i];
  //sort(a.rbegin(), a.rend());
  ll need = 0;
  ll nd[N];
  FOR(i,0,N) nd[i] = 0;
  while(1) {
    ll cnt = 0;
    bool ok = true;
    FOR(i,0,N) {
      nd[i] = a[i] / N;
      a[i] -= nd[i] * N;
      need += nd[i];
      cnt += nd[i];
    }
    FOR(i,0,N) {
      a[i] += cnt - nd[i];
      if(a[i] >= N) ok = false;
    }
    if(ok) {
      cout << need << endl;
      return 0;
    }
  }
  return 0;
}


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

typedef pair<int, int> Pair;

int n, m;
int low[100000];
int ord[100000];
bool used[100000];
vector<Pair> ans;
vector<int> es[100000];

void dfs(int v, int p, int &idx) {
    used[v] = true;
    low[v] = ord[v] = idx++;

    for (int i=0; i<es[v].size(); i++) {
        int u = es[v][i];
        if (!used[u]) {
            dfs(u, v, idx);
            low[v] = min(low[v], low[u]);
            if (ord[v] < low[u]) {
                int s = min(u, v);
                int t = max(u, v);
                ans.push_back(Pair(s, t));
            }
        } else if (u != p) {
            low[v] = min(low[v], ord[u]);
        }
    }
}
    

int main() {
    scanf("%d%d", &n, &m);
    for (int i=0; i<m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        es[a].push_back(b);
        es[b].push_back(a);
    }

    int _ = 0;
    dfs(0, 0, _);

    sort(ans.begin(), ans.end());
    for (int i=0; i<ans.size(); i++) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }
}

Measured memory_bytes: 5164
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]


    mint, mina =  f()
    for i in range(n-1):
        t,a = f()

        m = max((mint+t-1)//t, (mina+a-1)//a)
        
        mint = m * t
        mina = m * a

    print(mint + mina)


solve()


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

int N;

int main() {
    cin >> N;
    int cnt = 0;
    for (int i = 0; i < 4; i++) {
        if(N % 10 == 2) cnt += 1;
        N /= 10;
    }
    cout << cnt << endl;
}

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


//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Time()	cerr <<'\n' << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define fo(i,k,n) for(ll (i)=(k);(i)<(n);(i)++) 
#define ar array
// no change 

const ll MOD = 1e9+7;   // it is an prime...

template<typename T,typename L>
T power(T a, L b);				// to find reverse modulo its power(a,MOD-2);
template < typename T ,typename L> 
L coefficient(T n, T k);  // computing nCk

//const int MxN = 1e9+5;



void solve(){
	int n,k;
	cin >> n >>k;
	vi v(n);
	invec(v);
	sort(v.begin(),v.end());
	ll ans  = 0;
	for(int i= 0;i < k;i++){
		ans+=v[i];
	}
	cout << ans;






}
int main() {	
	FASTER;
	int T = 1;
	//cin >> T;		//cmt if one test case
	while(T--)solve();
}


template<typename T,typename L>
T power(T a, L b){
	
	T result = 1;
	while(b){
		if(b&1) result = (result% MOD * a%MOD) % MOD;
	   	a = (a%MOD * a%MOD) % MOD;
   		b/=2;	   
	}
	return result;
}

template < typename T ,typename L> 
L coefficient(T n, T k){  // computing nCk
	k = min(k,(n-k));
	L res = 1;
	for(T i = 0; i< k;i++){
		res *= (n-i);
		res /= (i+1);

	}
	return res;
}


Measured memory_bytes: 3636
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>

typedef long long ll;
using namespace std;

int main() {
    int N; cin >> N;
    ll A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll x[N];
    x[0] = A[0];
    for (int j = 1; j < N; j++) {
        if (j % 2 == 1) x[0] -= A[j % N];
        else x[0] += A[j % N];
    }

    for (int i = 0; i < N-1; i++) {
        x[i+1] = -x[i] + 2 * A[i];
    }

    for (int i = 0; i< N; i++) {
        cout << x[i];
        if (i != N-1) cout << ' ';
    }
    cout << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    int ans = a[n - 1] - a[0];

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


Measured memory_bytes: 3584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

int v[2][55];

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)return 0;
		REP(i,n)v[0][i]=n-i;
		REP(i,m){
			int p,c;
			cin>>p>>c;
			p--;
			copy(&v[i%2][0], &v[i%2][n], &v[(i+1)%2][0]);
			copy(&v[i%2][0], &v[i%2][p], &v[(i+1)%2][c]);
			copy(&v[i%2][p], &v[i%2][p+c], &v[(i+1)%2][0]);
		}
		cout << v[m%2][0] << endl;
	}
}

Measured memory_bytes: 1184
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	for i := 0; i <= x; i++ {
		if 2*i+4*(x-i) == y {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int k,x;cin>>k>>x;
    x=x-k+1;
    k=(k-1)*2+1;
    for(int i=x;i<x+k;i++)cout<<i<<' ';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<math.h>
#include<limits.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;

struct E{
	ll from;
	ll to;
	ll cost;
};

ll ans,n,m;
vector<E> e;
vl dp;



bool bellman_ford(ll s){
	dp[s] = 0;
	rep(count, n) rep(i, m){
		if (dp[e[i].from] + e[i].cost > dp[e[i].to]){
			dp[e[i].to] = dp[e[i].from] + e[i].cost;
			if (count == n - 1){
				rep(j, m){
					if (dp[e[j].from] + e[j].cost > dp[e[j].to]){
						dp[e[i].to] = dp[e[i].from] + e[i].cost;
						if (e[i].to == n - 1) return true;
					}
				}
			}
		}
	}
	return false;
}

int main(){
	cin >> n >> m;
	dp.resize(n, -INF);
	e.resize(m);
	rep(i, m){
		ll a, b,c; cin >> a >> b >> c;
		a--; b--;
		e[i].from = a;
		e[i].to = b;
		e[i].cost = c;
	}if (bellman_ford(0)) cout << "inf" << endl;
	else cout << dp[n - 1] << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;

int main(){
  int n; cin >> n;
  vs s(n); rep(i,n) cin >> s[i];
  int c = 0;
  rep(i,n){
    if(s[i] == "A") c++;
    else c--;
    if(c < 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  if(c != 0) cout << "NO" << endl;
  else cout << "YES" << endl;
}


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

int gcd(int a, int b){
    if(b==0)return 0;
    else return(b, a%b);
}

int main(){
  
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin>>n;
	vector<int> v(n);
	for(ll i=0; i<n; i++)cin>>v[i];
	sort(v.begin(),v.end());
	double ans=v[0];
	for(ll i=1; i<n; i++){
		ans=(ans+v[i])/2;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef struct{
  char M[36];
  int F[36];
}pre;
int main(){
  int i,j,N,s,mini;
  char c;
  pre inp,oup1,oup2;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf(" %c%d",&c,&s);
    inp.M[i]=c;
    inp.F[i]=s;
  }
  oup1=inp;
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(oup1.F[j]<oup1.F[j-1]){
        c=oup1.M[j];
        oup1.M[j]=oup1.M[j-1];
        oup1.M[j-1]=c;

        s=oup1.F[j];
        oup1.F[j]=oup1.F[j-1];
        oup1.F[j-1]=s;
      }
    }
  }

  for(j=0;j<N;j++)if(j!=N-1)printf("%c%d ",oup1.M[j],oup1.F[j]);else printf("%c%d\n",oup1.M[j],oup1.F[j]);
  printf("Stable\n");

  oup2=inp;
  for(i=0;i<N;i++){
    mini=i;
    for(j=i;j<N;j++){
      if(oup2.F[j] < oup2.F[mini]){
	mini=j;
      }
    }
    s=oup2.F[i];
      oup2.F[i]=oup2.F[mini];
      oup2.F[mini]=s;

      c=oup2.M[i];
      oup2.M[i]=oup2.M[mini];
      oup2.M[mini]=c;
  }

    for(j=0;j<N;j++)if(j!=N-1)printf("%c%d ",oup2.M[j],oup2.F[j]);else printf("%c%d\n",oup2.M[j],oup2.F[j]);
    
    for(i=0;i<N;i++)if(oup1.M[i]!=oup2.M[i])goto NS;
    
    printf("Stable\n");
    goto S;
 NS:
    printf("Not stable\n");
 S:
    
  return 0;
}



Measured memory_bytes: 2104
import sys
import math

a, b, h, m = map(float, sys.stdin.readline().split(" "))

l = (h + m / 60.) / 12. * 360.
s = m / 60. * 360.
t = abs(l - s) / 360. * 2. * 3.141592653589
ans = a * a + b * b - 2.0 * a * b * math.cos(t)
print(ans ** 0.5)

Measured memory_bytes: 62552
#include <stdio.h>
int main()
{
  int a[101],n,cou;
  scanf("%d",&n);
  for(cou=1;cou<=n;cou++){
    scanf("%d",&a[cou]);
  }
  for(cou=n;cou>=1;cou--){
    printf("%d",a[cou]);
    if(cou==1){
      break;
    }
      printf(" ");
  }
  printf("\n");
  return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 1e9 + 3;
const ll Log = 35;

vector<pll> V, V0;

ll dp[Log];

bool CMP(pll a, pll b){
	return a.S * b.F < a.F * b.S;
}
ll ans[1030][1030];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, m;
	cin >> n >> m;
	if(n <= m){
	for(int i = 1; i < (1 << n); i++){
		ll h = 0;
		for(int j = 0; j < n; j++){
			if(i >> j & 1){
				h = j;
				break;
			}
		}
		for(int j = 1; j < (1 << m); j++){
			ans[i][j] = (j % (1 << h) == 0 ? 1 : 0);
		}
	}
	} else {
		swap(n, m);
		for(int i = 1; i < (1 << n); i++){
		ll h = 0;
		for(int j = 0; j < n; j++){
			if(i >> j & 1){
				h = j;
				break;
			}
		}
		for(int j = 1; j < (1 << m); j++){
			ans[j][i] = (j % (1 << h) == 0 ? 1 : 0);
		}
		}
		swap(n, m);
	}
	for(int i = 1; i < (1 << n); i++){
		for(int j = 1; j < (1 << m); j++) cout << ans[i][j];
			cout << '\n';
	}
	return 0;
}


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

const int maxn = 110000;

int id[maxn];
int a[maxn], b[maxn];
int ta[maxn], to[maxn], from[maxn];

struct Level {
	int id, val, lvl;
	Level(int id = 0, int val = 0, int lvl = 0) : id(id), val(val), lvl(lvl) {}
} l[maxn];

inline bool operator < (const Level& lhs, const Level& rhs) {
	if(lhs.lvl != rhs.lvl) return lhs.lvl < rhs.lvl;
	return lhs.id < rhs.id;
}

inline bool operator > (const Level& lhs, const Level& rhs) {
	return lhs.id < rhs.id;
}

priority_queue<Level, vector<Level>, greater<Level>> q;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; ++ i) cin >> ta[i];
	for(int i = 0; i < n; ++ i) cin >> b[i];
	for(int i = 0; i < n; ++ i) id[i] = i;
	sort(id, id + n, [&](const int& i, const int& j) {
		return b[i] < b[j];
	});
	sort(b, b + n);
	for(int i = 0; i < n; ++ i) a[i] = ta[id[i]];
	for(int i = 0; i < n; ++ i) id[i] = i;
	sort(id, id + n, [&](const int& i, const int& j) {
		return a[i] < a[j];
	});
	int x = 0;
	int ff = 1;
	for(int i = 0; i < n; ++ i) {
		if(b[x] < a[id[i]]) {
			++ x; -- i;
			if(x == n) {
				ff = 0;
				break;
			}
			continue;
		}
		l[i] = Level(id[i], a[id[i]], x);
	}
	sort(l, l + n);
	for(int i = 0; i < n; ++ i) {
		to[l[i].id] = i;
		from[i] = l[i].id;
	}
	bool flag = false;
	if(ff) {
		int cnt = n - 2, st = 0;
		for(int i = 0; i < n; ++ i) {
			if(a[i] <= b[i]) {
				sort(a + i + 1, a + n);
				int f = 1;
				for(int j = i + 1; j < n; ++ j) {
					if(a[j] > b[j]) f = 0;
				}
				if(f) flag = true;
				break;
			}
			// find the last value which is not larger than b[i]
			for(; st < n && l[st].lvl <= i; ++ st) {
				q.push(l[st]);
			}
			if(q.empty()) {
				break;
			}
			auto cur = q.top(); q.pop();
			swap(a[i], a[cur.id]);
			l[to[i]].id = cur.id;
			to[cur.id] = to[i];
			assert(l[to[i]].lvl > i);
			if(cnt == 0) {
				break;
			}
			-- cnt;
		}
	}
	cout << (flag ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3968
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let v = input.trim().as_bytes();
    if v[0] == b'7' || v[1] == b'7' || v[2] == b'7'{
        print!("Yes");
    } else {
        print!("No");
    }
}

Measured memory_bytes: 2068
import java.io.*;
import java.util.*;
 
public class Main{
    static class FastReader{
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));} 
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace();}}return st.nextToken();} 
        int nextInt(){return Integer.parseInt(next());} 
        long nextLong(){return Long.parseLong(next());} 
        double nextDouble(){return Double.parseDouble(next());} 
        int[] readArray(int n){int[] a=new int[n];for (int i=0; i<n; i++) a[i]=nextInt();return a;}
        long[] readLongArray(int n){long[] a=new long[n];for (int i=0; i<n; i++) a[i]=nextLong();return a;}
        String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;} 
    }
    static int getgcd(int n1,int n2){
        while(n1 != n2){
            if(n1 > n2) n1 -= n2;
            else n2 -= n1;
        }
        return n1;
    }
    static boolean isSorted(int[] arr, int n){
        for(int i=1;i<n;i++){
            if(arr[i]<arr[i-1]) return false;
        }
        return true;
    }
    static boolean isPrime(long n){
        if(n==2) return true;
        else if(n%2==0) return false;
        for(int i=3;i<=n/2;i+=2){
            if(n%i==0) return false;
        }
        return true;
    }
    static void printArray(int[] arr){
        for(int x:arr){
            System.out.print(x+" ");
        }
        System.out.println();
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        FastReader s=new FastReader(); 
        int x=s.nextInt();int y=s.nextInt();
        if(y==(x*2)) System.out.println("Yes");
        else{
            int i=x,j=x*2;boolean test=true;
            while(i>0){
                if(j+2==y){
                    test=false;break;
                }j+=2;
                    i--;
            }
            if(test) System.out.println("No");
            else System.out.println("Yes");
        }

    }
}

Measured memory_bytes: 25396
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <bitset>
#include <array>

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	string s;
	while(n){
		n--;
		s=(char)(n%26+'a')+s;
		n/=26;
	}
	cout << s << '\n';
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b;
    rep(i, n) cin >> a[i];

    int s = n - 1;
    for (; s >= 0; s -= 2) {
        b.push_back(a[s]);
    }
    s++;
    for (; s < n; s += 2) {
        if (s < 0) continue;
        b.push_back(a[s]);
    }

    rep(i, n) {
        if (i == n - 1) cout << b[i] << endl;
        else cout << b[i] << " ";
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<bool> dp(n + 1), dp_next(n + 1);
    fill(dp.begin(), dp.end(), false);
    dp[0] = true;
    for (int i = 0; i <= n; i++) {
        fill(dp_next.begin(), dp_next.end(), false);
        for (int j = 0; j < n; j++) {
            if (dp[j]) {
                for (int k = 1; k + j <= n; k *= 6) {
                    dp_next[j + k] = true;
                }
                for (int k = 1; k + j <= n; k *= 9) {
                    dp_next[j + k] = true;
                }
            }
        }
        if (dp[n]) {
            cout << i << endl;
            return 0;
        }
        swap(dp, dp_next);
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using P = pair<int64_t, int64_t>;

int main() {
  int64_t N;
  cin >> N;
  map<P, int64_t> mp;
  vector<P> v;
  for (int64_t i = 0; i < N; i++) {
    int64_t x, y;
    cin >> x >> y;
    v.emplace_back(make_pair(x, y));
  }
  for (int64_t i = 0; i < N; i++) {
    for (int64_t j = i + 1; j < N; j++) {
      int64_t dx = v[i].first - v[j].first;
      int64_t dy = v[i].second - v[j].second;
      if (dx < 0) {
        dx *= -1;
        dy *= -1;
      } else if (dx == 0 && dy < 0) {
        dy *= -1;
      }
      mp[make_pair(dx, dy)]++;
    }
  }
  int64_t sum = 0;
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    sum = max(sum, itr->second);
  }
  cout << N - sum << endl;
  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
int x, y;
int main(void) {
    int a[] = { 0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1 };
    cin >> x >> y;
    cout << (a[x] == a[y] ? " Yes " : " No ") << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>

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

void solve(ll N) {
  int X = ceil(N/1.08);
  if (floor(1.08*X) > N) {
    cout << ":(" << endl;
  } else {
    cout << X << endl;
  }
}

int main() {
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque

def main():
    n,q=map(int,input().split())
    G=[[] for i in range(n)] #隣接配列
    P=[0]*n #親のポイント
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1
        b-=1
        G[a].append(b)
        G[b].append(a)
    for i in range(q):
        p,x=map(int,input().split())
        p-=1
        P[p]+=x
    
    Chk=[0]*n #訪問済みチェック
    q=deque([0])
    while q: #qが空になるまで(BFS:幅優先探索)
        now=q.popleft() #取り出す
        Chk[now]=1 #訪問済みにする
        for i in G[now]: #子に対し
            if Chk[i]==0: #未訪問のとき
                P[i]+=P[now] #ポイント加算
                q.append(i) #親としてqに入れる

    print(*P)

if __name__ == '__main__':
    main()

Measured memory_bytes: 93588
import copy
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
x = [1]*(a[0]+1)+[0]*(k-a[0])
for i in range(1,n):
  oldx = copy.copy(x)
  s = 0
  for j in range(a[i]+1):
    s = (s + oldx[j])%mod
    x[j] = s
  for j in range(a[i]+1,k+1):
    s = (s + oldx[j] -oldx[j-a[i]-1])%mod
    x[j] = s   
print(x[k])
    
    

Measured memory_bytes: 63504
#include <cstdio>
#include <iostream>

using namespace std;

const int N = 100;

int num[N];

void insertSort(int num[], int n) {//??卒??\?????\?????? 
	for (int i=0; i<n; ++i) {
		int j, ns = num[i];
		for (j=i-1; j>=0 && ns<num[j]; --j) num[j + 1] = num[j];
		num[j + 1] = ns;
		for (j=0; j<n; ++j) {
			if (j) printf (" ");
			printf ("%d", num[j]);
		}
		printf ("\n");
	}
}

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		for (int i=0; i<n; ++i) scanf ("%d", &num[i]);
		insertSort(num, n);
	}
	return 0;
}

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

#define MOD 1000000007

int main(){
	long long n, a[70], ans;
	unsigned long long ipt;
	bitset<60> bt;
	
	ans = 0;
	memset(a, 0, sizeof(a));
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>ipt;
		bt = ipt;
		for(int j=0;j<60;j++)
			a[j] += bt[j];
	}
	
	long long k = 1;
	for(int i=0;i<60;i++){
		ans += ((n - a[i]) * a[i] % MOD) * (k % MOD);
		ans %= MOD;
		k <<= 1;
	}
	cout<<ans<<endl;
	
	
}







Measured memory_bytes: 256
#pragma GCC optimize("03")
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1e9+7,N=200100;
ll tr[4*N],ar[2][N],dp[200100];
void update(ll node,ll l,ll r,ll id,ll val)
{
	if(l == r)
	{
		tr[node]=max(tr[node],val);
		return;
	}
	ll mid=(l+r)/2;
	if(id<=mid)
		update(2*node,l,mid,id,val);
	else
		update(2*node+1,mid+1,r,id,val);
	tr[node]=max(tr[2*node],tr[2*node+1]);
}
ll query(ll node,ll l,ll r,ll ql,ll qr)
{
	if(ql>r || qr<l)
		return -1;
	if(l>=ql && r<=qr)
		return tr[node];
	ll mid=(l+r)/2;
	return max(query(2*node,l,mid,ql,qr),query(2*node+1,mid+1,r,ql,qr));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,mx=0,d;
	cin>>n;
	for(ll i=0;i<=1;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			cin>>ar[i][j];
		}
	}
	for(ll i=1;i<=n;i++)
	{
		d=query(1,1,n,1,ar[0][i]-1);
		d=max(d,0ll);
		dp[ar[0][i]]=max(dp[ar[0][i]],d+ar[1][i]);
		update(1,1,n,ar[0][i],dp[ar[0][i]]);
	}
	for(ll i=1;i<=n;i++)
	{
		mx=max(mx,dp[i]);
	}
	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 10496
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
    string card,sub;
    int m, h;
    
    while(1){
        cin >> card;
        
        if(card == "-") break;
        
        cin >> m;
        
        for(int i = 0; i < m; i++){
            cin >> h;
            sub = card.substr(0, h);
            card.erase(0,h);
            card = card + sub;
        }
    
    cout << card << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long


int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  int x;
  scanf("%d", &x);
  printf("%d\n", a[x - 1]);
  
  return 0;
}

Measured memory_bytes: 256
// AtCoder Beginner Contest - Problem D: 756 (https://atcoder.jp/contests/abc114/tasks/abc114_d)
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

const vector<int> primes { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };

vector<ii> factorization(int n)
{
    vector<ii> f;

    for (const auto& p : primes)
    {
        if (p > n)
            break;

        int k = 0, base = p;

        while (n / base)
        {
            k += (n / base);
            base *= p;
        }

        f.push_back(ii(p, k));
    }

    return f; 
}

const int MAXP { 30 };
const int MAXD { 80 };

int st[MAXP][MAXD];

int dp(const vector<ii>& f, size_t idx, int D)
{
    const vector<int> ds { 1, 3, 5, 15, 25, 75 };
    int p, k;

    tie(p, k) = f[idx];

    if (idx == f.size())
        return D == 1 ? 1 : 0;

    if (st[idx][D] != -1)
        return st[idx][D];

    int res = 0;

    for (const auto& d : ds)
        if (k >= d - 1 and D % d == 0)
            res += dp(f, idx + 1, D / d);

    st[idx][D] = res;    

    return res;
}
   
void solve(int N)
{
    memset(st, -1, sizeof st);

    auto f = factorization(N);

    cout << dp(f, 0, 75) << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    solve(N);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;

ll fac[N];
ll invfac[N];
ll add(ll a,ll b){
    ll t=(a+b);
    if(t>=p)t-=p;
        return t;
}
ll sub(ll a,ll b){
    ll t=a-b+p;
    t=t%p;
    return t;
}
ll power(ll a,ll x){
    ll r=1;
    while(x!=0){
        if(x%2==1){
            r=r*a;r%=p;
        }
        a=a*a;a%=p;
        x=x/2;
    }
    return r;
}
ll mul(ll a,ll b){
    ll t=(a*b);
    if(t>=p)t%=p;
    return t;
}
ll ncr(ll n, ll r){
    if(n< r)return 0;
    return mul(fac[n],mul(invfac[n-r],invfac[r]));
}
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    fac[0]=1;
	for(ll i=1;i<N;i++){
	    fac[i]=fac[i-1]*i;
	    fac[i]%=p;
	}
	for(ll i=0;i<N;i++){
	    invfac[i]=power(fac[i],p-2);
	}
    while(T--){
    	ll n,k;cin>>n>>k;
        ll ans=0;
        ll hi=0,lo=0;ll t=0;
        for(ll i=1;i<=n+1;i++){
        	lo=lo+t;lo%=p;
        	hi=hi+(n-t);hi%=p;
        	t++;
        	if(i>=k){
        		ans=ans+(hi-lo+1+p)%p;ans%=p;
        	}
        }
        cout<<ans;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 6780
s = str(input())

num = int((len(s)-1) / 2)
num2 = int((len(s)+3) / 2)

f = s[:num]
b = s[num2-1:len(s)]

if f == f[::-1] and b == b[::-1] and s == s[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
n = int(input())
s = input()
mx = 0
for i in range(1,n):
  cnt = 0
  for j in range(ord('a'), ord('z')+1):
    c = chr(j)
    if c in s[0:i] and c in s[i:n]:
      cnt += 1
  mx = max(cnt, mx)
print(mx)

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

int main() {

    string S;

    cin >> S;

    if(S == "A"||S == "B" || S == "C" || S == "D" || S == "E" || S == "F" || S == "G" || S == "H" || S == "I" || S == "J" || S == "K" || S == "L" || S == "M" || S == "N" || S == "O" || S == "P" || S == "Q" || S == "R" || S == "S" || S == "T" || S == "U" || S == "V" || S == "W" || S == "X" || S == "Y" || S == "Z") cout << "A" << endl;

    else cout << "a" << endl;


}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;cin>>n;
	for(int i=n;i<=999;i++){
		if(i%111==0){
			cout<<i<<endl;
			return 0;
		}
	}
	

	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (int)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


int extend_gcd(int a, int b, int& x, int& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    int x1, y1;
    int d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

int rowNum[]={-1,0,0,1};
int colNum[]={0,-1,1,0};

int main()
{
	fastio
	int n,ans;
	cin>>n;

	ans=n+(n*n)+(n*n*n);

	cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    string s;
    cin>>s;
    stack<char> S;
    S.push(s[0]);
    rep(i, 1, s.length() - 1){
        if(S.empty()){
            S.push(s[i]);
            continue;
        }
        char p = S.top();
        if((s[i] - '0') ^ 1 ==  (p - '0')) S.pop();
        else S.push(s[i]);
    }
    int to = 0;
    while(!S.empty()) {
        to++;
        S.pop();
    }
    cout<<s.length() - to;
    return 0;
}

Measured memory_bytes: 512
from sys import stdin
N,C,K = [int(x) for x in stdin.readline().rstrip().split()]
 
data = []
for _ in range(N):
    data.append(int(input()))
data = sorted(data)
ans = 0
time = 0
buss = 0
 
for ind,i in enumerate(data):
    if buss == 0:
        time = i
    if time + K >= i:
        buss += 1
        if ind == N - 1 and time != i:
          ans += 1
    else:
        buss = 1
        tmp = time
        time = i
        ans += 1
        if ind == N - 1 and time - tmp > K:
            ans += 1
        
    if buss == C:
        if ind == N - 1 and i != time:
          ans -= 1
        time = i
        ans += 1
        buss = 0
    #print(time,buss,ans)
print(ans)

Measured memory_bytes: 8284
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int m,h;
	cin>>m;
	for(int i=1;i<n;i++){
		cin>>h;
		m=max(m,h);
		if(m-1>h){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256