akhauriyash/Code-Regression huggingface dataset:
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	int n, k, d, x;
	cin >> n >> k;
	vector<bool> arr(n + 1, false);
	while (k--) {
		cin >> d;
		while (d--) {
			cin >> x;
			arr[x] = true;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (arr[i] == false)
			ans++;
	}
	cout << ans << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int H,W,P;
struct st{
	unsigned long A,B;
};
st s[1000][1000];
string t[100];
int to_i[256];
string to_s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void sft(st&s,int x)
{
	s.A<<=1;
	s.A|=s.B>>63;
	s.B<<=1;
	s.B|=x;
	if(P<64)s.B&=(1uLL<<P)-1;
	else s.A&=(1uLL<<P-64)-1;
}
bool operator==(const st&a,const st&b){return a.A==b.A&&a.B==b.B;}
//Longest Common Prefix(s,s.substr(i)) O(|s|)
#include<vector>
vector<int>Zalgo(const vector<st>&s)
{
	vector<int>ret(s.size());
	ret[0]=s.size();
	int i=1,j=0;
	while(i<s.size())
	{
		while(i+j<s.size()&&s[j]==s[i+j])j++;
		ret[i]=j;
		if(j==0)
		{
			i++;
			continue;
		}
		int k=1;
		while(i+k<s.size()&&k+ret[k]<j)ret[i+k]=ret[k],k++;
		i+=k;j-=k;
	}
	return ret;
}
bool ok[1000][1000];
main()
{
	for(int i=0;i<64;i++)to_i[to_s[i]]=i;
	while(cin>>W>>H>>P,H)
	{
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)ok[i][j]=false;
		for(int i=0;i<H;i++)
		{
			st now={0uLL,0uLL};
			string a;cin>>a;
			for(int j=0;j<a.size();j++)
			{
				int w=to_i[a[j]];
				for(int k=0;k<6&&j*6+k<W;k++)
				{
					sft(now,w>>5-k&1);
					s[i][j*6+k]=now;
				}
			}
		}
		for(int i=0;i<P;i++)
		{
			t[i]="";
			string a;cin>>a;
			for(int j=0;j<a.size();j++)
			{
				int w=to_i[a[j]];
				for(int k=0;k<6&&j*6+k<P;k++)
				{
					t[i]+=(w>>5-k&1)+'0';
				}
			}
		}
		for(int rc=0;rc<4;rc++)
		{
			for(int tc=0;tc<2;tc++)
			{
				vector<st>X;
				for(int i=0;i<P;i++)
				{
					st now={0uLL,0uLL};
					for(int j=0;j<P;j++)sft(now,t[i][j]-'0');
					X.push_back(now);
				}
				for(int i=0;i+P<=W;i++)
				{
					vector<st>Y=X;
					for(int j=0;j<H;j++)
					{
						Y.push_back(s[j][i+P-1]);
					}
					vector<int>za=Zalgo(Y);
					for(int j=0;j+P<=H;j++)
					{
						if(za[j+P]>=P)ok[j][i]=true;
					}
				}
				for(int i=0;i<P;i++)reverse(t[i].begin(),t[i].end());
			}
			vector<string>tmp(P);
			for(int i=0;i<P;i++)tmp[i]=t[i];
			for(int i=0;i<P;i++)for(int j=0;j<P;j++)t[i][j]=tmp[j][P-i-1];
		}
		int cnt=0;
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)cnt+=ok[i][j];
		cout<<cnt<<endl;
	}
}



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

using namespace std;

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

