akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int N = (int)2*1e5;
int a[N];
int n;
int pre[N], suf[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	pre[0] = a[0];
	for (int i = 1; i < n; i++) {
		pre[i] = __gcd(pre[i-1], a[i]);
	}
	suf[n-1] = a[n-1];
	for (int i = n-2; i >= 0; i--) {
		suf[i] = __gcd(suf[i+1], a[i]);
	}

	int r = max(pre[n-2], suf[1]);
	for (int i = 1; i < n-1; i++) {
		r = max(r, __gcd(pre[i-1], suf[i+1]));
	}
	cout << r << endl;
}


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

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

	int A;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> A;
		A--;
		a[A]++;
	}

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

	int ans = 0;
	for (int i = 0; i < n - k; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	

	return 0;
}

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

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

using namespace std;

const ll MOD = 998244353;
const int MAXN = 300100;
ll fak[MAXN];

ll mul(ll a, ll b) {
  return (a * b) % MOD;
}

ll add(ll a, ll b) {
  return (a + b) % MOD;
}

ll pow(ll x, ll a) {
  ll out = 1, pot = x;
  while (a) {
    if (a & 1) out = mul(out, pot);
    pot = mul(pot, pot);
    a >>= 1;
  }
  return out;
}

ll choose(ll n, ll k) {
  return mul(fak[n], mul(pow(fak[k], MOD - 2), pow(fak[n - k], MOD - 2)));
}

