akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);


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


int main() {


ll n;
int k;
cin>>n>>k;

vector<int> vect;


while (n !=0){
  vect.push_back(n%k);
  n = n/k;
}

cout<<vect.size()<<"\n";
  
  return 0;
}


Measured memory_bytes: 3568
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int d=sc.nextInt();
    sc.close();
    int start=Math.max(a,c);
    int end=Math.min(b,d);
    int time=0;
    if(start<=end){
      time=end-start;
    }
    System.out.println(time);
  }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <algorithm>

int main()
{
  int n;
  scanf("%d", &n);
  int a[200000];
  int b[200000];
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", a + i);
  }
  memcpy(b, a, sizeof(int) * n);
  std::sort(b, b + n);
  int m1 = b[n / 2 - 1];
  char s1[24], s2[24];
  sprintf(s1, "%d", m1);
  sprintf(s2, "%d", b[n / 2]);
  for (int i = 0; i < n; ++i)
  {
    puts(a[i] <= m1 ? s2 : s1);
  }
  return 0;
}

Measured memory_bytes: 3712
from collections import deque
n,k = map(int,input().split())
ans = 0
ansl = []
sushi = []
sushi1 = deque()
sushi2 = []
various = [0 for i in range(n)]
v = 0
for i in range(n):
    td = list(map(int,input().split()))
    sushi.append(td)
sushi.sort(key=lambda x:x[1],reverse=True)
for i in range(n):
    if i < k:
        ans += sushi[i][1]
        if various[sushi[i][0]-1] == 0:
            v += 1
        various[sushi[i][0]-1] += 1
        sushi1.append(sushi[i])
    else:
        sushi2.append(sushi[i])
ansl.append(ans+v*v)
for i in range(n-k):
    if various[sushi2[i][0]-1] == 0:
        key = 0
        while key < 1 and len(sushi1) > 0:
            a,b = sushi1.pop()
            if various[a-1] > 1:
                key += 1
                various[a-1] -= 1
        if key > 0:
            various[sushi2[i][0]-1] += 1
            ans = ans + sushi2[i][1] - b
            v += 1
            ansl.append(ans+v*v)
print(max(ansl))

Measured memory_bytes: 30272
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(a+1):
   for j in range(b+1):
      for k in range(c+1):
         if (500 * i) + (100 * j) + (50 * k) == x:
            count += 1

print(count)

Measured memory_bytes: 9184
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
    fast_io();
    string a;
    string b;

    cin >> a >> b;
    int count = 0;
    for (int i = 0; i < a.size(); ++i) {
      if (a[i] == b[i]) count++;
    }
    cout << count <<endl;

}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[10001][10001];
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
            cin>>a[i][j];
    }
    for(int i=0;i<h;i++)
    {
        for(int k=0;k<2;k++)
        {
            for(int j=0;j<w;j++)
                cout<<a[i][j];
            cout<<endl;
        }
    }
}

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

