akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;


    ll N;
    ll A[200010],B[200010],C[200010];
    ll ans;
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N)cin>>A[i];
    REP(i,N)cin>>B[i];
    REP(loop,31){
        REP(i,N){
            C[i]=B[i]%(2LL<<(loop));
        }
        int cnt=0;
        std::sort(C,C+N);
        REP(i,N){
            ll a=((1LL<<loop)-(A[i])%(2LL<<loop));
            ll b=((2LL<<loop)-(A[i])%(2LL<<loop));
            cnt+=std::lower_bound(C,C+N,b)-std::lower_bound(C,C+N,a);
            a=(3*(1LL<<loop)-(A[i])%(2LL<<loop));
            b=(4*(1LL<<loop)-(A[i])%(2LL<<loop));
            cnt+=std::lower_bound(C,C+N,b)-std::lower_bound(C,C+N,a);
            cnt%=2;
        }
        cnt%=2;
        ans+=(1<<loop)*cnt;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4992
import collections

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

for i in range(N):
    sort[i] = sort[i] // 400

normal = [i for i in sort if i < 8]
incredible = [i for i in sort if i >= 8]

min = len(collections.Counter(normal))
max = len(collections.Counter(normal)) + len(incredible)

min = 1 if min < 1 else min


print(min, max)


Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  long N;
  cin >> N;
  long P[N];
  for (long i = 0; i < N; i++) cin >> P[i];

  long min = P[0];
  long ans = 1;
  for (long i = 1; i < N; i++) {
    if (min >= P[i]) {
      min = P[i];
      ans += 1;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int a, n;

void solve1(int x, int y) {
	int k = (y + x) / 2;
	cout << k << flush << "\n";
	string s;
	cin >> s;
	if (s == "Vacant")
		exit(0);
	if (k & 1) {
		if (s == "Male") 
			solve1(x, k);
		else
			solve1(k, y);
	}
	else {
		if (s == "Male") 
			solve1(k, y);
		else
			solve1(x, k);
	}
}

void solve2(int x, int y) {
	int k = (y + x) / 2;
	cout << k << flush << "\n";
	string s;
	cin >> s;
	if (s == "Vacant")
		exit(0);
	if (k & 1) {
		if (s == "Female") 
			solve2(x, k);
		else
			solve2(k, y);
	}
	else {
		if (s == "Female") 
			solve2(k, y);
		else
			solve2(x, k);
	}
}

int main() {
	int n;
	cin >> n;
	cout << 0  << flush << "\n";
	string s;
	cin >> s;
	if (s == "Vacant")
		return 0;
	if (s == "Male")
		solve1(0, n);
	if (s == "Female")
		solve2(0, n);
	return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <iomanip>
    
using namespace std;
    
int main(){
 long double r,pi=3.14159265358979;
 cin >> r;
 cout << std::fixed;
 cout << std::setprecision(6)<< r*r*pi << " " << 2*r*pi << endl;
 return 0;
}



Measured memory_bytes: 3256
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	long long a,b;
  	cin >> a >> b;
  	if(a==b){
      for(long long i=0; i<a; i++){
        cout << a;
      }
    }
  	else if(a>b){
      for(long i = 0; i<a; i++){
        cout << b;
      }
    }
  	else{
      for(long i = 0; i<b; i++){
        cout << a;
      }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int n, a, b, c, x;
	while (cin >> n >> a >> b >> c >> x&&n + a + b + c + x != 0) {
		int d[100];
		for (int i = 0; i < n; i++) cin >> d[i];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			while (x != d[i]) {
				x = (a*x + b) % c;
				sum++;
				if (sum > 10000) {
					cout << -1 << endl;
					goto stop;
				}
			}
			if (i != n - 1) {
				x = (a*x + b) % c;
				sum++;
			}
		}
		cout << sum << endl;
	stop:;
	}
}

Measured memory_bytes: 3000
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String t=br.readLine();
		int ans=0;
		int n=s.length();
		for(int i=0;i<n;i++)
		{
			if(s.charAt(i)!=t.charAt(i))
			ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 36948
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>;
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

signed main() {
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

public class Program
{

    public static void Main()
    {
        int[] n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        string[] s = new string[n[0]];
        for (int i = 0; i < n[0]; i++) s[i] = Console.ReadLine();
        for (int i = 0; i < n[1] + 2; i++) Console.Write("#");
        Console.WriteLine();
        for (int i = 0; i < n[0]; i++) Console.WriteLine("#" + s[i] + "#");
        for (int i = 0; i < n[1] + 2; i++) Console.Write("#");
        Console.WriteLine();
    }

    static int[] s_to_i(string[] s)
    {
        int[] ret = Array.ConvertAll<string, int>(s, delegate (string value) { return int.Parse(value); });
        return ret;
    }
}

Measured memory_bytes: 13396
import java.io.*;
import java.util.*;
public class Main{


public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int k=sc.nextInt();
	String s=sc.next();
  	int n=s.length();
	if(n<=k)
		System.out.println(s);
  	else
      	System.out.println(s.substring(0,k)+"...");
	
		
}

}


Measured memory_bytes: 38480
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
a = ""
for i in reversed(range(LS - LT + 1)):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            #print("".join(S))
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>#include<iostream>
#include<algorithm>
using namespace std;
char s[1000001];
int main() {
	int n, j, o, i, k, a = 0;
	scanf("%s", s);
	n = strlen(s);
	for (k = 0;k < n;k++) {
		for (j = k;s[j] == 'J';j++);
		for (o = j;s[o] == 'O';o++);
		for (i = o;s[i] == 'I';i++);
		if (o - j <= i - o&&j-k>=o-j)
			a = max(a, min(j - k,min(o-j, i - o)));
		if (i - k != 0)
			k = i - 1;
	}
	printf("%d\n", a);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  bool can = false;
  for(int i = 0; i <= N / 4; i++) {
    for(int j = 0; j <= N / 7; j++) {
      if (4 * i + 7 * j == N) {
        can = true;
        break;
      }
    }
  }
  if (can) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    vector<int> dishes(5);
    rep(i, 0, 5) cin >> dishes[i];

    int minLastDigit = 10; // except zero
    rep(i, 0, 5) {
        // calc last digit
        int lastDigit = 0;
        int num = dishes[i];
        do {
            lastDigit = num % 10;
            num %= 10;
        } while (num >= 10);

        if (lastDigit > 0)
            minLastDigit = min(minLastDigit, lastDigit);

        // round out
        if (lastDigit > 0)
            dishes[i] += (10-lastDigit);
    }

    int res = accumulate(dishes.begin(), dishes.end(), 0);
    if (minLastDigit < 10)
        res -= (10-minLastDigit);

    cout << res << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N),B(N);

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

  vector<vector<int>> dp(N+1,vector<int>(H+1));
  for(int i=1;i<H+1;i++) dp[0][i]=200000000;

  for(int i=1;i<N+1;i++){
    for(int j=1;j<H+1;j++){
      dp[i][j]=min(dp[i-1][j], dp[i][max(0,j-A[i-1])]+B[i-1]);
      //cout << dp[i][j] << " ";
    }
    // cout << endl;
  }

  cout << dp[N][H] << endl;


  return 0;
}

Measured memory_bytes: 39424
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double   pi = acos(-1.0) ;
const int     MOD = (int)998244353 ;
const int     INF = (int)0x3f3f3f3f ;
const LL     LINF = (LL)INF<<32|INF ;
const int    SINF = (uint)(-1)>>1 ;
const LL    SLINF = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double  eps = 1e-8 ;
const int    maxn = (int) 1e5+20 ;
const int    maxm = (int) 1000+20 ;
const int    maxk = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

int n;
int a[3];

void work()
{
    for(int i = 0; i < 3; i++) read(a[i]);
    sort(a, a + 3);

    int ans = INF;
    do
    {
        int tmp =  0;
        for(int i = 1; i < 3; i++) tmp += Abs(a[i] - a[i - 1]);
        ans = min(ans, tmp);
    }while(next_permutation(a, a + 3));

    cout <<ans <<endl;
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


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

int main() {
  int N, A[100000];
  int min;
  bool same_min = false;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  while (!same_min) {
    min = *min_element(A, &A[N]);
    for (int i = 0; i < N; i++) {
      if (A[i] != min)
        break;
      else if (i == N - 1 && A[i] == min)
        same_min = true;
    }
    for (int i = 0; i < N; i++) {
      if (A[i] > min) {
        A[i] = A[i] % min;
        if (A[i] == 0) A[i] = min;
      }
    }
  }
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 640
/*       Rohan Balot
    NSIT, New Delhi, India  */
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#include <queue>
#include <utility>
#include <unordered_set>

#include <cctype>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <ctime>
using namespace std;
 
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair
 
const int N = int( 1e5 ) + 1;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1);
const double eps = 1e-6;

void __answer()
{
	int n, m;
	cin >> n >> m;
	vector< vector<int> > v(n + 1);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	for (int i = 1; i <= n; i++) {
		cout << v[i].size() << endl;
	}
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifdef LOCAL
        freopen("sample_input.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B, C;
  ci(A, B, C);
  if(A == B){
    co(C);
  }
  else if(B == C){
    co(A);
  }
  else{
    co(B);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}


int main()
{
    int n;
    cin >> n;
    string x;
    cin >> x;
    for(int i=0;i<x.size();i++){
        int cur  =n;
        while(cur>0){
            if(x[i]=='Z'){
                x[i]='A';
                cur--;
                continue;
            }
            x[i]++;
            cur--;
        }
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A, B, num, i;
  cin >> A >> B;
  num = A;
  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }
  for(i=1; num<B; i++)
    num += A-1;
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
X,Y = map(int,input().split())
moneys = [0 for _ in range(3000)]
moneys[1] = 300000
moneys[2] = 200000
moneys[3] = 100000

answer = 0
answer += moneys[X]
answer += moneys[Y]
if (X==1 and Y==1):
    answer += 400000
print(answer)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int k,a,b;
    cin>>k>>a>>b;
    int tmp=a/k;
    if(a%k==0) cout<<"OK";
    else if(k*(tmp+1)<=b) cout<<"OK";
    else cout<<"NG";

    return 0;
}


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

int gcd(int y,int x);

int main(){
	int n;	cin>>n;
	int a[n+1];	for(int i=1;i<=n;i++)cin>>a[i];

	int l[n+2];		l[1]=0;
	int r[n+2];		r[n+1]=0;

	for(int i=1;i<=n;i++){
		//cout<<"L"<<endl;
		l[i+1] = gcd(l[i], a[i]);
	}
	for(int i=n;i>0;i--){
		//cout<<"R"<<endl;
		r[i] = gcd(r[i+1], a[i]);
	}

	int m[n+1];
	int ans=0;
	for(int i=1;i<=n;i++){
		m[i]=gcd(l[i], r[i+1]);
		ans = max(ans, m[i]);
	}

	cout<<ans<<endl;


	return 0;
}


int gcd(int y, int x){
	if(y<x) swap(y,x);

	if(x==0) return y;

	return gcd(x, y%x);

}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();
        int[] a = new int[Q];
        int[] b = new int[Q];
        int[] c = new int[Q];
        int[] d = new int[Q];
        for(int i=0;i<Q;i++){
            a[i]=sc.nextInt();
            b[i]=sc.nextInt();
            c[i]=sc.nextInt();
            d[i]=sc.nextInt();
        }
        int globalSum = 0;
        for(List<Integer> A:mkPerm(N, M)){
            int sum=0;
            for(int i=0;i<Q;i++){
                if(A.get(b[i]-1) - A.get(a[i]-1) == c[i]){
                    sum += d[i];
                }
            }
            globalSum = Math.max(globalSum, sum);
        }
        System.out.println(globalSum);
    }
    private static List<List<Integer>> mkPerm(int cnt, int M){
        if(cnt == 1){
            List<List<Integer>> ret = new ArrayList<>();
            for(int i=1;i<=M;i++){
                List<Integer> add = new ArrayList<>();
                add.add(i);
                ret.add(add);
            }
            return ret;
        }
        List<List<Integer>> res = mkPerm(cnt-1, M);
        List<List<Integer>> ret = new ArrayList<>();
        for(List<Integer> p:res){
            for(int i=p.get(p.size()-1);i<=M;i++){
                List<Integer> toAdd = new ArrayList<>(p);
                toAdd.add(i);
                ret.add(toAdd);
            }
        }
        return ret;
    }
}


Measured memory_bytes: 59740
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
#define ll long long
using namespace std;





int main(){
   
    int N,K;
    cin >> N >> K;
    if(K!=1) cout << N-K << endl;
    else cout << 0 << endl;
    
    return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))

g = [[] for _ in range(N+1)]
for i in range(M):
  a, b = map(int, input().split())
  g[a].append(b)
  g[b].append(a)

ans = 0
for j in range(1, N+1):
  for k in g[j]:
    if H[j] <= H[k]:
      break
  else:
    ans += 1
print(ans)

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

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}
int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 20452
N = int(input()) 
flag = True
def isTravel(ti, xi, yi):
    a_min = [0, xi, (xi+yi-ti)//2, (xi-yi-ti)//2]
    a_max = [ti, xi+ti, (xi+yi+ti)//2, (xi-yi+ti)//2]
    a = max(a_min)
    if max(a_min)<=min(a_max) and (xi+yi+ti)%2==0:
        return True
    else:
        return False

for _ in range(N):
    ti, xi, yi = map(int, input().split())
    if flag:
        if isTravel(ti, xi, yi):
            pass
        else:
            flag = False
        
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int q,flag = 0;
    string s;
    vector<char> a,a1;
    cin >> s >> q;
    for(int i=0;i<s.size();i++) a.push_back(s[i]);
    for(int i=s.size()-1;0<=i;i--)a1.push_back(s[i]);
    for(int i=0;i<q;i++){
       int t;
       cin >> t;
       if(t==1) flag++;
       if(t==2){
           char c;
           int f;
           cin >> f >> c;
           if((f+flag)%2){
                a1.push_back(c);
                a.insert(a.begin(),c);
           }
           else{
               a.push_back(c);
               a1.insert(a1.begin(),c);
           }
       }
     }
     if(flag%2){
         for(int i=0;i<a1.size();i++) cout << a1[i];
       cout << endl;
     }
     else{
       for(int i=0;i<a.size();i++) cout << a[i];
       cout << endl;
     }
}

Measured memory_bytes: 1520
N, Z, W = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
#Xさんが最初に全部引くか、Xさんが最後から2枚目まで引く
print(max(abs(W - A[-1]), abs(A[N - 2] - A[-1])))


Measured memory_bytes: 3188
import math
a,b,x = map(int,input().split())
volume = a*a*b

thita = 0
if x*2 >= volume:
    thita = math.atan((2/(a*a*a))*(volume-x))
else:
    thita = math.atan((a*b*b)/(2*x))
print(math.degrees(thita))


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

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

  int n;
  int k;
  string d;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    char t;
    cin >> t;
    d += t;
  }

  bool flag = true;
  while (flag){
    flag = false;
    string t = to_string(n);
    for(auto it :t){
      if (count(d.begin(), d.end(), it)) {
        flag = true;
        n++;
        break;
      }
    }
  }
  cout<<n;
  return 0;

}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif
    ll x, y;
    while(~scanf("%lld%lld", &x, &y)){
        int cnt = 0;
        while(x <= y){
            x *= 2;
            cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.nextLine();

		char[] c = s.toCharArray();

		int count = 0;
		for (int i = 0; i < c.length; i++) {

			if(c[i] == '2') {
				count++;
			}

		}

		System.out.println(count);

		sc.close();
	}

}


Measured memory_bytes: 23252
#include <cstdio>
#define maxk 1000005
using namespace std;

int remainders[maxk];

int main(int argc, char** argv)
{
	int k;
	scanf("%d", &k);
	int r = 0;
	for(int cnt=1; ; cnt++)
	{
		if(++remainders[r = (r * 10 + 7) % k] > 1)
		{
			puts("-1");
			return 0;
		}
		if(r == 0)
		{
			printf("%d\n", cnt);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n;
  cin>>h>>w>>n;
  vector<int> hs(h),ws(w);
  set<pair<int,int>> s;
  for(int i=0;i<n;i++){
     int r,c;
     cin>>r>>c;
     --r;--c;
    hs[r]++;
    ws[c]++;
    s.emplace(r,c);
  }
  int mh=0,mw=0;
  for(int i=0;i<h;i++) mh=max(mh,hs[i]);
  for(int j=0;j<w;j++) mw=max(mw,ws[j]);
  vector<int> is,js;
  for(int i=0;i<h;i++) if(mh==hs[i]) is.push_back(i);
  for(int i=0;i<w;i++) if(mw==ws[i]) js.push_back(i);
  int ans=mh+mw;
  for(int i:is) for(int j:js){
    if(s.count(pair(i,j))) continue;
    cout<<ans<<endl;
    return 0;
  }
  --ans;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 23800
n = int(input())
dic = {}
flag = True

for i in range(n):

    S = input()

    #print (dic)

    if i == 0:

        for j in S:

            if j in dic:
                dic[j] += 1
            else:
                dic[j] = 1

    sdic = {}

    for j in S:

        if j in sdic:
            sdic[j] += 1
        else:
            sdic[j] = 1

    cdic = dic.copy()

    for j in cdic:

        if j not in sdic:

            del dic[j]

        else:

            dic[j] = min(dic[j],sdic[j])

lis = []

for i in dic:

    lis += [i] * dic[i]

lis.sort()

print ( "".join(lis) )


Measured memory_bytes: 3064
import math
a, b, n = map(int, input().split())
 
 
def calc(a, b, n):
    return int(math.floor((a * n)/b) - (a * math.floor(n/b)))
 
if n <= b -1:
  print(calc(a,b,n))
else:
  print(calc(a,b,b-1))

Measured memory_bytes: 9108
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string N;
    cin >> N;
    if (N[0] == N[1] && N[1] == N[2]) {
        cout << "Yes" << endl;
    } else if (N[1] == N[2] && N[2] == N[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, maxWeight;
    cin >> n >> maxWeight;
    vector <long long> w(n+1,0);
    vector <long long> v(n+1,0);
    vector <long long> vSum(n+1,0);
    for(long long i = 1; i <= n; i++){
        cin >> w[i] >> v[i];
        vSum[i]=vSum[i-1]+v[i];
    }
    #if 0
    for(long long i = 0; i <= n; i++){
        cout << vSum[i] << endl;
    }
    cout << endl;
    #endif
    vector <vector <long long>> dp(n+1,vector<long long>(vSum.back()+1,maxWeight+1));
    dp[0][0]=0;
    for(long long i = 1; i <= n; i++){
        dp[i] = dp[i-1];
        for(long long j = 0; j < dp[i].size(); j++){

            if(j == 0){
                dp[i][j] = 0;
            }else if(j < v[i]){
                //do nothing
            }else{
                //if(j==v[i]){
                //    cout << dp[i-1][j] << endl;
                //    cout << dp[i-1][j-v[i]]+w[i] << endl;
                //}
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            }

        }
    }
    long long ans = 0;
    for(long long j = 0; j < dp.back().size(); j++){
        if(dp.back()[j]==0)continue;
        if(dp.back()[j]<=maxWeight)ans=j;
    }
    #if 0
    for(long long i = 0; i <= n; i++){
        for(long long j = 0; j < dp[i].size(); j++){
            if(dp[i][j]!=LONG_LONG_MAX)cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    #endif
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 83176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int d; cin >> d;
  
  cout << "Christmas";

  if(d != 25) rep(i, 25-d) cout << " Eve";

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll a;
  string s;
  char c[1200];
  cin >> s;
  a=s.length();
  rep(i,a)c[i]=s[i];
  if(c[5]=='1'||c[6]>'4'||(c[6]=='4'&&c[8]=='3'&&c[9]=='1'))printf("TBD");
  else printf("Heisei");
}

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

int main(){
  int n;
  cin>>n;
  vector<char> p(n);
  for(int i=0; i<n; i++)cin>>p[i];

  vector<int> e(n), w(n);
  int memo=0;
  
  for(int i=0; i<n; i++){
    if(p[i]=='W')memo++;
    w[i]=memo;
  }
  
  memo=0;
  for(int i=n-1; i>=0; i--){
    if(p[i]=='E')memo++;
    e[i]=memo;
  }

  int ans=n;
  for(int i=0; i<n; i++)ans=min(ans, w[i]+e[i]-1);

  cout<<ans<<endl;
  
}


Measured memory_bytes: 2944
#include <iostream>
#include <map>
#include <array>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;

void solve_b() {
  int n;
  cin >> n;
  vector<string> a(n*2);
  forn(i, n) {
    cin >> a[i]; a[i] += a[i];
  }
  forn(i, n) a[i + n] = a[i];
  vvi b(n*2, vi(n*2, 0));
  int ans = 0;
  fore(d, -n+1, n-1) {
    forn(i, 2 * n) forn(j, 2 * n) b[i][j] = 0;
    forn(i, 2 * n) forn(j, 2 * n) {
      int p = j + d, q = i - d;
      if (0 <= p && p < 2 * n && 0 <= q && q < 2 * n) {
        if (a[p][q] != a[i][j]) b[i][j] = 1;
      }
    }
    if (0) {
      cerr << d << endl;
      forn(i, 2 * n) forn(j, 2 * n) cerr << b[i][j] << " \n"[j + 1 == 2 * n];
    }
    forn(i, 2 * n) {
      forn(j, 2 * n) {
        if (i) b[i][j] += b[i - 1][j];
        if (j) b[i][j] += b[i][j - 1];
        if (i && j) b[i][j] -= b[i - 1][j - 1];
      }
    }
    if (0) {
      cerr << d << endl;
      forn(i, 2 * n) forn(j, 2 * n) cerr << b[i][j] << " \n"[j + 1 == 2 * n];
    }
    fore(i, n - 1, 2 * n - 2) {
      fore(j, n - 1, 2 * n - 2) {
        if (i - j != d) continue;
        int s = b[i][j];
        if (i >= n) s -= b[i - n][j];
        if (j >= n) s -= b[i][j - n];
        if (i >= n && j >= n) s += b[i - n][j - n];
        if (s == 0) {
          // cerr << d << ' ' << i << ' ' << j << endl;
          ans += 1;
        }
      }
    }
  }
  cout << ans << endl;
}

void solve_a() {
  int n;
  cin >> n;
  map<i64, int> M;
  M[0] = 1;
  i64 ans = 0, s = 0;
  forn(i, n) {
    int x;
    cin >> x;
    ans += M[s += x] += 1;
    ans -= 1;
  }
  cout << ans << endl;
}

int main() {
#ifdef HOME
  freopen("input.txt", "rt", stdin);
#endif
  solve_b();
  return 0;
}


Measured memory_bytes: 2176
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class MathUtil {
	public static void swap(int[] obj, int a, int b) {
		int tmp = obj[a];
		obj[a] = obj[b];
		obj[b] = tmp;
	}
}

class Dice {
	int N=6;
	int ten[] = new int[N+1];

	public Dice(int[] tenkaizu) {
		for(int i=1;i<=N;i++) {
			this.ten[i] = tenkaizu[i-1];
		}
	}

	@Override
	public boolean equals(Object obj) {
		return this.toNumberStr().equals(((Dice)obj).toNumberStr());
	}

	@Override
	public int hashCode() {
		return (int)Long.parseLong(toNumberStr());
	}

	public int showDice(int number) {
		return ten[number];
	}

	public void printDice() {
	    for(int i=1;i<=N;i++) {
            System.out.print(ten[i] + "\t");
        }
        System.out.println("");
    }

	public void rotate(String meirei) {
		switch (meirei) {
			case "N":
				rotate(1, 2, 6, 5);
				break;
			case "S":
				rotate(5,6, 2, 1);
				break;
			case "E":
				rotate(4, 6, 3, 1);
				break;
			case "W":
				rotate(1, 3, 6, 4);
				break;
		}
	}

	public void rotate(int a, int b, int c, int d) {
		MathUtil.swap(ten, a, b);
		MathUtil.swap(ten, b, c);
		MathUtil.swap(ten, c, d);
	}

	public void rotate(int a, int b, int c) {
		MathUtil.swap(ten, a, b);
		MathUtil.swap(ten, b, c);
	}

	/**
	 * ????????????????????¢??????d?????????
	 * @param d
	 */
	public void topTo(int d) {
		for(int i=0;i<4;i++) {
			rotate("W");
			if(showDice(1) == d) break;
		}
		for(int i=0;i<4;i++) {
			rotate("N");
			if(showDice(1) == d) break;
		}
	}

	public int findRight(int frontD) {
		int[] pos = {4,2,3,5};
		for(int i=0;i<4;i++) {
			if(ten[pos[i]] == frontD) {
				return ten[pos[(i+1)%4]];
			}
		}
		return -1;
	}

	public String toNumberStr() {
		String str = "";
		for(int i=1;i<=N;i++) {
			str += ""+ten[i];
		}
		return str;
	}
}

class DiceUtil {
	static Set<String> diceSet;
	public static boolean isSame(Dice d1, Dice d2) {
		diceSet = new HashSet<>();
		return dfs(d1, d2);
	}

	public static boolean dfs(Dice d1, Dice d2) {
		int n = diceSet.size();
		if(diceSet.contains(d1)) return false;
		if(d1.equals(d2)) return true;
		diceSet.add(d1.toNumberStr());
		if(n == diceSet.size()) return false;
		for(int i=0;i<4;i++) {
			d1.rotate("N");
			if(dfs(d1, d2)) return true;
		}
		for(int i=0;i<4;i++) {
			d1.rotate("E");
			if(dfs(d1, d2)) return true;
		}
		return false;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] men_str = in.nextLine().split(" ");
		int[] men_int = new int[6];
		for (int i = 0; i < 6; i++) {
			men_int[i] = Integer.parseInt(men_str[i]);
		}
		Dice dice = new Dice(men_int);
		men_str = in.nextLine().split(" ");
        for (int i = 0; i < 6; i++) {
			men_int[i] = Integer.parseInt(men_str[i]);
		}
		Dice dice2 = new Dice(men_int);

        if(DiceUtil.isSame(dice, dice2)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 27236
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;



int main() {
    fast
    char a,b;
    cin>>a>>b;
    int a1=a-'0';
    int a2=b-'0';

    string s1,s2;
    s1="";
    s2="";
    for(int i=0;i<a1;i++){
        s1+=b;
    }
    for(int i=0;i<a2;i++){
        s2+=a;
    }
    if(s1<s2){
        cout<<s1;
    }
    else
        cout<<s2;



	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
lst = set()
fst = set()
for i in range(m): 
  r = list(map(int,input().split()))
  if r[1] == n:
    lst.add(r[0])
  elif r[0] == 1:
    fst.add(r[1])
print('IMPOSSIBLE' if len(fst & lst) == 0 else 'POSSIBLE')

Measured memory_bytes: 19016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

using namespace std;

int main(void) {
	string a, b;
	cin >> a >> b;
	int b_keta = b.size();
	int a_ = stoi(a);
	int c;
	c = a_ * pow(10, b_keta) + stoi(b);
	//cout << c;
	for (int i = 0; i <= 316; i++) {
		if (i*i == c) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
 
readline = sys.stdin.readline
n, m, k = map(int, readline().split())
# ab = [list(map(int, readline().split())) for i in range(m)]
# cd = [list(map(int, readline().split())) for i in range(k)]
 
friend = [set() for i in range(n)]
not_friend = [set() for i in range(n)]
 
suggest_friends = [-1] * n
for i in range(m):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    friend[a].add(b)
    friend[b].add(a)
    # friend[b].append(a)
for i in range(k):
    c, d = map(int, readline().split())
    c -= 1
    d -= 1
    not_friend[c].add(d)
    not_friend[d].add(c)
    # not_friend[d].append(c)
for i in range(n):
    if suggest_friends[i] != -1:
        continue
    q = deque(friend[i])
    friend_group = set(friend[i])
    while q:
        p = q.popleft()
        for f in friend[p]:
            if not(f in friend_group):
                q.append(f)
                friend_group.add(f)
    num = len(friend_group)
    for f in friend_group:
        suggest_friends[f] = num - 1 - len(friend[f] | not_friend[f] & friend_group)
 
for i in range(n):
    if suggest_friends[i] == -1:
        suggest_friends[i] = 0
print(*suggest_friends)

Measured memory_bytes: 107432
#include <stdio.h>
#include <vector>
#include <algorithm>

#define minn(a,b) (a<=b?a:b)
#define abss(a,b) (a>=b?a-b:b-a)

int t1,t2,t3;

int n;
int x[100005];
int y[100005];

std::pair<int,int> xi[100005];  // {x, id}
std::pair<int,int> yi[100005];  // {y, id}

// {cost,{start,end}}
std::vector<std::pair<int,std::pair<int,int> > > g;

void push(int u,int v)
{
    t2=abss(x[u],x[v]);
    t3=abss(y[u],y[v]);
    //printf("%d %d has %d %d\n",u,v,t2,t3);
    g.push_back({minn(t2,t3),{u,v}});
}

int lv[100005];
int up[100005];

int get(int u)
{
    if (up[u]!=up[up[u]]) return up[u]=get(up[u]);
    return up[u];
}

long long ans=0;

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d%d",x+i,y+i);
        xi[i]={x[i],i};
        yi[i]={y[i],i};
        up[i]=i;
    }
    // get all relevant edges
    std::sort(xi,xi+n);
    std::sort(yi,yi+n);
    for (int i=1; i<n; i++) {
        push(xi[i-1].second,xi[i].second);
        push(yi[i-1].second,yi[i].second);
    }
    // kruskal
    std::sort(g.begin(),g.end());
    for (std::pair<int,std::pair<int,int> > e:g) {
        t1=get(e.second.first);
        t2=get(e.second.second);
        //printf("weird %d\n",e.first);
        if (t1!=t2) {
            ans+=e.first;
            //printf("use %d %d\n",e.second.first,e.second.second);
            if (lv[t1]<lv[t2]) up[t1]=t2;
            else if (lv[t1]>lv[t2]) up[t2]=t1;
            else {
                up[t1]=t2;
                lv[t2]++;
            }
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 7540
N,M=map(int,input().split())
e=[]
for i in range(M):
    a,b=map(int,input().split())
    #g[a-1].append(b-1)
    e.append([a-1,b-1])
#print('init g : ',g)
#print('e : ',e)

def dfs(G,v):
    #print('dfs start')
    #print('G,v : ',G,v)
    seen[v]=True
    #print('init seen : ',seen)
    for i in range(len(G[v])):
        if seen[G[v][i]]==True:
            #print('seen[',i,']==True')
            continue
        else:
            #print('call next')
            #print('G,G[v][i]',G,G[v][i])
            dfs(G,G[v][i])

cnt=0
for i in range(M):
    g=[[] for _ in range(N)]
    seen=[False for _ in range(N)]
    ee=e[:i]+e[i+1:]
    for j in range(M-1):
        a=ee[j][0]
        b=ee[j][1]
        g[a].append(b)
        g[b].append(a)
    #print('case : ',ee)
    #print('g : ',g)
    dfs(g,0)
    if False in seen:
        #print('cnt up')
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	ll n, k;
	cin >> n >> k;
	vector<ll> p(n), c(n);
	rep(i, n)
	{
		cin >> p[i];
		p[i]--;
	}
	rep(i, n)
	{
		cin >> c[i];
	}

	ll ans = -LINF;

	for (int i = 0; i < n; i++)
	{
		ll nk = 0;
		ll sum = 0;
		ll j = p[i];
		nk++;
		sum += c[j];

		ans = max(ans, sum);
		while (j != i)
		{
			j = p[j];
			nk++;
			sum += c[j];
			if(nk<=k)
			ans = max(ans, sum);
		}
		if (sum <= 0)
			continue;
		ll ans2 = sum * (max(k / nk - 1, 0LL));
		ans = max(ans, ans2);
		ll mk = k % nk + nk;
		if (k < nk)
			mk = k;
		j = i;
		while (mk)
		{
			j = p[j];
			mk--;
			ans2 += c[j];
			ans = max(ans, ans2);
		}

	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = (n/(a+b))*a;
    ll mod = n%(a+b);

    if(mod>a) ans+=a;
    else ans+= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, t = gets.split.map(&:to_i)
routes = n.times.map{gets.split.map(&:to_i)}
selectedRoutes = routes.select{|x| x[1] <= t}.sort_by{|x| x[0]}
if selectedRoutes.empty?
  puts "TLE"
  exit 0
end
p selectedRoutes[0][0]

Measured memory_bytes: 1916
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define EPS (1e-5)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int N, M;
int root;

vector<int> G[MAX];
int nroot[MAX];
int con[MAX];

int parent[MAX];

void solve(){
	queue<int> Q;
	
	Q.push(root);
	
	while(!Q.empty()){
		int temp = Q.front(); Q.pop();
		for(int x : G[temp]){
			con[x]++;
			if(con[x] != nroot[x]) continue;
			Q.push(x);
			parent[x] = temp;
		}
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(7);
	
	int A, B;
	
	cin>>N>>M;
	
	for(int i = 0; i < N+M-1; i++){
		cin>>A>>B;
		G[A].push_back(B);
		nroot[B]++;
	}
	
	for(int i = 1; i <= N; i++){
		if(!nroot[i]){
			root = i;
			break;
		}
	}
	
	solve();
	
	for(int i = 1; i <= N; i++){
		cout<<parent[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 8960