akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;


// xの桁数を返す関数
int digit_max(ll x){
    int dig = 0;
    while(x/pow(10,dig) >= 1)dig++;
    return dig;
}

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

int main(){
    ll n; cin >> n;
    auto f = [&](ll x, ll y) -> ll{
        return max(digit_max(x), digit_max(y));
    };
    ll ans = INF;
    rep(i,sqrt(n)+1){
        if(i <= 0)continue;
        if(n % i == 0)chmin(ans, f(i,n/i));
    }
    cout << ans << endl;
}

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

ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << a * b / euclidean_gcd(a,b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	vl a(5);
	rep(i,0,5)cin>>a[i];
	ll ans=MOD;
	do{
		ll cnt=0;
		rep(i,0,5){
			if(i==4){
				cnt+=a[i];
			}
			else{
				ll k=(a[i]+10-1)/10;
				cnt+=k*10;
			}
		}
		chmin(ans,cnt);
	}while(next_permutation(all(a)));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3584
import itertools
N = int(input())
L = list(map(int, input().split(' ')))
lengths = list(itertools.combinations(L, 3))
count = 0
for tri in lengths:
    tri = list(tri)
    tri.sort()
    if (tri[0]+tri[1]>tri[2]) and (tri[0]!=tri[1]) and (tri[1]!=tri[2]) and (tri[0]!=tri[2]):
        count+=1
print(count)

Measured memory_bytes: 20472
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a[2][105],sum1[105]={0},sum2[105]={0},sum[105]={0};
	cin>>n;
	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
/*	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			cout<<a[i][j];
		}
	}*/

	sum1[0]=a[0][0];
	for(int i=1;i<n;i++)
		sum1[i]+=sum1[i-1]+a[0][i];
	sum2[n-1]=a[1][n-1];
	//cout<<sum2[n-1];
	for(int i=n-2;i>=0;i--)
		sum2[i]+=sum2[i+1]+a[1][i];
//	for(int i=0;i<n;i++)
//		cout<<sum2[i];
	for(int i=0;i<n;i++)
		sum[i]=sum1[i]+sum2[i];
//	for(int i=0;i<n;i++)
//		cout<<sum[i]<<"  ";
	sort(sum,sum+n);
	printf("%d\n",sum[n-1]);
}
	

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

#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF	INT_MAX
#define LLINF LLONG_MAX

typedef long long				ll;
typedef pair <int, int> ii;

#define DEBUG false

int main() {
		ll n, m;
		cin >> n >> m;
		vector <ll>	 cnt(m);
		vector <ll>	 cnt2(m);
		map <ll, ll> mp;
		rep(i, n) {
				ll tmp;
				cin >> tmp;
				cnt[(ll) (tmp % m)]++;
				mp[tmp]++;
				if(mp[tmp] == 2) {
						mp[tmp] = 0;
						cnt2[(ll) (tmp % m)]++;
				}
		}

		ll ans = 0;

		ans += (ll) (cnt[0] / 2);
		if(DEBUG) cout << "ans0:" << ans << endl;
		REP(i, 1, (int) ((m + 1) / 2)) {
      if(DEBUG) cout << "i:"<<i<<endl;
				if(cnt[i] > cnt[m - i]) {
						ll p = cnt[m - i];
						ans += p;
            if(DEBUG) cout << "p:" <<p<<endl;
						if(cnt2[i] > 0 && cnt[i] - p >= 2) ans += min((ll) ((cnt[i] - p) / 2), cnt2[i]);
            if(DEBUG) cout << (ll) ((cnt[i] - p) / 2)<<endl;
						if(DEBUG) cout << "ans1:" << ans << endl;
				}
				else {
						ll p = cnt[i];
						ans += p;
						if(cnt2[m - i] > 0 && cnt[m - i] - p >= 2) ans += min((ll) ((cnt[m - i] - p) / 2), cnt2[m-i]);
						if(DEBUG) cout << "ans2:" << ans << endl;
				}
		}

		if(DEBUG) cout << "ans3:" << ans << endl;
		if(m % 2 == 0) ans += (ll) (cnt[(int) (m / 2)] / 2);
		if(DEBUG) cout << "ans4:" << ans << endl;

		cout << ans << endl;

		return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> data( H, vector<char>(W));
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >>data.at(i).at(j);
    }
  }
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int count = 0;
      
      if(data.at(i).at(j) == '#'){
        cout << '#';
        continue;
      }
      
      if(i!=0){
        //前列カウント
        if(j!=0){          
       	  if(data.at(i-1).at(j-1) == '#') count++;
        }
        if(data.at(i-1).at(j) == '#') count++;
        if(j!=W-1){
          if(data.at(i-1).at(j+1) == '#') count++;
        }
      }
      //現在列カウント
      if(j!=0){
        if(data.at(i).at(j-1) == '#') count++;
      }
      if(j!=W-1){
        if(data.at(i).at(j+1) == '#') count++;
      }
      if(i!=H-1){
        //後列カウント
        if(j!=0){
          if(data.at(i+1).at(j-1) == '#') count++;
        }
        if(data.at(i+1).at(j) == '#') count++;
        if(j!=W-1){
          if(data.at(i+1).at(j+1) == '#') count++;
        }
      }
      
      cout << count;
    }
    
    cout << endl;
    
  }
}