int main(){
int N;
  cin>>N;
  vector<int>l(1000);
  vector<int>r(1000);
  for(int i=0; i<N; i++){
   cin>>l[i]>>r[i];}
  
  int ans=0;
  for(int i=0; i<N; i++){
    if(r[i]<=100000){
    ans+=(r[i]-l[i]+1);}
    else{break;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace contest
{
    class Program
    {
        public class Q1
        {
            static public int func()
            {
                int MAX = 200;

                char text_split = ' ';

                for (int i = 0; i < MAX; i++)
                {
                    string read = Console.ReadLine();

                    if (read == null) break;
                    else
                    {
                        string[] words = read.Split(text_split);

                        if (words[1] == null) break;

                        int a_num = int.Parse(words[0]);
                        int b_num = int.Parse(words[1]);

                        //出力
                        int ab = a_num + b_num;
                        int count = 1;
                        while (ab >= 10)
                        {
                            ab /= 10;
                            count++;
                        }
                        Console.WriteLine("{0}", count);
                    }
                }
                return 0;
            }
        }

        public class Q2
        {
            /*
             * s it a Right Triangle?
                1 以上 1000 以下の３つの正の整数を入力し、それぞれの長さを３辺とする三角形が直角三角形である場合には
             * YES を、違う場合には NO と出力して終了するプログラムを作成して下さい。
             * 
             * input
             * 3
                4 3 5
                4 3 6
                8 8 8
             */
            static public int func()
            {

                string read = Console.ReadLine();
                int dataset_num = int.Parse(read);

                int[] num_array = new int[3];

                for (int i = 0; i < dataset_num; i++)
                {
                    //一行読み込む
                    var input_line = Console.ReadLine();

                    //空白で分割する
                    var line = input_line.Split();
                    int count = 0;
                    foreach (var num in line)
                    {
                        //数字に変換
                        num_array[count++] = int.Parse(num);
                    }
                    
                    //ソート
                    Array.Sort(num_array);

                    if (num_array[2] * num_array[2] == (num_array[0] * num_array[0] + num_array[1] * num_array[1]))
                    {
                        Console.WriteLine("YES");
                    }
                    else
                    {
                        Console.WriteLine("NO");
                    }

                }


                return 0;
            }
        }
        static int Main(string[] args)
        {
            Q2.func();

            Console.ReadKey();
            return 0;
        }

    }
}

Measured memory_bytes: 5620
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;
int a[N], pre[N];
ordered_set<pii> s;

void solve(){
	int n;
	cin >> n;
	fr(i, 1, n){
		cin >> a[i];
	}
	int l = -1, r = 1e9 + 5;
	int z = (n * (n + 1)) / 2;
	while(r - l > 1){
		int m = (l + r) >> 1;
		int tot = 0;
		s.clear();
		s.insert({0, 0});
		fr(i, 1, n){
			if(a[i] <= m)
				pre[i] = 1;
			else
				pre[i] = -1;
			pre[i] += pre[i - 1];
			tot += s.order_of_key({pre[i], -1e9});
			s.insert({pre[i], i});
		}
		if(tot >= z / 2 + 1){
			r = m;
		}
		else{
			l = m;
		}
	}
	cout << r;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int k,n;
	cin>>k>>n;
	int  sum=0,a;
	for(int i=0;i<n;i++){
		cin>>a;
		sum+=a;
	}
	if(sum>=k)
		cout<<"Yes\n";
	else 
		cout<<"No\n";


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  string s;
  cin>>s;
  int len=s.size();
  int sta[100000],tmp[100000],fin[100000],n=0;
  sta[0]=0;

  int a[len];
  rep(i,0,len) a[i]=0;

  rep(i,0,len-1){
    if(s[i]=='R' && s[i+1]=='L') tmp[n]=i;

    if(s[i]=='L' && s[i+1]=='R'){
      fin[n]=i;
      n++;
      sta[n]=i+1;
    }
  }
    fin[n]=len-1;


  rep(i,0,n+1){
    rep(j,sta[i],tmp[i]) cout<<"0"<<' ';

    cout<<(tmp[i]-sta[i])/2+1+(fin[i]-tmp[i])/2<<' ';
    cout<<(tmp[i]-sta[i]+1)/2+1+(fin[i]-tmp[i]-1)/2<<' ';

    rep(j,tmp[i]+2,fin[i]+1) cout<<"0"<<' ';
  }

}


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

#define int long long
#define MAX 2005

// #include "debug.cpp"

int mod = 1000000007;

int fact[MAX];
int inv[MAX];

int power(int a, int p){
	if(p == 0)
		return 1;

	int x = power(a, p/2);
	if(p%2 == 0){
		return x*x % mod;
	}
	return (x*x%mod) * a %mod;
}

int C(int n, int r){
	if(n<0 || r<0 ||r > n)
		return 0;

	int a = fact[n];
	int b = inv[r] * inv[n-r] % mod;

	return a*b%mod;
}

int32_t main(){
	
	fact[0] = 1;
	for(int i=1; i<MAX; i++){
		fact[i] = i*fact[i-1]%mod;
	}

	// print(fact, 10);
	for(int i=0; i<MAX; i++){
		inv[i] = power(fact[i], mod-2);
	}


	int s, i, j, ans = 0;
	cin >> s;
	int oris = s;
	for(i=1; i<oris; i++){
		s -= 3; 
		ans += C(s+i-1, i-1);
		ans %= mod;
	}

	cout << ans << "\n";

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=0;

int main(){
    GO();
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(i%5!=0&&i%3!=0){
            sum+=i;
        }
    }
    cout<<sum<<endl;
}




























Measured memory_bytes: 3656
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
ll gcd(ll m,ll n){
  if(0==n)return m;
  return gcd(n,m%n);
}

ll lcm(ll m,ll n){
  ll g=gcd(m,n);
  return (m/g*n);
}

int main(){
  CIN(n);VC1(n,a);
  ll mi = accumulate(ALL(a),0LL);
  COUT(mi - n);
 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  vector<int>s(m),c(m);
  r1(i,m) cin >> s.at(i) >> c.at(i);
  int a,b,e=-1;
  if(n==1) a=0,b=10;
  if(n==2) a=10,b=100;
  if(n==3) a=100,b=1000;
  string str;
  for(int i=a;i<b;i++) {
    str=to_string(i);
    e=i;
    r1(j,m) {
      char cha='0'+c.at(j);
      if(str.at(s.at(j)-1)!=cha) e=-1;
    }
    if(e==i) break;
  }
  cout << e << endl; 
}

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> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    ll n,m,d;
    cin >> n >> m >> d;
    if(d >= n){
        printf("%.10f",0.0);
        return 0;
    }if(d==0){
        printf("%.10f",((m-1)*(n-d))/(double)(n*n));
        return 0;
    }
    printf("%.10f",(2*(m-1)*(n-d))/(double)(n*n));
    return 0;
}

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

int main() {
    string abc;
    cin >> abc;
    int repeat = 0;
    for (int i = 0; i < 4; i ++) {
        char x = abc[i];
        int count = 0;
        for (int j = 0; j < 4; j++) {
            if (x == abc[j]) {
                count++;
            }
        }
        if (count == 2) {
            repeat++;
        }
    }
    if (repeat == 4) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main() {
	string S; 
	cin >> S; 
	int L = S.size();
	long long int ans = 0;  
	for(int bit = 0; bit < (1 << (L-1)); bit++){
                long long int A =  (long long)(S.at(0) - '0'); 
		for(int j = 0; j < L-1; j++){
			int k = (bit / (1 << j)) % 2; 
			if(k == 0){A = 10 * A + (long long)(S.at(j+1) - '0');}
			if(k == 1){ans += A, A =(long long)(S.at(j+1) - '0');}
		}
                ans += A; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

const int maxx = 1e4 + 5;
int a[maxx][maxx];
int b[maxx];

typedef long long ll;
ll sum;

int main(){
	int n, m, c;
	while(scanf("%d %d %d", &n, &m, &c) == 3){
		int flag = 0;
		for(int j = 0; j < m; j++) scanf("%d", &b[j]);
		for(int i = 0; i  < n; i++)
			for(int j = 0; j < m; j++)
				scanf("%d", &a[i][j]);
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = 0; j < m; j++){
				sum += a[i][j] * b[j];
			}
			if(sum + c > 0) flag++;
		}
		printf("%d\n", flag);
	}
	return 0;
}

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

using namespace std;

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

    bool flag = false;
    int st = a % b, A = a;;
    while (1) {
        if (A % b == c) flag = true;
        A += a;
        if (A % b == st) break; 
    }

    if (flag) puts("YES");
    else puts("NO");

    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;

struct UnionFind{
	std::vector<int> data;
	// dataの各要素について
	// 負の値:その集合のルートであること示す(spaghetti sourceではその絶対値は集合の要素数となっている)
	// 正の値:親ノードの番号(dataのインデックス)。root()を呼び出すたびに集合のルートを指すように書きなおされるので木はそんなに深くならない

	//初期化 size:最大要素数
	UnionFind(int size): data(size, -1){ }
	
	// 集合を併合する
	// すでに同じ集合だった場合は、falseが返る
	bool unite(int x, int y){
		x=root(x); y=root(y);
		if( x != y ){
			// yの属する集合のルートをxに変更
			data[y] = x;
		}
		return x!=y;
	}

	// 同じ集合かどうか判定
	bool find(int x, int y){
		return root(x) == root(y);
	}

	// 集合の識別番号を返す
	int root(int x){
		// 負の値を持つものがその集合のルート
		// 正の値は同じ集合に属するものを指す(辿ればいずれルートへ着く)
		return (data[x] < 0)? x : data[x]=root(data[x]);
	}
};


int main(){
	//ios_base::sync_with_stdio(0);
	int N, M;

	cin >> N >> M;
	UnionFind uf(N+M+1);
	rep(i,N){
		int K;
		cin >> K;
		rep(j,K){
			int L;
			cin >> L;
			uf.unite(i,N+L);
		}
	}
	bool ans=true;
	rep(i,N) if( !uf.find(0,i) ) ans = false;

	cout << (ans?"YES":"NO") << endl;

	return 0;
}



Measured memory_bytes: 1920
def main():
    N = int(input())
    A = list(map(int, input().split()))
 
    B = list(map(abs, A))
    C = [a for a in A if a < 0]
    if len(C) % 2 == 0:
        print(sum(B))
    else:
        print(sum(B) - min(B)*2)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const ll INF = 1<<30;
const ll MOD = 1e9+7;
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; }

vector<vector<ll> > dp1(3030,vector<ll>(3030,0)), dp2(3030,vector<ll>(3030,0));

int main(){
    ll N,T; cin >> N >> T;
    vector<pair<ll,ll> > V(N+10,make_pair(0,0));
    rep1(i,N){
        ll a,b; cin >> a >> b;
        V[i] = make_pair(a,b);
    }
    rep1(i,N){
        rep(j,T){
            chmax(dp1[i][j], dp1[i-1][j]);
            if(j-V[i].first >= 0){
                chmax(dp1[i][j], dp1[i-1][j-V[i].first]+V[i].second);
            }
        }
    }
    for(int i=N;i>=1;--i){
        rep(j,T){
            chmax(dp2[i][j], dp2[i+1][j]);
            if(j-V[i].first >= 0){
                chmax(dp2[i][j], dp2[i+1][j-V[i].first]+V[i].second);
            }
        }
    }
    
    ll res = 0;
    rep1(i,N){
        rep(j,T){
            chmax(res, dp1[i-1][j] + dp2[i+1][T-1-j] + V[i].second);
        }
    }
    cout << res << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define fori(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(n) fori(somethingStupid,1,(n))

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

bool tests = false;
void solve(){
    int n, x, t; cin >> n >> x >> t;
    cout << ((n-1)/x+1) * t << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    if (tests){
        cin >> t;
    }
    rep(t) solve();
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,k;
int a[200005];
int c[200005];
int ans;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        c[a[i]]++;
    }
    sort(c,c+n+1);
    for(int i=0;i<=n-k;i++){
        ans+=c[i];
    }
    cout<<ans<<endl;

}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int ans;
    for(int k=n; k>=1; k--){
        if(n%k != 0) continue;
        int t = n/k;
        bool ok = true;
        for(int i=0; i<n; i++){
            if(a[i] != a[i%t]){
                ok = false;
                break;
            }
        }
        if(ok){
            ans = k;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNING

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm> 
using namespace std;
typedef long long ll;
int main()
{
	ll a,i,p=1;
	scanf("%lld",&a);
	for(i=1;i<=a;i++)
		p=(p*i)%1000000007;
	printf("%lld\n",p);
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    m1,_=MI()
    m2,_=MI()
    if m1==m2:print(0)
    else:print(1)
main()

Measured memory_bytes: 3064
import sys
import re
inp = []
for cnt in range(2):
  inp.append(input())
  if not re.match(r"^[a-z]+$", inp[cnt]):
    sys.exit()

cnt = 0
for l in inp:
  if not 1 <= len(inp[cnt]) <= (10 + cnt):
    sys.exit()
  cnt = cnt + 1

if len(inp[0]) < len(inp[1]):
  if(inp[0] == inp[1][:-1]):
    print("Yes")
    sys.exit()
print("No")

Measured memory_bytes: 9812
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ = Printf.printf "%d\n" @@ if n = 1 && m = 1 then 1 else if n = 1 || m = 1 then n * m - 2 else if n = 2 || m = 2 then 0 else (n - 2) * (m - 2)

Measured memory_bytes: 384
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  ll n;cin>>n;
  vector<ll> count(61, 0LL);
  rep(i, n){
    ll a;cin>>a;
    for(int j=0;j<61;j++){
      count[j]+=ll(a&1);
      a>>=1;
    }
  }
  ll ans=0LL;
  ll digit=1LL;
  rep(i, 61){
    ans+=((count[i]*(n-count[i]))%MOD)*digit;
    ans%=MOD;
    digit=(digit*2)%MOD;
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int n, m, x;
int c[12];
int a[12][12];
int un[12];

int dfs(int u[], int k, int money);
int main() {

	/*string s, t;
	cin >> s;
	cin >> t;
	int i;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == t[i]) {

		}
		else {
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";
	return 0;*/

	/*int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a) {
		cout << k << endl;
	}
	else if (k <= a + b) {
		cout << a << endl;
	}else{
		cout << a - (k - a - b) << endl;
	}
	return 0;*/


	cin >> n >> m >> x;
	int i,j;
	
	for (i = 0; i < n; i++) {
		cin >> c[i];
		for (j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (i = 0; i < m; i++) {
		un[i] = 0;
	}
	cout << dfs(un, 0, 0) << endl;
	return 0;
	
}
int dfs(int u[], int k, int money) {
	//kを加えるのと加えないの．
	//cout << 'a\n';
	int i;
	int mmoney;
	int unn[12];
	int flag = 0;
	int money1, money2;
	mmoney = money + c[k];//kを買った場合のお金
	for (i = 0; i < m; i++) {
		unn[i] = u[i] + a[k][i];//理解度の追加
		if (unn[i] < x) {//理解が足りない
			flag = 1;
		}
	}
	if (k == n-1) {
		if (flag > 0) {
			return -1;
		}
		else {
			return mmoney;
		}
	}
	if (flag == 0) {
		money1 = mmoney;//そろったなら次から調べない．
	}
	else {
		money1 = dfs(unn, k + 1, mmoney);
	}
	money2 = dfs(u, k + 1, money);//kを買わない場合．
	if ((money1 == -1) && (money2 == -1)) {
		return -1;
	}
	else if (money1 == -1) {
		return money2;
	}
	else if (money2 == -1) {
		return money1;
	}
	else if (money2 < money1) {
		return money2;
	}
	else{
		return money1;
	}
}

Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
using namespace std;
int main(void) {
  int n;
  int a[100002];
  cin>>n;
  int prev=0;
  int total=0;
  a[0]=0;
  prev=a[0];
  for(int i=1; i<=n; i++) {
    cin>>a[i];
    total+=abs(prev-a[i]);
    prev=a[i];
  }
  a[n+1]=0;
  total+=abs(prev-a[n+1]);
  for(int i=1; i<=n; i++) {
    cout<<total-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1])<<endl;
  }
  return 0;
}


Measured memory_bytes: 1664
n=int(input())
m,M=[],[]
for i in range(n):
  a,b=map(int,input().split())
  m+=[a]
  M+=[b]
m.sort()
M.sort()
d=n//2
if n%2:
  print(M[d]-m[d]+1)
else:
  print(M[d-1]+M[d]-m[d-1]-m[d]+1)

Measured memory_bytes: 25564
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc138/tasks/abc138_d

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
#include <list>
using namespace std;

#include <stack>

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

struct Vertex
{
    list<int> towards;
    int counter{0};
};

void dfs(vector<Vertex>& v, int index, int parent = -1)
{
    auto& vt = v[index];
    for(auto pt = vt.towards.begin(); pt != vt.towards.end(); ++pt)
    {
        if(*pt == parent)
        {
            continue;
        }
        v[*pt].counter += vt.counter;
        dfs(v, *pt, index);
    }
}

int main(int argc, const char* argv[])
{
    int n, q;
    cin >> n >> q;

    vector<Vertex> v(n + 1);
    for(int i = 0; i < n - 1; ++i)
    {
        int a, b;
        cin >> a >> b;
        v[a].towards.push_back(b);
        v[b].towards.push_back(a);
    }

    for(int i = 0; i < q; ++i)
    {
        int p, x;
        cin >> p >> x;
        v[p].counter += x;
    }

    dfs(v, 1);

    for(int i = 0; i < n; ++i)
    {
        cout << v[i + 1].counter << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 28928
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools
plist = list(itertools.permutations([i+1 for i in range(n)]))
count = 1
resultp = 0
resultq = 0
for pp in plist:
    if(list(pp) == p):
        resultp = count
    if (list(pp) == q):
        resultq = count
    count += 1
print(abs(resultp - resultq))

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N;
string S[1000];

void solve(){
    rep(i,N)cin>>S[i];
    reps(i,1,N){
        rep(j,S[i].size()-1){
            if(isalpha(S[i][j+1])){
                S[i][j]='+';
                int k=i-1;
                while(k>=0&&S[k][j]=='.')S[k--][j]='|';
                break;
            }
        }
    }

    rep(i,N)rep(j,S[i].size())if(S[i][j]=='.')S[i][j]=' ';
    rep(i,N)cout<<S[i]<<endl;
}

signed main(){
    while(cin>>N,N)solve();
    return 0;
}

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

using namespace std;
using i64 = long long;

i64 gcd(i64 a, i64 b) {
    return b == 0 ? a : gcd(b, a % b);
}

i64 lcm(i64 a, i64 b) {
    return a / gcd(a, b) * b;
}

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

    i64 A, B;
    cin >> A >> B;
    cout << lcm(A, B) << "\n";

    return 0;
}

Measured memory_bytes: 256
def solve():
  x,y = (int(i) for i in input().split())
  ans = []
  #B 0回
  if x <= y:
    ans.append(y-x)
  #B 1回
  if -x <= y:
    ans.append(y+x+1)
  if x <= -y:
    ans.append(-y-x+1)
  #B 2回
  if -x <= -y:
    ans.append(x-y+2)
  return(min(ans))
  
  
  
if __name__ == '__main__':
  print(solve())

Measured memory_bytes: 3060
#include <iostream>
#include <map>

int main()
{
  int N;
  std::cin >> N;
  std::map<int, int> mp;

  for ( int i = 0; i < N; i++ ) {
    int a;
    std::cin >> a;
    mp[a]++;
  }
  
  int ans = 0;
  for ( auto itr = mp.begin(); itr != mp.end(); ++itr ) {
    if ( itr->second % 2 == 1 ) {
      ans++;
    }
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

template<long long mod> struct modint {
    long long x;
    modint(long long x=0) : x((x%mod+mod)%mod) {}
    static int get_mod() { return mod; }
    modint &operator+=(const modint &a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint &a) {
        if((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint &a) {
        x = (int) (1LL * x * a.x % mod);
        return *this;
    }
    modint &operator/=(const modint &a) {
        *this *= a.inv();
        return *this;
    }
    modint operator-() const { return modint(-x); }
    modint operator+(const modint &a) const { return modint(*this) += a; }
    modint operator-(const modint &a) const { return modint(*this) -= a; }
    modint operator*(const modint &a) const { return modint(*this) *= a; }
    modint operator/(const modint &a) const { return modint(*this) /= a; }
    bool operator==(const modint &a) const { return x == a.x; }
    bool operator!=(const modint &a) const { return x != a.x; }
    modint pow(long long t) const {
        if (!t) return 1;
        modint<mod> a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    modint inv() const {
        return pow(mod-2);
    }
    friend std::ostream &operator<<(std::ostream &os, const modint &a) { return os << a.x; }
    friend std::istream &operator>>(std::istream &is, modint &a) {
        long long t;
        is >> t;
        a = modint<mod>(t);
        return (is);
    }
};
//const long long mod = 998244353;
const long long mod = 1000000007;
using mint = modint<mod>;

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n),color(3,0);
    rep(i,n) std::cin >> a[i];

    std::vector<mint> v(n+1,0);
    mint ans = 1;
    for(int i=0; i<n; i++){
        mint cnt = 0;
        int f;
        if(a[i]==color[0]) {cnt+=1; f=0;}
        if(a[i]==color[1]) {cnt+=1; f=1;}
        if(a[i]==color[2]) {cnt+=1; f=2;}

        ans *= cnt;
        color[f]++;
    }

    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4532
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

int main() {
    int w, a, b;
    cin >> w >> a >> b;
    int ar = a + w, br = b + w, ans = 0;
    if (b > ar) ans = b - ar;
    else if (a > br) ans = a - br;
    cout << ans << endl;
}

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

void readtxt()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int main() {
	//readtxt();
	unsigned long long int x,temp=100;
	cin >> x;
	int count=0;
	while(temp<x)
	{
		temp = temp +(temp/100);
		++count;
	}
    cout << count << endl;
}

Measured memory_bytes: 3624
x,k,d = map(int, input().split())
if (x>0 and x-k*d>0):
    print(x-k*d)
    exit()
elif (x<0 and x+k*d<0):
    print(abs(x+k*d))
    exit()
x = abs(x)
a = x//d
b = x%d
if (k-a)%2==0:
    print(b)
else:
    print(d-b)


Measured memory_bytes: 9204
package main

import (
	"fmt"
	"math"
)

func main() {
	var H int
	fmt.Scan(&H)

	var c int
	for 0 < H {
		H /= 2
		c++
	}
	r := int(math.Pow(2, float64(c)))
	fmt.Println(r - 1)
}


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

int main() {
    int n;
    cin >> n; 
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }   
    int ans=-1;
    bool flag=true;
    while(flag){
        for (int i=0;i<n;i++){
            if (a[i]%2==1){
                flag=false;
            }else{
                a[i]/=2;
            }
        }
        ans+=1;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define INF 100000000

int main(){
  int H, W, i, j;
  while(cin >> H >> W) {
    int data[52][52] = {};
    for(i = 0; i <= H+1; i++)
      for(j = 0; j <= W+1; j++)
	data[i][j]  = INF;
    
    for(i = 1; i<=H; i++) {
      for(j = 1; j <= W; j++)
	scanf("%1d", &data[i][j]);
    }
    for(i = 1; i<=H; i++) {
      for(j = 1; j <= W; j++){
	if(!(i == 1 && j == 1))data[i][j] = data[i][j] + min(data[i][j-1], data[i-1][j]);
      }
    }
    cout << data[H][W] << endl;
  }
  
  return 0;
}

    

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  repi(i,1,3501){
    repi(j,2,3501){
      if((4*i*j - n*i - n*j) != 0 &&    (n*i*j)%(4*i*j - n*i - n*j)==0 && (n*i*j)/(4*i*j - n*i - n*j) > 0){
	cout<<i<<" "<<j<<" "<<(n*i*j)/(4*i*j - n*i - n*j)<<endl;
	return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    ll a,b,c,ans=0; cin >> a >> b >> c;
    ll A = a, B = b, C = c;
    while(a%2==0 && b%2==0 && c%2==0){
        int x = b/2 + c/2;
        int y = a/2 + c/2;
        int z = a/2 + b/2;
        a = b = c = 0;
        a += x;
        b += y;
        c += z;
        if(a == A && b == B && c == C){cout << -1 << endl; return 0;}
        ans++;
    }
    cout << ans << endl;
}





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

int main(){
    
    int a, b;
    string s;

    cin >> s;

    a = stoi(s.substr(0,2));
    b = stoi(s.substr(2,2));
    if(a>=1 && a<=12 && b>=1 && b<=12){
        cout << "AMBIGUOUS" << endl;
    }else if(a>=1 && a<=12){
        cout << "MMYY" << endl;
    }else if(b>=1 && b<=12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

struct uf{
  private:
    vi par, rank, size;
  public:
    uf(i64 n){ init(n); }
    void init(i64 n){
      par.resize(n);
      rank.resize(n,0);
      size.resize(n,1);
      rep(i,n) par[i] = i;
    }
    i64 root(i64 x){
      if(par[x] == x) return x;
      return par[x] = root(par[x]);
    }
    bool same(i64 x, i64 y){ return root(x) == root(y); }
    void unite(i64 x, i64 y){
      x = root(x), y = root(y);
      if(x==y) return;
      if(rank[x]==rank[y]) rank[x]++;
      if(rank[x]<rank[y]) swap(x,y);
      par[y] = x;
      size[x] += size[y];
    }
    i64 num(i64 x){ return size[root(x)]; }
};

void Main()
{
  i64 N, M;
  cin >> N >> M;
  vi P(N);
  cin >> P;
  vvi XY(M, vi(2));
  cin >> XY;

  struct uf U(N);
  rep(i, M){
    U.unite(XY[i][0] - 1, XY[i][1] - 1);
  }

  vvi pos(N);
  vvi num(N);

  rep(i,N){
    pos[U.root(i)].emplace_back(i);
    num[U.root(i)].emplace_back(P[i] - 1);
  }

  i64 ans = 0;
  rep(i,N){
    if(pos[i].size() == 0) continue;
    sort(rng(pos[i]));
    sort(rng(num[i]));
    i64 p0 = 0, p1 = 0;
    while(p0 < pos[i].size() and p1 < num[i].size()){
      if(pos[i][p0] == num[i][p1]) {
        ans++;
        p0++;
        p1++;
        continue;
      }
      if(pos[i][p0] < num[i][p1]){
        p0++;
        continue;
      }
      p1++;
    }
  }

  cout << ans << "\n";
}

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

Measured memory_bytes: 19712
def main():
    X, N = [int(s) for s in input().strip().split()]

    if N == 0:
        print(X)
        return
    
    ps = [int(s) for s in input().strip().split()]

    p_max = max(ps)
    p_min = min(ps)

    for d in range(100):
        cand = X - d

        if cand < p_min:
            print(cand)
            return
        
        if cand not in ps:
            print(cand)
            return

        cand = X + d

        if cand > p_max:
            print(cand)
            return

        if cand not in ps:
            print(cand)
            return

main()


Measured memory_bytes: 9204
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m,c = map(int, input().split())
b = list(map(int, input().split()))

r=0
for i in range(0,n):
  a = list(map(int, input().split()))
  rr=c
  for j in range(0,m):
    rr=rr+a[j]*b[j]
  if rr>0:
    r=r+1
print(r)


Measured memory_bytes: 3060
/* Dedication has no limitation 
                   - Ulisses Jr.
*/
// 01 June  2019
// Location: Japan
#include <bits/stdc++.h>
using namespace std;

int main()
{int n,k;
 cin >> n >> k;
 string s;
 cin >> s;
 s[k-1] = tolower(s[k-1]);
 cout << s << endl;
 
}

Measured memory_bytes: 256
tailrec fun gcd(a: Int, b: Int): Int {
    return if (b == 0) {
        a
    } else {
        gcd(b, a % b)
    }
}

fun main() {
    val n = readLine()?.toInt() ?: return
    var total = 0
    repeat(n) {
        val a = it + 1
        repeat(n) {
            val b = it + 1
            repeat(n) {
                val c = it + 1
                total += gcd(gcd(a, b), c)
            }
        }
    }
    println(total)
}


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

using namespace std;

using ll = long long;
template<class T> using v = vector<T>;

void bfs(ll node, ll N, const v<v<ll>> &edge, v<ll> &dist)
{
    v<bool> visit(N+1);
    queue<ll> q;
    q.push(node);
    dist.clear();
    dist.resize(N+1);
    
    dist[node] = 0;
    while(!q.empty()){
        node = q.front();
        q.pop();
        visit[node] = true;
        
        for(const auto n : edge[node]){
            if(visit[n]) continue;
            q.push(n);
            dist[n] = dist[node] + 1;
        }
    }
}

int main()
{
    ll N, u, V;
    cin >> N >> u >> V;
    v<v<ll>> edge(N + 1);
    for(ll i = 0; i < N; ++i){
        ll a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
   
    v<ll> dist_u(N+1), dist_v(N+1);
    bfs(u, N, edge, dist_u);
    bfs(V, N, edge, dist_v);
    ll d_v = 0;
    for(ll i = 1; i <= N; ++i){
        if(dist_v[i] > dist_u[i]){
            d_v = max(d_v, dist_v[i]);
        }
    }
    cout << d_v - 1;
    cout << endl;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  ans1(s[2]==s[3]&&s[4]==s[5]);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int cur = 1;
  int i;
  
  for(i=0;i<n;i++)
  {
   	int a ;
    cin >> a;
    if(a==cur)
    {
      cur++;
    }
  }
  if(cur==1)
  {
    cout << -1 << endl;
  }
  else
  {
    cur--;
    cout << n- cur << endl;
  }
  return 0;
}


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

int main(){
	
	int max[3]={0,0,0};
	int m;
	int i;
	
	for(i = 0; i< 10; i++){
		cin >> m;
		if(m > max[2]){
			if( m > max[1]){
				max[2] = max[1];
				if(m > max[0]){
					max[1] = max[0];
					max[0] = m;
				}
				else{
					max[1] = m;
				}
			}
			else{
				max[2] = m;
			}
		}
	}
	
	for(i=0;i<3;i++){
		cout << max[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160