int main() {
  string s, p;
  cin >> s >> p;
  string n;
  n = s.substr(0,p.size());
  string object;
  object = s + n;

  if(object.find(p) == -1) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3596
n,T = map(int,input().split())
possibeans = []
for i in range(n):
    c,t = map(int,input().split())
    if t <= T:
        possibeans.append(c)
if(len(possibeans) == 0):print("TLE")
else:
    ans = min(possibeans)
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	int ms = f / 100 * e;
	vector <bool> dp0(f + 1,0);
	vector <int> v;
	dp0[0] = 1;
	for(int i = 1;i <= f;++i){
		if(i - 100 * a >= 0 and dp0[i - 100 * a]) dp0[i] = 1, v.push_back(i);
		else if(i - 100 * b >= 0 and dp0[i - 100 * b]) dp0[i] = 1, v.push_back(i);
	}
	vector <bool> dp1(ms + 1,0);
	dp1[0] = 1;
	vector <int> v1;
	for(int i = 1;i <= ms;++i){
		if(i - c >= 0 and dp1[i - c]) dp1[i] = 1, v1.push_back(i);
		else if(i - d >= 0 and dp1[i - d]) dp1[i] = 1, v1.push_back(i);
	}
	double maxx = -1;
	pair <int,int> out = {100 * a,0};
	for(int i : v){
		for(int j : v1){
			if(j + i <= f and j <= i / 100 * e and (double)j / (j + i) > maxx){
				maxx = (double)j / (j + i);
				out = {j + i,j};
			}
		}
	}
	cout << out.first << " " << out.second << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

using namespace std;

#define ll long long
#define mod 1000000007
#define debug(n) cerr << #n << ':' << n << endl;


ll ext(ll a,ll b,ll &x, ll&y){
  if(!b){
    x=1;y=0;
    return a;
  }
  ll d = ext(b,a%b,y,x);
  y -= a/b *x;
  return d;
}


ll modi(ll a, ll m){
  ll x,y;
  ext(a,m,x,y);
  return (m+x%m)%m;
}

int main(){
  ll n, k;cin >> n >> k;

  ll l = n - k;
  vector<ll>red(l + 1, l + 1);
  for(ll i = 1; i < l + 1; ++i)
    red[i] = (((red[i - 1] * (l+1-i))%mod) * modi(i+1,mod))%mod;
  vector<ll>blue(k,1);
  for(ll i = 1; i < k; ++i)
    blue[i] = (((blue[i - 1] * (k-i))%mod) * modi(i,mod))%mod;
  for(ll i = 0; i < k; ++i){
    //   debug(red[i]);
    //    debug(blue[i]);
    if(i < l + 1)
      cout << (red[i] * blue[i])%mod << endl;
    else
      cout << 0 << endl;
  }
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if (p[i-1]<=p[i] and p[i]<=p[i+1]) or (p[i+1]<=p[i] and p[i]<=p[i-1]):
    ans+=1
print(ans)

Measured memory_bytes: 3060
"""
import sys
input = sys.stdin.readline

def main():
    



    
if __name__ == "__main__":
    main()

"""

import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, n, func, e, arrange=None):
        self.init(n)
        self.func = func
        self.e = e
        self.make_arrange(arrange)
    
    def init(self, n):
        self.inf = pow(2, 32)
        self.n = n
        self.N = 1
        while self.N < self.n:
            self.N *= 2
        self.size = self.N * 2
    
    def make_arrange(self, arrange):
        self.set_arrange(arrange)
        self.construct(arrange)

    def set_arrange(self, arrange):
        if arrange == None:
            self.segment = [self.e]*(self.size)
            return
        self.segment = [0]*(self.N) + arrange + [self.e]*(self.size-self.N-self.n)
    
    def construct(self, arrange):
        if arrange == None:
            return
        for i in range(self.N-1, 0, -1):
            self.segment[i] = self.func(self.segment[2*i], self.segment[2*i+1])
    
    def update(self, i, x):
        i += (self.N - 1)
        self.segment[i] = x
        while i > 1:
            i = i//2
            self.segment[i] = self.func(self.segment[2*i], self.segment[2*i+1])
    

    def count(self, l, r):
        res = self.e
        l += self.N-1
        r += self.N
        while r > l:
            if l & 1:
                res = self.func(res, self.segment[l])
                l += 1
            if r & 1:
                r -= 1
                res = self.func(res, self.segment[r])
            l >>= 1
            r >>= 1
        return res
    
    """
    二分探索
    これは区間[l, r]にてx以上となる最小のインデックスを返すメソッド
    まずfind_l：二分木左側を探索し、そこに条件を満たすものがなかったらfind_：右側を探索
    インデックスの最大最小により左右を使い分ける
    """

    def bisect_sub(self, a, b, k, l, r, x):
        if r <= a or b <= l:
            return b+1
        if self.segment[k] < x:
            return b+1
        if k >= self.N:
            return r
        
        find_l = self.bisect_sub(a, b, 2*k, l, (l+r)//2, x)
        if find_l <= b:
            return find_l

        find_r = self.bisect_sub(a, b, 2*k+1, (l+r)//2, r, x)
        return find_r

    def bisect(self, l, r, x):
        return self.bisect_sub(l-1, r, 1, 0, self.size-self.N, x)

mod = 998244353

def main():
    n, k = map(int, input().split())
    a = [None]*n
    sub = 1
    e = 0
    func = max
    ma = 300001
    seg = SegmentTree(ma, func, e)
    ans = 0
    for i in range(n):
        a = int(input())
        sub = seg.count(max(0, a-k), min(a+k, ma)) + 1
        ans = max(ans, sub)
        seg.update(a, sub)
    
    print(ans)

main()


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

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<int> t(s.size()+5),u(s.size()+5),v(s.size()+5);

    for(int i = 0;i < s.size()-1;i ++){
        if(s.at(i) == 'R' && s.at(i+1) == 'L'){
            t.at(i) = 1;
        }
    }

    for(int i = 0;i < s.size();i ++){
        v.at(i) = 1;
    }

    for(int i = 0;i < s.size()-2;i ++){
        if(s.at(i) == 'R' && s.at(i+1) == 'R'){
            v.at(i+2) += v.at(i);
            v.at(i) = 0;
        }
    }

    for(int i = s.size()-1;i >= 2;i --){
        if(s.at(i) =='L' && s.at(i-1) == 'L'){
            v.at(i-2) += v.at(i);
            v.at(i) = 0; 
        }
    }

    for(int i = 0;i < s.size();i ++){

        if(v.at(i) == 0){
            continue;
        }

        for(int j = i;;){

            if(t.at(j) == 0){

                if(s.at(i) == 'R'){
                    j ++;
                }else{
                    j --;
                }

                continue;
            }


            if((i % 2 == j % 2)){
                u.at(j) += v.at(i);
                break;
            }else if((i % 2 != j % 2)){
                u.at(j+1) += v.at(i);
                break;
            }

        }
    }

    for(int i = 0;i < s.size()-1;i ++){
        cout << u.at(i) << " " ;
    }
    cout << u.at(s.size()-1) << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int d,t,s;
  cin >> d >> t >> s;
  if (d <= s*t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    vector<int> input(9), v(9);
    for(int i=0; i<9; ++i){
        cin >> input[i];
        v[i] = i + 1;
    }

    int cnt = 0;
    do{
        bool ng = false;
        for(int i=0; i<9; ++i){
            if(input[i] != -1 && input[i] != v[i])
                ng = true;
        }
        if(ng)
            continue;

        int x = v[3] * 100 + (v[1] + v[4]) * 10 + (v[0] + v[2] + v[5]);
        int y = v[6] * 100 + v[7] * 10 + v[8];
        if(x == y)
            ++ cnt;
    }while(next_permutation(v.begin(), v.end()));

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	HashMap<Integer, Integer> dict = new HashMap<>();
		int N = sc.nextInt();      	 
      	int Current;
      	for(int i=0 ;i<N;i++)
        {
          	Current=sc.nextInt();
          	if(dict.containsKey(Current))
            {
          		System.out.println("NO");
              	System.exit(0);
            }
          	else 
            {
              	dict.put(Current, 1);              	
            }
        }
      	System.out.println("YES");
	}
}

Measured memory_bytes: 100396
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    k = II()
    sevens = 7%k
    for i in range(1, k+1):
        if sevens % k == 0:
            print(i)
            return
        sevens = (10*sevens + 7)%k
    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9104
using System;

namespace SandboxForAtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var input = Console.In;

            var r = input.ReadLine();

            int radius = int.Parse(r);

            var pi = Math.PI;

            var length = 2 * radius * pi;

            Console.WriteLine(length);
        }
    }
}


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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int w[n];
	int right = 0,left = 0;
	for(int i=0;i<n;i++){
		cin >> w[i];
		right += w[i];
	}
	int ans = right;
	// keisan
	for(int i=0;i<n-1;i++){
		left += w[i];
		right -= w[i];
		ans = min(ans,abs(right - left));
	}
	// syutsuryoku
	cout << ans << endl;
}