Measured memory_bytes: 256
from collections import defaultdict


def factorize(n):
    facts = defaultdict(int)
    while n % 2 == 0:
        n //= 2
        facts[2] += 1
    m = 3
    while m * m <= n:
        while n % m == 0:
            facts[m] += 1
            n //= m
        m += 2
    if 1 < n:
        facts[n] += 1
    return facts


N = int(input())

ans = 0
facts = factorize(N)
for num in facts.values():
    for i in range(1, num + 1):
        if i <= num:
            num -= i
            ans += 1
        else:
            break
print(ans)

Measured memory_bytes: 9460
#include<cstdio>
#define MAX 10000
int check(int n){
    int A,ans=0,i;
    bool flag;
    for(;n>0;n--){
        flag=0;
        scanf("%d",&A);
        if(A<2)continue;
        else if(A==2){
            ans++;
            continue;
        }
        if(A%2==0)continue;
        for(i=3;i<=A/i;i+=2){
            if(A%i==0){
                flag++;
                break;
            }
        }
        if(flag)continue;
        ans++;
    }
    return ans;
}
int main(){
    int n;
    scanf("%d",&n);
    printf("%d\n",check(n));
    return 0;
}


Measured memory_bytes: 2640
#include <bits/stdc++.h> 
#define LL long long int
using namespace std; 
 
int main() 
{ 
    int n;
    double a[10], b[10];
    cin>>n;
    int p[n];
    for(int i=1;i<=n;i++) {
        cin>>a[i]>>b[i];
        p[i-1]=i;
    }

    vector<double> avg;
    do {
        double av = 0.0;
        for(int i=1;i<n;i++) {
            av += sqrt(
                ( pow(a[p[i]] - a[p[i-1]], 2) )
            +   ( pow(b[p[i]] - b[p[i-1]], 2) )
            );
        }
        avg.push_back(av);
            
        // std::cout << p[0] << ' ' << p[1] << ' ' << p[2] << '\n';
    } while ( std::next_permutation(p,p+n) );

    double ans = 0.0;
    for(int i=0;i<=avg.size();i++) {
        ans += avg[i];
    }
    
    double fact = 1;
    for(int i=1;i<=n;i++) {
        fact *= i*1.0;
    }

    cout.precision(17);
    cout<<ans/fact<<endl;
}

Measured memory_bytes: 892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		string[] s = new string[N];
		for(int i = 0; i < N; i++)
			s[i] = Console.ReadLine();

		int M = Int32.Parse(Console.ReadLine());
		string[] t = new string[M];
		for(int i = 0; i < M; i++)
			t[i] = Console.ReadLine();
	
		int ans = 0;
		for(int i = 0; i < N; i++)
		{
			int tmp = 1;
			for(int j = 0; j < N; j++)
			{
				if(i == j)
					continue;
				if(s[i].CompareTo(s[j]) == 0)
					tmp++;
			}
			for(int j = 0; j < M; j++)
				if(s[i].CompareTo(t[j]) == 0)
					tmp--;

			ans = Math.Max(ans,tmp);
		}

		Console.WriteLine(ans);
	}
}





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