int main() {
  ios_base::sync_with_stdio(false);

  fak[0] = 1;
  FOR(i, 1, MAXN) fak[i] = mul(fak[i - 1], i);

  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  ll out = 0;
  REP(i, n + 1) {
    ll tr = k - a * i;
    ll j = tr / b;
    if (tr % b != 0) continue;
    if (i > n || j > n || j < 0) continue;
    out = add(out, mul(choose(n, i), choose(n, j)));
  }

  cout << out << "\n";

  return 0;
}

Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
    #define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	 const int N =1e5;
    
     int mod= 998244353;
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};  
    
	 
 
     void solve(){
        int n;
        cin>>n;
        vi v(n,0);
        int sum=0,maxi=1e18;
        rep(i,0,n) {
			cin>>v[i];
		}
		
		
		rep(i,1,101) {
			 int nv=0;
			    rep(j,0,n) {
					    int nax=abs(v[j]-i);
					    nax*=nax;
					    nv+=nax;
					}
					if(nv<maxi)
					 maxi=nv;
			}
			
			cout<<maxi<<endl;  
	 }
	
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, K := sc.nextInt(), sc.nextInt()
	H := sc.nextIntSlice(N)
	sort.Ints(H)
	ans := 0
	for i := N - 1; i >= 0; i-- {
		if K > 0 {
			K--
		} else {
			ans += H[i]
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 4736
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

signed main()
{
    string s;
    cin>>s;
    if(s == "AAA" || s == "BBB")
    {
        puts("No");
    }
    else puts("Yes");
    return 0;
}

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

#define f(i,n) for(i=0;i<n;i++)
#define vi vector<int>

int main()
{
    int n, i;
    cin >> n;
    vi v(n);
    f(i,n ) cin >> v[i];
    priority_queue<int,vector<int>, greater<int>>pq;
    int toko = 0;
    f(i,n)
    {
        if(i==0) toko++;
        else
        {
            bool b=true;
            if(pq.top() < v[i]) b = false;

            if(b) toko++;
        }

        pq.push(v[i]);
        
    }

    cout << toko;
}

Measured memory_bytes: 2168
#include<stdio.h>
int main()
{ int N,M;
 int i,j;
 int count=0;
 scanf("%d%d",&N,&M);
 for(i=1;i<N;i++)
 { 
   for(j=i+1;j<=N;j++)
  { 
     count++;
  }
 } 
  for(i=1;i<M;i++)
 { 
    for(j=i+1;j<=M;j++)
  { 
    count++;
  }
 } 
 printf("%d",count);
 return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM =  1000000007;

int main()
{
    // 整数の入力
    ll N,A;
    vector<map<int,int>> shougens;
    cin >> N;
    for(int i = 0;i< N;i++){
        cin >> A;
        map<int,int> shougen;
        for(int j = 0;j< A;j++){
            ll x,y;
            cin >> x >> y;
            x--;
            shougen[x] = y;
        }
        shougens.push_back(shougen);
    }

    ll best = 0;
    for (int bit = 0; bit < (1<<N); ++bit) {
        bool is_clear = true;
        ll clear_count = 0;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) {
                clear_count++;
                for (auto p: shougens[i]){
                    ll x = p.first;
                    ll y = p.second;
                    if ( (bit & (1<<p.first)) && y == 0){
                        is_clear = false;
                        break;
                    }else if(!(bit & (1<<p.first)) && y == 1){
                        is_clear = false;
                        break;
                    }
                }
            }
        }
        if (is_clear){
            best = max(best,clear_count);
        }
    }
    cout << best << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

long N, M;
vector<pair<long, long>> AB;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  AB.resize(N);
  for (long i = 0; i < N; i++) {
    long ai, bi;
    cin >> ai >> bi;
    AB[i] = make_pair(ai, bi);
  }
  sort(AB.begin(), AB.end());

  long ans = 0;
  for (long i = 0; i < N; i++) {
    if (AB[i].second < M) {
      M -= AB[i].second;
      ans += (AB[i].first * AB[i].second);
    } else {
      ans += (AB[i].first * M);
      M = 0;
      break;
    }
  }

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

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> dp(n,INT_MAX),h(n);
    for (int i = 0;i < n;++i) cin >> h[i];
    dp[0] = 0;
    for (int i = 1;i < n;++i) for (int j = max(0,i-k);j < i;++j) dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
int main(){
  int S,h,m,s, t;
  scanf("%d",&S);
   
  h=S/3600;
  t=S%3600;
  m=t/60;
  s=t%60;
 
printf("%d:%d:%d\n",h,m,s);
 
return 0;
}


Measured memory_bytes: 2096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            int ans = -1;
            int num = 0;
            for (int i = 1; i <= k; i++) {
                num = (10 * num + 7) % k;
                if (num == 0) {
                    ans = i;
                    break;
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35836
N, K = map(int, input().split())
x = list(map(int, input().split()))
L = [0]*(N-K+1) 

for i in range(N-K+1):
    L[i] = min((abs(x[i])+abs(x[i+K-1]-x[i])),(abs(x[i+K-1])+abs(x[i+K-1]-x[i])))
        
print(min(L))

Measured memory_bytes: 14384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<cmath>
#include<iomanip>
using namespace std;

int main(void){
	int v,j,i,A[1000],N;
	cin>>N;
	for(int x=0;N>x;x++){
		cin>>A[x];
	}for(int x=0;N>x;x++){
		cout<<A[x];
		if(x!=N-1){
			cout<<" ";
		}else{
			cout<<endl;
		}}
	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
			A[j+1]=v;
		}
		for(int x=0;N>x;x++){
			cout<<A[x];
			if(x!=N-1){
				cout<<" ";
			}else{
				cout<<endl;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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 <typename F,typename T>
struct SegTree{
  // 二項演算merge,単位元identify
  T identity;
  F merge; 
  int size;
  vector<T> dat;
  
  // 二項演算fと単位元idを渡して宣言する
  SegTree(F f,T id):merge(f),identity(id){}

  // データの要素の数nを渡して初期化、sizeはnより大きい2の冪乗
  void init(int n){
    size = 1;
    while(size<=n) size *= 2;
    dat.resize(size*2-1,identity);
  }

  // 配列を渡して0(n)で初期化
  void build(vector<T> vec){
    rep(i,vec.size()) dat[size-1+i] = vec[i];
    dfs(0);
  }
  
  T dfs(int k){
    if(k>=size-1) return dat[k];
    else return dat[k] = merge(dfs(2*k+1),dfs(2*k+2));
  }

  // index kの要素をaに変更
  void update(int k,T a){
    k += size - 1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  // 区間[a,b)に対するクエリに答える。(k,l,r)=(0,0,size)
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return identity;
    
    if(a<=l&&r<=b) return dat[k]; 
    else return merge(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<size){
      rep(i,num){
	if(dat[i+index]==identity) cout << "e ";
	else cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
  }
  
};

vector<int> compress(vector<int> a) {
  int n = a.size();
  vector<int> vals;
  rep(i,n) vals.push_back(a[i]);

  sort(vals.begin(), vals.end());
  vals.erase(unique(vals.begin(), vals.end()), vals.end());

  vector<int> res;
  rep(i,n) {
    int id = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
    res.push_back(id);
  }

  return res;
}

int LIS(vector<int> a) {
  int n = a.size();
  a = compress(a);
  
  auto f = [&](int a, int b) { return max(a, b); };
  int id = 0;
  SegTree<decltype(f), int> seg(f, id);
  seg.init(n);
  int res = 0;
  rep(i,n) {
    int x = seg.query(0, a[i], 0, 0, seg.size);
    seg.update(a[i], x+1);
    chmax(res, x+1);
  }
  return res;

}

int main()
{
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  cout << LIS(a) << "\n";
  return 0;
}



Measured memory_bytes: 4996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(), a.end());
  int res = (a[1] - a[0]) + (a[2] - a[1]);
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define ld long double
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
} 

void solve(){
	lli n; cin >> n;
	vi a(n);
	NA(i,0,n) cin >> a[i];
	lli sm = 0, ans = 0;
	for(lli i=n-1; i>-1; --i) {
		ans = (ans + ((sm * a[i]) % MOD)) % MOD;
		sm = (sm + a[i]) % MOD;
	}
	cout << ans;
	return;
}

int main(){
    fastIO;
    lli t = 1;
	// cin >> t;
	NA(i,0,t) {
		// cout << "Case #" << i+1 << ": "; 
		solve();
	}
	return 0;
}



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

int main(){
	string s,t;
	cin >> s >> t;
	REP(i,s.length()){
		char mem = s[0];
		REP(i,s.length() - 1){
			s[i] = s[i + 1];
		}
		s[s.length() - 1] = mem;
		if(s == t){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

struct BinaryIndexedTree{
    private:
    vector<int> dat;
    public:
    BinaryIndexedTree(int n_){
        dat.resize(++n_,0);
    }
    void add(int a,int w){
        for (int i=a;i<=dat.size();i+=i&-i) dat[i]+=w;
    }
    int sum(int a){
        int res=0;
        for (int i=a;i>0;i-=i&-i) res+=dat[i];
        return res;
    }
    int binarysearch(int w){
        if (w<=0) return 0;
        int x=0;
        int n=1;
        while(n*2<=dat.size()) n*=2;
        for (int k=n;k>0;k/=2){
            if (x+k<=n&&dat[x+k]<w){
                w-=dat[x+k];
                x+=k;
            }
        }
        return x;
    }
};

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
        a[i]-=K;
    }
    vector<ll> sum(N+1);
    sum[0]=0;
    rep(i,N) sum[i+1]=sum[i]+a[i];
    vector<ll> compress=sum;
    sort(compress.begin(),compress.end());
    compress.erase(unique(compress.begin(),compress.end()),compress.end());
    rep(i,N+1) sum[i]=lower_bound(compress.begin(),compress.end(),sum[i])-compress.begin()+1;
    ll s=compress.size();
    BinaryIndexedTree BIT(++s);
    ll ans=0;
    rep(i,N+1){
        ans+=BIT.sum(sum[i]);
        BIT.add(sum[i],1);
    }
    cout << ans << endl;
}

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

int N;
int A[100010];
int MAX = 0,MIN = 100000;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d",&A[i]);
        if(MAX < A[i])
        {
            MAX = A[i];
        }
        if(MIN > A[i])
        {
            MIN = A[i];
        }
    }
    printf("%d\n",MAX - MIN);
    return 0;
}


Measured memory_bytes: 256
#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;
#define ld           long double
#define vi           vector<int>
#define pii          pair<int,int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
#define int          long long
const int INF = 0x3F3F3F3F3F3F3F3F;
const int MOD = 998244353;
ld EPS = 1e-12;


int modexp(int base, int exp)
{
    int res = 1;
    while( exp>0 )
    {
        if( exp&(int)1 ) res *= base, res %= MOD;
        base *= base, base %= MOD, exp >>= (int)1;
    }
    return res;
}

// Extended Euclidean Algorithm ax + by = gcd(a,b)
// returns gcd and stores x and y
int exgcd(int a, int b, int &x, int &y)
{
    int g = a; x = 1, y = 0;
    if( b ) g = exgcd( b,a%b,y,x ), y -= (a/b)*x;
    return g;
}

// Modular Multiplicative Inverse of a (mod m)
int modinv(int a, int m)
{
    int x, y;
    exgcd( a,m,x,y );
    return ( x+m )%m;
}

const int N = 2e5 + 5;
int fact[N];

short rain()
{
    // ifstream fin("ip.txt"); ofstream fout("op.txt");
    // int t;cin>>t;rep(test,1,t)
    {
        int n, m, k;
        cin >> n >> m >> k;
        fact[0] = 1;
        rep(i,1,n)
            fact[i] = (fact[i-1]*i)%MOD;
        int ans = 0;
        rep(i,0,k)
        {
            int b = m;
            b *= modexp( m-1, n-1-i );
            b %= MOD;
            b *= fact[n-1];
            b %= MOD;
            b *= modinv( fact[i], MOD );
            b %= MOD;
            b *= modinv( fact[n-1-i], MOD );
            b %= MOD;
            ans += b;
            ans %= MOD;
        }
        cout << ans << endl;
    }

    return 0;
}

signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int start = 1000*clock()/CLOCKS_PER_SEC;
    cout << fixed << setprecision(15);           rain();
    cerr << 1000*clock()/CLOCKS_PER_SEC-start << "ms\n";
}

Measured memory_bytes: 5176
S = input()

N = len(S)

ans = 0
for i in range(2**(N-1)):
    tmp = S[0]
    for j in range(len(S)-1):
        flag = (i >> j) & 1

        if flag:
            tmp += "+" + S[j+1]
        else:
            tmp += S[j+1]

    num = list(map(int, tmp.split("+")))
    ans += sum(num)

print(ans)


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

const int inf = 1e9;
const ll linf = 1e18;

template <ll mod> class modint
{
private:
    ll x;

public:
    modint(ll x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(ll n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

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


    int n; cin >> n;
    vector<ll> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    mint ans = 0;
    
    for (int i = 1; i <= n - 1; i++) {
        static mint prob = 1;
        ans += (mint)(x[i] - x[i-1]) * prob;
        prob += mint(i + 1).inv();
    }

    mint fact = 1;
    for (int i = 2; i <= n - 1; i++) fact *= mint(i);

    ans *= fact;
    cout << ans << endl;
    return 0;
}

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

const int NMAX = 2e5 + 10;
int num[NMAX];
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d",&n);
	for(register int i = 2;i <= n;i++)
	{
		int pre;
		scanf("%d",&pre);
		num[pre]++;
	}
	for(register int i = 1;i <= n;i++)
		printf("%d\n",num[i] );
	return 0;
}

Measured memory_bytes: 4492
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

int n;
int a[N];

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	sort(a+1,a+n+1);
	int x=n,y=1;
	while(y<=a[x])x--,y++;
	x++,y--;
	bool ans=0;
	if ((a[x]-y)%2)ans=1;
	int w=x;
	while(a[w-1]>=y)w--;
	if ((x-w)%2)ans=1;
	if (ans)printf("First\n");else printf("Second\n");
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main()
{
	int a, b, c, i;
	int syou, amari, kosuu = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a;i <= b;i++) {
		syou = c / i;
		amari = c%i;
		if (amari == 0) {
			kosuu++;
		}
	}
	printf("%d\n", kosuu);
	return 0;
}

Measured memory_bytes: 2744
import java.util.*;
import java.util.stream.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),q=s.nextInt();
		int[]p=new int[n],r=new int[n];
		p[0]=-1;

		for(int i=0;i<n-1;++i) {
			int a=s.nextInt()-1;
			int b=s.nextInt()-1;
			p[b]=a;
		}
		for(int i=0;i<q;++i)
			r[s.nextInt()-1]+=s.nextInt();

		for(int i=1;i<n;++i)
			r[i]+=r[p[i]];
//		System.err.println(Arrays.toString(p));
//		System.err.println(Arrays.toString(r));
		System.out.println(Arrays.stream(r).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
	}
}


Measured memory_bytes: 158076
size_a, size_b = gets.split(" ").map(&:to_i)
image_a = size_a.times.map { gets.chomp.chars }
image_b = size_b.times.map { gets.chomp.chars }

max_idx = size_a - size_b
answer = false
(0..max_idx).each do |i|
  (0..max_idx).each do |j|
    answer = image_b == image_a[i, size_b].map { |s| s[j, size_b] }
    break if answer
  end
  break if answer
end

puts answer ? "Yes" : "No"


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

using namespace std;

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

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;


int main(void) {
    int n, m, com, s, g;
    while(cin >> n >> m >> com >> s >> g, n){
        s--,g--;
        vi x(m),y(m),d(m),c(m);
        rep(i,m){
            cin >> x[i] >> y[i] >> d[i] >> c[i];
            x[i]--,y[i]--,c[i]--;
        }


        int dp[100][100];
        rep(i,100)rep(j,100)dp[i][j] = INF;
        rep(i,100)dp[i][i] = 0;

        vi p(com);
        rep(i,com) cin >> p[i];
        rep(i,com){
            //cout << i << endl;
            vi q(p[i]-1),r(p[i]);
            rep(j,p[i]-1)cin >> q[j];
            rep(j,p[i])cin >> r[j];
            q.push_back(100*200);

            int cost[100*200+5];
            cost[0] = 0;
            int ind = 0;
            loop(j,1,100*200+5){
                if(j>q[ind])ind++;
                cost[j] = cost[j-1] + r[ind];
            }


            int v[100][100];
            rep(j,100)rep(k,100)v[j][k] = INF;
            rep(j,100)v[j][j]=0;

            rep(a,m)if(c[a] == i){
                v[x[a]][y[a]] = v[y[a]][x[a]] = min(v[x[a]][y[a]],d[a]);
            }

            rep(k,n)rep(ii,n)rep(jj,n){
                v[ii][jj] = min(v[ii][jj], v[ii][k]+v[k][jj]);
            }

            rep(ii,n)rep(jj,n)if(v[ii][jj]<INF){
                dp[ii][jj] = min(dp[ii][jj],cost[v[ii][jj]]);
            //    cout << ii << " " << jj << " cost=" << cost[v[ii][jj]]<<endl;
            }

        }


        //rep(i,n)rep(j,n)cout << i <<" " << j << " " << dp[i][j] << endl;

        rep(k,n)rep(i,n)rep(j,n){
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
        }
        if(dp[s][g] == INF)dp[s][g] = -1;
        cout << dp[s][g] << endl;
    }
}



Measured memory_bytes: 3416
from collections import defaultdict, deque

N, M = map(int, input().split())
D = {}
Edges = []


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF = UnionFind(M)
for i in range(M):
    p, q, c = map(int, input().split())
    p, q = p-1, q-1
    Edges.append((p, q))

    if (p, c) in D:
        UF.union(D[p, c], i)
    D[p, c] = i

    if (q, c) in D:
        UF.union(D[q, c], i)
    D[q, c] = i

UF.all_find()

Firm_Node = defaultdict(set)
for i in range(M):
    p, q = Edges[i]
    Firm_Node[UF.par[i]].add(p)
    Firm_Node[UF.par[i]].add(q)

G = defaultdict(list)
for firm, node in Firm_Node.items():
    for n in node:
        G[n].append(firm + N)
        G[firm + N].append(n)


def dijkstra(x):
    d = {x: 0, N-1: 10**9}
    visited = {x}

    # d, u
    queue = deque([(0, x)])

    while queue:
        u = queue.pop()[1]
        visited.add(u)

        for node in G[u]:
            d.setdefault(node, float('inf'))
            if (node not in visited) and d[node] > d[u] + 1:
                d[node] = d[u] + 1
                if d[N-1] < 10**9:
                    return d
                queue.appendleft([d[u]+1, node])
    return d


dist = dijkstra(0)
print(dist[N-1] // 2 if dist[N-1] < 2*M else -1)


Measured memory_bytes: 228204
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
//string s;
#define rep2(x,from,to) for(long long x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
int n;
int b[3];
string s;
int l[55][55];
int r[55][55];
int a[55][55];
int main()
{
    cin>>s;
    if(s[0]=='S')
    {
        cout<<"Cloudy"<<endl;
    }
    if(s[0]=='R')
    {
        cout<<"Sunny"<<endl;
    }
    if(s[0]=='C')
    {
        cout<<"Rainy"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int l,r,ce=0;
  for(int i=0;i<n;i++){
    if(s[i]=='E'){
      ce++;
    }
  }
  int cnt=0,lw,re,ans=n;
  for(int i=0;i<n;i++){
    if(s[i]=='E'){
      lw=i-cnt;
      cnt++;
      re=ce-cnt;
    }
    if(s[i]=='W'){
      lw=i-cnt;
      re=ce-cnt;
    }
    ans=min(ans,lw+re);
  }
  cout << ans << endl;
}


Measured memory_bytes: 900
def f(n, m):
    to = {}
    for _ in range(m):
        u, v = map(int, input().split())
        to.setdefault(u, [])
        to[u] += [v]
    s, t = map(int, input().split())
    vst = [[False] * 3 for _ in range(n + 1)]
    a = [s]
    vst[s][0] = True
    cnt = 0
    while a:
        b = []
        cnt += 1
        j = cnt % 3
        for ak in a:
            if ak not in to: continue
            for i in to[ak]:
                if vst[i][j]: continue
                vst[i][j] = True
                b.append(i)
            if vst[t][0]:
                print(cnt // 3)
                exit()
        a = b
    print(-1)

n, m = map(int, input().split())
f(n, m)


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

int main(){

    int N, a[100];
    cin >> N;
    for( int i = 0; i < N; i++ ) cin >> a[i];

    int Alice = 0, Bob = 0;
    sort( a, a+N, greater<int>() );

    for( int i = 0; i < N; i++ ){
        if( i%2 == 0 ) Alice += a[i];
        if( i%2 == 1 ) Bob += a[i];
    }

    cout << Alice - Bob << endl;

    return 0;

}

Measured memory_bytes: 256
N, M = map(int, input().split())
key = []
for _ in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    unlock = 0
    for i in range(1, N+1):
        if i in c:
            unlock += 2 ** (i-1)
    key.append((a, unlock))

dp = [[float('inf') for _ in range(2 ** N)] for _ in range(M + 1)]
dp[0][0] = 0
for i in range(M):
    for state in range(2 ** N):
        next_state = state | key[i][1]
        dp[i+1][next_state] = min(dp[i][state] + key[i][0], dp[i+1][next_state])
    for state in range(2 ** N):
        dp[i+1][state] = min(dp[i+1][state], dp[i][state])

if dp[-1][-1] < 10 ** 10:
    print(dp[-1][-1])
else:
    print(-1)


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

using namespace std;

void fast();

/*
*
* Watch out! Another Buggy Code From Muhammad_Mamdouh, Happy Coding;
*
*/

int main()
{
    fast();
    string s; cin >> s;

    int sum = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        sum += s[i] - '0';
    }

    sum % 9 ? cout << "No" : cout << "Yes";

    return 0;
}

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    int next = 1;
    rep(i, N){
        int a; cin >> a;
        if(a == next) next++;
    }
    if(next == 1) cout << -1 << endl;
    else cout << N - (next-1) << endl;
    return 0;
}

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

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

int main(){
	string W,T;
	long long int n, x = 0, y = 0;
	cin >> n;
	REP(i, n){
		cin >> W >> T;
		if (W > T){
			x += 3;
		}
		else if (W < T){
			y += 3;
		}
		else{
			x++;
			y++;
		}
	}
	cout << x << " " << y << '\n';
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

long tenr[12] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000};

int gettop(long n){
  while(n>=10){
    n/=10;
  }
  return (int)n;
}
int getketan(long n){
  int ret=0;
  while(n>0){
    ret++;
    n/=10;
  }
  return ret;
}

int main(){
  priority_queue<long, vector<long>, greater<long>>rung;
  vector<long>runrun;
  for(int i=1; i<10; i++){
    rung.push(i);
  }
  for(int i=1; i<12; i++){
    rung.push(tenr[i]);
  }
  while(runrun.size()<100100){
    long cand = rung.top();
    cerr << cand << endl;
    rung.pop();
    runrun.push_back(cand);
    int t = gettop(cand);
    int n = getketan(cand);
    if(t==1){
      for(int i=n+1; i<12; i++){
        rung.push(cand+tenr[i]);
      }
    }
    if(1<t)rung.push(cand+tenr[n]*(t-1));
    rung.push(cand+tenr[n]*t);
    if(t<9)rung.push(cand+tenr[n]*(t+1));
  }
  int k;
  cin >> k;
  cout << runrun[k-1];
  return 0;
}

Measured memory_bytes: 3696
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		char[] str = sc.next().toCharArray();
		
		for(int i=0; i<str.length; i++) {
			for(int j=i+1; j<str.length; j++) {
				if(str[i] == str[j]) {
					System.out.println("no");
					return;
				}
			}
		}
		
		System.out.println("yes");
	}

	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21204
import math, collections
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
mod = 10**9 + 7
C = collections.Counter()
gcd = math.gcd
a0 = 0
for a, b in AB:
    if a == b == 0:
        a0 += 1
    elif a == 0:
        C[0, -1] += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        C[a, b] += 1
ans = 1
for a, b in C:
    if C[b, -a]:
        continue
    elif C[-b, a]:
        ans *= (pow(2, C[a, b], mod) + pow(2, C[-b, a], mod) - 1) % mod
        ans %= mod
    else:
        ans *= pow(2, C[a, b], mod)
        ans %= mod
ans += a0 - 1
ans %= mod
print(ans)


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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define rjm	rep(j,m)


#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}


#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define INF bit(60)



li a[100100];

int main(int argc, char *argv[]) {
	li n;
	cin >> n;
	rin{cin >> a[i]; a[i]--;}
	li res = 0;
	rin{
		if (a[a[i]] == i)res++;
	}
	cout << res / 2 << endl;

	return 0;
}

Measured memory_bytes: 1152
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n, a, b, c, d = get_li()
    s = get_str()
    if "##" in s[a:c]:
        print("No")
        return
    if "##" in s[b:d]:
        print("No")
        return
    if c > d and ("..." not in s[b:d]) and s[b-2:b+1] != "..." and s[b-1:b+2] != "..." and s[d-2:d+1] != "...":
        print("No")
        return
    print("Yes")
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


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

int main() {
    long int N, W;
    cin >> N >> W;
    vector<long int> weights(N);
    vector<long int> values(N);

    for (long int i=0; i<N; i++) {cin >> weights.at(i); cin >> values.at(i);}

    vector<vector<long int>> dp(N+1, vector<long int>(W+1));
    dp.at(0).at(0) = 0;

    for (long int i=0; i<N; i++) {
        dp.at(i).at(0) = 0;
        for (long int j=0; j<W+1; j++) {
            if (j < weights.at(i)) dp.at(i+1).at(j) = dp.at(i).at(j);
            else {
                dp.at(i+1).at(j) = max(
                    dp.at(i).at(j-weights.at(i)) + values.at(i),
                    dp.at(i).at(j));
                }
        }
        cout << endl;
    }
    cout << dp.at(N).at(W) << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll now = 0;
    ll ans = 0;
    rep(i,n){
        if(a[i] < now){
            ans += now-a[i];
        }   
        now = max(now,a[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << endl;
    } else {
        cout << b - a << endl;
    }
    return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> v;
    for(int i=1;i*i<=m;i++){
        if(m%i!=0)continue;
        v.push_back(m/i);
        if(n<=i){
            cout<<m/i<<endl;
            return 0;
        }
    }
    for(auto it=--v.end();;it--){
        if(*it>=n){
            cout<<m/(*it)<<endl;
            return 0;
        }
    }
}


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

using namespace std;

int main(){
  string s,p;

  cin >> s >> p;
  s = s + s;
  if(s.find(p) != string::npos){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
long long fu(long long x)
{
    if(x==0||x==1)
        return x;
    if(x%4==0)
    return x;
   if(x%2==0)
    return x+1;
    return fu(x-1)^x;
}
int main()
{
   long long a,b;   
    cin>>a>>b;
    cout<<(fu(a-1)^fu(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<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	int c,a,b;
	cin>>c>>a>>b;
	ll ans = c*a/2;
	ote(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n,m;
 cin>>n>>m;
 vector<ll> h(n);
 for(ll i=0;i<n;i++) cin>>h[i];
 vector<vector<ll> > g(n);
 for(ll i=0;i<m;i++){
  ll a,b;
  cin>>a>>b;
  a--,b--;
  g[a].push_back(b);
  g[b].push_back(a);
 }
 ll cnt  =0;
 for(ll i=0;i<n;i++){
  bool flag = true;
  for(ll j=0;j<g[i].size();j++){
   if( h[i] <= h[ g[i][j] ] )flag = false;
  }
  if( flag )cnt++;
 }
 cout<<cnt<<endl;
    return 0;
}


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

void solve(long long S, long long W)
{
    cout << (S <= W ? "unsafe" : "safe") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long S;
    scanf("%lld", &S);
    long long W;
    scanf("%lld", &W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3760
n, k = map(int,input().split())
mod = 10**9+7

l = 0
ll = 0
r = n
rr = n

ans = 0
for i in range(1, n+2):
    # print(i,l,r)
    if i >= k:
        ans = (ans + r-l+1) % mod
    ll += 1
    rr -= 1
    l += ll
    r += rr
    

print(ans)

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

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int l[Q], r[Q];
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
  }

  int count_ac[N];
  count_ac[0] = 0;
  for (int i = 0; i < N - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') count_ac[i + 1] = count_ac[i] + 1;
    else count_ac[i + 1] = count_ac[i];
  }

  for (int i = 0; i < Q; i++) {
    cout << count_ac[r[i] - 1] - count_ac[l[i] - 1] << endl;
  }
}


Measured memory_bytes: 2176
N = int(input())
A = list(map(int, input().split()))
dic = {}

for i in range(N):
    if not A[i] in dic:
        dic[A[i]] = 0
    dic[A[i]] += 1

ans = 0
for k,v in dic.items():
    if k <= v: ans += v - k
    else: ans += v
print(ans)

Measured memory_bytes: 17780
def gcd(a,b)
  a, b = b, a % b while b > 0
  a
end

n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort

if n == 1
  puts (a[0] - x).abs
else
  d = []
  (n - 1).times do |i|
    d.push a[i + 1] - a[i]
  end
  
  g = d.shift
  d.each do |t|
    g = gcd(g, t)
  end
  
  xd = []
  a.each do |t|
    xd.push (t - x).abs
  end
  
  puts xd.map{|d| gcd(d, g)}.max
end


Measured memory_bytes: 11896