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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int idx = 1;
vll dats;
vll ans;
vvint G;

void dfs(int u, int p) {
	for (auto &v : G[u]) {
		if (p == v) continue;
		ans[v] = dats[idx++];
		dfs(v, u);
	}
}

void Main() {
	int N; cin >> N;

	ans = vll(N);
	G = vvint(N);
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dats = vll(N); cin >> dats;
	sort(rbegin(dats), rend(dats));

	ans[0] = dats[0];
	dfs(0, -1);

	ll sum = 0;
	for (int i = 1; i < N; i++) {
		sum += dats[i];
	}
	cout << sum << endl;
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 4580
import Foundation
var X: String = readLine()!
var x: Int = Int(X)!
var flag = false
for i in -200...200{
  for j in -200...200{
    if pow(Double(i),5)-pow(Double(j),5)==Double(x){
      flag = true
      print(i,j)
      break
    }
  }
  if flag{
    break
  }
}

Measured memory_bytes: 13400
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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


	cin >> N >> M >> K;
	cout << min(N*M, K) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, kk, tmp, xx;
	cin >> nn >> kk;
	if(nn - 1 <= kk)
	{
		for(int64 ii = 0;ii < nn;ii++)
		{
			cout << nn << ' ';
		}
		puts("\n");
		return 0;
	}
	int64 memo[nn+2] = {0}, aa[nn+2] = {0};
	for(int64 ii = 1;ii <= nn;ii++)
	{
		cin >> tmp;
		xx = ii - tmp;
		if(xx < 0)
		{
			xx = 0;
		}
		memo[xx]++;
		xx = ii + tmp;
		if(xx > nn)
		{
			xx = nn;
		}
		memo[xx+1]--;
	}
	for(int64 ii = 0;ii < kk && ii < 100;ii++)
	{
		for(int64 jj = 1;jj <= nn;jj++)
		{
			memo[jj] += memo[jj-1];
			aa[jj] = memo[jj];
			memo[jj-1] = 0;
		}
		memo[nn] = 0;
		memo[nn+1] = 0;
		for(int64 jj = 1;jj <= nn;jj++)
		{
			xx = jj - aa[jj];
			if(xx < 0)
			{
				xx = 0;
			}
			memo[xx]++;
			xx = jj + aa[jj];
			if(xx > nn)
			{
				xx = nn;
			}
			memo[xx+1]--;
		}
	}
	for(int64 ii = 1;ii <= nn;ii++)
	{
		cout << aa[ii] << ' ';
	}
	puts("\n");
	return 0;
}

Measured memory_bytes: 6688
s = input()
result = 0
for i in range(len(s)):
    if (i+1)%2 == 1:
        if s[i] == "L":
            result = 1
    else:
        if s[i] == "R":
            result = 1
if result == 0:
    print("Yes")
else :
    print("No")


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;













struct node {
    node *ch[2];
    node() {
	ch[0]=ch[1]=NULL;
    }
};






ll n, l;
node *trie;


void add(string s) {
    node *cur = trie;
    for (char c: s) {
	if (cur->ch[c-'0'] == NULL) cur->ch[c-'0'] = new node();
	cur = cur->ch[c-'0'];
    }
}

ll G;

void dfs(node *at, int len=0) {
    if (len == l) return;
    int count = 0;
    if (at->ch[0] == NULL) count++;
    if (at->ch[1] == NULL) count++;

    if (count == 1) {
        ll cur = l-len;
	ll res = 1;
	while (cur%2 == 0) {
	    res=res*2;
	    cur=cur/2;
	}
	G = G ^ res;
    }

    for (int i=0; i<2; i++) {
	if (at->ch[i] != NULL) {
	    dfs(at->ch[i], len+1);
	}
    }
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    trie=new node();
    cin>>n>>l;
    for (int i=0; i<n; i++) {
	string s; cin>>s;
	add(s);
    }

    dfs(trie);



    if (G==0) out("Bob");
    out("Alice");

    

    return 0;
}


