akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int i,n,a[100000],cnt,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	sort(a,a+n);
//	for(i=0;i<n;i++)	printf("%d\n",a[i]);
	x=1;
	cnt=0;
	for(i=1;i<n;i++)	{
		if(a[i]==a[i-1])	{
			x++;
		}
		else {
			if(a[i-1]<x)	cnt+=x-a[i-1];
			else if(a[i-1]>x)	cnt+=x;
			x=1;
		}
	}
	if(a[n-1]<x)	cnt+=x-a[n-1];
	else if(a[n-1]>x)	cnt+=x;
	printf("%d\n",cnt);
    return 0;
}


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

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  int a;
  int l = 0, r = 0;
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (0 <= a && a <= x) l++;
    else r++;
  }
  cout << min(r, l) << endl;
}


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

import std.math;

void main() {
    int n;
    scan(n);
    auto s = readln.split;

    foreach (ch ; s) {
        if (ch == "Y") {
            writeln("Four");
            return;
        }
    }

    writeln("Three");
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

vector<int> s(6), b(6);
int tmp;

string com = "NNNNEEEE";

bool isSame(vector<int> a, vector<int> b) {
    for (int i = 0; i < 6; ++i) {
        if (a[i] != b[i]) return false;
    }
    return true;
}

signed main() {
    for (int i = 0; i < 6; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < 6; ++i) {
        cin >> b[i];
    }
    
    for (int n = 0; n < 8; ++n) {
        do {
            for (int i = 0; i < n; ++i) {
                if(isSame(s, b)) {
                    cout << "Yes" << endl;
                    return 0;
                }
                
                if (com[i] == 'N') {
                    tmp = s[5];
                    s[5] = s[4];
                    s[4] = s[0];
                    s[0] = s[1];
                    s[1] = tmp;
                }
                else if (com[i] == 'E') {
                    tmp = s[5];
                    s[5] = s[2];
                    s[2] = s[0];
                    s[0] = s[3];
                    s[3] = tmp;
                }
                else if (com[i] == 'W') {
                    tmp = s[5];
                    s[5] = s[3];
                    s[3] = s[0];
                    s[0] = s[2];
                    s[2] = tmp;
                }
                else if (com[i] == 'S') {
                    tmp = s[5];
                    s[5] = s[1];
                    s[1] = s[0];
                    s[0] = s[4];
                    s[4] = tmp;
                }
            }
        } while (next_permutation(com.begin(), com.end()));
    }

	cout << "No" << endl;
}


Measured memory_bytes: 3212
#include <iostream>

using namespace std;

int main() {
    long int n, m;
    long int ans = 0;

    cin >> n >> m;
    if (n == 1 && m == 1){
        cout << 0 << endl;
        return 0;
    }
    if (n >= 2){
        ans += n * (n - 1) / 2;
    }
    if (m >= 2){
        ans += m * (m - 1) / 2;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

vector<int> edge[100010];
int ans[100010];
int dist[100010];

void bfs() {
	for(int i = 0; i < 100010; ++i) {
		dist[i] = INF;
	}
	dist[0] = 0;
	queue<pair<int, int>> que;
	que.emplace(0, 0);
	while(not que.empty()) {
		int from, c;
		tie(from, c) = que.front();
		que.pop();
		for(int to : edge[from]) {
			if(c >= dist[to]) continue;
			dist[to] = c;
			ans[to] = from;
			que.emplace(to, c + 1);
		}
	}
}

int main() {
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	bfs();
	cout << "Yes" << '\n';
	for(int i = 1; i < n; ++i) {
		cout << ans[i] + 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 11100
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	xm := make(map[int]int)
	sum := 0
	for i := 0; i < n; i++ {
		a := scanInt()
		xm[a]++
		sum += a
	}

	wr := bufio.NewWriter(os.Stdout)
	q := scanInt()
	for i := 0; i < q; i++ {
		b, c := scanInt(), scanInt()
		sum -= b * xm[b]
		sum += c * xm[b]
		wr.WriteString(strconv.Itoa(sum) + "\n")
		xm[c] += xm[b]
		delete(xm, b)
	}
	wr.Flush()
}


Measured memory_bytes: 8300
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    int ans = 0;
    int test_num = 1;
    int cnt = 0;
    while(1) {
        if ( cnt == n ) break;
        test_num *= 3;
        ++cnt;
    }
    int even = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if ( a % 2 == 0 ) ++even;
    }
    cnt = 0;
    int allodd = 1;
    while(1) {
        if ( cnt == even ) break;
        allodd *= 2;
        ++cnt;
    }
    cout << test_num - allodd << endl;
    return 0;
}


Measured memory_bytes: 256
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

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)*}};}
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)*}};}
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:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        s: chars
    }

    let mut ans = 0;
    for c in &s {
        let n = if *c == '+' { 1 } else { -1 };
        ans += n;
    }

    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
