akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main {
    static HashMap<Integer,ArrayList<Integer>> to = new HashMap<Integer,ArrayList<Integer>>();
    static int[] ans;
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(2*n < m || n > 2*m || (n+m) % 3 != 0){
            System.out.println(0);
        }else{
            long cnt = (n+m) / 3;
            for(long i = 0; i <= cnt; i++){
                if(n == 2*i+(cnt-i)){
                    System.out.println(nCk(cnt,i,mod));
                    return;
                }
            }
        }
    }
    
    public static long nCk(long n,long k,long M) {
        long ret = 1;
        long min = Math.min(k, n-k);
        for(long i=1;i<=min;i++) {
            ret = (ret * pow(i,M-2,M)) % M;
        }
        for(long i=n-min+1;i<=n;i++) {
            ret = (ret * i) % M;
        }
        return ret;
    }

    public static long pow(long a,long b,long M) {
        long ret = 1;
        long tmp = a;
        while(b>0) {
            if((b&1)==1){
                ret = (ret * tmp) % M;
            }
            tmp = (tmp * tmp) % M;
            b = b>>1;
        }
        return ret;
    }
    
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        } 
    }
}


Measured memory_bytes: 22864
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <numeric>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
static string S, T;

void solve(void) {
  FOR0(i, N) {
    cout << S[i] << T[i];
  }
  cout << endl;
}

int main(void) {
  cin >> N;
  cin >> S;
  cin >> T;
  solve();
  return 0;
}

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

int dp[1001];
int main() {
	int m;
	while (scanf("%d", &m), m) {
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		rep(i, m) {
			int a, b; scanf("%d%d", &a, &b);
			for (int j = 1000; j >= 0; j--) {
				for (int k = 1; k <= b; k++) {
					if (j >= a*k)dp[j] += dp[j - a*k];
				}
			}
		}
		int g; scanf("%d", &g);
		rep(i, g) {
			int n; scanf("%d", &n);
			printf("%d\n", dp[n]);
		}
	}
}

Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N, M;
    cin >> N >> M;
    if(N == M) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	for(string a,b;cin>>a>>b;){
		int m=a.size(),n=b.size();
		int res=0;
		for(int i=-m+1;i<n;i++){
			int k=0;
			for(int j=max(-i,0);j<m && i+j<n;j++){
				if(a[j]!=b[i+j])
					k=0;
				else
					k++;
				res=max(res,k);
			}
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <fstream>
using namespace std;
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
template<class T>
void printv(vector<T> & vec) { for (T e : vec) cout << e << ' '; cout << endl; }



int main() {	
	
	int l, r, d;
	int count = 0;
	cin >> l >> r >> d;
	REP(i, l, r + 1) {
		if (i % d == 0)
			count++;
	}
	cout << count << endl;
	system("pause");
	return 0;
}

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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n+2];
  for(i=1;i<=n;i++)cin>>a[i];
  a[0]=0;a[n+1]=0;
  for(i=0;i<=n;i++)cnt+=max(a[i]-a[i+1],a[i+1]-a[i]);
  for(i=0;i<n;i++)cout<<cnt+max(a[i]-a[i+2],a[i+2]-a[i])-max(a[i]-a[i+1],a[i+1]-a[i])-max(a[i+1]-a[i+2],a[i+2]-a[i+1])<<endl;
}

Measured memory_bytes: 1664
s=str(input())
even = ["L","U", "D"]
odd = ["R", "U", "D"]
a = []
b = []
for i in range(len(s)):
     if (i+1)%2 == 0:
            if s[i] in even:
                a.append(True) 
            else:
                a.append(False)
     elif (i+1)%2 != 0:
            if s[i] in odd:
                b.append(True) 
            else:
                b.append(False)
if all(a) and all(b):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from sys import stdin

while True:
    s = stdin.readline().rstrip()
    if s == "-":
        break
    else:
        m = int(stdin.readline().rstrip())
        for i in range(m):
            h = int(stdin.readline().rstrip())
            s = s[h:]+s[:h]
        else:
            print(s)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n;
    int p;
    Scd(n);
    int ans = 0;
    bool mul = 0;
    Rep(i,n){
        Scd(p);
        if( p == i+1 ){
            if( mul ){
                ans++;
                mul = false;
            }else{
                mul = true;
            }
        }else{
            if( mul ) ans++;
            mul = false;
        }
    }
    if( mul ) ans++;

    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll power = 18;

