akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ff(i,a,b) for(int i=a;i<b;++i)
#define fr(i,a,b) for(int i=a;i>b;--i)
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define FR(i,a,b) for(int i=a;i>=b;--i)
#define rc(t) char t;cin>>t
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rl(t) long t;cin>>t
#define rb(t) bool t;cin>>t
#define rll(t) long long t;cin>>t
#define mp(x,y) make_pair((x),(y))
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define set_bits(a) __builtin_popcount(a)
#define inf INT_MAX


using namespace std ;


typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector< vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<long long, int> > vpli;
typedef vector<pair<long long, long long> > vpll;
typedef vector<int>::iterator ii;
typedef vector<vi>::iterator ivi;
typedef unordered_map<int, int> umapii;
typedef unordered_map<int, bool> umapib;
typedef unordered_map<int, string> umapis;
typedef unordered_map<string, int> umapsi;
typedef unordered_map<string, string> umapss;
typedef map<int, int> mapii;
typedef map<string, int> mapsi;
typedef map<int, string> mapis;
typedef map<pair<int, int>, int> mappiii;
typedef map<int, pair<int,int> > mapipii;
typedef map<int, bool> mapib;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef unordered_set<int> useti;
typedef set<int> seti;
typedef priority_queue<int> mxpq;
typedef priority_queue< int, vector<int>, greater<int> > mnpq;


const int maxn = 2e5 + 17, maxv = 1e6 + 17, M = 1e9 + 7;


inline ll mod(ll a,ll b=M){
	a %= b ;
	if(a<0) a += b ;
	return a ;
}

///////////////////////////////////////////////////////////////////////////////




int main(){
	
	IOS ;

	rs(s) ; rll(k) ;
	char prev = '1' ;
	ll c = 1 ;
	ll diff = 0 ;
	FF (i,0,s.length()) {
		if (s[i] != prev) {
			diff += c/2 ;
			c = 1 ;
		} 
		else {
			c++ ;
		}

		prev = s[i] ;
	}

	ll first = 1 ;
	prev = s[0] ;

	ll i = 1 ;
	while (s[i++] == prev) {
		first++ ;
	}

	if (first == s.length()) {
		cout << (first*k)/2 << endl ;
		return 0 ;
	}

	reverse(s.begin(), s.end()) ;

	ll last = 1 ;
	char prev2 = s[0] ;

	i = 1 ;
	while (s[i++] == prev2) {
		last++ ;
	}

	ll extra = 0 ;
	if (prev == prev2 && first%2 && last%2) {
		extra = k-1 ;
	}



	cout << (diff*k + extra) << endl ;
	
}

Measured memory_bytes: 256
N = int(input())

lst = []
# listにN個の数値を格納
for i in range(N):
    lst.append(int(input()))

lst.sort()
lstsum = sum(lst)
p_list = [ i / 10 for i in lst if i % 10 != 0 ]

if len(p_list) == 0:
    print(0)
elif lstsum % 10 != 0:
    print(lstsum)
else:
    for i in range(N):
        ans = lstsum - lst[i]
        if ans % 10 != 0:
            print(ans)
            exit(0)


Measured memory_bytes: 3060
S = input()
T = input()

chk1 = [[] for _ in range(26)]
chk2 = [[] for _ in range(26)]
for i in range(len(S)):
    s1 = ord(S[i]) - 97
    s2 = ord(T[i]) - 97
    if len(chk1[s1]) == 0:
        chk1[s1].append(T[i])
    else:
        if chk1[s1][0] == T[i]:
            pass
        else:
            print('No')
            exit()
    if len(chk2[s2]) == 0:
        chk2[s2].append(S[i])
    else:
        if chk2[s2][0] == S[i]:
            pass
        else:
            print('No')
            exit()    
print('Yes')