Measured memory_bytes: 5100
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int r = scan.nextInt();
	int g = scan.nextInt();
	int b = scan.nextInt();

	int num = r*100+g*10+b;

	if(num % 4 == 0){
	    System.out.println("YES");
	}else{
	    System.out.println("NO");
	}
    }
}


Measured memory_bytes: 22100
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,P;
	string S;
	while(cin>>N>>M) {
		VI ac(N);
		VI wa(N);
		ll a=0, pe=0;
		REP(i, M) {
			cin>>P>>S;
			P--;
			if(S=="AC" && !ac[P]) {
				ac[P]++;
				a++;
				pe+=wa[P];
			}
			if(S=="WA") {
				wa[P]++;
			}
		}
		
		cout<<a<<" "<<pe<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1792
n = int(input())

a = []
for i in range(26):
	a.append(chr(i+ord('a')))

ans = ''
while n:
	d = (n-1) % 26 + 1
	ans += a[d-1]
	n = (n-1) // 26

ans = ''.join(reversed(ans))
print(ans)

Measured memory_bytes: 9176
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    string s; cin >> s;

    string t = s;
    reverse(t.begin(), t.end());

    size_t N = s.length();
    dump(s, t);

    int res = 0;
    for (size_t i = 0; i < N; ++i) {
        if (s[i] != t[i]) {
            res++;
        }
    }

    cout << res / 2 << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, P;

vector<int> nprimes;

bool isPrime(int x) {
	for (int i=2; i*i<=x; i++) if (x%i==0) return false;
	return x>1;
}
void nPrimes() {
	nprimes.clear();
	for (int i=N+1; ; i++) {
		if (isPrime(i)) nprimes.push_back(i);
		if (nprimes.size() > P) break;
	}
}

void solve() {
	vector<int> all;
	int size = (int)nprimes.size();
	for (int i=0; i<size; i++) {
		for (int j=i; j<size; j++) {
			all.push_back(nprimes[i] + nprimes[j]);
		}
	}
	sort(all.begin(), all.end());
	cout << all[P-1] << endl;
}

int main() {
	while (1) {
		cin >> N >> P; if (N==-1 && P==-1) break;
		nPrimes();
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
	int l,n;
	cin >> n >> l;
	string a[100];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a,a+n);
	for(int i = 0; i < n; i++)
		cout << a[i];
} 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    sa = input().strip()
    sb = input().strip()
    sc = input().strip()
    i, j, k = 0, 0, 0
    turn = 'a'
    ans = ''
    while True:
        if turn == 'a':
            if i == len(sa):
                ans = 'A'
                break
            turn = sa[i]
            i += 1
        elif turn == 'b':
            if j == len(sb):
                ans = 'B'
                break
            turn = sb[j]
            j += 1
        else:
            if k == len(sc):
                ans = 'C'
                break
            turn = sc[k]
            k += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

ll n;
double dp[305][305][305];

void init(){
	
	loop(i,0,301)
		loop(j,0,301)
			loop(k,0,301)
				dp[i][j][k]=-1;
}

double expDP(ll x,ll y,ll z)
{
	if(x==0 && y==0 && z==0)
		return 0.0;
		
	if(x<0 || y<0 || z<0)
		return 0.0;
		
	if(dp[x][y][z]!=-1)
		return dp[x][y][z];
	
	double ans;
	ans = (n + expDP(x-1,y,z)*x + expDP(x+1,y-1,z)*y + expDP(x,y+1,z-1)*z)/(x+y+z);
	
	dp[x][y][z]=ans;
	
	return ans;
}

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

    ll p[n],one=0,two=0,three=0;
    loop(i,0,n)
    {
        cin>>p[i];

        if(p[i]==1)
            one++;
        else if(p[i]==2)
            two++;
        else
            three++;
    }

    cout<<fixed<<setprecision(12)<<expDP(one,two,three)<<endl;

}

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

int main(void){
	int H, W;

	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				printf("#");
			}
			puts("");
		}
		puts("");
	}

	return 0;
}

Measured memory_bytes: 1120
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXN = 100000;

