akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<int> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i = 0; m > i; i++){
    int l,r;cin>>l>>r;
    auto y = lower_bound(a.begin(),a.end(),l) - a.begin();
    auto z = upper_bound(a.begin(),a.end(),r) - a.begin()-1;
    cout << z-y+1 << endl;
  }
}


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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

ll gcd(ll a, ll b)
{
    ll tmp;
    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    ll r;
    r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main()
{
    ll n, X;
    cin >> n >> X;
    ll x[100001];
    rep(i, 0, n) cin >> x[i];

    if (n == 1)
    {
        cout << llabs(X - x[0]) << endl;
        return 0;
    }
    ll ans = INF;
    rep(i, 0, n - 1)
    {
        ans = min(ans, gcd(llabs(X - x[i + 1]), llabs(X - x[i])));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

const ll MAXN = 100010;
ll N, M;
vector<vector<ll>> g(MAXN);
vector<bool> vis(MAXN);

void dfs(ll x) {
    if (vis[x]) return;
    vis[x] = 1;
    for (ll y:g[x]) dfs(y);
}

int main() {
	cin >> N >> M;
    rep (i, M) {
        ll X, Y, Z;
        cin >> X >> Y >> Z;
        --X;
        --Y;
        g[X].push_back(Y);
        g[Y].push_back(X);
    }

    ll ans = 0;
    rep (i, N) vis[i] = 0;
    rep (i, N) {
        if (vis[i] == 0) {
            dfs(i);
            ++ans;
        }
    }

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


Measured memory_bytes: 8832
S = input()
ans = 0
idx = 0
a_count = 0
while idx < len(S):
    if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
    idx += 1
print(ans)

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    
    if(k<=a){
        cout << k;
    }
    else{
        if (k-a<=b){
            cout << a;
        }
        else{
            cout << a - (k-a-b);
        }
    }
}

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

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

  vector<int> v(n);
  for (int& e : v) cin >> e;

  vector<int> dp(n, 0);
  for (int i = 1; i < n; i++) {
    int& t = dp[i];
    t = dp[i - 1] + abs(v[i] - v[i - 1]);
    if (i > 1) t = min(t, dp[i - 2] + abs(v[i] - v[i - 2]));
  }

  cout << dp.back() << endl;

  return 0;
}


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

using namespace std;

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

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

void dfs(vvi &v, vi &dp, int s)
{
    int najveci = -1;
    for(auto e : v[s])
    {
        if(dp[e]==-1)
        {
            dfs(v, dp, e);
        }
        najveci = max(najveci,dp[e]);
    }
    dp[s]=najveci+1;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vvi v(n+1);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
    }

    vi dp(n+1, -1);
    int najveci=0;
    for(int i=1; i<=n;i++)
    {
        if(dp[i]==-1)
        {
            dfs(v,dp,i);
        }
        //cout<<i<<" : "<<dp[i]<<'\n';

        najveci=max(najveci,dp[i]);
    }

    cout<<najveci<<'\n';

    return 0;
}


Measured memory_bytes: 10240
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define x first
#define y second


int main() {
    string s;
    while(cin>>s){
        int J=0,I=0;
        rep(i,s.size()-2){
            if(s.substr(i,3)=="JOI")J++;
            if(s.substr(i,3)=="IOI")I++;
        }
        cout<<J<<endl<<I<<endl;
    }
    return 0;
}

        
        

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int a, b;
  cin >> a >> b;
  int ans = a+b;
  if(a+b>=24) ans -= 24;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  string s; cin >> s;
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}

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

int main(){
  vector<char> c(6);
  REP(i,6) cin>>c.at(i);
  if(c.at(0)==c.at(5) && c.at(1)==c.at(4) && c.at(2)==c.at(3)) cout<<"YES";
  else cout<<"NO";
}

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

int main() {
	int n, q;
	cin >> n;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int b, e, k, ans = 0;
		cin >> b >> e >> k;
		for (int j = b; j < e; ++j) {
			if (a[j] == k) ++ans;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3092
import numpy as np
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))