ll move(vector<vector<ll>>& d, ll a, ll b) {
  ll res = 0;
  ll now = a;
  while (now < b) {
    ll temp = 0;
    for (ll i = 0; i < power; ++i) {
      if (d.at(i).at(now) < b) {
        temp = i;
      }
      else {
        break;
      }
    }
    res +=  pow(2, temp);
    now = d.at(temp).at(now);
    // cout << "now" << now << "\n";
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> X(N + 1, 0);
  for (ll i = 1; i <= N; ++i) {
    cin >> X.at(i);
  }
  ll L;
  cin >> L;
  vector<vector<ll>> d(power, vector<ll>(N + 1));
  d.at(0).at(N) = N;
  for (ll i = 0; i < N; ++i) {
    d.at(0).at(i) = upper_bound(X.begin(), X.end(), min(X.at(i) + L, X.at(N))) - X.begin() - 1;
  }
  for (ll i = 0; i < power - 1; ++i) {
    for (ll j = 0; j <= N; ++j) {
      d.at(i + 1).at(j) = d.at(i).at(d.at(i).at(j));
    }
  }
  // for (ll i = 0; i < power; ++i) {
  //   for (ll j = 0; j <= N; ++j) {
  //     cout << d.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }

  ll Q;
  cin >> Q;
  for (ll i = 0; i < Q; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    cout << move(d, a, b) << "\n";
  }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

string S;

int main() {
    cin >> S;
    REP (i, S.size()) cout << "x";
    cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long k = long.Parse(input[0]);
		long s = long.Parse(input[1]);
		long answer = 0;

    for(long i = 0; i <= k; i++)
    {
      for(long j = 0; j <= k; j++)
      {
        if(s-i-j >= 0 && s-i-j <= k) answer++;
      }
    }

		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#define SENTINEL (1000000001)
#define putChar(c) ; *p = (c); ++p;

int c = 0;
int S[500000];
int L[250001];
int R[250001];
char str[5500010];
char *p = str;

static void Merge(int A[], int left, int mid, int right);
static void MergeSort(int A[], int left, int right);
static int getNum(void);
static void putNum(int n);

int main(void) {
	register int i;
	int n;
	
	fread(str, sizeof(char), 5500000, stdin);
	n = getNum();
	for (i = 0; i < n; ++i) {
		S[i] = getNum();
	}
	
	MergeSort(S, 0, n);
	
	--n;
	p = str;
	for (i = 0; i < n; ++i) {
		putNum(S[i]);
		putChar( ' ' );
	}
	putNum(S[i]);
	putChar( '\n' );
	
	putNum(c);
	putChar( '\0' );
	
	puts(str);

	return 0;
}

int getNum(void) {
	int n = 0;
	while ((*p >= '0') && (*p <= '9')) {
		n = n * 10 + (int)(*p - '0');
		++p;
	} 
	++p;
	return n;
}

void putNum(int n) {
	int d = n / 10;
	if (n < 10) {
		putChar( '0' + (char)n );
		return;
	}
	if (d) putNum(d);
	putChar( '0' + (char)(n % 10) );
}

void Merge(int A[], int left, int mid, int right) {
	int i = 0, j = 0, k = left;
	int n1 = mid - left;
	int n2 = right - mid;
	memcpy(L, A + left, n1 * sizeof(int));
	memcpy(R, A + mid, n2 * sizeof(int));
	L[n1] = R[n2] = SENTINEL;
	for (; k < right; ++k) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			++i;
		} else {
			A[k] = R[j];
			++j;
		}
	}
}

void MergeSort(int A[], int left, int right) {
	int mid;
	if (left + 1 >= right) {
		return;
	}
	mid = (left + right) >> 1;
	MergeSort(A, left, mid);
	MergeSort(A, mid, right);
	Merge(A, left, mid, right);
	c += right - left;
}

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
  int X;
  cin >> X;
  int ans = 1;
  for (int i = 2; i <= (int)sqrt(X); i++) {
    int exp = i;
    for(;;) {
      exp *= i;
      if (exp > X) break;
      ans = max(ans, exp);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3688
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 200005
using namespace std;
int n,sum[MN][26];long long f[MN];
char ch[MN];
int main(){
	scanf("%s",ch+1);int n=strlen(ch+1);
	for(int i=1;i<=n;i++)memcpy(sum[i],sum[i-1],sizeof(sum[i-1])),sum[i][ch[i]-'a']++;f[0]=1;
	for(int i=1;i<=n;i++)f[i]=f[i-1]+i-sum[i][ch[i]-'a'];
	printf("%lld\n",f[n]);
}



Measured memory_bytes: 22272
N, M = list(map(int,input().split()))
a = []
for i in range(M):
    a.append(list(map(int,input().split())))
a = sorted(a, key=lambda x: x[1])
left = -1
ans = 0
for i in range(M):
    if left < a[i][0]:
      left = a[i][1] - 1
      ans += 1
print(ans)

Measured memory_bytes: 65368
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define vvl vector<vector<long long>>
#define all(A) A.begin(), A.end()

int main() {
    ll n, x, y; cin >> n >> x >> y;
    x--; y--;

    vvl g(n, vl(n));
    vl ans(n);

    g[x][y] = 1;
    rep(i,n){
        xrep(j,i+1,n){
            g[i][j] = min(j - i, abs(i-x) + 1 + abs(j-y));
            ans[g[i][j]-1]++;
        }
    }
    
    rep(i,n-1) cout << ans[i] << endl;
}

Measured memory_bytes: 34924
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

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

	string s;
	cin >> s;

	int rc = 0;
	int ans = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R')
			rc++;
	}

	for (int i = rc; i < n; i++) {
		if (s[i] == 'R')
			ans++;
	}

	cout << ans << endl;

	return 0;
}

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

/*int main() {
    int n, a;
    cin >> n >> a;
    if (n % 500 > a) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}*/

int main() {
    int n;
    cin >> n;
    priority_queue<int> pq;
    for (int i = 0; i < n; i++) {
        int val;
        cin >> val;
        pq.push(val);
    }
    int alice = 0, bob = 0;
    bool b = 1;
    while (!pq.empty()) {
        if (b) {
            alice += pq.top();
        } else {
            bob += pq.top();
        }
        b = !b;
        pq.pop();
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int t,n,s,f,a[20],i;
	while(cin>>t){
		if(t==0)break;
		cin>>n;
	for(i=0;i<n;i++){
		cin>>s>>f;
		a[i]=f-s;	
	}a[n]=0;
	for(i=0;i<n;i++){
		a[i+1]=a[i]+a[i+1];
	}if(a[n]>=t){
		cout<<"OK"<<endl;
	}if(a[n]<t){
		t=t-a[n];
		cout<<t<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int  a,b;
    cin>>a>>b;
    for(int i=1;i<=10000;i++ )
    {
        if(i*8/100==a&&i/10==b){cout<<i;return 0;}
    }
    cout<<"-1";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    string s;

    cin >> s;

    if (s == "Sunny") cout << "Cloudy";
    else if (s == "Cloudy") cout << "Rainy";
    else cout << "Sunny";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> x(N, 0);
  vector<int> y(N, 0);
  REP(i, N){
    cin >> x[i] >> y[i];
  }
  vector<int> np(N, 0);
  REP(i, N){
    np[i] = i;
  }
  double ans = 0;
  int cnt = 0;
  do{
    double tmp = 0;
    int x1 = x[np[0]], y1 = y[np[0]];
    for(int i = 1; i < N; i++){
      tmp += sqrt((x1-x[np[i]])*(x1-x[np[i]]) + (y1-y[np[i]])*(y1-y[np[i]]));
      x1 = x[np[i]]; y1 = y[np[i]];
    }
    ans += tmp;
    cnt++;
  }while(next_permutation(np.begin(), np.end()));
  cout << fixed << setprecision(10) << ans/cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
    int D,T,S;
    cin>>D>>T>>S;
    double c;
    c=(double)D/(double)S;
    if(c<=T){
        cout<<"Yes";return;
    }
    else{
        cout<<"No";return;
    }
}
int main()
{
    solve();
}

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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define PRINT(s) cout<<s
#define PRINTS(s) cout<<s<<' '
#define PRINTL(s) cout<<s<<endl
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long

using namespace std;



int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    string s;
    cin>>s;

    while(true){
        s.pop_back();
        if(s.size()%2==1)continue;
        if(s.substr(0,s.size()/2)==s.substr(s.size()/2)){
            cout<<s.size()<<endl;
            return 0;
        }
    }

    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;



bool is_pal(int n){
    string s = to_string(n);
    string r = s;
    reverse(r.begin(), r.end());
    return r == s;
}

int main() {
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for(int i=a;i<=b;i++){
        if(is_pal(i)){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';

void solve(){
    ll i,j,k,l,m,n,u,v,x,y,d,t,s;
    cin>>d>>t>>s;
    string st= t*s>=d?"Yes":"No";
    cout<<st<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

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

	int cur_max = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] < cur_max-1) {
			cout << "No" << endl;
			return 0;
		}
		cur_max = max(cur_max, v[i]);
	}

	cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int count = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == (t.charAt(i))) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22608
from collections import defaultdict
N=int(input())

def pow25(x):
  f2=f5=0
  while x%2==0:
    x//=2
    f2+=1
  while x%5==0:
    x//=5
    f5+=1
  return f2,f5

pow25_dic=defaultdict(int)
for _ in range(N):
  a=input()
  if "." in a:
    seisu,shosu=a.split(".")
    seisu=int(seisu)
    shosu=int(shosu.ljust(9,'0'))    
    bunshi=10**9*seisu+shosu
  else:
    bunshi=10**9*int(a)
    
  pow25_dic[pow25(bunshi)]+=1
#print(pow25_dic)

pow25_key_list=[]
for key in pow25_dic:
  pow25_key_list.append(key)
#print(pow25_key_list)

answer=0
for i in range(len(pow25_key_list)):
  f2,f5=pow25_key_list[i]
  value=pow25_dic[(f2,f5)]
  if f2>=9 and f5>=9:    
    answer+=value*(value-1)//2
    
  for j in range(i+1,len(pow25_key_list)):
    f2_2,f5_2=pow25_key_list[j]
    if f2+f2_2>=18 and f5+f5_2>=18:
      value2=pow25_dic[(f2_2,f5_2)]
      answer+=value*value2
      
print(answer)

Measured memory_bytes: 9344
S,T = input(),input()
 
convert = dict()
 
bl = True
for s,t in zip(S,T):
  if s in convert and convert[s] != t:
    bl = False
    break
  convert[s] = t
 
# 変換先の重複チェック
after = convert.values()
if len(after) != len(set(after)):
  bl = False
 
print('Yes' if bl else 'No')

Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class CWalkOnMultiplicationTable {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll N;
	    in >> N;
	    ll answer = LLONG_MAX;
	    REP(i,1,min((ll)(1e6+1),N)) {
	        if (N % i == 0) {
	            ll candidate = i + N / i - 2;
	            answer = min(answer, candidate);
	        }
	    }
	    out << answer << "\n";
	}
};


signed main() {
	CWalkOnMultiplicationTable solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
ps=[list(map(str,input().split())) for _ in range(m)]

str_l=["WA"]*n
int_l=[0]*n

num=0
ac=0
for pp,s in ps:
    p=int(pp)-1
    if s=="AC":
        str_l[p]="AC"
    else:
        if str_l[p]!="AC":
            int_l[p]+=1

for i in range(n):
    if str_l[i]=="AC":
        num+=int_l[i]
        ac+=1
print(ac,num)

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

ll n,k;

int main(){
    cin >> n >> k;
    ll a[n];
    for(ll i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    if(k==0){
        cout << a[n-1] << endl;
        return 0;
    }
    ll ok=a[n-1];
    ll ng=0;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        ll count=0;
        for(ll i=0;i<n;i++){
            if(a[i]%mid==0) count+=a[i]/mid-1;
            else count+=a[i]/mid;
        }
        if(count<=k) ok=mid;
        else ng=mid;
    }
    cout << ok << endl;
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  string s;
  while (cin >> s) {
    int n = 0;
    n += (bool)count(s.begin(), s.end(), 'N');
    n -= (bool)count(s.begin(), s.end(), 'S');
    int m = 0;
    m += (bool)count(s.begin(), s.end(), 'E');
    m -= (bool)count(s.begin(), s.end(), 'W');
    cout << (n == 0 && m == 0 ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long int dp[99][21];
int main(void)
{
	int suu[100],n,i,j;
	scanf("%d",&n);
	for(i=0;i<=n;i++){
		for(j=0;j<=20;j++) dp[i][j]=0;
	}
	for(i=0;i<n;i++) scanf("%d",&suu[i]);
	dp[0][suu[0]]=1;
	for(i=0;i<n-2;i++){
		for(j=0;j<=20;j++){
			if(dp[i][j]!=0){
				if(j+suu[i+1]<=20) dp[i+1][j+suu[i+1]]+=dp[i][j];
				if(j-suu[i+1]>=0) dp[i+1][j-suu[i+1]]+=dp[i][j];
			}
		}
	}
	printf("%lld\n",dp[n-2][suu[n-1]]);
	return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    int a[3];
    rep(i,3){
        cin >> a[i];
    }
    int k;cin >>  k;
    int cur = 0;
    int sum = 0;
    while(k){
        int t;
        if(a[cur]>0){
            if(a[cur]>k){
                sum+=k*(1-cur);
                k = 0;
            }else{
                sum+=a[cur]*(1-cur);
                k-=a[cur];
                a[cur] = 0;
            }
        }else{
            cur++;
        }
    }
    cout << sum << endl;
}

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

int n,ans;

int main()
{
	scanf("%d",&n);
	int las=-1;
	for(int i=1;i<=n;++i) {
		char s=getchar();
		while(!(s>='a'&&s<='z')) s=getchar();
		if(las!=s-'a') las=s-'a',ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int n,m;
    cin >> n >> m;
    if(n%2 == 1){
        REP(i,m){
            cout << i+1 << " " << n-i-1 << endl;
        }
    }
    else{
        REP(i,m){
            int k;
            if(i< n/4){
                cout << i+1 << " " << n/2 - i << endl;
                k = i;
            }
            else{
                cout << n/2 +1 + (i-k) << " " << n+1 - (i-k) << endl;
            }
        }

    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		for(int i=0;i<N;i++) {
			int l=sc.nextInt();
			ans=ans+Math.min(Math.abs(l-K), l);
		}
		System.out.println(ans*2);
	}
}

Measured memory_bytes: 21844
use proconio::*;
use std::cmp::min;

fn main() {
    input! {
        n: i64,
    }

    let mut res = n;
    loop {
        let mut isPrime = true;

        for i in 2..1000 {
            if i >= res {
                break;
            }
            if res % i == 0 {
                isPrime = false;
                break;
            }
        }

        if isPrime {
            break;
        }
        res += 1;
    }
    println!("{}", res);
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i){
    cin >> a[i];
  }
  int s = 0;
  for (int i = 0; i < n; ++i){
    s += a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i){
    if (a[i]*4*m >= s) cnt++;
  }
  if (cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<double,int> P;

int xs[21];
int ys[21];
double h[21];
int n;
double Hypot(int x, int y)
{
	return sqrt(x*x+y*y);
}
bool ok(int x, int y, int done, double t)
{
	if(done+1==(1<<n))
	{
		return true;
	}

	vector<P> q;
	for(int i=0;i<n;i++){
		if(done&(1<<i))continue;
		double d=t+Hypot(xs[i]-x,ys[i]-y);
		if(d>=h[i]){
			return false;
		}
		q.push_back(P(d,i));
	}
	sort(q.begin(),q.end());
	for(auto p : q)
	{
		int i=p.second;
		if(ok(xs[i],ys[i],done|(1<<i),p.first)){
			return true;
		}
	}
	return false;
}
void exec()
{
	int hx,hy,dx,dy;
	cin >> n >> hx >> hy >> dx >> dy;
	if((n|hx|hy|dx|dy)==0){
		exit(0);
	}
	for(int i=0;i<n;i++){
		cin >> xs[i] >> ys[i];
		h[i]=Hypot(xs[i]-dx,ys[i]-dy);
	}
	if(ok(hx,hy,0,0)){
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}
int main() {
	while(1)exec();
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 50000001
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans,cnt;


int main() {
	ll K,X;
	cin >> K >> X;
	
	if (K * 500 >= X) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A;
  for(int i = 0;i < M;i++){
    int input;
    cin >> input;
    A.push_back(input);
  }
  int sum = accumulate(A.begin(),A.end(),0);
  int output = N - sum;
  if(output >= 0)cout << output;
  else cout << -1;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int l;
	cin >> l;
	int nodenum = 20;
	while(l < (1 << nodenum)) nodenum--;
	nodenum++;
	vector<pair<pair<int, int>, int> > v;
	for(int i = 1; i < nodenum; i++){
		v.push_back(make_pair(make_pair(i, i + 1), 0));
		v.push_back(make_pair(make_pair(i, i + 1), (1 << (i - 1))));
	}
	int rest = l - 1;
	for(int i = nodenum - 1; i > 0; i--){
		int tmp = rest - ((1 << (i - 1)) - 1);
		// cout << i << " " << tmp << endl;
		if(tmp >= (1 << (nodenum - 1))){
			v.push_back(make_pair(make_pair(i, nodenum), tmp));
			rest = tmp - 1;
		}
	}
	cout << nodenum << " " << v.size() << endl;
	for(int i = 0; i < v.size(); i++){
		cout << (v[i].first).first << " " << (v[i].first).second << " " << v[i].second << endl;
	}
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n, h;
  cin >> n >> h;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  int count = 0;
  for (int i = 0; i < n && b[i] > a[0]; i++) {
    count++;
    h -= b[i];
    if (h <= 0) {
      cout << count << endl;
      return 0;
    }
  }
  count += (h + a[0] - 1) / a[0];
  cout << count << endl;
}


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

int cmp(const long *a, const long *b){
    if(*a==*b){
        return 0;
    }else if(*a<*b){
        return 1;
    }else{
        return -1;
    }
}

int main(void){
    long n, h;
    scanf("%ld %ld", &n, &h);
    static long b[100000];
    long am = 0;
    for(long i=0; i<n; i++){
        long a;
        scanf("%ld %ld", &a, b+i);
        am = a>am ? a : am;
    }
    qsort(b, n, sizeof(long), (int (*)(const void *, const void *))cmp);
    long m=0;
    while(b[m]>am && h>0){
        h-=b[m];
        m++;
    }
    if(h>0){
        m+=(h+am-1)/am;
    }
    printf("%ld", m);
    return 0;
}


Measured memory_bytes: 1788
import math
import numpy as np
def yakusu(num):
    top = []
    bot = []
    for i in range(int(math.sqrt(num))):
        k = i+1
        if num%k == 0:
            top.append(num//k)
            bot.append(k)
    return top + bot[::-1]

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
start = x[0]
x = np.array(x[1:])
x -= start
# print(x)

for ans_pred in yakusu(x[0]):
    if ans_pred == 1:
        break
    flag = True
    for i in x:
        if i % ans_pred != 0:
            flag= False
            break
    if flag:
        break

print(ans_pred)

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;





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

vector<int> arr(100001,0);
for(int i = 0 ; i< n ;i++)
    {
        int c;
        cin>>c;
        arr[c]++;
    }
int pos =-1;
int ans = 0;
if(ans<arr[0]+arr[1])
{
    ans = arr[0]+arr[1];
    pos=0;
}

if(ans<arr[100000]+arr[100001])
{
    ans = arr[100000]+arr[100000-1];
    pos=100000;
}

for(int index = 1 ;index<100000;index++)
{
    if(ans<arr[index]+arr[index-1]+arr[index+1])
    {
        ans = arr[index]+arr[index-1]+arr[index+1];
        pos = index;
    }
}
    cout<<ans<<endl;


 return 0;
}


Measured memory_bytes: 3708
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！

int main() {
    int n, m;
    cin >> n >> m;
    cout << ((n * (n - 1)) / 2) + (m * (m - 1) / 2) << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
const int INF = numeric_limits<int>::max()/2;

struct UF {
	vector<int> data;
	UF(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

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

    int n,m;cin>>n>>m;
    UF uf(n);
    vector<vector<int>> v(m);
    for(int i=0;i<n;i++){
        int k;cin>>k;
        for(int j=0;j<k;j++){
            int l;cin>>l;l--;
            v[l].push_back(i);
        }
    }
    for(int i=0;i<m;i++){
        if(v[i].size()<2) continue;
        for(int j=1;j<(int)v[i].size();j++){
            uf.unite(v[i][j],v[i][j-1]);
        }
    }
    if(uf.size(0)==n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 4608
str = gets.chomp

a = str[0..1]
b = str[2..3]

mon = %w[01 02 03 04 05 06 07 08 09 10 11 12]
year = %w[00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99]
MMYY  = mon.any? { |m| m == a } && year.any? { |y| y == b }
YYMM  = mon.any? { |m| m == b } && year.any? { |y| y == a }
res =
  if MMYY && YYMM
    'AMBIGUOUS'
  elsif MMYY
    'MMYY'
  elsif YYMM
    'YYMM'
  else
    'NA'
  end
puts res


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

int _find(int n,int s,int e, int w){
    if(n and !s){return 0;}
    if(s and !n){return 0;}
    if(e and !w){return 0;}
    if(w and !e){return 0;}
    return 1;
}
void solve(){

    string str;
    cin>>str;
    
    int n,s,e,w;
    n=s=e=w=0;
    for(char ch:str){
        switch(ch){
            case 'N':
                n++;
                break;
            case 'S':
                s++;
                break;
            case 'E':
                e++;
                break;
            case 'W':
                w++;
                break;
        }
    }
    if(_find(n,s,e,w)){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3644
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        int x = 0;

        if(A<=B){
            for(int i=A; i>0; i--){
                if(A%i==0 && B%i==0){
                    x += 1;
                    if(x==K){
                        System.out.println(i);
                    }
                }
            }
        }
        else if(A>B){
            for( int i=B; i>0; i--){
                if(A%i==0 && B%i==0){
                    x += 1;
                    if(x==K){
                        System.out.println(i);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 21844
N = int(input())
s = []
for i in range(N):
	s.append(int(input()))
s.sort()
sum = sum(s)
ans = 0
if sum % 10 != 0:
	ans = sum
else:
	for i in range(N):
		if s[i] % 10 != 0:
			ans = sum - s[i]
			break
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
#define pb push_back
#define mp make_pair
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define N 100010
int visited[N], A[N];
vector<int> graph[N];
set<int> cur;
void dfs(int s){
	visited[s] = 1;
	cur.insert(s);
	for(int i=0;i<graph[s].size();i++){
		if(!visited[graph[s][i]]){
			dfs(graph[s][i]);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>A[i];
		A[i]--;
	}
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		graph[x-1].pb(y-1);
		graph[y-1].pb(x-1);
	}
	int ans = 0;
	set<int> rt;
	for(int i=0;i<n;i++){
		if(!visited[i]){
			cur.clear();
			dfs(i);
			for(auto j = cur.begin(); j != cur.end(); j++){
				if(cur.find(A[*j]) != cur.end())
					ans++;
			}
		}
	}
	cout<<ans<<'\n';

	
}

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

struct s_skill {
	int a;
	int b;
};

int main() {
	int h, n;

	cin >> h >> n;

	vector<s_skill> slist(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> slist[i].a >> slist[i].b;
	}

	vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, INT32_MAX));

	for (int i = 0; i < n; ++i)
	{
		for (int j = 1; j <= h; ++j)
		{
			if (j <= slist[i].a)
			{
				dp[i + 1][j] = min(dp[i][j], (ll)slist[i].b);

			}
			else
			{
				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - slist[i].a] + (ll)slist[i].b);
			}
		}
	}

	cout << dp[n][h];
}


Measured memory_bytes: 78592
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int N=105;
char s[N],t[N];
int n,m;
int main() {
  scanf("%s",s);
  scanf("%s",t);
  n=strlen(s);m=strlen(t);
  if(m!=(n+1)) {
    puts("No");
    return 0;
  }
  for (int i=0;i<n;++i) {
    if(s[i]!=t[i]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
signed main(){
    int x;
    cin>>x;
    int i=x;
    while(true){
		if(IsPrime(i)){
          cout<<i<<'\n';
          return(0);
        }
        i++;
    }
    return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
using namespace std;
#define F first
#define S second
const int INF = 1 << 31, MAX_N = 5000;
typedef pair<int, int> P;

void dijkstra();
void bfs(int s, int dis, int cost);
int n, k;
vector<int> road[MAX_N + 1];
int taxi[MAX_N + 1][2];
int reach[MAX_N + 1];

int main(){
	fill(reach + 2, reach + MAX_N + 1, INF);
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		scanf("%d%d", &taxi[i][0], &taxi[i][1]);
	}
	for (int i = 0; i < k; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		road[a].push_back(b);
		road[b].push_back(a);
	}
	dijkstra();
	cout << -reach[n] << endl;
	return 0;
}

priority_queue<P> pq;

void dijkstra(){
	bfs(1, taxi[1][1], -taxi[1][0]);
	while (!pq.empty()){
		P p = pq.top();
		pq.pop();
		if (reach[p.S] < p.F){
			reach[p.S] = p.F;
			bfs(p.S, taxi[p.S][1], p.F - taxi[p.S][0]);
		}
	}
}



void bfs(int s, int dis, int cost){
	queue<P> que;
	bool rea[5001]={};
	que.push(P(s, dis));
	while (!que.empty()){
		P p = que.front();
		que.pop();
		if (p.S){
			for (int i = 0; i < road[p.F].size(); i++){
				if (!rea[road[p.F][i]]){
					rea[road[p.F][i]] = 1;
					que.push(P(road[p.F][i], p.S - 1));
						if (reach[road[p.F][i]] < cost){
						pq.push(P(cost, road[p.F][i]));
					}
				}
			}
		}
	}
}

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

const int N = 300054;

int n, S, So, Se;
int a[N], s[N];

inline void down(int &x, const int y) {x > y ? x = y : 0;}

inline bool check(int x) {
	int i, min = 0;
	for (i = 2; i < n; i += 2) if (s[i - 1] >= min + x) down(min, s[i]);
	return s[n] >= min + x;
}

int main() {
	int i, ans, L, R, M;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", a + i), S += a[i], s[i] = s[i - 1] + (i & 1 ? (So += a[i], a[i]) : (Se += a[i], -a[i]));
	ans = (n & 1 ? ({for (L = 0, R = So; L < R; check(M = (L + R + 1) / 2) ? L = M : R = M - 1); Se + L;}) : std::max(So, Se));
	printf("%d %d\n", ans, S - ans);
	return 0;
}

Measured memory_bytes: 2560
N = int(input())
M = int(N**(1/2))+2

A = [0 for _ in range(N+1)]
for x in range(1, M):
    for y in range(1, M):
        for z in range(1, M):
            f = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if f <= N:
                A[f] += 1
for a in A[1:]:
    print(a)

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

#pragma GCC optimize "trapv"
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define drep(i,a,b) for(int i=a; i>b; i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define inf 1e+18L
#define mod 1000000007

const auto pi = 3.14159265358979;

template <typename T>
T numdigits(T n)
{
    return (floor(log10(n)) + 1);
}

template <typename T>
T modpower(T x, T y, T m=mod)
{
    T res = 1;
    x %= m;
    if(x == 0) return 0;
    while(y > 0)
    {
        if(y&1) res = (res*x)%m;
        y >>= 1;
        x = (x*x)%m;
    }
    return res;
}

void solve()
{
    //code
    int r;
    cin >> r;
    cout << fixed << setprecision(10) << 2*pi*r << "\n";
}

int main()
{
    FASTIO
//    int t;
//    cin >> t;
//    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3808
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	while (true) {
	  int n = sc.nextInt();
	  if (n == 0) {
		break;
	  }
	  int[] incomeData = new int[n];
	  double averageIncome = 0;
	  for (int i = 0; i < n; i++) {
		incomeData[i] = sc.nextInt();
		averageIncome += incomeData[i];
	  }
	  averageIncome /= n;
	  int count = 0;

	  for (int i = 0; i < n; i++) {
		if (incomeData[i] <= averageIncome) {
		  count++;
		}
	  }
	  System.out.println(count);
	}
  }
}



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

using namespace std;

int main(void) {

	int N;
	cin >> N;

	vector<int> vec1;
	int v;
	int i;
	for (i = 0; i < N; i++) {
		cin >> v;
		vec1.push_back(v);
	}

	vector<int> vec2;
	copy(vec1.begin(), vec1.end(), back_inserter(vec2));
	sort(vec2.begin(), vec2.end());

	int mi = N / 2 - 1;
	for (i = 0; i < N; i++) {
		int mid;
		if (vec1[i] <= vec2[mi]) {
			mid = vec2[mi + 1];
		} else {
			mid = vec2[mi];
		}
		cout << mid << endl;
	}

	return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int a, b, x;
    cin >> a >> b;
    if (a == b) return cout << a, 0;
    x = a++;
    while (a % 4 != 0) x ^= a++;
    a = b - b % 4;
    while (a <= b) x ^= a++;
    cout << x;
}

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

int main() {
  int n;
  int ans = 101010101;
  vector<int> sum(100);
  cin >> n;
  vector<int> x(n,0);
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
 
  for(int p = 1; p <=100; p++){
    for(int i = 0; i < n; i++){
      
      sum[p] += (x[i]-p)*(x[i]-p);
    }
    ans = min(sum[p],ans);
  }
  
  cout << ans <<endl;
  
}


Measured memory_bytes: 256