const long long oo=165430000;
bool check,vis[11000];
long long n,m,lazy,ans,linkk[11000],t;
struct node
{
	long long n,y,v;
}e[110000];
struct point
{
	int x,y;
}a[120],b[120];
long long read() 
{ 
    bool flag=true; 
    long long num=0;char c=getchar(); 
    for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=false; 
    for(;c>='0'&&c<='9';c=getchar()) 
    num=(num<<3)+(num<<1)+c-48; 
    if(flag) return num; 
     else return -num; 
} 
void insert(int a,int b,int v){
	e[++t].y = b;e[t].n = linkk[a];e[t].v = v;linkk[a] = t;
	e[++t].y = a;e[t].n = linkk[b];e[t].v = 0;linkk[b] = t;
	return;
}
void init()
{
	n = read();
	t = 1;
    for(int i = 1;i <= n;++i) a[i].x = read(), a[i].y = read();
    for(int i = 1;i <= n;++i) b[i].x = read(), b[i].y = read();
    for(int i = 1;i <= n;++i)
     for(int j = 1;j <= n;++j)
      if(a[i].x < b[j].x&&a[i].y < b[j].y) 
       insert( i , j + n , 1) ; 
    for(int i = 1;i <= n;++i)
     insert( 2 * n + 1 , i , 1) , insert( i + n, 2 * n + 2 , 1);
    return;
}
void dfs(int x,long long point)
{
	vis[x]=true;
	if(x==2*n+2) 
	{
		ans+=point;
		check=true;
	    lazy=point;	
	    return;
	}
	for(int i=linkk[x];i;i=e[i].n)
	 if(!vis[e[i].y]&&e[i].v>0)
	  {
	  	dfs(e[i].y,min(point,e[i].v));
	  	if(check)
	  	 {
	  	   e[i].v-=lazy;
	  	   e[i^1].v+=lazy;
	  	   return;
	  	 }
	  } 
	return;
}
int main()
{
	init();
	check=true;
	while(check)
	 {
	 	check=false;
	 	memset(vis,0,sizeof(vis));
	    dfs(2*n+1,oo);
	 }
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat May  2 21:14:11 JST 2020
 **/

signed main() {
    Int a, b, n;
    std::cin >> a >> b >> n;
    Int q = std::min(b - 1, n);
    std::cout << (a * q) / b << std::endl;
}


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

int main(){
  int N,x;
  cin>>N>>x;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int i;
  for(i=0;i<N;i++){
    if(x>=v[i])x-=v[i];
    else break;
  }
  int ans=i;
  if(i==N&&x!=0)ans--;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll A, B, C;
    cin >> A >> B >> C;
    if(!cin) return;
    ll ans;
    ans = min(A+B+1, C);
    ans += B;
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


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

int sz[2050];int val[2050];

int k,n;
int h[999999][4]; int dp[999999][4];
int knp( int i , int f1)
{
    if(i>n) return 0;
    if( dp[i][f1] != -1 )
        return dp[i][f1];

     int ret=0;
    for (int j=1;j<=3;j++){

             if( j != f1 )
                ret = max( ret , h[i][j] + knp( i+1,j ) );

    }

    return  ( dp[i][f1] = ret );


}




int main()
{
   cin>>n;
   memset(dp,-1,sizeof(dp));

   for(int i=1;i<=n;i++){
          cin >> h[i][1] >> h[i][2] >>h[i][3];

   }
cout << knp(1,0) <<endl;


return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> k(n);
    vector<vector<int>> a(n,vector<int>(m));
    vector<vector<int>> result(n);
    for(int i = 0;i < n;i++){
        cin >> k[i];
        for(int j = 0;j < k[i];j++){
            cin >> a[i][j];
            if(i == 0){
                result[i].push_back(a[i][j]);
            }
            else{
                auto res = find(result[i-1].begin(),result[i-1].end(),a[i][j]);
                if(!(res == result[i-1].end())){
                    result[i].push_back(a[i][j]);
                }
            }
        }
    }
    cout << result[n-1].size() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0;i<n;i++)
typedef vector<int> vec;
long modpow(long a,long n,long mod){
  long ans=1;
  while (n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n=n/2;
  }
  return ans; 
}
long modinv(long a,long mod){
  return modpow(a,mod-2,mod);
}
long cx(long x,long n,long mod){
    long cx=1;
    rep(i,x){
    cx=cx*(n-i)%mod;
    cx=cx*modinv(i+1,mod)%mod;
  }
  return cx;
}
int main(){
  long mod=1000000007;
  long n,a,b,ans,ca,cb;
  cin>>n>>a>>b;
  ans=(modpow(2,n,mod)-1-cx(a,n,mod)-cx(b,n,mod)+3*mod)%mod;

  cout<<ans;
}

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

using namespace std;

typedef int ll;

ll dp[20010][256];
int book[20];
int input[20010];
int N, M;

static const ll MAX = 100000000;

void init() {
  fill(&dp[0][0], &dp[20009][256], MAX);
}

void solve() {
  dp[0][128] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 256; j++) {
      for (int k = 0; k < M; k++) {
        int tar = j + book[k];
        if (tar < 0) {
          tar = 0;
        } else if (tar > 255) {
          tar = 255;
        }
        ll sub = tar - input[i];
        sub *= sub;
        dp[i + 1][tar] = min(dp[i + 1][tar], dp[i][j] + sub);
      }
    }
  }

  ll mn = MAX;
  for (int i = 0; i < 256; i++) {
    mn = min(mn, dp[N][i]);
  }
  printf("%ld\n", mn);
}