lenA=len(A)
Amax=max(A)
ind=A.index(Amax)
del A[ind]
Amax2=max(A)

AA=np.repeat(Amax,lenA, axis=0)
AA[ind]=Amax2
for x in AA:
  print(x)


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

using namespace std;

int main(){
    int N, K, Q; cin >> N >> K >> Q;
    map<int, int> A;
    for(int i=1; i<=N; i++){
        A[i] = 0;
    }
    
    for(int i=0; i<Q; i++){
        int a; cin >> a;
        A.at(a)++;
    }
    
    for(int i=1; i<N+1; i++){
        if(A.at(i) <= Q-K ) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    
        
    
    
}



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

int main(){
    int a,b;
    cin >> a >> b;
    if(b>=0){
        cout << max(a+b,a*b) << endl;
    }else{
        cout << max(a-b,a*b) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int a, b;
    std::cin >> a >> b;

    if(1 == (a + b) % 2){
        std::cout << "IMPOSSIBLE" << std::endl;
    }else{
        std::cout << (a + b) / 2 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {

            string str = Console.ReadLine();
            int ans = 0;
            if (str == "SUN") ans = 7;
            else if (str == "MON") ans = 6;
            else if (str == "TUE") ans = 5;
            else if (str == "WED") ans = 4;
            else if (str == "THU") ans = 3;
            else if (str == "FRI") ans = 2;
            else ans = 1;

            Console.WriteLine(ans);



        }
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */


Measured memory_bytes: 13140
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main(void){

  
  string S,T;
  int count = 0;
  cin >> S >> T;

  for(int i=0; i < 3 ; i++){
    if(S[i] == T[i]){
      count++;
    }
    
  }


 cout << count << endl;
  return 0;
}




Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 1
stop = False
for i in range(n):
  if a[i] == 0 :
    stop = True
  
aaa = False

if stop :
  print(0)
else :
  for j in range(n):
    if aaa == False:
      ans *= a[j]
      if ans > 1000000000000000000:
        aaa = True
  if aaa == True:
    print(-1)
  else :
    print(ans)
  
    

Measured memory_bytes: 21800
import java.net.SecureCacheResponse;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        int ans = Math.max(
                (x*10) + y + z,
                Math.max(
                        x + (y * 10) + z,
                        x + y + (z * 10)
                )
        );

        System.out.println(ans);
    }
}


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

t = [0]
x = [0]
y = [0]

for _ in range(N):
    a, b, c = list(map(int, input().split()))
    t.append(a)
    x.append(b)
    y.append(c)

# print(f"t:{t}\nx:{x}\ny:{y}")

for index in range(1, N + 1):
    distance = (x[index] - x[index - 1]) + (y[index] - y[index - 1])
    duration = t[index] - t[index - 1]
    if duration < distance or duration % 2 != distance % 2:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 11844
#include<iostream>
#include<string>

using namespace std;
int main(){
    int n,sum=1,num,here=1,up=5,down=2,right=3,left=4;
    string str;

    while(1){
    cin >> n;
    if(n==0)break;
    for(int i=0;i<n;i++){
        cin >> str;
        if(str=="North"){
            num=down;
            down=7-here;
            up=here;
            here=num;
            sum=here+sum;

        }else
        if(str=="South"){
            num=up;
            up=7-here;
            down=here;
            here=num;
            sum=here+sum;


        }else
        if(str=="East"){
            num=left;
            left=7-here;
            right=here;
            here=num;
            sum=here+sum;

        }else
        if(str=="West"){
            num=right;
            right=7-here;
            left=here;
            here=num;
            sum=here+sum;

        }else
        if(str=="Left"){
            num=down;
            down=left;
            left=up;
            up=right;
            right=num;
            sum=here+sum;


        }else
        if(str=="Right"){
            num=down;
            down=right;
            right=up;
            up=left;
            left=num;
            sum=here+sum;


        }
    }

    cout << sum << endl;
    sum=1;
    here=1;
    right=3;
    left=4;
    up=5;
    down=2;
    }
return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
signed k,s,cnt;
signed main()
{
    scanf("%d%d",&k,&s);
    for(register signed x=0;x<=k;++x)for(register signed y=0;y<=k;++y)if(s-x-y>=0&&s-x-y<=k) ++cnt;
    printf("%d\n",cnt);
    return 0;
}

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

int search(vector<int> &a, int key, int size){
  int left = 0; int right = size;
  int p;
  while(left != right){
    p = (left+right) / 2;
    if (a[p] < key) left = p+1;
    else right = p;
  }
  return left;
}

int main(){
  int n;
  scanf("%d", &n);
  vector<int> a;
  vector<int> b;
  int k;
  for (int i = 0; i < n; i++){
    scanf("%d", &k);
    a.push_back(k);
  }
  for (int i = 0; i < n; i++){
    scanf("%d", &k);
    b.push_back(k);
  }
  int ans = 0;
  int t2 = 1;
  for (int bit = 0; bit < 29; bit++){
    t2 *= 2;
    vector<int> d;
    for (int j = 0; j < n; j++){
      d.push_back(b[j] % t2);
    }
    sort(d.begin(), d.end());
    int count = 0;
    for (int i = 0; i < n; i++){
      int c = a[i] % t2;
      if (t2 / 2 >= c) count += search(d, t2-c, n) - search(d, t2/2-c, n);
      else count += n - search(d, t2-c, n) + search(d, t2*3/2-c, n);
      count %= 2;
    }
    ans += (count % 2) * t2/2;
  }

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

  return 0;
}


Measured memory_bytes: 3680
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		long a = (long)(in.nextInt()), b = (long)(in.nextInt());

		// out.println(a + " " + b);
		for (int i=1; i<n; ++i) {
			int c = in.nextInt(), d = in.nextInt();
			long na = -1, nb = -1;

			if (c<a || d<b) {
				long per = Math.max((a+c-1)/c, (b+d-1)/d);
				na = per * c;
				nb = per * d;
			} else {
				na = c;
				nb = d;
			}

			a = na;
			b = nb;

			// out.println(a + " " + b);
		}

		long ans = a + b;
		out.println(ans);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

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

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

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

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pll> vec(n);
    rep(i,n){
        cin >> vec[i].fi >> vec[i].se;
    }
    sort(all(vec),[&](P p, P q){
        return p.fi + p.se > q.fi + q.se;
    });
    ll ans = 0;
    rep(i,n){
        if(i % 2 == 0){
            ans += vec[i].fi;
        }else{
            ans -= vec[i].se;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        a: i64,
        b: i64,
    }

    println!("{}", max(a+b, max(a-b, a*b)));
}


Measured memory_bytes: 4352
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int N, K;
	cin >> N >> K;
	vector<modulo> dp = { 1 };
	int sum = 0;
	for (int i = N; i >= 1; --i) {
		sum += (sum + i) / i;
		vector<modulo> ndp(sum + 1);
		for (int j = 0; j < dp.size(); ++j) {
			for (int k = 0; k <= K; ++k) {
				ndp[j + (k <= i ? (j + k) / i : 0)] += dp[j];
			}
		}
		dp = ndp;
	}
	modulo ans = 0;
	for (int i = 0; i <= sum; ++i) {
		ans += dp[i] * i;
	}
	modulo base = modulo(K + 1).binpow(N) * N * K * modulo(2).inv();
	cout << (base - ans).get() << endl;
	return 0;
}

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

int main(){
    int N; cin >> N;
    string S;
    cin >> S;
    long long R=0, G=0, B=0;
    for(auto x : S){
        if(x == 'R') R++;
        else if(x == 'G') G++;
        else B++;
    }
    long long ans=R*B*G;
    for(int i=0; i<N-2; i++){
        for(int j=i; 2*j-i<N; j++){
            if(S[i]!=S[j] && S[j]!=S[2*j-i] && S[2*j-i]!=S[i]){
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i=0; i<N; i++) {
    cin >> h[i];
  }
  
  vector<int> v(N, 0);
  for (int i=N-2; i >= 0; i--) {
    int best = 1000000000;
    for (int j=i+1; j < N && j <= i+2; j++) {
      int tmp = h[i] - h[j];
      if (tmp < 0) tmp = -tmp;
      tmp += v[j];
      if (tmp < best) best = tmp;
      //cout << i << "," << j << ":" << best << "\n";
    }
    //cout << i << "=" << best << "\n";
    v[i] = best;
  }
  /*
  for (int i=0; i<N; i++) {
    cout << v[i] << " ";
  }
  */
  cout << v[0] << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ull unsigned long long int 
#define ldb long double 
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
int main()
{
  fastio;   //to reduce time
  cin.tie(0), cout.tie(0);
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	
	int r;
	int P[N];
	int diff = 0;
	for(r=0; r<N; r++){
		scanf("%d", &P[r]);
		if (P[r] != r+1) diff++;
	}
	
	if(diff<=2) printf("YES");
	else printf("NO");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
vector<int> adj[100001];
bool visited[100001];

int dfs(int node) {
  if (visited[node]) return 0;
  visited[node] = true;
  for (auto u: adj[node]) dfs(u);
  return 1;
}

int main() {
  int N, M; cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int cnt = 0;
  for (int i = 1; i <= N; ++i) cnt += dfs(i);
  cout << cnt-1;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define pool(i, a, b) for(int i = a; i > b; i--)
#define pb push_back

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

const int nax = 405;
ll dp[nax][nax];

int main()
{
	int n;
	fastIO;
	scanf("%d", &n);
	vector<int> a(n);
	for(int& x: a)
		scanf("%d", &x);
	// loop(i, 0, n)
	// 	cout << a[i] << " ";
	// 	cout << "\n";
	auto sum = [&](int L, int R)
	{
		ll s = 0;
		loop(i, L, R)
			s += a[i];
		return s;
	};

	// dp[i][j] represents cost of adding i -> j to a new element
	for(int L = n - 1; L >= 0; L--)
	{
		for(int R = L; R < n; R++)
		{
			if(L == R)
				dp[L][R] = 0;
			ll s = sum(L, R);

			for(int i  = L; i <= R - 1; i++)
			{
				if(!dp[L][R])
				{
					dp[L][R] = dp[L][i] + dp[i + 1][R] + sum(L, R);
				}
				dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
			}
		}
	}


	// loop(i, 0, n){
	// 	loop(j, 0, n)
	// 		cout << dp[i][j] << " ";
	// 	cout << "\n";
	// }
	cout << dp[0][n - 1];

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>
#include <time.h>
using namespace std;


int main(){
	int N,M;
	cin>>N>>M;
	int cnt[M]={};
	for(int i=0;i<N;i++){
		int K;
		cin>>K;
		for(int j=0;j<K;j++){
			int a;
			cin>>a;
			cnt[a-1]++;
		}
	}
	int ans = 0;
	for(int i=0;i<M;i++){
		if(cnt[i]==N)ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
if n%2==0:
  for i in range(n//2):
    ans=ans+a[i]*2
  print(ans-a[0])
else:
  for i in range(n//2):
    ans=ans+a[i]*2
  print(ans-a[0]+a[n//2])
  

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

int N;
string s;

char answer(char left, char center, char right) {
    if ((center == 'S' && left == right) ||
        (center == 'W' && left != right)) {
        return 'o';
    } else {
        return 'x';
    }
}

bool isOK(string ans) {
    //0番目について
    if (answer(ans[N - 1], ans[0], ans[1]) != s[0]) {
        return false;
    }

    for (int i = 1; i < N - 1; i++) {
        if (answer(ans[i - 1], ans[i], ans[i + 1]) != s[i]) {
            return false;
        }
    }

    //N - 1番目について
    if (answer(ans[N - 2], ans[N - 1], ans[0]) != s[N - 1]) {
        return false;
    }

    return true;
}

int main() {
    cin >> N >> s;

    for (string ans : {"SS", "SW", "WS", "WW"}) {
        for (int i = 1; i < N - 1; i++) {
            if (s[i] == 'o') {
                if (ans[i - 1] == 'S' && ans[i] == 'S') {
                    ans += "S";
                } else if (ans[i - 1] == 'S' && ans[i] == 'W') {
                    ans += "W";
                } else if (ans[i - 1] == 'W' && ans[i] == 'S') {
                    ans += "W";
                } else if (ans[i - 1] == 'W' && ans[i] == 'W') {
                    ans += "S";
                } else {
                    assert(false);
                }
            } else {
                if (ans[i - 1] == 'S' && ans[i] == 'S') {
                    ans += "W";
                } else if (ans[i - 1] == 'S' && ans[i] == 'W') {
                    ans += "S";
                } else if (ans[i - 1] == 'W' && ans[i] == 'S') {
                    ans += "S";
                } else if (ans[i - 1] == 'W' && ans[i] == 'W') {
                    ans += "W";
                } else {
                    assert(false);
                }
            }
        }

        if (isOK(ans)) {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;

int main(){
	for (long long i=1;i<=9;i++){
		for (long long j=1;j<=9;j++){
		cout << i << "x" << j << "=" << i*j << endl;
		if (j==9){
		break;}
		}
	}
    return 0;
}

Measured memory_bytes: 2992
/**
*	created: 21.08.2020 15:37:56
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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 double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = LLONG_MAX;
const int MOD = 1000000007;
// const int MOD = 998244353;

template <typename T> T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {if (n & 1) ret *= a; a *= a; n >>= 1;}
    return ret;
}

template <int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {if ((x = x_ % mod + mod) >= mod) x -= mod;}
    ModInt& operator+=(ModInt rhs) {if ((x += rhs.x) >= mod) x -= mod; return *this;}
    ModInt& operator-=(ModInt rhs) {if ((x -= rhs.x) < 0) x += mod; return *this;}
    ModInt& operator*=(ModInt rhs) {x = (unsigned long long)x * rhs.x % mod; return *this;}
    ModInt& operator/=(ModInt rhs) {x = (unsigned long long)x * rhs.inv().x % mod; return *this;}
    ModInt operator-() const {return -x < 0 ? mod - x : -x;}
    ModInt operator+(ModInt rhs) const {return ModInt(*this) += rhs;}
    ModInt operator-(ModInt rhs) const {return ModInt(*this) -= rhs;}
    ModInt operator*(ModInt rhs) const {return ModInt(*this) *= rhs;}
    ModInt operator/(ModInt rhs) const {return ModInt(*this) /= rhs;}
    bool operator==(ModInt rhs) const {return x == rhs.x;}
    bool operator!=(ModInt rhs) const {return x != rhs.x;}
    ModInt inv() const {return pow(*this, mod - 2);}
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {s << a.x; return s;}
    friend istream& operator>>(istream& s, ModInt<mod>& a) {s >> a.x; return s;}
};

using mint = ModInt<MOD>;

mint fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep2(i,2,MAX){
        fac[i] = fac[i-1] * (mint)i;
        inv[i] = (mint)MOD - inv[MOD%i] * (mint)(MOD/i);
        finv[i] = finv[i-1] * inv[i];
    }
}

mint COM(int n,int k) {
    if (n < k or n < 0 or k < 0) return 0;
    return fac[n] * finv[k] * finv[n-k];
}

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b; cin >> a >> b;
    if ((a + b) % 3 != 0) {cout << 0 << endl; return 0;}
    int n = (a + b) / 3;
    COMinit();
    mint ans = COM(n,a-n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27052
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		
		if(N % 500 <= A) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 22608
from operator import itemgetter

n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
deltas = []

for i, x in enumerate(h, 1):
    avg = t - x * 0.006
    delta = abs(a - avg)
    deltas.append((i,delta))
answer = min(deltas, key=itemgetter(1))[0]
print(answer)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<ll, 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 LLINF = 1LL << 60;
using namespace std;

const ll mod = 1e9 + 7;
ll dp[101][5][5][5];

string agct[] = { "A", "G", "C", "T" };

bool ng(int p3, int p2, int p1) {
    string tmp = "";
    tmp += agct[p3] + agct[p2] + agct[p1];
    return tmp == "AGC";
}

int N;

ll solve(int n, int p3, int p2, int p1) {
    ll& ret = dp[n][p3][p2][p1];

    if (n >= N) return 1;
    if (ret >= 0) return ret;

    ret = 0;
    rep(p, 4) {
        if (ng(p2, p1, p) or ng(p2, p, p1) or ng(p1, p2, p)) continue;
        if (ng(p3, p1, p) or ng(p3, p2, p)) continue;
        ret += solve(n+1, p2, p1, p) % mod;
    }
    return ret;
}

int main() {
    cin >> N;
    rep(i, N+1) rep(j, 4) rep(k, 4) rep(l, 4) dp[i][j][k][l] = -1;
    cout << solve(0, 3, 3, 3)%mod << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int H, W, D;
pair<int, int> pr[90005];
ll d[900005];

int main(void) {
    scanf("%d %d %d", &H, &W, &D);
    for (int i=1; i<=H; i++) for (int j=1; j<=W;j++) {
      int a;
      scanf("%d", &a);
      pr[a] = mp(i, j);
    }
    
    for(int i=1; i<=H*W; i++) {
      if (i<D) d[i] = 0;
      else {
        d[i] += abs(pr[i].first - pr[i-D].first) + abs(pr[i].second - pr[i-D].second) + d[i-D];
      }
    }
    
    int Q, ans = 0;
    scanf("%d", &Q);
    rep(i, 0, Q){
      int l, r;
      scanf("%d %d", &l, &r);
      printf("%lld\n", d[r] - d[l]);
    }

	return 0;
}


Measured memory_bytes: 2560
def main():
    N=int(input())
    B=list(map(int, input().split()))
    A=[-10**9]*N
    A[0]=B[0]
    A[1]=B[0]
    for i in range(1,N-1):
        if A[i] > B[i]:
            A[i] = B[i]
        A[i+1] = B[i]
    print(sum(A))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import math
n,a,b = map(int,input().split())
mod = 10**9+7
k = 2
def Base_10_to_n(X,k):
  if (int(X/k)):
    return Base_10_to_n(int(X/k),k)+str(X%k)
  return str(X%k)
STR = Base_10_to_n(n,k)
ans = 1
cur = 2
for i in range(len(STR)):
    if STR[len(STR)-1-i] == '1':
        ans *= cur
        ans = ans%mod
    cur *= cur
    cur %= mod
    
ans -= 1
ans = ans%mod
L = [a,b]
cur = n
cur2 = n
for i in range(1,a):
    cur *= (n-i)*(pow(i+1, mod-2, mod))
    cur %= mod
for i in range(1,b):
    cur2 *= (n-i)*(pow(i+1, mod-2, mod))
    cur2 %= mod
cur %= mod
cur2 %= mod
ans -= cur
ans -= cur2
if ans < 0:
    while ans < 0:
        ans += mod
print(ans)

Measured memory_bytes: 3064
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;;
    for(int ok=1;ok<=t;ok++)
    {
        ll n;
        cin>>n;
      string s;
      cin>>s;
      ll x=0,y=0,z=0;
      for(int i=0;i<n;i++)
      {
        if(s[i]=='R')
            x++;
        if(s[i]=='G')
            y++;
        if(s[i]=='B')
            z++;
      }
      ll ans=x*y*z;
      for(int i=1;i<=(n-1)/2;i++)
      {
        for(int j=1;j<=n;j++)
        {
            if(j+2*i>n)
                break;
            if(s[j-1]!=s[j-1+i]&&s[j-1]!=s[j-1+2*i]&&s[j-1+i]!=s[j-1+2*i])
                ans--;
        }
      }
      cout<<ans;

     
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,x,i,c=0,n,h,w;
    cin>>n>>h;
    w=n+h;
    if(w%3==0||n%3==0||h%3==0) cout<<"Possible"<<endl;
    else  cout<<"Impossible"<<endl;


  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;

int main() {
    int n; cin >> n;
    int64_t k; cin >> k;
    vector<int> a(n);
    for (auto &e : a) cin >> e;

    int ct, cs, cn;
    {
        vector<int> visited(n, -1);
        visited[0] = 0;

        int w = 0;
        while (visited[a[w] - 1] == -1) {
            visited[a[w] - 1] = visited[w] + 1;
            w = a[w] - 1;
        }

        ct = visited[a[w] - 1];
        cs = a[w] - 1;
        cn = visited[w] + 1 - visited[a[w] - 1];
    }

    if (k < ct) {
        int cur = 0;
        while (k--) {
            cur = a[cur] - 1;
        }
        cout << cur + 1 << endl;
        return 0;
    }

    k -= ct;

    int cnt = k % cn;
    int cur = cs;
    while (cnt--) {
        cur = a[cur] - 1;
    }

    cout << cur + 1 << endl;
}



Measured memory_bytes: 4852
#include <iostream>

int main()
{
  int n, r;
  std::cin >> n;
  r = n % 10;
  switch(r)
  {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      std::cout << "hon";
      return 0;
    case 0:
    case 1:
    case 6:
    case 8:
      std::cout << "pon";
      return 0;
    case 3:
      std::cout << "bon";
      return 0;
  }
}

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

int main() {
    int N,W;
    cin >> N >> W;
    vector<int> v(N),w(N);
    vector<vector<int> > dp(N+1, vector<int>(W+1,0));

    rep(i,N)
        cin >> v.at(i) >> w.at(i);
    
    rep(i,N)
        rep(j,W+1)
            if(w.at(i) > j)
                dp.at(i+1).at(j) = dp.at(i).at(j);
            else
                dp.at(i+1).at(j) = max(dp.at(i).at(j), dp.at(i).at(j-w.at(i))+v.at(i));

    cout << dp.at(N).at(W) << endl;
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
 
 
int main() {
double x,y,z;
cin >> x >> y;
double ans = x/y;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n, h, Ma = 0;
    cin >> n >> h;
    int B[n];
    repi(i, n, 0)
    {
        int a, b;
        cin >> a >> b;
        Ma = max(Ma, a);
        B[i] = b;
    }
    sort(B, B + n, greater<int>());
    ll ans = 0, sum = 0;
    repi(i, n, 0)
    {
        if (B[i] < Ma || h <= 0)
        {
            break;
        }
        ans++;
        h -= B[i];
    }
    if (h <= 0)
    {
        cout << ans << endl;
    }
    else
    {
        ans += (h + Ma - 1) / Ma;
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
  string input;
  cin >> input;
  int output = 0;
  for (int i=0; i<input.size(); i++){
    if (input.at(i)=='1'){
      output++;
    } else {
      ;
    }
  }
  cout << output << endl;
}

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

vector<int64_t> divs(int64_t N){
    vector<int64_t> res;
    for(int64_t i=1; i*i <= N; i++) if(N%i == 0){
        res.push_back(i);
        if(i < N/i) res.push_back(N/i);
    }
    return res;
}

int main(){
    int64_t N;
    cin >> N;

    int64_t ans = divs(N-1).size()-1;
    auto D = divs(N);
    for(int64_t k : D) if(k != 1){
        int64_t n = N;
        while(n%k == 0) n /= k;
        if(n%k == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	char C = getcha();
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return A;
}

int P[100001];
int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

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


	int N = getint(), M = getint();
	int p[100001];
	rep1(i, N) p[i] = getint();

	rep1(i, N) P[i] = -1;
	rep(i, M) {
		int a = Find(getint());
		int b = Find(getint());
		if (a == b) continue;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
	}

	int kotae = 0;
	rep1(i, N) kotae += Find(i) == Find(p[i]);

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
bool ok (int d, const vector<int>& a, int k) {
  vector<int> rem;
  int inc = 0;
  for (int i : a) {
    rem.push_back(i % d);
    inc += d - i % d;
  }
  sort(rem.begin(), rem.end());
  int dec = 0;
  for (int i : rem) {
    dec += i;
    inc -= d - i;
    if (dec == inc && inc <= k) return true;
  } 
  return false;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int ans = 0;
  for (int i = 1; i * i <= sum; i++) {
    if (sum % i) continue;
    if (ok(i, a, k)) ans = max(ans, i);
    if (ok(sum / i, a, k)) ans = max(ans, sum / i);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N){
    cin >> A.at(i);
  }
  
  vector<int> B = A;
  sort(B.begin(), B.end());
  
  
  rep(i, N){
    if(B.at(N-1) != A.at(i)) cout << B.at(N-1) << endl;
    else cout << B.at(N-2) << endl;
  }
  
  
  
  return 0;
}




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

int main()
{
	char c;
	int nI[27] = { 0 };
	while (cin >> c)
	{
		int n = tolower(c);
		nI[n - '`'] += 1;
	}
	for (int i = 1; i < 27; i++)
	{
		printf("%c : %d\n", '`' + i, nI[i]);
	}
	return 0;
}

Measured memory_bytes: 3228
#標準出力からの読み込み
n = int(input())

#判定ロジック
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

output = 0
divisor = num_divisors_table(n-1)

output = sum(divisor)

print(output)


Measured memory_bytes: 16632
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}


int main() {
    LL N, K;
    cin >> N >> K;

    cout << (K == 1 ? 0 : N - K) << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
map<ll, vector<pair<ll, ll>>> mp;
int n;
ll x, d;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    cin>>x>>d;
    if(d==0) {
        cout<<(x==0 ? 1 : (n+1))<<"\n";
        return 0;
    }
    owo(i, 0, n+1) {
        ll rem = (1LL*x*i)%d;
        ll add = (1LL*x*i)/d;
        ll left = (1LL*i*(i-1))/2;
        ll right = 1LL*n*i-((1LL*i*(i+1))/2);
        mp[rem].senpai({left+add, right+add});
    }
    ll ans = 0;
    for(auto p: mp) {
        vector<pair<ll, ll>> ok = p.second;
        sort(ok.begin(), ok.end());
        ll last = -INFLL;
        for(auto nn: ok) {
            if(nn.first>last) {
                ans+=nn.second-nn.first+1;
            }else {
                ans+=max(nn.second-last, 0LL);
            }
            last = max(last, nn.second);
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 25448
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int a,b;
    cin >> a >> b;
    string s = "", t = "";
    rep(i,a)s += '0'+b;
    rep(i,b)t += '0'+a;
    if(s < t)cout << s << endl;
    else cout << t << endl;
}


Measured memory_bytes: 888
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100010;
int ans=0,tot=0,sum=0,n,l,r;
char s[maxn],a[maxn];
void read(int &k){
	k=0; int f=1; char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while ('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
	k*=f;
}
int main(){
	scanf("%s",s);
	int n=strlen(s);
	l=0; r=n-1;
	while (l<=r){
		if (s[l]==s[r]) l++,r--;
		else {
			if (s[l]=='x'&&s[r]!='x') ans++,l++;
			else if (s[l]!='x'&&s[r]=='x') ans++,r--;
			else if (s[l]!='x'&&s[r]!='x'){
				printf("-1");
				return 0;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256