int main(void){
  int n;
  cin>>n;
  bool flag = false;
  while(n!=0) {
   int t = n%10;
    n = n / 10;
    if(t == 7) {
     flag = true;
      break;
    }
  }
  
  if(flag)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 3636
def bitDP():
    dp = [[0] * N for _ in range(1 << N)]
    dp[1][0] = 1
    for i in range(1 << N):
        for v in range(N):
            if  (i >> v) & 0:
                continue
            j = i ^ (1 << v)
            for u in range(N):
                if (j >> u) & 1 and v in E[u]:
                    dp[i][v] += dp[j][u]
    res = sum(dp[-1][u] for u in range(1, N))
    return res

N, M = map(int, input().split())
E = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    E[a-1].add(b-1)
    E[b-1].add(a-1)

print(bitDP())

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	d0 := scanInt()
	if d0 > 0 {
		fmt.Println(0)
		return
	}

	xm := make(map[int]int, n)
	for i := 1; i < n; i++ {
		d := scanInt()
		xm[d]++
	}

	const mod = 998244353
	ans := 1
	for k, v := range xm {
		if k-1 != 0 && xm[k-1] == 0 {
			fmt.Println(0)
			return
		}

		if xm[k-1] >= 2 {
			for i := 0; i < v; i++ {
				ans *= xm[k-1]
				ans %= mod
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int n, k, ans = 0;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> a(1, 1);
	for (int i = 1; i < n; ++i) {
		if (s[i] == s[i - 1]) {
			a.back() += 1;
			ans += 1;
		}
		else {
			a.push_back(1);
		}
	}
	ans += min((int)a.size() - 1, 2 * k);
	cout << ans;
}

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

int		main(void)
{
	int N, max, tmp;

	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	for (int i = 0; i < N - 1; i++)
	{
		max = i;
		for (int j = i + 1; j < N; j++)
		{
			if (a[max] < a[j])
				max = j;
		}
		tmp = a[i];
		a[i] = a[max];
		a[max] = tmp;
	}
	int sum = 0, A = 0;

	for (int i = 0; i < N; i ++)
		sum += a[i];
	for (int i = 0; i < N; i += 2)
		A += a[i];
	cout << A - (sum - A) << endl;
}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll p[1005];
ll n[1005];

int main() {
	ll x; cin >> x;
	for(int i=0;i<=1000;i++){
		p[i] = i;
		n[i] = (-1)*i;
		for(int j=1;j<5;j++){
			p[i] *= i%MOD;
			n[i] *= i%MOD;
		}
	}
	ll a = 0LL;
	ll b = 0LL;
	for(int i=0;i<=1000;i++){
		for(int j=0;j<=1000;j++){
			if(p[i]-p[j]==x){
				a = i;
				b = j;
				cout << a << ' ' << b << endl;
				return 0;
			}
			if(p[i]-n[j]==x){
				a = i;
				b = j*(-1);
				cout << a << ' ' << b << endl;
				return 0;
			}
			if(n[i]-n[j]==x){
				a = i*(-1);
				b = j*(-1);
				cout << a << ' ' << b << endl;
				return 0;
			}
		}
	}
	cout << a << ' ' << b << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 100000, MAX_K = 1000;

int N, K;
int fld[2*MAX_K][2*MAX_K], S[4*MAX_K+1][4*MAX_K+1], S_mod[2*MAX_K+1][2*MAX_K+1];

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

  int ox, oy;
  rep( i, N )
  {
    int x, y;
    char c;
    scanf( "%d%d %c", &x, &y, &c );

    if( c == 'W' )
      y += K;

    x %= 2*K;
    y %= 2*K;
    //++fld[(x+add)%(2*K)][y%(2*K)];
    //++fld[x%(2*K)][(y+add)%(2*K)];
    
    ++S[x][y];
    --S[x][y+K];
    --S[x+K][y];
    ++S[x+K][y+K];

    ++S[x+K][y+K];
    --S[x+K][y+2*K];
    --S[x+2*K][y+K];
    ++S[x+2*K][y+2*K];

    /*nx = (x+add)%(2*K), ny = y%(2*K);
    left = std::max( 0, nx-K ), bottom = std::min( 2*K-1, ny+K );
    
    ++S[left][ny];
    --S[nx+1][ny];
    --S[left][bottom];
    ++S[nx+1][bottom];*/
  }

  rep( i, 4*K+1 ) rep( j, 4*K )
    S[i][j+1] += S[i][j];
  rep( i, 4*K ) rep( j, 4*K+1 )
    S[i+1][j] += S[i][j];

  rep( i, 4*K ) rep( j, 4*K )
    S_mod[i%(2*K)][j%(2*K)] += S[i][j];

  int ans = 0;
  rep( i, 2*K ) rep( j, 2*K )
    ans = std::max( ans, S_mod[i][j] );

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

  return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define endl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using P = pair<ll, ll>;

/*追加部分*/



/*main関数*/

int main() {
FASTIO;
    ll x, y; cin >> x >> y;
    vector<ll> ans;
    ans.pb(x);

    while(true){
        if(x*2 <= y){
            x *= 2;
            ans.pb(x);
        }
        else{
            break;
        }
    }

    cout << (int)ans.size() << endl;

return 0;
}

Measured memory_bytes: 3660
import numpy as np
N, D = map(int, input().split())
coords = np.array([np.array([int(i) for i in input().split()]) for _ in range(N)])
ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    a = coords[i]
    b = coords[j]
    d = np.linalg.norm(a-b)
    ans += d == d.astype(np.integer)
    
print(ans)

Measured memory_bytes: 12448
#include<stdio.h>

int main(void){

char s[100];

scanf("%s",&s);

int i,count=0;

for(i=0;i<100;i++){
if(s[i]=='\0'){break;}
}

  for(int j=0;j<i/2;j++){
    if(s[j]!=s[i-j-1]){count++;}
}

printf("%d",count);

return 0;
}


Measured memory_bytes: 1732
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define mp make_pair
#define pb push_back
#define FI first
#define SE second
#define FOR(i,a,b) for(int (i)=((int)a); (i)<((int)b); (i)++) // [a,b)
#define REP(i,N) FOR((i), 0, ((int)N)) // [0,N)
#define INF (1 << 30)
#define iMACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
#define icin1(_1) int _1; cin >> _1
#define icin2(_2, ...) int _2; cin >> _2; icin1(__VA_ARGS__)
#define icin3(_3, ...) int _3; cin >> _3; icin2(__VA_ARGS__)
#define icin4(_4, ...) int _4; cin >> _4; icin3(__VA_ARGS__)
#define icin5(_5, ...) int _5; cin >> _5; icin4(__VA_ARGS__)
#define icin6(_6, ...) int _6; cin >> _6; icin5(__VA_ARGS__)
#define icin7(_7, ...) int _7; cin >> _7; icin6(__VA_ARGS__)
#define icin8(_8, ...) int _8; cin >> _8; icin7(__VA_ARGS__)
#define icin9(_9, ...) int _9; cin >> _9; icin8(__VA_ARGS__)
#define icin(...) iMACRO(__VA_ARGS__,icin9,icin8,icin7,icin6,icin5,icin4,icin3,icin2,icin1)(__VA_ARGS__)
#define lcin(x) ll x; cin >> x
#define dcin(x) double x; cin >> x
#define scin(s) string s; cin >> s
#define aout(x) cout << x << endl
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vcin(v,N) vi v(N); REP(i,N) cin >> v[i]
#define vcinl(v,N) vl v(N); REP(i,N) cin >> v[i]
#define vmax(v) *max_element(all(v)) // 遅い？いつか書き直す
#define vmin(v) *min_element(all(v))
#define vidx(v,it) distance((v).begin(),(it))
#define vsum(v) accumulate(all(v),0)
#define vsumr(v,a,b) accumulate((v).begin()+(a),(v).begin()+(b),0) //[a,b)
#define vfnd(v,val) find(all(v),val) // itrを返す。存在しない場合v.end()を返す
#define vcnt(v,val) count(all(v),val)
#define vrep(v,it) for(auto it=(v).begin(); it != (v).end(); ++it)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0) // IOS;で高速化

// デバッグ用
// dbg(...) printfと同様に使用可能 
// trc(var) (変数名)=(値)と表示
// stopif(val) 条件分が真の時に止まる
// vdbg(v) vの中身を表示
#ifdef LOCAL
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
    #define trc(var) cout << #var << "=" << var << endl
    #define trc2(v) cout << #v << "={"
    #define stopif(val) assert( !(val) )
    #define vdbg(v) vector_debug(v)
#else
    #define dbg(...) 1
    #define trc(var) 1
    #define trc2(v) 1
    #define stopif(val) 1
    #define vdbg(v) 1
#endif

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > vvi;
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}
ll gcd(ll a, ll b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}
template<typename C> inline void vector_debug(vector<C> v){trc2(v);ostream_iterator<C> o(cout,",");copy(all(v),o);cout<<"}"<<endl;}
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

// icin(x)    int x; cin >> x;
// vcin(A,N)  vi(vl) Aを宣言してcinで初期化
// aout(x)    cout << x << endl;

int main(){ IOS;
    icin(x,y);
    aout(x+y/2);
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
struct UnionFind {
	vector<int> par;
	vector<int> sizes;

	UnionFind(int n) {
		par.resize(n);
		sizes.resize(n);
		REP(i, n) {
			par[i] = i;
			sizes[i] = 1;
		}
	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return;
		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
	}
	int size(int x) {
		return sizes[root(x)];
	}
};


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi p(n);
	REP(i, n) {
		cin >> p[i];
		p[i]--;
	}
	UnionFind uf(n);
	vi x(m), y(m);
	REP(i, m) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
		uf.unite(x[i], y[i]);
	}
	vvi a(n), b(n);
	REP(i, n) {
		a[uf.root(i)].push_back(i);
		b[uf.root(i)]. push_back(p[i]);
	}

	REP(i, n) {
		sort(ALL(a[i]));
	}
	REP(i, n)sort(ALL(b[i]));

	int ans = 0;
	REP(i, n) {
		int j = 0, k = 0;
		while (j < a[i].size() && k < b[i].size()) {
			if (a[i][j] == b[i][k]) {
				ans++;
				j++;
				k++;
			}else if (a[i][j] < b[i][k]) {
				j++;
			}
			else {
				k++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 13184
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		String s=nextLine();
		int n=s.length();
		if(s.charAt(0)==s.charAt(n-1))
			out.println(n%2==0?"First":"Second");
		else
			out.println(n%2==0?"Second":"First");
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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


int main(){
    int N;
    cin >> N;
    ll ans;
    cin >> ans;
    for(int i = 1; i < N; i++){
        ll b;
        cin >> b;
        ll temp = gcd(max(ans,b),min(ans,b));
        ans = ans / temp * b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  long long int i,j,k,l;
  long long int N,M;
  long long int space;
  long long int A,B,C,D,K;
  scanf("%ld %ld %ld %ld",&A,&B,&C,&K);
  
  if( A >= K ){
    printf("%ld\n",K);
  }
  else if( (A+B) >= K ){
    printf("%ld\n",A);
  }
  else{
    D = K - (A+B);
    space = A - D;
    printf("%ld\n",space);
  }
 
  return 0; 
  
}

Measured memory_bytes: 1732
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
  
int main(){
    bigint N , M , K  ; cin >> N >> M >> K ;
    vll arr , brr ;
    arr.push_back(0) ;
    for( int i = 1 ; i <= N ; i++ ){
        int x ; cin >> x ;
        arr.push_back(arr[i-1]+x) ;
    }
    bigint x ; cin >> x ;
    brr.push_back(x) ;
    for( int i = 1 ; i < M ; i++ ){
        cin >> x ;
        brr.push_back(x+brr[i-1]) ;
    }
    bigint ans = 0 ;
    for( bigint i = 0 ; i <= N ; i++ ){
        bigint bacha = K - arr[i] ;
        if( bacha < 0 )
            break ;
        auto idx = upper_bound(brr.begin(), brr.end(), bacha ) - brr.begin() ;
        ans = max( ans , i + idx ) ;
    }
    cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 8008
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>


using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef map<string,int> si;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}


vector<int> used;
vector<vector<int>> connect;
int n,m;
vector<int> a,b;

bool dfs(int now, int bridge) {
    bool ret=true;

    queue<int> st;
    st.emplace(now);
    while(st.size()>0){
        int e = st.front();
        st.pop();
        used[e]=1;

        REP(i,0,n){
            if(connect[e][i]==1 && used[i]!=1) if(a[bridge]!=min(e,i) || b[bridge]!=max(e,i)) st.push(i);
        }
    }
    REP(i,0,n) if(used[i]!=1) {ret = false;}
    used = vector<int>(n,0);

    return ret;
}

int atcoder() {
    cin >> n >> m;
    REP(i,0,m){
        int tmpa,tmpb;
        cin >> tmpa >> tmpb;
        a.push_back(tmpa);
        b.push_back(tmpb);
        a[i]--; b[i]--;
    }
    int ans=0;

    
    used = vector<int>(n,0);
    connect = vector<vector<int>> (n,vector<int>(n,0));
    REP(i,0,m) connect[a[i]][b[i]] = connect[b[i]][a[i]] = 1;
    
    REP(i,0,m) if(!dfs(0,i)) ans++;
    cout << ans << ENT;

    return 0;
}

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


Measured memory_bytes: 256
#/bin/sh
read A B C D
SUM1=`expr $A \* $B`
SUM2=`expr $C \* $D`

if [ $SUM1 -gt $SUM2 ]; then
 echo $SUM1
elif [ $SUM1 -lt $SUM2 ]; then
   echo $SUM2
else
   echo $SUM1
fi

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

using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	string xa="";
	string xb="";
	for(int i=1;i<=a;i++){
		xa+=char('0'+b);
	}
	for(int i=1;i<=b;i++){
		xb+=char('0'+a);
	}
	cout<<min(xa,xb)<<endl;
	return 0;
}


Measured memory_bytes: 256
#import numpy as np
import sys
#from collections import deque
#import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


x = xnxn()

for i in range(5):
    if x[i] == 0:
        print(i+1)


Measured memory_bytes: 9136
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



int main() {
	cout << fixed << setprecision(18);
	long double d,res=0;
	cin>>d;
	if(d>=1.0&&sqrt(d*d-(int)d*(int)d)<=1)res=(int)d+1.0;
	res=max(res,d*sqrt(2));
	cout<<res<<endl;
	
} 


Measured memory_bytes: 3360
n = int(input())
s = []
c1 = 0 
c2 = 0
c3 = 0
c4 = 0
for i in range(n):
    s.append(input()) 
    if s[i] == 'AC':
        c1 += 1
    elif s[i] == 'WA':
        c2 += 1
    elif s[i] == 'TLE':
        c3 += 1
    elif s[i] == 'RE':
        c4 += 1

print('AC x',c1)
print('WA x',c2)
print('TLE x',c3)
print('RE x',c4)

Measured memory_bytes: 16332
#include<stdio.h>
int main (){
  int a,b;
  scanf("%d %d",&a,&b);

  if(a < b){
    printf("a < b\n");
  }
  if( a ==b ){
    printf("a == b\n");
      }
  if (a > b){
    printf("a > b\n");
  }

  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	int ans=0;
	if(x==1)ans+=300000;
	else if(x==2)ans+=200000;
	else if(x==3)ans+=100000;
	if(y==1)ans+=300000;
	else if(y==2)ans+=200000;
	else if(y==3)ans+=100000;
	if(x==1&&y==1)ans+=400000;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
counter = 0
summention = 0
minus = []
for i in range(n):
    if a[i] < 0:
        summention += -a[i]
        counter += 1
        minus.append(-a[i])
    else:
        summention += a[i]
        minus.append(a[i])

if counter%2 == 0:
    print(summention)
else:
    print(summention-2*min(minus))

Measured memory_bytes: 14252
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        prime = self.sieve(110000)
        while True:
            n, p = map(int, raw_input().split())
            if n == -1 and p == -1:
                break
            l = [e for e in prime if e > n]
            s = []
            for i in range(100):
                for j in range(100):
                    if i < j:
                        continue
                    s.append(l[i] + l[j])
            s.sort()
            print s[p-1]
            
        
        return None

    def sieve(self, n):
        f = [True for i in xrange(n+1)]
        f[0] = False
        f[1] = False
        i = 2
        while i * i <= n:
            if f[i]:
                j = 2
                while i * j <= n:
                    f[i * j] = False
                    j += 1
            i += 1
        return [i for i in xrange(n+1) if f[i]]
        

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 5676
//package cp;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
	long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
	void swap(long a,long b) {long temp=a;a=b;b=temp;}
	StringBuilder sb=new StringBuilder();
	Integer[] ARR=new Integer[5];
	//Integer sort-TLE-Initialize object elements i.e a[0].
	long ceil(double n) {
//		System.out.println(n);
		return (long)Math.ceil(1.0*n);}
	void divisor(long n,int start) {
		int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
		if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
	
	public static void main(String[] args) throws IOException {	
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		Main obj=new Main();
		int n=Readers.nextInt();
		int k=Readers.nextInt();
		int[] a=new int[n];
		ArrayList<BigInteger> arr=new ArrayList<>();
		for (int i = 0; i < a.length; i++) {
			a[i]=Readers.nextInt();
		}
		for(int i = k; i < n; i++){
			if(a[i] > a[i - k])System.out.println("Yes");
			else System.out.println("No");
		}
		out.flush();
	}
}
class Readers {
 
    static BufferedReader reader;
 
    static StringTokenizer tokenizer;
 
 
 
    /** call this method to initialize reader for InputStream */
 
    static void init(InputStream input) {
 
        reader = new BufferedReader(
 
                     new InputStreamReader(input) );
 
        tokenizer = new StringTokenizer("");
 
    }
 
 
 
    /** get next word */
 
    static String next() throws IOException {
 
        while ( ! tokenizer.hasMoreTokens() ) {
 
            //TODO add check for eof if necessary
 
            tokenizer = new StringTokenizer(
 
                   reader.readLine() );
 
        }
 
        return tokenizer.nextToken();
 
    }
 
 
 
    static int nextInt() throws IOException {
 
        return Integer.parseInt( next() );
 
    }
 
	
 
    static double nextDouble() throws IOException {
 
        return Double.parseDouble( next() );
 
    }
    
    
    static long nextLong() throws IOException{
    	
		return Long.parseLong(next());
	}
 
}


Measured memory_bytes: 84584
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
template <typename Tu>
static inline constexpr bool is_multiplication_safe(Tu a, Tu b) {
  return !a || b <= std::numeric_limits<Tu>::max() / a;
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll z = c - a - b;

  string ans = ((4 * a * b) < (z * z)) ? "Yes" : "No";
  string ans2 = (2 * sqrt(a) * sqrt(b) < z) ? "Yes" : "No";
  string finalans;

  if (is_multiplication_safe(z, z)) {
    finalans = ans;
  } else {
    finalans = ans2;
  }

  cout << finalans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
 
N = int(input())
ans = len(make_divisors(N-1))-1
lis = make_divisors(N)
for n in lis:
    G = N
    if n==1:
        continue
    while G%n==0:
        G //= n
    if G%n==1:
        ans += 1
print(ans)

Measured memory_bytes: 65508
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    forn(i, n) cin >> a[i];
    forn(i, n) cin >> b[i];
    sort(all(a));
    sort(all(b));
    ll ans = 1;
    int j = 0;
    for (int i = 1; i < n; i++)
    {
        while (max(a[j], b[j]) < min(a[i], b[i])) j++;
        ans = ans * (i - j + 1) % MOD;
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0; i<n; i++)
		cin >> h[i];
	int num=1;
	for(int i=n-1; i>0; i--){
		for(int j=i-1; j>=0; j--){
			if(h[j]>h[i])
				break;
			if(j==0)
				num++;
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;cin >> n;
	__int128_t ans = 1;
	__int128_t inf = LLINF;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	sort(ALL(v));
	REP(i, n){
		ans *= v[i];
		if(ans > inf){
			cout << -1 << endl;
			return 0;
		}
	}

	cout << (ll)ans << endl;

	return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a >= 10 || b >= 10) cout << -1 << endl;
    else cout << a * b << endl;
    return 0;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    if((k-x/d)<0)
    {
        cout << x-k*d << endl;
        return 0;
    }else
    {
        if((k-(x/d))%2==0)
        {
            cout << abs(x-d*(x/d)) << endl;
            return 0;
        }else
        {
            cout << abs(x-d*((x/d)+1)) << endl;
            return 0;
        }
        
    }
    

}

Measured memory_bytes: 3612
import math
import heapq

N, M = list(map(int, input().split()))
A = list(map(lambda a: -int(a), input().split()))
A.sort()
heapq.heapify(A)

for i in range(M):
  a = heapq.heappop(A)
  a = -(-a / 2.0)
  heapq.heappush(A, a)

amount = 0
for a in A:
  amount += math.floor(-a)
print(amount)

Measured memory_bytes: 14380
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
typedef long long ll;

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

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define clr(a) memset(a,0,sizeof(a))
#define reset(a) memset(a,-1,sizeof(a))
#define mod 1000000007
#define pi acos(-1)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

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


int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    fastio
    
    vector<pair<int,int> > vec;
    int n,a,b;
    cin>>n;
    int tmp = n;
    while(n--){
        cin>>a>>b;
        vec.pb({a,b});
    }

    for(int i=0; i<tmp-2; i++){
        int j=i+1;
        int k = i+2;
        if(vec[i].first == vec[i].second && vec[j].first == vec[j].second && vec[k].first == vec[k].second){
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	for(int i=0;i<=10000;i++){
		for(int j=-10000;j<=-1;j++){
			if(i*i*i*i*i-j*j*j*j*j==x){
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
	}
	for(int i=0;i<=10000;i++){
		for(int j=10000;j>=0;j--){
			if(i*i*i*i*i-j*j*j*j*j==x){
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
	}
	for(int i=-10000;i<=-1;i++){
		for(int j=-1;j>=-10000;j--){
			if(i*i*i*i*i-j*j*j*j*j==x){
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
	}
}


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

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

  string S; cin >> S;
  int K; cin >> K;

  int len = S.size();
  int K_MAX = 4;
  vector<vector<ll>> eq(len, vector<ll>(K_MAX + 1, 0));
  vector<vector<ll>> lt(len, vector<ll>(K_MAX + 1, 0));

  eq[0][1] = 1;
  lt[0][1] = S[0] - '1';
  lt[0][0] = 1;

  for (ll i = 1; i < len; i++) {
    int d = S[i] - '0';
    if (d == 0) {
      for (ll k = 0; k < K_MAX; k++) {
        eq[i][k] += eq[i - 1][k];
      }
    } else {
      for (ll k = 0; k < K_MAX; k++) {
        eq[i][k + 1] += eq[i - 1][k];
        lt[i][k + 1] += eq[i - 1][k] * (d - 1);
        lt[i][k] += eq[i - 1][k];
      }
    }

    for (ll k = 0; k < K_MAX; k++) {
      lt[i][k + 1] += lt[i - 1][k] * 9;
      lt[i][k] += lt[i - 1][k];
    }
  }

  cout << (eq[len - 1][K] + lt[len - 1][K]) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;
string s;
long long int dps[100001][3][3];
string t = "ABC";
int questioncnt = 0;
long long int fastexp(long long int b, int e) {
	long long int ans = 1;
	while (e != 0) {
		if (e % 2) {
			ans *= b;
			ans %= MOD;
		}
		b *= b;
		b %= MOD;
		e /= 2;
	}
	return ans;
}

long long int dp(int index, int letter, int cnt) {
	if (letter == 3)
		return fastexp(3, questioncnt - cnt);
	else if (index >= s.length())
		return 0;
	if (dps[index][letter][cnt] == -1) {
		if (s[index] == t[letter])
			dps[index][letter][cnt] = (dp(index + 1, letter + 1, cnt) + dp(index + 1, letter, cnt)) % MOD;
		else if (s[index] == '?')
			dps[index][letter][cnt] = (dp(index + 1, letter + 1, cnt + 1) + dp(index + 1, letter, cnt)) % MOD;
		else dps[index][letter][cnt] = dp(index + 1, letter, cnt);
	}
	return dps[index][letter][cnt];
}

int main() {
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '?')
			questioncnt++;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				dps[i][j][k] = -1;
			}
		}
	}
	cout << dp(0, 0, 0) << endl;
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int n, q;
	cin >> n >> q;
	ll black = (ll)(n-2)*(n-2);
	vi a(n+1, n), b(n+1, n);

	int h = n, w = n;

	while(q--){
		int k, x;
		cin >> k >> x;
		if(k==1){
			if(x < w){
				FOR(i,x,w){
					b[i] = h;
				}
				w = x;
			}
			black -= b[x] - 2;
		}
		else{
			if(x < h){
				FOR(i,x,h){
					a[i] = w;
				}
				h = x;
			}
			black -= a[x] - 2;
		}
	}

	cout << black << endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 6368
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <time.h>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> Pii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const LL mod = 1000000007;
const int N = 1e5 + 5;
const double Pi = acos(-1.0);
const int maxn = 2e5 + 5;
LL f(LL a,LL b){
    return ((b % a == 0) ? a * 2 * (b / a) - a : a * 2 * (b / a) +  f(b%a,a));
}
int main() {
#ifdef local
    freopen("in", "r", stdin);
    //  freopen("w","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    LL n,x;
    cin>>n>>x;
    cout<< n + f(x,n - x)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int w,h;
	while(cin>>h>>w){
		if(w==0&&h==0) break;
		int t=w*w+h*h,a=0,ww=w,hh=h;
		while(a==0){
			while(pow(t-(hh+1)*(hh+1),0.5)>(hh+1)){
				hh++;
				ww=pow(t-hh*hh,0.5);
				if(ww*ww+hh*hh==t){
					a++;
					break;
				}
			}
			if(a==0){
				t++;
				hh=1;
				ww=pow(t-hh*hh,0.5);
				if(ww*ww+hh*hh==t){
					a++;
				}
			}
		}
		cout<<hh<<" "<<ww<<endl;
	}
    return 0;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input! {
        n: usize, m: usize,
        c: [i64; m]
    }
    // dp_table[i] => i円を支払うのに必要なコインの最小枚数
    // dp_table[i] = min(dp_table[i], dp_table[i - value] + 1
    let mut dp_table = vec![1000000007; n + 1];
    dp_table[0] = 0;
    for i in 1..n + 1 {
        for &j in &c {
            if j <= i as i64 {
                dp_table[i] = min(dp_table[i], dp_table[i - (j as usize)] + 1)
            }
        }
    }
    println!("{}", dp_table[n]);
}


Measured memory_bytes: 5032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>

using namespace std;

int main()
{
    int n;
    vector<double> v;
    

    cin >> n;

    for (int i = 0; i < n; i++) {
        double a;
        cin >> a;
        v.push_back(a);
    }

    while (v.size() != 1) {
        sort(v.begin(), v.end());
        v.push_back((v[0]+v[1])/2.0);
        v.erase(v.begin());
        v.erase(v.begin());
    }

    printf("%.14lf\n", v[0]);
}


Measured memory_bytes: 256