int main() {
    while (true) {
      scanf("%d %d ", &N, &M);
      if (N == 0 && M == 0) {
        break;
      }
      init();
      for (int i = 0; i < M; i++) {
        scanf("%d ", &book[i]);
      }
      for (int i = 0; i < N; i++) {
        scanf("%d ", &input[i]);
      }
      solve();
    }
}

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

dp = [[0] * (n + 2) for i in range(n)]
dp[0][1] = 1 - p[0]
dp[0][2] = p[0]

for i in range(1, n):
    for j in range(1, i + 3):
        dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i])

ans = 0
for i in range(n//2 + 2, n + 2):
    ans += dp[n - 1][i]

print(ans)

Measured memory_bytes: 261640
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;		

boost::optional<std::vector<index_t>> topological_sort(std::vector<std::set<index_t>>const& edge)
{
	auto const N = edge.size();
	std::vector<index_t> ret(N);
	index_t now = N;
	enum mark
	{
		none,
		temp,
		conf
	};
	std::vector<mark> vec(N);
	std::function<bool(index_t)> visit = [&](index_t i)
	{
		if (vec[i] == temp)
		{
			return false;
		}
		else if (vec[i] == none)
		{
			vec[i] = temp;
			for (auto&& n : edge[i])
			{
				if (!visit(n))
				{
					return false;
				}
			}
			vec[i] = conf;
			ret[--now] = i;
		}
		return true;
	};
	for (auto i : boost::irange(index_t(), N))
	{
		if (vec[i] != none)
		{
			continue;
		}
		if (!visit(i))
		{
			return boost::none;
		}
	}
	return ret;
}

void Main()
{
	std::size_t N, M;
	std::cin >> N >> M;
	std::vector<std::set<index_t>> edge(N);
	std::vector<index_t> count(N);
	for (auto i : boost::irange<index_t>(1, N + M))
	{
		index_t a, b;
		std::cin >> a >> b;
		--a; --b;
		edge[a].emplace(b);
		++count[b];
	}
	auto sorted = topological_sort(edge);
	for (auto i : *sorted)
	{
		std::set<index_t> erase;
		for (auto n : edge[i])
		{
			if (count[n] != 1)
			{
				erase.emplace(n);
				--count[n];
			}
		}
		for (auto n : erase)
		{
			edge[i].erase(n);
		}
	}
	std::vector<boost::optional<index_t>> prev(N);
	std::stack<std::pair<boost::optional<index_t>, index_t>> stack;
	stack.emplace(boost::none, sorted->at(0));
	while (stack.size())
	{
		auto p = stack.top();
		stack.pop();
		prev[p.second] = p.first;
		for (auto n : edge[p.second])
		{
			stack.emplace(p.second, n);
		}
	}
	for (auto p : prev)
	{
		if (!p)
		{
			std::cout << 0 << std::endl;
		}
		else
		{
			std::cout << *p + 1 << std::endl;
		}
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 17656
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

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

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

int main() {
	int k;
	int ans = 0;
	cin >> k;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				ans += gcd(gcd(i, j), l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3596
#n,k=gets.split(' ').map(&:to_i)
h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
a=Array.new(3)
a[0] = h[2]
a[1] = h[0]
a[2] = h[1]

puts a


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

int main() {
  string s,t;
  cin>>s;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(s[i]=='0')t.push_back('0');
    else if(s[i]=='1')t.push_back('1');
    else {
      if(t.size()!=0)t.pop_back();
    }
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 3608
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
count = 0
for i in range(N):
    for j in range(i+1, N):
        if L[i] == L[j]:
            continue
        count += 1
        if j < N-1 and L[j] == L[j+1]:
            continue

        l = L[i] + L[j]

        id = bisect.bisect_left(L, l)
        # print(L[i], L[j], id)
        ans += (id - j - 1)*count
        count = 0
# print(L)
print(ans)


Measured memory_bytes: 9192
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

const [n, k]: number[] = input[0].split(' ').map((x: string): number => +x);
const s: string[] = input[1].split('');
let ans: string = '';
for(let i = 0; i < k-1; i++){
    ans += s[i];
}
ans += s[k-1].toLowerCase();
for(let i = k; i <n; i++){
    ans += s[i];
}

console.log(ans);




Measured memory_bytes: 7372
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
MOD=10**9+7
dp=np.zeros((n+1,k+1),dtype=np.int64)
dp[0][0]=1
cnt=1
for i in range(n):
    dp[i+1]=dp[i]
    dp[i+1][a[i-1]+1:]-=dp[i][:-(a[i-1]+1)]
    np.cumsum(dp[i+1],out=dp[i+1])
    dp[i+1]%=MOD
print(dp[n][k])

Measured memory_bytes: 90572
package main

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

func main() {
	N := ReadInt()
	S := ReadString()
	max := 0
	x := 0
	for i := 0; i < N; i++ {
		if S[i] == 'I' {
			x++
		} else {
			x--
		}
		max = Max(max, x)
	}
	fmt.Println(max)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  ll N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  ll sum = 0; rep(i,N) sum += A[i];
  if (sum%(N*(N+1)/2)!=0) { cout << "NO" << endl; return 0; }
  ll count = sum / (N*(N+1)/2);
  ll num = 0;
  rep(i,N) {
    ll diff = A[i] - A[(i+1)%N];
    if (diff+count<0||(diff+count)%N!=0) { 
      cout << "NO" << endl;
      return 0;
    }
    num += (diff+count)/N;
  }
  string result = (num==count) ? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int score,total,check[3],r;
  int i;
  char grade;

  while(1){
    total = 0;
    for(i=0;i<3;i++){
      check[i] = 0;
    }
    for(i=0;i<3;i++){
      scanf("%d",&score);
      if(score>-1){
        if(i==2){
          r = score;
        }
        else {
          total += score;
        }
      }
      else{
        check[i] = 1;
      }
    }
    if (check[0] && check[1] && check[2]){
      break;
    }
    if (check[0] || check[1]){
      total -= 100;
    }
    if(total<30){
      grade = 'F';
    }
    else if(total<50){
      grade = 'D';
      if(r>=50){
        grade = 'C';
      }
    }
    else if(total<65){
      grade = 'C';
    }
    else if(total<80){
      grade = 'B';
    }
    else{
      grade = 'A';
    }

    printf("%c\n", grade);
  }


  return 0;
}


Measured memory_bytes: 2044
n = int(input())
ac = wa = tle = re = 0

for i in range(n):
    t = input()
    if(t == 'AC'):
        ac += 1
    elif(t == 'WA'):
        wa += 1
    elif(t == 'TLE'):
        tle += 1
    elif(t == 'RE'):
        re += 1
    else:
        continue

print("AC x ",ac)
print("WA x ",wa)
print("TLE x ",tle)
print("RE x ",re)



Measured memory_bytes: 9124
#include <iostream>

using namespace std;

int main()
{
	int n, t, min, max;
	cin >> n;
	cin >> min;
	cin >> t;
	max = t - min;
	if (t < min)
		min = t;
	for (int i=0; i < n-2; i++) {
		cin >> t;
		if (t - min > max)
			max = t - min;
		if (t < min)
		        min = t;
	}
	cout << max << endl;
	
	return 0;
}

Measured memory_bytes: 1164
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = nextInt()
    val nums = mutableMapOf(s to 1)

    var num = s
    var index = 2

    while (true) {
        if (num % 2 == 0) {
            num /= 2
        } else {
            num = 3 * num + 1
        }

        if (nums[num] == null) {
            nums[num] = index
        } else {
            println(index)
            return
        }

        index++
    }
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33860
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};

int h,w,cnt=0;
int mas[55][55];
void dfs(int y,int x){
    mas[y][x]=0;
    for(int i=0;i<8;i++){
        int ny=y+dy[i];
        int nx=x+dx[i];
        if(ny<0||nx<0||ny>=h||nx>=w)continue;
        if(mas[ny][nx]==1){
            dfs(ny,nx);
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true){
        cin>>w>>h;
        if(h==0&&w==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>mas[i][j];
            }
        }
        cnt=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(mas[i][j]==1){
                    cnt++;
                    dfs(i,j);
                }
            }
        }
        cout<<cnt<<endl;
    }
}




Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int d = max( { a, b, c }), ans = a + b + c - d;
  rep(i,k)
    d *= 2;
  ans += d;
  cout << ans;
}


Measured memory_bytes: 256
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
Result = False
op = ["+", "-"]

def func(sign, num1, num2):
    if sign == "+":
        result = num1 + num2
    else:
        result = num1 - num2
    return result

for i in range(2):
    op1 = op[i]
    r1 = func(op1, A, B)
    for j in range(2):
        op2 = op[j]
        r2 = func(op2, r1, C)
        for k in range(2):
            op3 = op[k]
            r3 = func(op3, r2, D)
            if r3 == 7:
                Result = True
            if Result:
                break
        if Result:
            break
    if Result:
        break

print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
int q,n;
string a,b;
 
int main() {
  
	cin >> a >> b;
	cout << b << a;
 	
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
	let inputs = input.split("\n");
	let nm = inputs[0].split(' ').map((num) => (parseInt(num, 10)));
	let n = nm[0];
	let m = nm[1];

	let shops = [];
	for(let i = 0; i < n; i++) {
		let stats = inputs[i+1].split(' ').map((num) => (parseInt(num, 10)));
		shops.push({price: stats[0], stock: stats[1] })
	}

	shops.sort((a, b) => {
		if(a.price > b.price) return -1;
		if(a.price < b.price) return 1;
		return 0;
	})

	let totalCount = 0;
	let totalPrice = 0;
	while(totalCount < m) {
		let shop = shops.pop();
		if((m - totalCount) >= shop.stock) {
			totalCount += shop.stock;
			totalPrice += shop.stock * shop.price;
		} else {
			totalPrice += (m - totalCount) * shop.price;
			totalCount = m;
		}
	}

	console.log(totalPrice);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 53476
n=int(input())
a = list(map(int, input().strip().split()))
a.sort()
lim=10**6+1
ans=0
multiples=[False]*lim

for i in range(n):
    if multiples[a[i]]==True:
        continue
    elif i!=n-1 and a[i]==a[i+1]:
        pass
    else:
        ans+=1
    for j in range(a[i],lim,a[i]):
        multiples[j]=True

print(ans)

Measured memory_bytes: 32244
#include <iostream>

using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if (a > b)
        cout << "a > b" << endl;
    if (a < b)
        cout << "a < b" << endl;
    if (a == b)
        cout << "a == b" << endl;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main () {
	int num, ctr, temp;
	scanf("%d", &num);
	for(int i = 1; i <= 9; i++) {
		if(num % i == 0) {
			temp = i;
			for(int j = 1; j <= 9; j++) {
				if(temp*j == num) {
					ctr++;
				}
			}
		}
	}
	if(ctr > 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
			
	
	return 0;
}

Measured memory_bytes: 1664
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	pii x;
	cin>>n;
	for(int i=1;i<=n;i++){
		ll y=0,z=i;
		for(int j=1;z%2==0;j++){
			z/=2;
			y++;
		}
		if(y>=x.S)
			x={i,y};
	}
	cout<<x.F;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
	long long N,A,B;
	cin>>N>>A>>B;
	if(A==B)cout<<1<<endl;
	else if(A>B || N==1)cout<<0<<endl;
	else cout<<(B-A)*(N-2)+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=20000005;
const int MOD=998244353;
int n,A,B;
long long fac[N],inv[N];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
void init(int n=20000000)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[n]=ksm(fac[n],MOD-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%MOD;
	return;
}
long long C(int n,int m)
{
	if(m>n) return 0;
	else return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
long long Catalan(int n,int m)
{
	return (C(n+m,n)-C(n+m,n+1)+MOD)%MOD;
}
int main()
{
	init();
	scanf("%d%d%d",&n,&A,&B);
	if(B==0)
	{
		printf("1");
		return 0;
	}
	long long ans=0;
	for(int k=0;B+k<n&&k<=A;k++)
		ans=(ans+Catalan(B-1,k)*C(n-B-k-1+A-k,A-k)%MOD)%MOD;
	if(A+B==n) ans=(ans+Catalan(B-1,A))%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 316328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            char[] input = br.readLine().toCharArray();

            String result = "No";
            if (input[0] == input[1] && input[1] == input[2] || input[1] == input[2] && input[2] == input[3]) {
                result = "Yes";
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }

    static void swap(List<String> list, int index1, int index2) {
        String tmp = list.get(index1);
        list.set(index1, list.get(index2));
        list.set(index2, tmp);
    }
}

Measured memory_bytes: 23124
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

struct px {
        ll x, c;
        bool operator < (const px & a) const {
            return x < a.x;
        }

        void read() {
            cin >> x >> c;
        }
    };

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

    ll N, D, A;
    cin >> N >> D >> A;

    px X[N];
    REP(i, N) {
        X[i].read();
        X[i].c = (X[i].c + A - 1) / A;
    }

    sort(X, X + N);

//    REP(i, N) cout << X[i].x << " " << X[i].c << endl;

    ll ans = 0;
    ll l = 0, c[N], k = 0;
    REP(i, N) {
        while(l < i && X[i].x - X[l].x > 2 * D) k -= c[l++];

        c[i] = max(X[i].c - k, 0LL);
        ans += c[i];
        k += c[i];
    }

    
    cout << fixed << setprecision(20);
    cout << ans << endl;

}


Measured memory_bytes: 4992
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int l;
		int r;
		int sit=0;

		for (int i=0; i<N; i++){
			l = sc.nextInt();
			r = sc.nextInt();
			sit += r - l + 1;
		}
		System.out.println(sit);
	}
}





Measured memory_bytes: 25944
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = 1000000007;

int main() {
    int N, K; cin >> N >> K;
    ll ans = K;
    rep(i,N-1) ans *= K-1;
  
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3628
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

#define int long long
const int maxn = 2e5 + 20;
int n, k;
int vis[maxn], a[maxn];
vector <int> ans;
signed main() {
	read(n); read(k);k++;
	For (i, 1, n) read(a[i]);
	int x = 1;
	while(vis[x] == 0) {
		vis[x] = 1;
		ans.push_back(x);
		x = a[x];
	}
	int p = ans.size();
	int pos;
	For (i, 0, p - 1) {
		if (ans[i] == x) {
			pos = i;
			break;
		}
	}
	if (k <= pos + 1) {
		cout << ans[k - 1] << endl;
	}
	else {
		k -= pos;
		int len = p - pos;
		int kk = k % len;
		if (kk == 0) cout << ans[p - 1];
		else cout << ans[pos + kk - 1];
	}
	return 0;
}


Measured memory_bytes: 8404
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	string S;
	cin>>S;
	REP(i,S.size()){
		if(i%2==0){
			if(S[i]!='R'&&S[i]!='U'&&S[i]!='D'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else{
			if(S[i]!='L'&&S[i]!='U'&&S[i]!='D'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))

char s[100][100];

int main()
{
    int n,m;
    cin>>n>>m;
    F(i,1,n) scanf("%s",s[i]+1);
    F(i,1,n)F(j,1,m)
    {
        int cnt=0;
        if(s[i][j]=='#') continue;
        if(s[i-1][j]=='#') cnt++;
         if(s[i-1][j+1]=='#') cnt++;
          if(s[i][j-1]=='#') cnt++;
           if(s[i][j+1]=='#') cnt++;
            if(s[i+1][j-1]=='#') cnt++;
             if(s[i+1][j]=='#') cnt++;
              if(s[i+1][j+1]=='#') cnt++;
               if(s[i-1][j-1]=='#') cnt++;
               s[i][j]=cnt+'0';
    }
    F(i,1,n) printf("%s\n",s[i]+1 );
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void){
  int i,n = 0;
  char w[11], t[1001];
 
  scanf("%s", w);
 
  do{
    scanf("%s",t);
    if(!strcmp(t,"END_OF_TEXT")) break;
      for(i=0;t[i]!='\0';i++)
        if(t[i]<91) t[i] += 32;
    if( !strcmp(w,t) ) n++;
  }while(1);
 
  printf("%d\n",n);
 
  return 0;
}


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

using namespace std;

int main() {

	long  n,W;

	cin >> n >> W;

	vector< long > w(n+1 );
	vector< long > v(n+1);

	long V;
	V = 0;
	for (long  i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
		V += v[i];
	}

	vector<vector<long long>> dp(n+2,vector<long long>(100100,2000000000));

	dp[0][0] = 0;

	for (long  i = 1; i <= n; i++) {
		for (long  j = 0; j <= 100005; j++) {
			if (j - v[i] >= 0) {
				dp[i][j] = min(dp[i-1][j], dp[i - 1][j - v[i]] + w[i]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}

	for (long i = V+1; i >0; i--) {
		if (dp[n][i] <= W ) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n,m,d;
    int ma[90005][2],ans[90005];
    cin >> n >> m >> d;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            int a;
            scanf("%d",&a);
            ma[a][0]=i;
            ma[a][1]=j;
        }
    for(int i=1;i<=n*m;i++)
    {
        if(i<=d) ans[i]=0;
        else
        {
            ans[i]=ans[i-d]+abs(ma[i][0]-ma[i-d][0])+abs(ma[i][1]-ma[i-d][1]);
        }
    }
    int q,l,r;
    cin >> q;
    while(q--)
    {
        scanf("%d %d",&l,&r);
        printf("%d\n",ans[r]-ans[l]);
    }
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <string.h>
int main (void){
    int loop1;
    int how_data;
    int how_long;
    scanf("%d %d",&how_data,&how_long);
    char moji[101][101];
    for(loop1=0;loop1<how_data;loop1++){
        scanf("%s",moji[loop1]);
    }
    char temp[101];
    for(loop1=0;loop1<how_data-1;loop1++){
        if(strcmp(moji[loop1],moji[loop1+1])>0){
            strcpy(temp,moji[loop1]);
            strcpy(moji[loop1],moji[loop1+1]);
            strcpy(moji[loop1+1],temp);
            loop1=-1;
        }
    }
    for(loop1=0;loop1<how_data;loop1++){
        printf("%s",moji[loop1]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
N, M, K=map(int, input().split())

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def root(self, x):
        p, seq = self.parent[x], list()
        while p >= 0:
            seq.append(x)
            x, p = p, self.parent[p]
        for c in seq: self.parent[c] = x
        return x

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

    def count(self, x): return -self.parent[self.root(x)]

    def unite(self, x, y):
        if self.count(x) < self.count(y): x, y = y, x
        xr, yr = self.root(x), self.root(y)
        if xr == yr: return
        self.parent[xr] += self.parent[yr]
        self.parent[yr] = xr

friend_or_block = [set() for _ in range(N)]
friends_chain = UnionFindTree(N)

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    friends_chain.unite(a, b)
    friend_or_block[a].add(b)
    friend_or_block[b].add(a)

for _ in range(K):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    if friends_chain.same(c, d):
        friend_or_block[c].add(d)
        friend_or_block[d].add(c)

print(' '.join(map(str, [friends_chain.count(i) - len(friend_or_block[i]) - 1 for i in range(N)])))


Measured memory_bytes: 68692
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;

long long int fact(long long int k) {
	long long int sum = 1;
	for (long long int i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long int power(int a, int b) {
	long long int  ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}


int main()
{
	long long int m1, m2, d1, d2;

	cin >> m1 >> d1;
	cin >> m2 >> d2;

	if(m1 + 1 == m2 && d2 == 1)
		cout << 1 << endl;
	else
		cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100000

typedef struct{
    char name[10];
    int num;
} que;

que Q[MAX];
int head = 0;
int tail = 0;

int isEmpty();
int isFull();
void enque(char *,int);
void deque();

int main(){
    int n,q,i,number,time = 0;
    char Name[10];

    scanf("%d%d",&n,&q);
    if(1 > n || n > 100000) exit(3);
    if(1 > q || q > 1000) exit(4);

    for(i = 0;i < n;i++){
        scanf("%s%d",Name,&number);
        if(1 > number || number > 50000) exit(5);

        enque(Name,number);
    }
    while(isEmpty() != 1){
        if(Q[head].num <= q){
            time += Q[head].num;
            if(1 > time || time > 1000000) exit(6);
            printf("%s %d\n",Q[head].name,time);
            deque();
        }
        else{
            Q[head].num -= q;
            time += q;
            if(1 > time || time > 1000000) exit(6);
            enque(Q[head].name,Q[head].num);
            deque();
        }
    }

    return 0;
}

int isEmpty(){
    if(head == tail) return 1;
    else return 0;
}

int isFull(){
    if(head == (tail + 1) % MAX) return 1;
    else return 0;
}

void enque(char *naame,int x){
    if(isFull() == 1){
        printf("que is full\n");
        exit(1);
    }
    strcpy(Q[tail].name,naame);
    Q[tail].num = x;

    if(tail + 1 == MAX) tail = 0;
    else tail++;
}

void deque(){
    if(isEmpty() == 1){
        printf("que is empty\n");
        exit(2);
    }
    if(head + 1 == MAX) head = 0;
    else head++;
}


Measured memory_bytes: 3264
#include <iostream>

using namespace std;

int main(void) {
  string str;
  cin >> str;

  bool n, w, s, e;
  n = false;
  w = false;
  s = false;
  e = false;
  
  for(int i = 0; i < str.length(); i++) {
    switch(str[i]) {
    case 'N':
      n = true;
      break;
    case 'W':
      w = true;
      break;
    case 'S':
      s = true;
      break;
    case 'E':
      e = true;
      break;
    default:
      break;
    }
  }

  if(n == s && w == e) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
}

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

int main()
{
    ll N; cin >> N;
    ll maxv = sqrt(N);
    map<ll,ll> m;

    for (int i = 1; i < maxv; ++i) {
        for (int j = 1; j < maxv; ++j) {
            for (int k = 1; k < maxv; ++k) {

                ll tmp = i*i + j*j + k*k + i*j + j*k + k*i;
                //cout << tmp << endl;
                if (tmp <= N) {
                    m[tmp]++;
                }

            }
        }
    }

    for (int i = 1; i <= N; ++i) {
        cout << m[i] << endl;
    }

}


Measured memory_bytes: 4064
import random
from random import randint
random.seed(0)

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

N = 30000
Q = [[randint(0, (D-1)), randint(0, 25)] for i in range(N)]
for d, q in Q:
    old = ans[d]
    ans[d] = q + 1
    if score_calc(ans) > total:
        total = score_calc(ans)
    else:
        ans[d] = old

for i in range(D):
    print(ans[i])


Measured memory_bytes: 88732
#include <cstdio>
#include <cctype>
#include <array>
#include <set>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int n = 0, c = gcu();
	// bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
//template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

struct board {
	enum {size = 3};
	struct pos {int r, c;};
	typedef array<array<int, size>, size> arr;
	arr b;
	pos p;
	int f, g, h;

	void read() {
		for (int i = 0; i < size; i++)
			for (int j = 0; j < size; j++) {
				b[i][j] = in();
				if (!b[i][j])
					p.r = i, p.c = j;
			}
		g = 0;
		f = h = hn(b);
	}
	void print() {
		for (auto &r: b) {
			for (int &c: r)
				out(&c == &r[0]?"":" ", c);
			out('\n');
		}
		out('\n');
	}

	int hn(arr &a) {
		int l = 0;
		for (int i = 0; i < size; i++)
			for (int j = 0; j < size; j++) {
				int k = a[i][j] ? a[i][j] - 1 : size * size - 1;
				l += abs(i - k / 3) + abs(j - k % 3);
			}
		return l;
	}

	int solver() {
		static const pos to[] = {-1, 0, 0, -1, 1, 0, 0, 1};
		set<arr> m;
		priority_queue<board> q;
		q.push(*this);
		while (!q.empty()) {
			board a = q.top();
			q.pop();
//			out(a.f,  '\n');
//			a.print();
			auto it = m.find(a.b);
			if (it != m.end())
				continue;
			m.insert(a.b);
			if (!a.h)
				return a.g / 2;
			for (pos o: to) {
				o.r += a.p.r, o.c += a.p.c;
				if (0 <= o.r && o.r < size && 0 <= o.c && o.c < size) {
					board c = a;
					swap(c.b[a.p.r][a.p.c], c.b[o.r][o.c]);
					c.g += 2;
					c.h = hn(c.b);
					c.f = c.g + c.h;
					c.p = o;
					q.push(c);
				}
			}
		}
		return -1;
	}
};

bool operator < (const board &a, const board &b) {
	return a.f > b.f;
}

int main() {
	board b;
	b.read();
	out(b.solver(), '\n');
}



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

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

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

int main()
{
    int i, j, k, n, m, t, x, y, s=0, c=0, l;
    cin >> n >> x >> y;
    for(i=x; i<=y; i++)
    {
        if(i%n==0)
        {
            s++;
            break;
        }
    }
    if(s==0)
        cout << "NG\n";
    else
    {
        cout << "OK\n";
    }
    
}


Measured memory_bytes: 3620