vector<int> g[1 + MAXN], first, second;
bool seen[1 + MAXN];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int root;
    for (int i = 1; i <= n; i++)
        if (g[i].size() > 0) {
            root = i;
            break;
        }
    int node = root;
    while (1) {
        seen[node] = true;
        first.push_back(node);
        bool found = false;
        for (auto &it : g[node])
            if (!seen[it]) {
                node = it;
                found = true;
                break;
            }
        if (!found)
            break;
    }
    bool ok = true;
    for (auto &it : g[root])
        if (!seen[it]) {
            node = it;
            ok = false;
            break;
        }
    if (ok) {
        cout << first.size() << "\n";
        for (auto &it : first)
            cout << it << " ";
        return 0;
    }
    while (1) {
        seen[node] = true;
        second.push_back(node);
        bool found = false;
        for (auto &it : g[node])
            if (!seen[it]) {
                node = it;
                found = true;
                break;
            }
        if (!found)
            break;
    }
    cout << first.size() + second.size() << "\n";
    for (int i = first.size() - 1; i >= 0; i--)
        cout << first[i] << " ";
    for (auto &it : second)
        cout << it << " ";
    return 0;
}


Measured memory_bytes: 6904
def getNumNeg(L):
  return sum([i<0 for i in L])
  
def findmax2(L):
  numNeg = getNumNeg(L)
  absL = list(map(abs, L))
  if numNeg % 2 == 0:
    print(sum(absL))
  else:
    print(sum(absL)-2*min(absL))
        
n = int(input())
a = list(map(int, input().split()))
findmax2(a)


Measured memory_bytes: 14284
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    string s;
    ll i;
    cin >> s;
    bool ans = true;
    for(i = 0; i < s.size(); i++){
        if(i&1 && s[i] == 'R'){
            ans = false;
        }
        else if(!(i&1) && s[i] == 'L'){
            ans = false;
        }
    }
    if(!ans){
        cout << "No\n";
    }
    else{
        cout << "Yes\n";
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
num = max(a)
aset = [0 for i in range(num+1)]

for i in a:
  aset[i] += 1
#print(aset)
if aset[0] == 1 and a[0] == 0:
  ans = 1
  for i in range(1,num+1):
    ans *= (aset[i-1]**aset[i]) %mod
    #print(aset[i-1], aset[i])
  print(ans %mod)

else:
  print(0)

"""
10
0 1 1 1 1 1 1 3 2 1
"""

Measured memory_bytes: 56492
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 3e6 + 5;

ll n, m, k;
ll trie[N][2];
int node = 0;
string song[N];
int t[N];

void Solve(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> song[i] >> t[i];
    }
    string s;
    cin >> s;
    ll res = 0;
    for(int i = 1, ok = 0; i <= n; i++){
        if(ok) res += t[i];
        if(song[i] == s){
            ok = 1;
        }

    }
    cout << res;
}

int main(){
    Speed;
    int query = 1;
//    cin >> query;
    while(query--){
        Solve();
    }
}


Measured memory_bytes: 26880
#include<stdio.h>

#define MAX 100
#define INFTY 1<<21
#define WHITE 0
#define GRAY 1
#define BLACK 2

int g_n, g_M[MAX][MAX];

void dijkstra();

int main(){

  scanf("%d",&g_n);
  for(int i = 0; i < g_n; i++){
    for(int j = 0; j < g_n; j++){
      g_M[i][j] = INFTY;
    }
  }

  int k, c, u, v;
  for(int i = 0; i < g_n; i++){
    scanf("%d %d",&u, &k);
    for(int j = 0; j < k; j++){
      scanf("%d %d", &v, &c);
      g_M[u][v] = c;
    }
  }

  dijkstra();
  
  return 0;
}