Measured memory_bytes: 3636
//
// Created on 4/26/19.
//
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, c, d, e, k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    if (e - a <= k) {
        cout << "Yay!" << endl;
    }
    else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_a, number_b, answer;
    number_a = Integer.parseInt(sc.next());
    number_b = Integer.parseInt(sc.next());
    answer = Math.max(Math.max(number_a + number_b, number_a - number_b), number_a * number_b);
    System.out.println(answer);
  }
}


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

int main(){
  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
#include<bits/stdc++.h>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int h[N];
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }
    sort(h, h + N);

    int ans = 1e9 + 1;
    for (int i = 0; i + K - 1 < N; i++)
    {
        ans = min(ans, h[i + K - 1] - h[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
using namespace std;
# define F(i, s, t) for (int i = (s), _ = (t); i <= _; i ++)
# define LL long long
int u[3005], pr[3005], tot, n, ans;
map<LL, LL> cnt, rev;
namespace IO {
	const int S = 10000000;
	char s[S], *h = s+S, *t = h;
	char nchar() {
		if (h == t) fread(s, 1, S, stdin), h = s;
		return *h ++;
	}
	LL rd() {
		LL x = 0; char c;
		do { c = nchar(); } while (! isdigit(c));
		do { x = x*10+c-'0', c = nchar(); } while (isdigit(c));
		return x;
	}
}
using IO::rd;
LL Sim(LL x) {
	LL y = 1;
	F(i, 1, tot)
		if (x % pr[i] == 0) {
			int cnt = 0;
			while (x % pr[i] == 0)
				x /= pr[i], cnt ++;
			cnt %= 3;
			while (cnt --)
				y *= pr[i];
		}
	return y * x;
}
LL Rev(LL x) {
	LL y = 1;
	F(i, 1, tot)
		if (x % pr[i] == 0)
			x /= pr[i], y *= pr[i], x % pr[i] ? y *= pr[i] : x /= pr[i];
	LL w = sqrt(x);
	return w * w == x ? y * w : y * x * x;
}
int main() {
	u[1] = 1;
	F(i, 2, 3000)
		if (! u[i]) {
			pr[++ tot] = i;
			for (int j = i + i; j <= 3000; j += i)
				u[j] = 1;
		}
	n = rd();
	F(i, 1, n) {
		LL x = rd();
		x = Sim(x);
		if (! rev.count(x)) {
			LL y = Rev(x);
			rev[x] = y, rev[y] = x;
		}
		cnt[x] ++;
	}
	if (cnt.count(1))
		ans ++;
	for (auto it = rev.begin(); it != rev.end(); it ++)
		if (it -> first < it -> second)
			ans += max(cnt[it -> first], cnt[it -> second]);
	printf("%d\n", ans);
	return 0;
}

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

int main() {

    int N, L;
    cin >> N >> L;

    vector<string> S(N);
    rep(i,N) cin >> S[i];

    sort(S.begin(), S.end());

    rep(i, N) cout << S[i];

    cout << endl;


    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
#define pb push_back
using namespace std;

bool list[21][21];
int incnt[21];
int used[21];

int main(){
	int m,n,a,b;
	cin>>m>>n;
	rep(i,m+1){
		rep(j,m+1)list[i][j]=false;
		incnt[i]=used[i]=0;
	}
	rep(i,n){
		cin>>a>>b;
		list[b][a]=true;
		incnt[a]++;
	}
	vector<int> ans;
	int now=-1;
	while(1){
		now=-1;
		loop(i,1,m+1)if(incnt[i]==0 && !used[i])now=i;
		if(now==-1)break;
		used[now]=true;
		ans.pb(now);
		loop(i,1,m+1)if(list[now][i]){
			list[now][i]=false;
			incnt[i]--;
		}
	}
	for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

int N, K;
int g, Ans;

int main() {
	register int i; int x;
	scanf("%d%d", &N, &K);
	for(i = 1; i <= N; ++i)
		scanf("%d", &x), g = __gcd(g, x), Ans = max(Ans, x);
	puts(K % g || K > Ans ? "IMPOSSIBLE" : "POSSIBLE");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m, q, l, r;
    cin >> n >> m >> q;
    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
    for(int i =0 ; i < m; i++) {
        cin >> l >> r;
        dp[l][r] += 1;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dp[i][j] += dp[i][j-1];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dp[i][j] += dp[i-1][j];
        }
    }
    while(q--) {
        cin >> l >> r;
        cout << dp[r][r] - dp[r][l-1] - dp[l-1][r] + dp[l-1][l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int n,m;
vector<ll> x,y;

ll doit(vector<ll>& x){
	int n=x.size();
	ll s=0,r=0;
	fore(i,0,n){
		r+=(i*x[i]%MOD+MOD-s)%MOD;r%=MOD;
		s+=x[i];s%=MOD;
	}
	return r;
}

int main(){
	scanf("%d%d",&n,&m);
	fore(i,0,n){
		int k;
		scanf("%d",&k);
		if(k<0)k+=MOD;
		x.pb(k);
	}
	fore(i,0,m){
		int k;
		scanf("%d",&k);
		if(k<0)k+=MOD;
		y.pb(k);
	}
	printf("%lld\n",(doit(x)*doit(y))%MOD);
	return 0;
}





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

using namespace std;

typedef long long ll;

int main()
{
    ll n, a;
    cin>>n;
    ll amin;
    for(int i = 0; i < 5; ++i)
    {
        if(i == 0)
        {
            cin>>a;
            amin = a;
        }
        else
        {
            cin>>a;
            amin = min(a, amin);
        }
    }
    if(n % amin == 0)
        cout<<(5+n/amin-1)<<endl;
    else
        cout<<(5+n/amin)<<endl;
    return 0;
}


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

counter = 0

for i in range(n-2):
  min_list = []
  min_list.append(Data[i])
  min_list.append(Data[i+1])
  min_list.append(Data[i+2])
  if min_list[1] != min(min_list) and min_list[1] != max(min_list):
    counter += 1

print(counter)

Measured memory_bytes: 3060
# coding: utf-8
#a, b, c, d = map(int,input().split())
S=int(input())

def modcomb(n,r,mod):
    X, Y =  1, 1
    r = min(r, n-r)
    for i in range(1,r+1):
        X = X * (n-i+1) % mod
        Y = Y * i % mod
    
    return X * pow(Y,mod-2,mod) % mod

ans = 0
MOD=  10 ** 9 + 7
for i in range(1, S//3+1):#数列の長さ
    k = S-3 * i
    ans += modcomb(k+i-1, i-1, MOD)
print(ans%MOD)

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

int N, A, B;

int main() {
    scanf("%d %d %d", &N, &A, &B);

    cout << max(0LL, 1LL * (N - 1) * B + A - 1LL * (N - 1) * A - B + 1);
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003



int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);
	
	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);
	
	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);
	
	return ret;

}

int number(State &begin){
	int ret =0;
	
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}



int main(void){
	
	int n;
	cin>>n;
	
	ll o=0,e=0;
	ll a;
	
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==0)
			e++;
		else
			o++;
		if(o%2==0){
			e++;
			o-=2;
		}
	}
	
	if(o%2==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd(a, b)

n = int(input())
t = [int(input()) for i in range(n)]

ans = t[0]
for t_i in t[1:]:
	ans = lcm(ans, t_i)

print(ans)

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

#define rep(i,a,b) for(int i = a; i < b; i++)

int main() {
    int N,M;
    cin >> N >> M;

    vector<int> S[M];
    rep(i,0,M) {
        int k;
        cin >> k;
        rep(j,0,k) {
            int tmp;
            cin >> tmp;
            tmp--;
            S[i].push_back(tmp);
        }
    }

    int P[M];
    rep(i,0,M) cin >> P[i];

    int ans = 0;

    rep(mask,0,1<<N) {
        bool flag = true;
        rep(i,0,M) {
            int cnt = 0;
            for (int s: S[i]) {
                if ((mask >> s) & 1) {
                    cnt++;
                }
            }
            if (cnt % 2 != P[i]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = b + min(a + b + 1, c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;

ll dx[]= {0,0,1,-1};
ll dy[]= {-1,1,0,0};
ll n,m;
string s[30];
ll vis[30][30];
ll dis[30][30];
ll mx;
pii node;
ll ch(ll i,ll j)
{
    if(i<0||i>=n||j<0||j>=m)
        return 0;
    return 1;
}

void bfs(ll i,ll j)
{
    vis[i][j]=1;
    dis[i][j]=0;
    queue<pii>q;
    q.push({i,j});
    ll ans=0;
    while(!q.empty())
    {
        ll x=q.front().fi;
        ll y=q.front().se;
        q.pop();
        // vis[x][y]=1;
        for(ll k=0; k<4; k++)
        {
            ll x1=x+dx[k];
            ll y1=y+dy[k];
            if(ch(x1,y1)&&s[x1][y1]=='.'&&!vis[x1][y1])
            {
                vis[x1][y1]=1;
                dis[x1][y1]=1+dis[x][y];
                ans=max(ans,dis[x1][y1]);
                q.push({x1,y1});
            }
        }


    }
    mx=ans;



}

int main()
{

    cin>>n>>m;
    for(ll i=0; i<n; i++)
    {
        cin>>s[i];
    }
    ll ans=0;
    for(ll i=0; i<n; i++)
    {
        for(ll j=0; j<m; j++)
        {
            if(s[i][j]=='.')
            {
                memset(vis,0,sizeof(vis));
                memset(dis,0,sizeof(dis));
                mx=0;
                bfs(i,j);
                //cout<<"pp";
                ans=max(ans,mx);
            }
        }
    }

    cout<<ans<<nn;






}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define nmax
#define pii pair<int,int>
#define pb push_back
using namespace std;

int main()
{
    vector<pair<string,int>>v;
    int n;
    cin>>n;
    for (int i=1;i<=n;++i){
        string nm;
        int d;
        cin>>nm>>d;
        v.pb(make_pair(nm,d));
    }
    string wh;
    cin>>wh;
    bool found = false;
    int ans = 0;
    for (int i=0;i<n;++i){
        if (found){
            ans += v[i].second;
        } else {
            if (v[i].first == wh){
                found = true;
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

#define REP( i, n) for( int i = 0; i < (n); ++i)
#define FOR( i, a, b) for( int i = (a); i < (b); ++i)

#define pb push_back

const int INF = 1001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

vector<int> a;
int n;
int abc;

void merge( int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int l[n1], r[n2];
  REP( i, n1){
    l[i] = a[left+i];
  }
  REP( i, n2){
    r[i] = a[mid+i];
  }
  l[n1] = INF;
  r[n2] = INF;
  int i = 0, j = 0;
  FOR( k, left, right){
    ++abc;
    if( l[i] <= r[j]){
      a[k] = l[i];
      ++i;
    }else{
      a[k] = r[j];
      ++j;
    }
  }
}

void mergeSort( int left, int right){
  if( left+1 < right){
    int mid = (left+right)/2;
    mergeSort( left, mid);
    mergeSort( mid, right);
    merge( left, mid, right);
  }
}


int main(){
  cin >> n;
  a.resize(n);
  abc = 0;
  REP( i, n){
    cin >> a[i];
  }

  mergeSort( 0, n);

  REP( i, n-1){
    cout << a[i] << " ";
  }
  cout << a[n-1] << endl;
  cout << abc << endl;

}

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

int main() {
  long long int  a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (b>0 && d>0){
    if(a*c > b*d){
      cout << a*c << endl;
    }
    else{
  cout << b*d <<endl;
    }
 }
 else if(b<=0 && d>0){
   if(c<0){
     cout << a*c << endl;
   }
   else{
	 cout << b*c << endl;
   }
 }
 else if (b>0 && d<=0){
   if(a<0){
     cout << a*c << endl;
   }
   else{
	 cout << a*d << endl;
   }
 }
 else if(b<= 0 && d <= 0){
 cout << a*c << endl;
 }
  
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100002;
struct node{
	int x,id;
}a[N];
int n,i,id[N],cnt,b[N],mx[N];
ll ans[N];
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
	int x=0,fl=1;char ch=gc();
	for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
	for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
	return x*fl;
}
inline void wri(ll a){if(a<0)a=-a,putchar('-');if(a>=10)wri(a/10);putchar(a%10|48);}
inline void wln(ll a){wri(a);puts("");}
bool cmp(node a,node b){return a.x<b.x || a.x==b.x && a.id<b.id;}
int main(){
	n=rd();
	for (i=1;i<=n;i++) a[i].x=rd(),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	id[++cnt]=a[1].id;b[1]=1;mx[1]=a[1].x;
	for (i=2;i<=n;i++)
		if (a[i].x==a[i-1].x) b[cnt]++;
		else id[++cnt]=a[i].id,b[cnt]=1,mx[cnt]=a[i].x;
	for (i=cnt;i;i--) ans[id[i]]+=1ll*b[i]*(mx[i]-mx[i-1]),b[i-1]+=b[i],id[i-1]=min(id[i-1],id[i]);
	for (i=1;i<=n;i++) wln(ans[i]);
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
long long a[200001];
long long b[200001];
int main()
{
    long long n,i;
    cin >> n;
    for(i=2;i<=n;i++)
    {
        cin >> a[i];
        b[a[i]]++;
    }
    for(i=1;i<=n;i++)
    {
        cout << b[i] << " ";
    }
}


Measured memory_bytes: 6720
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

typedef long long LL;
int INF=0x3f3f3f3f;

int main(){
    ios_base::sync_with_stdio(false);
    
    LL A,B,C,D,E,F;
    LL ans1=0,ans2=0;
    double tmp,LD=-1;
    cin>>A>>B>>C>>D>>E>>F;
    
    for(int a=0;a*A*100<=F;a++){
        for(int b=0;a*A*100+b*B*100<=F;b++){
            for(int c=0;a*A*100+b*B*100+c*C<=F;c++){
                for(int d=0;a*A*100+b*B*100+c*C+d*D<=F;d++){
                    if(c*C+d*D>(a*A+b*B)*E) break;
                    tmp=(1.0)*(c*C+d*D)/(a*A*100+b*B*100+c*C+d*D);
                    if(LD<tmp) {LD=tmp;ans1=(a*A*100+b*B*100+c*C+d*D);ans2=(c*C+d*D);}
                }
            }
        }
    }
    
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}

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

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

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = k * (ll)pow(k-1, n-1);
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanVecInt(P, N);
    vector<int> count;
    count.emplace_back(0);
    loop(i, N){
        if (P[i] == i + 1){
            ++count.back();
        }else{
            if (0 < count.back()){
                count.emplace_back(0);
            }
        }
    }
    int result = 0;
    for (auto& n : count){
        result += (n + 1) / 2;
    }
    printf("%d\n", result);
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main() {
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2]){
		cout<<"Yes"<<endl;
	}
	else if(s[1]==s[2]&&s[2]==s[3]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

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

using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  
  vector<int> v1(n);
  vector<int> v2;
  
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    v1[i] = a;
    int b[a];
    for (int j=0;j<a;j++){
      cin >> b[j];
      v2.push_back(b[j]);
    }
  }
  
  int cnt=0;
  for(int i=1;i<m+1;i++){
    size_t n_count = std::count(v2.begin(), v2.end(), i);
    if (n_count==n){
      cnt += 1;
    }
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,k,n,m,l,x,y,build[1001][2],assign[1001],assign2[1001],prev[1001][1001];
double route[11][1001][1001];

void backtrack(int from,int to){
	int z=prev[from][to];

	if(from==to)return;
	if(z==from){
		printf("%d ",assign[from]);
		return;
	}
	backtrack(from,z);
	backtrack(z,to);
	
}

int main(){
	while(scanf("%d",&n)*n){
		for(i=0;i<n;i++){
			scanf("%d %d %d",&assign[i],&build[i][0],&build[i][1]);
			assign2[assign[i]]=i;
		}
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				l=(build[i][0]-build[j][0])*(build[i][0]-build[j][0])+(build[i][1]-build[j][1])*(build[i][1]-build[j][1]);
				if(l<=2500){
					route[0][i][j]=sqrt((double)l);
					route[0][j][i]=sqrt((double)l);
					prev[i][j]=i;
					prev[j][i]=j;
				}
				else{
					route[0][i][j]=999999999;
					route[0][j][i]=999999999;
				}
			}
		}

		for(l=1;pow(2.0,l-1)<n-1;l++){
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					route[l][i][j]=route[l-1][i][j];
					for(k=0;k<n;k++){
						if(route[l][i][j]>route[l-1][i][k]+route[l-1][k][j]){
							route[l][i][j]=route[l-1][i][k]+route[l-1][k][j];
							prev[i][j]=k;
						}
					}
				}
			}
		}

		l--;

		for(scanf("%d",&m);m>0;m--){
			scanf("%d %d",&x,&y);
			x=assign2[x];
			y=assign2[y];
			if(x==y){
				printf("%d\n",assign[y]);
			}
			else if(route[l][x][y]<999999999){
				backtrack(x,y);
				printf("%d\n",assign[y]);
			}
			else printf("NA\n");
		}

	}
	return 0;
}

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

int main(){
  string N; cin >> N;
  long long ans;
  for(long long i=0;i<N.size();i++){
    ans += N.at(i) - '0';
  }
  if(ans%9 == 0)  cout << "Yes" << endl;
  else  cout << "No" << endl;
}

Measured memory_bytes: 3680
def maxelm(matrix):
	ans = 0
	for i in matrix:
		m = max(i)
		ans = max(ans, m)
	return ans
	
def resolve():
	import numpy as np
	from collections import deque

	h, w = map(int, input().split())
	s = [input() for i in range(h)] # [[input()] for ...] は誤答 （文字列も配列であることを考えると3重配列になっちゃう） 
	directions = [[0, 1], [0, -1], [1, 0], [-1, 0]] # [y軸, x軸]
	ans = 0

	for sh in range(h): # start hight
		for sw in range(w):
			if s[sh][sw] == "#":
				continue
			distance = [[-1 for j in range(w)] for i in range(h)]
			distance[sh][sw] = 0
			q = deque([[sh, sw]]) # 1段目の[]はdequeの引数がイテラブルであるため、2段目の[]はy軸x軸のペアを表現するため

			while q:
				y, x = q.popleft() # アンパックしてくれる
				for i, j in directions:
					ny, nx = y+i, x+j

					# エリア内判定
					if not ((0 <= ny < h) and (0 <= nx < w)):
						continue
					# 壁判定
					elif s[ny][nx] == "#":
						continue
					# 訪問済み判定
					elif distance[ny][nx] != -1:
						continue

					distance[ny][nx] = distance[y][x] + 1
					q.append([ny, nx]) # q.append([[ny, nx]]) は誤答
			ans = max(ans, maxelm(distance))
			#ans = max(ans, np.max(distance))
	print(ans)
resolve()

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

// Union-Find
struct UnionFind {
    vector<int> par;
    vector<int> scale1;
    vector<int> rank;
    int size1;
    // par[i]はiの親の番号
    // scale[i]はiが親の時にのみ意味を持ち, その木の要素の数
    // rank[i]はiが親の時にのみ意味を持ち, その木のrank(union操作に使う)
    // 実はrankを導入してもほとんど速度変わらない
    // sizeは木の数
    // scaleとsizeはオプションなので必要なら消してもいい

    //最初は全てが根であるとして初期化
    UnionFind(int N) : par(N), scale1(N,1), rank(N,0){
        for(int i = 0; i < N; i++) par[i] = i;
        size1 = N;
    }

    // データxが属する木の根を再帰で得る
    int root(int x){
        if (par[x] == x) return x;
        par[x] = root(par[x]); // 親を根にする付け替えによって次回以降の参照を高速化
        return par[x];
    }

    // xとyの木を併合(rankの大きい方の根を小さい方の根の親にする)
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(rank[rx] > rank[ry]){
            par[ry] = rx;
            scale1[rx] += scale1[ry];
        }else if(rank[rx] < rank[ry]){
            par[rx] = ry;
            scale1[ry] += scale1[rx];
        }else{
            // 同じならxを根に
            par[ry] = rx;
            scale1[rx] += scale1[ry];
            rank[rx]++;
        }
        size1--;
    }

    // 2つのデータx, yが属する木が同じならtrueを返す関数
    bool same(int x, int y){
        return root(x) == root(y);
    }

    // xの属する木の要素の数を返す関数
    int scale(int x){
        return scale1[root(x)];
    }

    // 木の数を返す関数
    int size(){
        return size1;
    }
};

int main() {
    int N,M;
    cin >> N >> M;
    vector<int>X(M);
    vector<int>Y(M);
    vector<int>Z(M);
    for (int i = 0; i < M; ++i) {
      cin >> X[i] >> Y[i] >> Z[i];
    }

    UnionFind tree(N);
    for(int i=0; i<M; i++){
        tree.unite(X[i]-1, Y[i]-1);
    }
    int ans = tree.size();
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

struct max_flow {
  struct edge { ll to, cap, rev; };
  ll V;
  vector<vector<edge>> G;
  vector<ll> itr, level;

  max_flow(ll V) : V(V) { G.assign(V,vector<edge>()); }

  void add_edge(ll from,ll to,ll cap) {
    G[from].push_back((edge) {to, cap, (ll) G[to].size()});
    G[to].push_back((edge) {from, 0, (ll) G[from].size()-1});
  }

  void bfs(ll s) {
    level.assign(V,-1);
    queue<ll> q;
    level[s] = 0; q.push(s);
    while (!q.empty()) {
      ll v = q.front(); q.pop();
      for(auto &e: G[v]){
        if (e.cap > 0 and level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }

  ll dfs(ll v, ll t, ll f) {
    if (v == t) return f;
    for (ll& i = itr[v]; i < (ll) G[v].size(); ++i) {
      edge& e = G[v][i];
      if (e.cap > 0 and level[v] < level[e.to]) {
        ll d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  ll run(ll s, ll t) {
    ll ret = 0, f;
    while (bfs(s), level[t] >= 0) {
      itr.assign(V,0);
      while ((f = dfs(s, t, inf)) > 0) ret += f;
    }
    return ret;
  }
};

int main(){

  ll n;
  cin >> n;
  vec a(n),b(n),c(n),d(n);
  for(ll i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  for(ll i=0;i<n;i++){
    cin >> c[i] >> d[i];
  }

  auto g=max_flow(2*n+2);

  for(ll i=0;i<n;i++){
    for(ll j=0;j<n;j++){
      if(a[i]<c[j] && b[i]<d[j])g.add_edge(i+1,j+n+1,1);
    }
  }
  for(ll i=1;i<n+1;i++)g.add_edge(0,i,1);
  for(ll i=n+1;i<2*n+1;i++)g.add_edge(i,2*n+1,1);

  cout << g.run(0,2*n+1) << endl;


}

Measured memory_bytes: 3816
#include <stdio.h>
int main() {
	int n,h,maxH=0,ans=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h);
		if(maxH<=h){
			ans++;
			maxH=h;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    int solve(int64 n) {
        unordered_set<int64> ret;
        auto div1 = devider(n - 1);
        // for(const auto& i : div1) cout << i << " ";
        // cout << endl;
        for(int i = 1; i < div1.size(); ++i) ret.insert(div1[i]);
        // cout << "show result of div1: \n";
        // for(const auto& rr : ret) cout << rr << " ";
        // cout << endl;
        auto div2 = devider(n);
        //cout << "size div2: " << div2.size() << endl;
        for(int i = 1; i < div2.size(); ++i) {
            int64 temp = n;
            while(temp % div2[i] == 0) temp /= div2[i];
            if(temp % div2[i] == 1) ret.insert(div2[i]);
        }
        // cout << "show result of div2: \n";
        // for(const auto& rr : ret) cout << rr << " ";
        // cout << endl;
        return ret.size();
    }

    vector<int64> devider(int64 n) {
        vector<int64> ret;
        for(int64 i = 1; i * i <= n; ++i) {
            if(n % i == 0) {
                ret.push_back(i);
                if(i * i != n) ret.push_back(n / i);
            }
        }
        sort(begin(ret), end(ret));
        return ret;
    }
};

int main() {
    int64 n;
    cin >> n;
    Solution sol;
    auto ret = sol.solve(n);
    cout << ret << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >>n;
  ll a,b,c,d,e;
  cin >> a>>b>>c>>d>>e;
  ll m = min(a,min(b,min(c,min(d,e))));
  ll ans = 4 + (n + m - 1) / m;
  cout << ans << endl;
  return 0;
}

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

if K % 2 == 0 or K % 5 == 0:
  print(-1)
  exit()
  
t = 7
if t % K == 0:
  print(1)
  exit()

t %= K

for i in range(2,K+1):
  t = t*10 + 7
  if t % K == 0:
    print(i)
    exit()
  else:
    t %= K
    
print(-1)

Measured memory_bytes: 63340
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,y,a,b,c;
    long long int p,q,r;
    cin>>x>>y>>a>>b>>c;
    std::deque<long long int> A;
    std::deque<long long int> B;
    for (int i=0;i<a;i++) {
        cin>>p;
        A.emplace_back(p);
    }
    for (int i=0;i<b;i++) {
        cin>>q;
        B.emplace_back(q);
    }
    sort(A.begin(),A.end(),greater<long long int>());
    sort(B.begin(),B.end(),greater<long long int>());
    std::deque<long long int> ABC;
    for (int i=0;i<x;i++) {
        ABC.emplace_back(A[i]);
    }
    for (int i=0;i<y;i++) {
        ABC.emplace_back(B[i]);
    }
    for (int i=0;i<c;i++) {
        cin>>r;
        ABC.emplace_back(r);
    }
    sort(ABC.begin(),ABC.end(),greater<long long int>());
    long long int sum=0;
    for (int i=0;i<x+y;i++) {
        sum+=ABC[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 7536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    rep(i, 0, 3) if(s[i] == s[i+1]) {
        cout << "Bad" << endl;
        return 0;
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll a,b; cin >> a >> b;
  string s; cin >> s;
  REP(i, a+b+1){
    if(i==a){
      if(s[i] != '-') no();
    }else{
      if(s[i] == '-') no();
    }
  }
  yes();
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();

    let ans = a.iter().fold(a[0], |a, &x| gcd(a, x));

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn gcd(n: u64, m: u64) -> u64 {
    if n % m == 0 {
        m
    } else {
        gcd(m, n % m)
    }
}


Measured memory_bytes: 4352