Measured memory_bytes: 9428
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int x,a,b;
	cin >> x;
	for (int i = 1; i * i <= x; i++) {
		if (x % i == 0) {
			long long k = i;
			long long m = x / k * 16;
			long long a = 80 * k * k * k * k +m*20;
			if (a >= 0 && (sqrt(a) - (int)(sqrt(a)) <= 1e-8))
			{
				long long t = (int)(sqrt(a));
				if ((-10 * k * k + t) >= 0) {
					if (t % 10 == 0) {
						long long b = (t / 10 - k * k), l = 0;
						if ((sqrt(b) - (long long)sqrt(b)) <= 1e-8) {
							l = (long long)(sqrt(b));
							if (l ^ k == 0) {
								cout << (l + k) / 2 << ' ' << (l - k) / 2 << endl; return 0;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(){
  int a,b,c,ans=0;
  scanf("%d %d %d",&a,&b,&c);
  while(a<=b){
    if(c%a==0){
      ans++;
    }
    a++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
 
int N;
vector<int> S[1000];
 
int main()
{
	scanf("%d", &N);
 
	int a = -1;
	for (int i = 1; i <= 1000; ++i) {
		if (i * (i - 1) / 2 == N) {
			a = i;
			break;
		}
	}
	if (a == -1) {
		puts("No");
		return 0;
	}
	puts("Yes");
	printf("%d\n", a);
 
	int idx = 1;
	for (int i = 0; i < a; ++i) {
		for (int j = i + 1; j < a; ++j) {
			S[i].push_back(idx);
			S[j].push_back(idx++);
		}
	}
	for (int i = 0; i < a; ++i) {
		printf("%d", S[i].size());
		for (int j : S[i]) printf(" %d", j);
		puts("");
	}
 
	return 0;
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N, K; cin >> N >> K;
    vl A(N); REP(i, N) cin >> A[i], A[i]--;
    vi visited(N);

    int pos = 0;
    int count = 0;
    bool frag = false;
    while(K > 0)
    {
        if(!frag && visited[pos] != 0)
        {
            K %= (count - visited[pos]);
            frag = true;
        }
        else visited[pos] = count;
        if(K == 0) break;
        K--; count++;
        pos = A[pos];
    }
    cout << pos+1 << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
#define VLCIN(a, n) REP(i,n){cin >> a[i];}
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll x;
/******* define variable end *******/
int solve() {
	cin >> x;
	if(x <= 599) cout << 8 << endl;
	else if(x <= 799) cout << 7 << endl;
	else if(x <= 999) cout << 6 << endl;
	else if(x <= 1199) cout << 5 << endl;
	else if(x <= 1399) cout << 4 << endl;
	else if(x <= 1599) cout << 3 << endl;
	else if(x <= 1799) cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	ll N;
	cin >> N;

	int kokomade = sqrt(N) + 1;

	int saishou = 100;
	rep1(i, kokomade) {
		if (N % i == 0) {
			ll A = i;
			ll B = N / i;
			A = max(A, B);
			int keta = 0;
			while (A) {
				keta++;
				A /= 10;
			}
			saishou = min(saishou, keta);
		}
	}
	co(saishou);

	Would you please return 0;
}

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

using namespace std;
typedef long long Int;
Int n, m, res;
Int sum[108000];
Int a[108000];


Int dist(Int l, Int r){
  if(l <= r)return r - l;
  else return r + m - l;
}

int main(){
  cin >> n >> m;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(i){
      int l = a[i-1], r = a[i];
      if(l <= r){
	if(l + 1 >= r)continue;
	sum[l + 2]++;
	sum[r + 1]-=r-l;
	sum[r + 2]+=r-l-1;
      }
      if(l > r){
	sum[l + 2]++;
	int p = r + m - l;
	sum[0] += p - r;
	sum[1] -= p - r - 1;
	sum[r + 1]-=p;
	sum[r + 2]+=p-1;	
      }
    }
  }
  for(int i = 1;i < 108000;i++){
    sum[i] += sum[i-1];
  }
  for(int i = 1;i < 108000;i++){
    sum[i] += sum[i-1];
  }
  int ans = 1;
  for(int i = 1;i <= m;i++){
    if(sum[ans] < sum[i])ans = i;
  }
  for(int i = 0;i < n;i++){
    if(i){
      res += min(dist(a[i-1],a[i]), dist(ans, a[i]) + 1);
    }
  }
  cout << res << endl;
  return 0;
}

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

int main() {
	int N, M, Q, L, R, p, q;
	cin >> N >> M >> Q;
	vector<vector<int>> a(N);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--;
		R--;
		a[L].push_back(R);
	}
	for (vector<int>& i : a) sort(i.begin(), i.end());
	for (int i = 0; i < Q; i++) {
		cin >> p >> q;
		p--;
		q--;
		int b = 0;
		for (int j = p; j <= q; j++) b += upper_bound(a[j].begin(), a[j].end(), q) - a[j].begin();
		cout << b << endl;
	}
}

Measured memory_bytes: 2176
a = list(map(int,input().split()))
r,g,b= a[0],a[1],a[2]
k=int(input())
m=0
for i in range(k):
    if g>r:
        break
    g*=2
    m+=1
d = k -m
b=b*(2**d)

if b>g and g >r:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int main() {

	int a, b;

	while (cin >> a >> b, a != 0 && b != 0) {

		int dp[17][17] = { 0 };
		int n;

		cin >> n;

		dp[1][1] = 1;

		for (int i = 1; i <= n; i++) {
			int x, y;
			cin >> x >> y;
			dp[x][y] = -1;
		}

		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {

				if (dp[i][j] != -1) {
					if (j != 1 && dp[i][j - 1] != -1) {
						dp[i][j] += dp[i][j - 1];
					}

					if (i != 1 && dp[i - 1][j] != -1) {
						dp[i][j] += dp[i - 1][j];
					}
				}
			}
		}

		cout << dp[a][b] << endl;
	}

	return 0;

}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i + 2 < n; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

int[] digits(int n) {
    if (n == 0) return [0];

    int[] ds;
    while (n > 0) {
        ds ~= n % 10;
        n /= 10;
    }
    ds.reverse();
    return ds;
}

void main() {
    int n = readint;
    auto ds = digits(n);

    writeln(n % ds.sum == 0 ? "Yes" : "No");
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn dfs(e: &Vec<Vec<usize>>, cur: usize, par: usize, colors: &mut Vec<Option<usize>>, c: usize) -> bool {
    if let Some(cur_c) = colors[cur] {
        return cur_c == c
    }
    colors[cur] = Some(c);
    for &to in e[cur].iter() {
        if to != par {
            if !dfs(e, to, cur, colors, 1-c) {
                return false;
            }
        }
    }
    true
}


fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      abs: [(usize1, usize1); m],
    }

    let mut e = vec![vec![]; n];
    for (a, b) in abs {
        e[a].push(b);
        e[b].push(a);
    }

    let mut colors = vec![None; n];
    let biparitie = dfs(&e, 0, n, &mut colors, 0);

    if biparitie {
        let mut b = 0;
        let mut w = 0;
        for c in colors.into_iter().map(|v|v.unwrap()) {
            if c == 0 {
                b += 1;
            } else {
                w += 1;
            }
        }
        puts!("{}\n", b*w - m);
    } else {
        puts!("{}\n", n*(n-1)/2 - m);
    }
}


Measured memory_bytes: 14972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class F>
int upper_bound(int i0, int i1, F f) {
    while (i0 < i1) {
        int i = (i0 + i1) / 2;
        if (f(i)) i0 = i + 1; else i1 = i;
    }
    return i0;
}

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

    int n, x;
    cin >> n >> x;

    vector<ll> a(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[n - i];
    }
    for (int i = 0; i < n; i++) {
        a[i + 1] += a[i];
    }

    ll r = 1LL << 60;
    for (int k = 1; k <= n; k++) {
        ll s = (ll)x * (n + k) + a[k] * 5;
        for (int i = k; i < n; i += k) {
            s += (a[min(i + k, n)] - a[i]) * ((i / k) * 2 + 3);
            if (s >= r) break;
        }
        r = min(r, s);
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

#define max(a, b) (a > b ? a : b)

int main()
{
    int no_of_elements, sum;
    scanf("%d %d", &no_of_elements, &sum);

    int max_gcd = 1;

    for(int i = 1; i*i <= sum; i++)
    {
        if(sum%i == 0)
        {
            long long factor_1 = i, factor_2 = sum/i;

            if(factor_1*no_of_elements <= sum) max_gcd = max(max_gcd, factor_1);

            if(factor_2*no_of_elements <= sum) max_gcd = max(max_gcd, factor_2);
        }
    }

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


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};
#define int ll
int dp [1502] [152];
int n, m, s;
vector<vector<int>> mp;
vector<pll> st;
int func(int pos, int stnum, int spc) {
	if (spc == m+1)
		return -1;
	if (stnum == s)
		return 0;
	if (dp[stnum][spc] != -1)
		return dp[stnum][spc];
	int res = LLONG_MAX;
	int w = st[stnum].first;
	int sb = st[stnum].second;
	REP(i, mp[pos+1].size()) {
		int cand = func(pos + 1, mp[pos + 1][i], spc);
		if (cand == -1)
			continue;
		if (sb >= 0 && mp[pos+1][i] != s) {
			cand += (sb + st[mp[pos + 1][i]].second)*abs(w-st[mp[pos + 1][i]].first);
		}
		res = min(res, cand);
	}
	REP(i, mp[pos + 2].size()) {
		int cand = func(pos + 2, mp[pos + 2][i], spc+1);
		if (cand == -1)
			continue;
		if (sb >= 0 && mp[pos + 2][i] != s) {
			cand += (sb + st[mp[pos + 2][i]].second)*abs(w - st[mp[pos + 2][i]].first);
		}
		res = min(res,cand);
	}
	dp[stnum][spc] = res;
	if (res == LLONG_MAX)
		res = -1;
	return res;
}

signed main() {
	while (scanf("%lld %lld", &n, &m)) {
		if (n == 0)
			break;
		Fill(dp, -1);
		mp.clear();
		mp.resize(n+2);
		st.clear();
		s = 0;
		REP(i, n) {
			int c;
			scanf("%lld", &c);
			REP(j, c) {
				int a, b;
				scanf("%lld %lld", &a, &b);
				mp[i].push_back(s);
				st.push_back({ a,b });
				s++;
			}
		}
		mp[n].push_back(s);
		st.push_back({ -1,-1 });
		st.push_back({ -1,-1 });
		printf("%lld\n", func(-1, s+1, 0));
	}
	return 0;
}

Measured memory_bytes: 5000
import collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N - 1)]
G = collections.defaultdict(set)
for a, b in AB:
    G[a].add(b)
    G[b].add(a)
visited = [False] * (N + 1)
visited[1] = True
Q = collections.deque([1])
while Q:
    i = Q.popleft()
    for j in G[i]:
        if not visited[j]:
            visited[j] = True
            Q += [j]
visited = [False] * (N + 1)
visited[i] = True
Q = collections.deque([[i, 0]])
while Q:
    i, d = Q.popleft()
    for j in G[i]:
        if not visited[j]:
            visited[j] = True
            Q += [[j, d + 1]]
if (d + 1) % 3 == 2:
    print('Second')
else:
    print('First')


Measured memory_bytes: 126752
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            int sum = 0;
            int x = i;
            while (true) {
                if (x / 10 != 0) {
                    sum += x % 10;
                    x /= 10;
                } else {
                    sum += x;
                    break;
                }
            }
            if (a <= sum && sum <= b) {
                ans += i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n = int(input())
p = list(map(float, input().split()))

dp = [[0 for _ in range(n+1)] for _ in range(n+1)]

dp[0][0] = 1

for i in range(1, n+1):
  dp[i][0] = dp[i-1][0] * (1-p[i-1])
  
for i in range(1, n+1):
  for j in range(1, i+1):
    dp[i][j] = dp[i-1][j] * (1-p[i-1]) + dp[i-1][j-1] * p[i-1]
    
print(sum(dp[-1][(n+1)//2:]))

Measured memory_bytes: 329608
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const ll INF = 10010001010;
const int inf = 1000034000;

typedef tuple<string, int, int> TUP;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    int ans = 0;
    int dp[N];
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
        dp[i] = inf;
    }
    dp[0] = 0;
    dp[1] = abs(H[1] - H[0]);
    for (int i = 2; i < N;i++)
    {
        chmin(dp[i],dp[i-1] + abs(H[i-1] - H[i]));
        chmin(dp[i],dp[i-2] + abs(H[i] - H[i-2]));
    }
    cout << dp[N - 1] << endl;

}


Measured memory_bytes: 1024
import heapq as hp
import sys
input = sys.stdin.readline

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

q1 = []
for i in range(N):
    hp.heappush(q1, A[i])

Psum = [0]*(N+1)
Psum[0] = sum(q1)

for i in range(N):
    a1 = hp.heappop(q1)
    p = max(a1, A[N+i])
    hp.heappush(q1, p)
    Psum[i+1] = Psum[i] + p - a1

q2 = []
for i in range(N):
    hp.heappush(q2, -A[i+2*N])

Qsum = [0]*(N+1)
Qsum[N] = sum(q2)

for i in range(N-1, -1, -1):
    a2 = hp.heappop(q2)
    p = max(a2, -A[N+i])
    hp.heappush(q2, p)
    Qsum[i] = Qsum[i+1] + p - a2


for i in range(N+1):
    if i == 0:
        ans = Psum[i]+Qsum[i]
    ans = max(Psum[i]+Qsum[i], ans)
print(ans)

Measured memory_bytes: 39516
n = gets.to_i
s = gets.chomp

r, g, b = 0, 0, 0
s.each_char do |c|
  case c
    when 'R'; r += 1
    when 'G'; g += 1
    when 'B'; b += 1
  end
end

all = r * g * b

count = 0

# 2. iとjは全探索
n.times do |i|
  (i+1..(n+i)/2).each do |j|
    # Si != Sj
    next if s[i] == s[j]
    
    k = 2*j - i
    count += 1 if k < n and s[k] != s[i] and s[k] != s[j]
  end
end

p all - count


Measured memory_bytes: 14216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
const int INF = 2e9;

int main(){
    int n, t;
    cin >> n >> t;
    int a[n];
    int m[n+1];
    m[0] = INF;
    rep(i,n){ 
        cin >> a[i];
        m[i+1] = min(a[i],m[i]);
    }
    int l = -1;
    for(int i = 1; i < n; i++) l = max(l,a[i]-m[i]);
    int c = 0;
    for(int i = 1; i < n; i++) if(l == a[i]-m[i]) c++;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;

int main(){
   int n;cin>>n;
   vector<ll> a(n);
   rep(i,n)cin>>a[i];
   ll dp[n+1][2];
    dp[0][0] = 0;
    dp[0][1] = -INFTY;

    rep(i,n){
        dp[i+1][0] = max(dp[i][0]+a[i],dp[i][1]-a[i]);
        dp[i+1][1] = max(dp[i][0]-a[i],dp[i][1]+a[i]);
    }
    cout<<dp[n][0]<<endl;
return 0;
}

Measured memory_bytes: 2560
x,n = gets.split.map(&:to_i)
if n == 0
  puts x
  exit
end

a = gets.split.map(&:to_i)

b = (0..101).to_a
ans = 0
cnt = 10**10
(b - a).each do |i|
  diff = (x-i).abs
  if diff < cnt
    ans = i
    cnt = diff
  end
end
puts ans


Measured memory_bytes: 14360
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int l[N],r[N],lv[N],rv[N];
int main(){
	const int inf=1023456789;
	int n,mx=-1,mn=1023456789,md=-1;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d%d",&l[i],&r[i]);
	for(int i=0;i<n;i++){
		mx=max(mx,l[i]);
		mn=min(mn,r[i]);
		md=max(md,r[i]-l[i]);
	}
	int ans1=2+md+max(mn-mx,-1);
	for(int i=0;i<n;i++){
		lv[i]=mn-l[i];
		rv[i]=r[i]-mx;
	}
	map<int,int> p;
	p[inf]=inf;
	for(int i=0;i<n;i++){
		auto it=p.lower_bound(lv[i]);
		int tr=-1,tl=-1;
		while(it!=p.end()&&it->second>=rv[i]){
			tl=max(tl,it->first);
			tr=max(tr,it->second);
			it=p.erase(it);
		}
		if(tl>=0) p[tl]=rv[i];
		if(tr>=0) p[lv[i]]=max(p[lv[i]],tr);
	}
	int ans2=0;
	for(auto it=p.begin();it!=p.end();++it){
		if(it->first<inf&&it->second<inf){
			ans2=max(ans2,it->first+it->second+2);
		}
	}
	printf("%d\n",max(ans1,ans2));
	return 0;
}

Measured memory_bytes: 6528
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }.groupBy { it }.entries.sortedBy { it.key }
    val aMax = aa.maxBy { it.key }!!.key
    val isDividable = BooleanArray(aMax+1){false}

    aa.forEach { a ->
        if (isDividable[a.key]) return@forEach
        if (a.value.size > 1) isDividable[a.key] = true

        for (i in a.key*2 until isDividable.size step a.key) {
            isDividable[i] = true
        }
    }

    println(aa.count { !isDividable[it.key] })
}

Measured memory_bytes: 107656
N = int(input())
h = [i for i in map(int, input().split())]    
memo = [0] * (N+1)
for i in range(N):
    if i == 0:
        pass
    elif i == 1:
        memo[1] = abs(h[1]-h[0])
    else:
        memo[i] = min(memo[i-1]+abs(h[i]-h[i-1]),  memo[i-2]+abs(h[i]-h[i-2]))
print(memo[N-1])

Measured memory_bytes: 13980
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define ll long long

using namespace std;

int main(){

    int n;
    vector<vector<int>> edge;
    vector<int> c;
    vector<int> ansv;

    int sum = 0;
    int maxc = 0;

    cin >> n;

    //1オリジンに対応のようなもの
    for(int i = 0; i <= n; i++){
        vector<int> tmp;
        edge.push_back(tmp);
    }

    for(int i = 0; i < n - 1; i++){
        int tmpa,tmpb;
        cin >> tmpa >> tmpb;

        edge[tmpa].push_back(tmpb);
        edge[tmpb].push_back(tmpa);
    }

    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        sum += tmp;
        maxc = max(maxc,tmp);
        
        c.push_back(tmp);
    }

    sum = sum - maxc;

    sort(c.begin(),c.end());
    int ci = 0;

    for(int i = 0; i <= n; i++){
        ansv.push_back(0);
    }

    while(ci < n - 1){

        vector<int> tmpv;

        for(int i = 1; i <= n; i++){
            if(edge[i].size() == 1){
                cerr << i << endl;
                tmpv.push_back(i);
            }
        }

        queue<int> erases;

        for(int i = 0; i < tmpv.size(); i++){
            int node = tmpv[i];
            ansv[node] = c[ci];
            ci++;
            
            //int to = edge[node][0];

            //cerr << "node:" << node;
            //cerr << " to:" << to << endl;

            /*
            edge[node].erase(edge[node].begin());

            for(int j = 0; j < edge[to].size(); j++){
                if(edge[to][j] == node){
                    edge[to].erase(edge[to].begin() + j);
                }
            }*/

            erases.push(node);
        }

        while(!erases.empty()){
            int node = erases.front();
            int to = edge[node][0];

            if(edge[node].size() != 0){
                edge[node].erase(edge[node].begin());
            }

            for(int i = 0; i < edge[to].size(); i++){
                if(edge[to][i] == node){
                    edge[to].erase(edge[to].begin() + i);
                }
            }

            erases.pop();
        }
    }

    for(int i = 1; i <= n; i++){
        if(ansv[i] == 0){
            ansv[i] = c[ci];
        }
    }
    
    //output
    cout << sum << endl;
    for(int i = 1; i < n; i++){
        cout << ansv[i] << " ";
    }

    cout << ansv[n] << endl;

    return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
int main(){
    string S; cin >> S;
    vector<ll> idx; idx.push_back(-1);//RLとなる箇所のindexを管理
    vector<ll> diff; //Rの数、Lの数、Rの数、...と格納
    //vector<ll> idx_LR; //LRとなる箇所のindexを管理
    rep(i,S.length()-1){
        if(S[i] == 'R' && S[i+1] == 'L') idx.push_back(i);
        else if(S[i] == 'L' && S[i+1] == 'R') idx.push_back(i);
    }
  	idx.push_back(S.length()-1);
    rep(i,idx.size()) diff.push_back(idx[i+1] - idx[i]);
	//cout << diff.size() << endl;
  	ll child[S.length()]; rep(i,S.length()) child[i] = 0;
    for(ll i=0; i<diff.size()-1; i+=2){
        ll tmp1 = diff[i]; ll tmp2 = diff[i+1]; ll tmp3 = idx[i+1];
      	//cout << tmp1 << " " << tmp2 << " " << tmp3 << endl;
        child[tmp3] = (tmp1+1)/2 + tmp2/2;
        child[tmp3+1] = tmp1/2 + (tmp2+1)/2;
    }

    rep(i,S.length()) cout << child[i] << " ";
}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAXN = 2*1e5+10;
const ll INF = 1e10;

ll n;
ll a[MAXN], b[MAXN];
P task[MAXN];

void solve() {
  for (int i=0;i<n;i++) {
    task[i] = P(b[i] - a[i], i);
  }
  sort(task, task+n);
  ll cur = 0;
  ll maxT = 0;
  for (int i=0;i<n;i++) {
    P p = task[i];
    if (cur > p.first && maxT - cur < a[p.second]) {
      cout << "No" << endl;
      return;
    }
    cur = cur + a[p.second];
    maxT = max(maxT, b[p.second]);
  }
  cout << "Yes" << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i] >> b[i];
  }
  solve();
}


Measured memory_bytes: 6528
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    long A,B,K;
    cin>>A>>B>>K;
    
    set<long> s;
    for(int i=0;i<K;i++) if(A+i<=B) s.insert(A+i);
    for(int i=0;i<K;i++) if(B-i>=A) s.insert(B-i);
    
    for(auto ite=s.begin();ite!=s.end();++ite)cout<<*ite<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

void sample() {

    rep(m, 4) {
        vector<ll> v;
        rep(i, 1 << m) v.push_back(i);
        rep(i, 1 << m) v.push_back(i);
        int n = v.size();
        vector<int> arr(n);
        rep(i, n) arr[i] = i;

        do {
            set<ll> xx;
            rep(i, 1 << m) {
                vector<int> k;
                rep(j, n) if (v[arr[j]] == i) k.push_back(j);

                ll x = 0;
                for (int j = k.front(); j <= k.back(); j++) {
                    x ^= v[arr[j]];
                }
                xx.insert(x);
            }
            if (xx.size() == 1 && (*xx.begin()) != 0) {

                cout << *xx.begin() << ':';
                rep(i, n) cout << v[arr[i]] << ' ';
                cout << endl;

            }
        } while (std::next_permutation(arr.begin(), arr.end()));

    }

}

int main() {
//    sample();
//    ret();
    int n;
    ll k;
    cin >> n >> k;

    if (k == 0) {
        vector<int> ans;
        rep(i, 1 << n) ans.push_back(i), ans.push_back(i);
        for (int i : ans) cout << i << ' ';
        ret();
    }

    if (n == 1 && k == 1) {
        cout << -1 << endl;
        ret();
    }

    if (k >= (1 << n)) {
        cout << -1 << endl;
        ret();
    }


    vector<int> ans;
    rep(i, k) ans.push_back(i);
    ans.push_back(k);
    rep(i, k) ans.push_back(k - i - 1);
    for (int i = (1 << n) - 1; i > k; i--) ans.push_back(i);
    ans.push_back(k);
    for (int i = k + 1; i < (1 << n); i++) ans.push_back(i);

    for (int i : ans) cout << i << ' ';


}


Measured memory_bytes: 4324
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

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

int main(){
  ll n, x;
  cin >> n >> x;
  vll X(n+1);
  rep(i, n){
    cin >> X[i];
  }
  X[n] = x;
  sort(X.begin(), X.end());
  vll dist(n);
  rep(i, n){
    dist[i] = X[i + 1] - X[i];
  }
  if (dist.size() == 1){
    cout << dist[0] << endl;
  }
  else{
    ll ans = gcd(dist[0], dist[1]);
    for (int i = 2;i < n; i++){
      ans = gcd(ans, dist[i]);
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 1792
#include<cstdio>//AT3959
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=200010;

struct B{
	int u,id;
	bool operator<(const B&rhs)const{
		return u<rhs.u;
	}
};

B b[N];

int n,a[N],aans;

int main(){
	scanf("%d",&n);
	if(n==1){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i].u=a[i];
		b[i].id=i;
	}
	sort(b+1,b+1+n);
	int cnt=1;
	for(int i=2;i<=n;i++){
		if(b[i].id>b[i-1].id){
			cnt++;
		}
		else{
			aans=max(cnt,aans);
			cnt=1;
		}
	}
	// cnt=1;
	// for(int i=n-1;i;i--){
	// 	if(b[i].id>b[i+1].id){
	// 		cnt++;
	// 	}
	// 	else{
	// 		aans=max(cnt,aans);
	// 		cnt=1;
	// 	}
	// }
	aans=max(cnt,aans);
	printf("%d\n",n-aans);
	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int MOD = 1e9+7;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	ll ans = 0;

	ll p10 = 1;
	F0R(i, N) p10 = (10 * p10) % MOD;
	ll p9 = 1;
	F0R(i, N) p9 = (9 * p9) % MOD;
	ll p8 = 1;
	F0R(i, N) p8 = (8 * p8) % MOD;
	print((((p10 - (2 * p9 - p8)) % MOD) + MOD) % MOD);
}

Measured memory_bytes: 3664
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
bool book[500100];
long long sum=0;
string a,b;
void read(int &x)
{
	int i=1; x=0; char a=getchar();
	while(a<'0'||a>'9')
	{
		if(a=='-') i=-1;
		a=getchar();
	}
	while(a>='0'&&a<='9')
	{
		x=x*10+a-48;
		a=getchar();
	}
	x*=i;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9) write(x/10);
	putchar(x%10+48);
}
int main()
{
	cin>>a;
	cin>>b;
	for(long long i=1;i*i<=200100;i++)
	book[i*i]=1;
	string s=a+b;
	int q=s.size();
	int n=q;
	for(int i=0;i<q;i++)
	{
		sum+=(s[i]-48)*pow(10,(n-1));
		n--;
	}
	if(book[sum]==0) printf("No");
	else printf("Yes");
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    int n, d, a;
    cin >> n >> d >> a;
    vector<pair<int, int>> dt(n);
    ll ans = 0;

    rep(i, n) { cin >> dt[i].first >> dt[i].second; }
    sort(dt.begin(), dt.end());

    queue<pair<ll, ll>> q;
    ll diff = 0;

    rep(i, n) {
        while (!q.empty() && q.front().first < dt[i].first) {
            diff -= q.front().second;
            q.pop();
        }

        dt[i].second -= a * diff;
        if (dt[i].second > 0) {
            ll num = (dt[i].second + a - 1) / a;
            ans += num;
            q.emplace(dt[i].first + 2 * d, num);
            diff += num;
        }
    }

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


Measured memory_bytes: 3456
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
vll par(MAX),siz(MAX);

//par[i]=iならiは根（はじめは全て根）
void init(ll n){
  rep(i,0,n){
    par[i]=i;siz[i]=1LL;
  }
  return;
}
//xの根
ll root(ll x){
  return (par[x]==x)?x:par[x]=root(par[x]);
}
//xが根の木とyが根の木を繋げる
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y){return;}
  if(siz[x]<siz[y]){swap(x,y);}
  siz[x]+=siz[y];
  par[y]=x;
}
//根が同じかどうか
bool same(ll x,ll y){
  return root(x)==root(y);
}
int main(){
  ll n,m,k;cin>>n>>m>>k;
  init(n);
  vvll g1(n,vll(0)),g2(n,vll(0));
  rep(i,0,m){
    ll a,b;cin>>a>>b;
    a--;b--;
    unite(a,b);
    g1[a].push_back(b);
    g1[b].push_back(a);
  }
  
  rep(i,0,k){
    ll a,b;cin>>a>>b;
    a--;b--;
    g2[a].push_back(b);
    g2[b].push_back(a);
  }
  rep(i,0,n){
    ll ans=siz[root(i)]-1-g1[i].size();
    for(auto u:g2[i]){
      if(same(i,u))ans--;
    }
    cout<<ans<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 23172
x=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
if 400 <= x <= 599:
    ans=8
if 600 <= x <= 799:
    ans=7
if 800 <= x <= 999:
    ans=6
if 1000 <= x <= 1199:
    ans=5
if 1200 <= x <= 1399:
    ans=4
if 1400 <= x <= 1599:
    ans=3
if 1600 <= x <= 1799:
    ans=2
if 1800 <= x <= 1999:
    ans=1
print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}


ll p[maxn], q[maxn], r[maxn];

int main()
{
  ios::sync_with_stdio(false);
  int a,b,c,x,y;
  cin >> x >> y >> a >> b >> c;
  
  for(int i = 0; i < a; i++)
  {
    cin >> p[i];
  }

  for(int i = 0; i < b; i++)
  {
    cin >> q[i];
  }

  for(int i = 0; i < c; i++)
  {
    cin >> r[i];
  }

  sort(p, p + a);
  sort(q, q + b);
  sort(r, r + c, greater<ll>());

  ll sumP = 0, sumQ = 0;

  for(int i = 0, j = a - 1; i < x; i++, j--)
    sumP += p[j];


  for(int i = 0, j = b - 1; i < y; i++, j--)
    sumQ += q[j];


  int pp = a - x, pq = b - y, pr = 0;



  ll ans = sumP + sumQ;

  //debug(ans);

  while(pr < c)
  {
    if(pp == a || pq == b)
      break;
    ll val = 0;
    if(-p[pp] > -q[pq])
    {
      val = sumP - p[pp] + r[pr] + sumQ;
      //debug(val);
      sumP -= p[pp];
      sumP += r[pr]; 
      pp++;
    }
    else
    {
      //debug(q[pq]);
      val = sumQ - q[pq] + r[pr] + sumP;
      sumQ -= q[pq];
      sumQ += r[pr]; 
      pq++;
    }
    //cout << val << endl;    
    if(val > ans)
    {
      ans = val;
    }
    else
      break;
    
    pr++;
  }


  ll val = 0;
  while(pr < c && pp < a && (sumP - p[pp] + r[pr] + sumQ > ans))
  {
    val = sumP - p[pp] + r[pr] + sumQ;
    sumP -= p[pp];
    sumP += r[pr]; 
    pp++;
    pr++;
    ans = val;
  }


  while(pr < c && pq < b && (sumQ - q[pq] + r[pr] + sumP > ans))
  {
    val = sumQ - q[pq] + r[pr] + sumP;
    sumQ -= q[pq];
    sumQ += r[pr]; 
    pq++;
    ans = val;
    pr++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int m;
    cin >> m;
    vector<lP> dc(m);
    rep(i, m){ cin >> dc[i].first >> dc[i].second;}

    ll dd = 0;
    ll keta = 0;
    rep(i, m){
        dd += dc[i].first *dc[i].second;
        keta += dc[i].second;
    }

    ll keta_up = 0;
    ll keta_matu = 0;
    while(dd >= 10){
        keta_up += dd/10;
        keta_matu = dd%10;
        dd /= 10;
        dd += keta_matu;
    }



    cout << keta-1+keta_up << endl;
}



Measured memory_bytes: 3328
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math
import random

sys.setrecursionlimit(1000000)

INF = 10 ** 18

n = input()
ls = []
n_ = n

i = 2
while True:
    if i * i > n:
        break
    while n % i == 0:
        n /= i
        ls.append(i)
    i += 1

if n != 1:
    ls.append(n)

print str(n_) + ": " + " ".join(map(str, ls))


Measured memory_bytes: 6932
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
  vector<int> A(3);
  rep(i, 0, 3) cin >> A[i];
  sort(A.begin(), A.end());
  int ans = 0;
  while(A[1] > A[0]) {
    A[0] += 2;
    ans++;
  }
  if(A[0] > A[1]) {
    A[1]++;
    A[2]++;
    ans++;
  }
  ans += A[2] - A[1];
  cout << ans << endl;
  return 0;
}


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

int main() {
	
	int N, A, B;
	cin >>N >>A >>B;
	
	if(N*A<=B){
		
		cout <<N*A <<endl;
		
	}
	else{
		
		cout <<B <<endl;
		
	}
}

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

using namespace std;

#define INF 2e9

using ii = pair<int,int>;

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

    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> heights(n);
    vector<int> dp(n,INF);
    dp[0] = 0; //minimum cost
    for(auto& x : heights)
    {
        cin >> x;
    }

    for(int i=0;i<n;++i)
    {
        for(int j=0;j<=k;j++){
            if(i-j>=0)
                dp[i] = min(dp[i],dp[i-j] + abs(heights[i] - heights[i-j]));
        }
    }

    cout << dp[n-1] << '\n';


    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '.')  continue;
            bool flag = false;
            for(int k = 0; k < 4; ++k){
                int x = i + dx[k], y = j + dy[k];
                if(x < 0 || x >= h || y < 0 || y >= w)  continue;
                if(s[i][j] == s[x][y]){
                    flag = true;
                    break;
                }
            }
            if(!flag){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256