void dijkstra(){
  int minv;
  int d[MAX], color[MAX];

  for(int i = 0; i < g_n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] =0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i = 0; i < g_n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(int v = 0; v < g_n; v++){
      if(color[v] != BLACK && g_M[u][v] != INFTY){
	if(d[v] > d[u] + g_M[u][v]){
	  d[v] = d[u] + g_M[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for(int i = 0; i < g_n; i++){
    printf("%d ",i);
    if(d[i] == INFTY) printf("-1\n");
    else printf("%d\n", d[i]);
  }
}



Measured memory_bytes: 2108
N=input()
N='0'+N
M=len(N)
INF=10**12
DP1=[INF]*(M+1)
DP2=[INF]*(M+1)
DP1[0]=0
for i in range(M):
  DP1[i+1]=min(DP1[i]+int(N[i]),DP2[i]+10-int(N[i]))
  DP2[i+1]=min(DP1[i]+int(N[i])+1,DP2[i]+9-int(N[i]))
print(min(DP1[M],DP2[M]+1))

Measured memory_bytes: 70384
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h> 
 
using namespace std;
 
 
#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

int main(){
    string s;
    cin>>s;
    ll len=s.size(),cnt=0,sum=0,mx=0;
    for(ll i=0;i<len;i++){
        ll j=i;
        while(s[j]==s[j+1] and j<len-1){
            j++;
        }
        ll in=j-i+1;
        if(s[i]=='<'){
            sum += (in*(in-1))/2;
            mx=in-1;
        }
        else{
            sum += max(in,mx+1);
            in--;
            sum += (in*(in+1))/2;
        }
        i=j;
    }
    if(s[len-1]=='<'){
        sum += mx+1;
    }
    pfl(sum);
    return 0;
}

Measured memory_bytes: 900
'use strict'

const main = arg => {
    var input = arg.trim().split("\n");
    input = input.slice(0, input.indexOf("END_OF_TEXT"))
    const w = input[0].toLowerCase();
    const t = input.slice(1).join(" ").replace(/[.\"\']/g, "").split(" ").filter(str => str.match(/[A-Za-z]/));
    var count = 0;

    t.forEach(str => {
        if(str.toLowerCase() === w){ count++; }
    });
    console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15452
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Lazy.Char8 as B
--
import qualified Data.List as L
import qualified Data.Vector.Unboxed as U

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt3 :: Parser (Int,(Int,Int))
parseInt3 = do
    x<-parseInt
    y<-parseInt
    a<-parseInt
    return (a,(x,y))

parse :: Parser ((Int,Int), [(Int,(Int,Int))])
parse = do
    w<-parseInt
    h<-parseInt
    n<-parseInt
    liftM ((,) (w,h)) $ replicateM n parseInt3

main=do
    ((w,h),xyas) <- fromJust.evalStateT parse <$> B.getContents
    let l = maximum.(:) 0.map (fst.snd) $ filter((==1).fst)xyas
    let r = minimum.(:) w.map (fst.snd) $ filter((==2).fst)xyas
    let b = maximum.(:) 0.map (snd.snd) $ filter((==3).fst)xyas
    let t = minimum.(:) h.map (snd.snd) $ filter((==4).fst)xyas
    print $ (max 0 (r-l)) * (max 0 (t-b))

Measured memory_bytes: 508
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,sight[4][2];
double s;

int main(){
	while(scanf("%lf",&s)!=EOF){
		if(s<0.2)sight[3][i%2]++;
		else if(s<0.6)sight[2][i%2]++;
		else if(s<1.1)sight[1][i%2]++;
		else sight[0][i%2]++;
		i++;
	}
	for(i=0;i<4;i++)printf("%d %d\n",sight[i][0],sight[i][1]);
	return 0;
}

Measured memory_bytes: 628
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define INF 100000000
#define MAX 200001
#define MOD 1000000009
ll fac[MAX],finv[MAX],inv[MAX];
typedef vector<vector<int> > Graph;
using P=pair<int,int>;

vector<P> p;

int main(){
    ld ans=0;
    int n,k;cin>>n>>k;
    vector<ld> x(n+1,0);
    for(int i=1;i<n+1;i++){
        ld p;cin>>p;
        x[i]=(p+1.0)/2.0;
        x[i]+=x[i-1];
    }
    for(int i=0;i<n-k+1;i++){
        ld res=x[i+k]-x[i];
        ans=max(ans,res);
    }
    cout<<setprecision(7)<<ans<<endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <bitset>
#include <vector>
using namespace std;
#define PB push_back
const int N=1e2+10;
bitset<N>went,in;
vector<int> graph[N];
bool f=true;
void dfs(int now){
    if(in[now]){
        f=false;
        return ;
    }
    else if(went[now])return ;
    in[now]=true;
    went[now]=true;
    for(int i=0;i<graph[now].size();i++)dfs(graph[now][i]);
    in[now]=false;
    return ;
}
int main(){
    int n,m,l,r;
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
    }
    in.reset();
    went.reset();
    for(int i=0;i<n;i++)if(!went[i])dfs(i);
    
    if(f)printf("0\n");
    else printf("1\n");
}


Measured memory_bytes: 2720
# import numpy as np
# import scipy as sp
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# a=[int(input()) for _ in range (n)]  #リスト入力  改行でa1 ... anのとき
# s=[list(map(str,list(input()))) for i in range(h)]  # 文字列の二次元配列入力
# s = [list(map(int, input().split())) for i in range(n)] # 数値の二次元配列入力
# a = b[:], a = [x[:] for x in b] # deepcopy
# chr(ord('a') + 1) # chrのインクリメント
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#
s, t = map(str, input().split())

a, b = map(int, input().split())
u = input()

if u == s:
    a -= 1
else:
    b -= 1

print(a, b)


Measured memory_bytes: 38384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    double W, H,x, y;
    cin >> W >> H >> x >> y;
    int s;
    if ( y == H / 2 && x == W / 2)
    {
        s = 1;
    }
    else{
        s = 0;
    }
    double t = 0.5 * W * H;
    printf("%.10lf %d\n", t,s);
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
S=[int(i) for i in input()]
L = len(S)


if L%2 == 1:
    mid = (L-1)//2
    midnum = S[mid]
    a = 0
    while mid-a != -1 and S[mid-a] == S[mid+a] == midnum:
        a += 1
    print(mid+a)
else:
    mid = (L-1)//2
    midnum1 = S[mid]
    midnum2 = S[mid+1]
    a = 0
    while mid-a != -1 and S[mid-a] == S[mid+1+a] == midnum1 == midnum2:
        a += 1
    print(mid+a+1)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    int ac=0,wa=0,tle=0,re=0;
    cin >> n;
    for(int i=0;i<n;i++){
        string input;
        cin >> input;
        if(input=="AC")ac++;
        if(input=="WA")wa++;
        if(input=="TLE")tle++;
        if(input=="RE")re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
    cin>>n>>k;
    rep(i,n){
        cin>>x;
        A.pb(x);
    }
}
void solve() {
    ll ok=INF,ng=0;
    while(ok-ng>1){
        ll mid=(ok+ng)/2;
        a=0;
        rep(i,n){
            a+=(A[i]+mid-1)/mid;
        }
        if(a<=k+n)ok=mid;
        else ng=mid;
    }
    print(ok);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>

int main()
{
    int n, m;
    ll ans;

    cin >> n >> m;
    if (n == 2 || m == 2)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << (ll)max(1, n - 2) * (ll)max(1, m - 2) << endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k,cnt;
int main()
{
	char s[105];
	cin>>s;
	int len = strlen(s);
	for(int i = 0; i<len; i++) 
	{
		if(s[i] != '1') break;
		cnt++;
	}
	cin>>k;
	if(k <= cnt) printf("1\n");
	else printf("%c\n",s[cnt]);
	return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
const ll mod=998244353;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
ll n,a[N],s[N];
int x,m,vis[N];
void solve()
{
	cin >> n >> x >> m;
	if(n == 1) { cout << x << endl; return; }
	a[1] = s[1] = x; vis[x] = 1;
	int k = 0, len = 0;
	for(int i=2; i<=m+2; i++) {
		int y = (a[i-1] * a[i-1]) % m;
		a[i] = y;
		s[i] = s[i-1] + y;
		if(i == n) { cout << s[i] << endl; return; }
		if(vis[y]) { k = vis[y] - 1; len = i - vis[y]; break; }
		vis[y] = i;
	}
	ll ans = s[k];
	ans += (n - k) / len * (s[k+len] - s[k]);
	ans += s[k + (n - k) % len] - s[k];
	cout << ans << endl;
}
int main()
{
	int T=1;
	while(T--) solve();
}

Measured memory_bytes: 4732
w,h,n=map(int,input().split())

P=[[1 for i in range(h)] for j in range(w)]

for i in range(n):
  x,y,a=map(int,input().split())
  
  if a==1:
    for k in range(x):
      for l in range(h):
        P[k][l]=0
  
  elif a==2:
    for k in range(x,w):
      for l in range(h):
        P[k][l]=0
  
  elif a==3:
    for k in range(w):
      for l in range(y):
        P[k][l]=0
  
  else:
    for k in range(w):
      for l in range(y,h):
        P[k][l]=0
         
ans=0
for g in range(w):
  for f in range(h):
    ans+=P[g][f]
print(ans)

Measured memory_bytes: 3064
from collections import deque
def bfs(g,v):
    q=deque([v]) ; vis=[0]*n
    vis[v]=1 ; stg[v]=0
    while q:
        v=q[0]
        for p in g[v]:
            if vis[p]==0: 
                q.append(p)
                vis[p]=1
                stg[p]=stg[v]+1
        q.popleft()
n=int(input())
g=[[] for i in range(n)]
for _ in range(n):
    a=[int(i)-1 for i in input().split()]
    for i in a[2:]: g[a[0]].append(i)
stg=[-1]*n
bfs(g,0)
for i in range(n):
    print(i+1,stg[i])
    



Measured memory_bytes: 6040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5;
ll n,m,w,a[maxn],b[maxn],d[maxn],c[maxn],k,depth;
bool check()
{
	int mid=(n+1)/2;
	if((b[mid]==1&&b[mid+1]==1)||(b[mid]==1&&b[mid-1]==1))return 1;
	if((b[mid]==0&&b[mid+1]==0)||(b[mid]==0&&b[mid-1]==0))return 0;
	for(int i=1;i<=(n-1)/2;i++){
		if(b[mid+i]==b[mid+i-1])return b[mid+i];
		if(b[mid-i]==b[mid-i+1])return b[mid-i];
	}
	if(depth%2==1)return b[mid];
	else return (b[mid]^1);
}
int main(){
	ll r,l=1;
	scanf("%lld",&depth);n=depth*2-1;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	r=n;ll mid = l+r>>1;
	while(l <= r)
    {
    	mid=l+r>>1;
    	for(int i=1;i<=n;i++)
    		if(a[i]>=mid)b[i]=1;
    		else b[i]=0;
        if(!check())
            r=mid-1; 
        else
            l=mid+1;
    }
    printf("%lld\n",l-1);
}

Measured memory_bytes: 4480
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const llint mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
int main(void){
	int n;cin>>n;cout<<48-n<<endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define M 998244353

int n;
string s;
ll r = 1;

vector<int> v[3];
int z[303030];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) r = (r*i)%M;
	cin >> s;
	for (int i = 0; i < 3*n; i++) {
		if (s[i] == 'R') v[0].push_back(i);
		if (s[i] == 'G') v[1].push_back(i);
		if (s[i] == 'B') v[2].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		int a = v[0][i];
		int b = v[1][i];
		int c = v[2][i];
		for (int j = 0; j < 3; j++) {
			if (a > b) swap(a,b);
			if (b > c) swap(b,c);
		}
		z[a] = 1; z[b] = 2; z[c] = 3;
	}
	int u = 0;
	for (int i = 0; i < 3*n; i++) {
		if (z[i] == 1) u++;
		if (z[i] == 2) {
			r = (r*u)%M;
			u--;
		}
	}
	for (int i = 3*n-1; i >= 0; i--) {
		if (z[i] == 3) u++;
		if (z[i] == 2) {
			r = (r*u)%M;
			u--;
		}
	}
	cout << r << "\n";
}


Measured memory_bytes: 3324
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
t=list(map(int,input().split()))
v=list(map(int,input().split()))
l=[]
for i in range(N):
    l+=[v[i]]*t[i]
l.append(0)
T=sum(t)
for i in range(T-1,0,-1):
    if l[i]<l[i+1]:
        l[i+1]=l[i]+0.5
s=[100]*(T+1)
s[0],s[-1]=0,0
c=1
while c:
    c=0
    for i in range(1,T):
        if s[i]>s[i-1]+1:
            s[i]=s[i-1]+1
            c=1
        if s[i]>s[i+1]+1:
            s[i]=s[i+1]+1
            c=1
        if s[i]>l[i]:
            s[i]=int(l[i])
            c=1
a=0
for i in range(T):
    if s[i+1]!=s[i]:
        a+=(s[i+1]+s[i])/2
    else:
        if s[i]<l[i]:
            a+=s[i]+0.25
        else:
            a+=s[i]
print(a)

Measured memory_bytes: 41820
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    char X, Y; cin >> X >> Y;
    if (X < Y) cout << "<" << endl;
    else if (X > Y) cout << ">" << endl;
    else cout << "=" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){

    int n;

    scanf("%d",&n);
    int BUFF[n];
    for(int i = 0;i<n;i++){
        scanf("%d",&BUFF[i]);
    }
    for(int i = n-1;0<=i;i--){
        printf("%d",BUFF[i]);
        if(i != 0){
            printf(" ");
        }
    }

    printf("\n");
    return 0;
}



Measured memory_bytes: 2604
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);
ll t[120] = {};

int main()
{
	int x,a,b;
	ll ans;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b)) {
		cout << "B" << endl;
	}
	else {
		cout << "A" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;

class Unionfind {
    vector<int> parent;
    vector<int> rank;
    vector<int> size;
public:
    Unionfind(const int n) {
        parent.reserve(n);
        rank.reserve(n);
        size.reserve(n);
        for(int i=0; i<n; i++) {
            parent[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    // recursively find root element
    int find(const int x) {
        if (parent[x] == x) return x;
        // reconnect root and x
        return parent[x] = find(parent[x]);
    }
    // merge x and y trees, < O(log n)
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        // union by rank
        if (rank[x] < rank[y]) {
            parent[x] = y;
            size[y] += size[x];
        }
        else {
            parent[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
            size[x] += size[y];
        }
    }
    bool isUnited(ll x, ll y) { return find(x) == find(y); }
    // get size of tree
    int getsize(int x) {
        return (size[find(x)]);
    }

};

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    int l, r;
    Unionfind uf(N);
    vector<set<int> > a(N);
    rep(i, M) {
        cin >> l >> r;
        --l, --r;
        uf.unite(l, r);
        a[l].insert(r);
        a[r].insert(l);
    }
    vector<set<int> > b(N);
    rep(i, K) {
        cin >> l >> r;
        --l, --r;
        b[l].insert(r);
        b[r].insert(l);
    }
    int ans;
    rep(i, N) {
        ans = uf.getsize(i) - 1;
        set<int> block = b[i];
        rep(j, a[i].size()) ans--;
        for(auto &j: b[i]) if(uf.isUnited(i, j)) ans--;
        cout << ans << ' ';
    }
    cout << endl;




	return 0;
}


Measured memory_bytes: 30080
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        HashSet<string> set = new HashSet<string>();
        for (int i = 0; i < n; i++)
        {
            var query = Console.ReadLine().Split();
            if (query[0] == "insert")
                set.Add(query[1]);
            else
                Console.WriteLine(set.Contains(query[1]) ? "yes" : "no");
        }
    }
}



Measured memory_bytes: 48376
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    for (int i = X-K+1; i < X+K; i++) {
        printf("%d%c", i, i == X+K-1 ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 256
import math
from decimal import *

dice = [1,2,3,4,5,6]

x = int(input())

times = math.floor(Decimal(x)/Decimal(11))
amari = x%11

if amari > 6:
    ans = 2*times + 2
elif amari >= 1:
    ans = 2*times + 1
else:
    ans = 2*times
print(ans)

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN], B[MAXN];
int h[MAXN], par[MAXN];
int dp[MAXN];
bool good[MAXN];
queue<int> Q;
vector<int> G[MAXN], adj[MAXN];

void dfs(int node){
	h[node]=h[par[node]]+1;
	for (int v:G[node]) if (v!=par[node]){
		par[v]=node;
		dfs(v);
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>x>>y;
	for (int i=1; i<n; i++) cin>>A[i]>>B[i];
	for (int i=1; i<n; i++){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	h[0]=-1;
	dfs(y);
	for (int i=1; i<n; i++){
		int u=A[i], v=B[i], d=0;
		while (u!=v && d<=2){
			if (h[u]>h[v]) swap(u, v);
			v=par[v];
			d++;
		}
		if (d==3) good[A[i]]=good[B[i]]=1;
		else{
			adj[A[i]].pb(B[i]);
			adj[B[i]].pb(A[i]);
		}
	}
	memset(dp, 63, sizeof(dp));
	dp[x]=0;
	Q.push(x);
	while (Q.size()){
		int v=Q.front();
		Q.pop();
		if (h[v]<dp[v]) continue ;
//		debug2(v, dp[v])
		ans=max(ans, 2*h[v]);
		if (h[v]==dp[v]) continue ;
		if (good[v]) kill(-1)
		for (int u:adj[v]) if (dp[u]>dp[v]+1){
			dp[u]=dp[v]+1;
			Q.push(u);
		}
	}
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 42820
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
elif x in c and y in c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)

int w, h;
int d[4][2]={{1,0},{-1,0},{0,-1},{0,1}};
string M[80];
int visit[80][20];
int par[160];
struct P{
	vector<double> ps;
	int gl;
	int gr;
	P(){ps.clear();gl=100;gr=0;}
} peace[160];

void check(int y, int x, char c, int idx){
//	printf("check %d %d %c %d\n", y, x, c, idx);
	visit[y][x] = 1;
	peace[idx].ps.push_back(x+0.5);
	if(y+1 == h || (M[y+1][x] != M[y][x] && M[y+1][x] != -1)){
		peace[idx].gr = max(peace[idx].gr, x+1);
		peace[idx].gl = min(peace[idx].gl, x);
	}
	M[y][x] = idx;
	REP(i, 4){
		int dy=y+d[i][1];
		int dx=x+d[i][0];
		if(dx<0||dy<0||w<=dx||h<=dy) continue;
		if(!visit[dy][dx] && M[dy][dx] == c) check(dy, dx, c, idx);
	}
}

int dfs(int r){
	REP(i, 160) if(par[i] == r){
		if(!dfs(i)) return 0;
		peace[r].ps.insert(peace[r].ps.end(), peace[i].ps.begin(), peace[i].ps.end());
	}
//	REP(i, peace[r].ps.size()) printf("%.2f ", peace[r].ps[i]);
//	puts("");
	if(peace[r].ps.size() == 0) return 1;
	double m = (double)accumulate(peace[r].ps.begin(), peace[r].ps.end(), 0.0) / peace[r].ps.size();
//	printf("%d -> %d %.2f %d\n", r, peace[r].gl, m, peace[r].gr);
	return peace[r].gl+1e-8 < m && peace[r].gr > m+1e-8;
}

int solve(){
	int idx = 0;
	REP(i, h){
		REP(j, w){
			if(M[i][j]!=-1 && !visit[i][j]){
				check(i, j, M[i][j], idx++);
			}
		}
	}
	REP(i, 160) par[i] = -1;
	REP(i, h-1){
		REP(j, w){
			if(M[i][j] != -1 && M[i+1][j] != -1 && M[i][j]!=M[i+1][j]){
				par[M[i][j]] = M[i+1][j];
			}
		}
	}
	REP(i, 160) if(par[i] == -1) return dfs(i);
	return 0;
}

main(){
	int i,j;
	while(cin >> w >> h, w){
		REP(i, 160) peace[i] = P();
		memset(visit, 0, sizeof(visit));
		REP(i, h){
			cin >> M[i];
			REP(j, w) if(M[i][j] == '.') visit[i][j] = 1, M[i][j] = -1;
		}
		cout << (solve() ? "STABLE":"UNSTABLE") << endl;
	}
	return 0;
}

Measured memory_bytes: 1308