akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
// #define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t.first << " " << t.second << endl;} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}
typedef long long ll;
typedef pair<int, int> pii;

//Template Ends
int n, h, w, m;
pair<int, int> a[N];

set<pii> ms;

void solve() {
	map<int, int> rows, cols;

	cin >> h >> w >> m;

	for (int i = 0; i < m; i++ ) {
		cin >> a[i].first >> a[i].second;
		ms.insert({a[i].first, a[i].second});
	}

	sort(a, a + n);

	for (int i = 0; i < m; i++) {
		rows[a[i].first]++;
		cols[a[i].second]++;
	}


	vector<pair<int, int>> v, b;
	for (auto kv : rows) {
		v.pb({kv.second, kv.first});
	}
	sort(all(v), greater<pii>());

	// print_container(v);

	for (auto kv : cols) {
		b.pb({kv.second, kv.first});
	}
	sort(all(b), greater<pii>());

	// print_container(b);

	int mx_rows = v[0].first;
	int mx_cols = b[0].first;

	ll ans = mx_rows + mx_cols - 1;

	// deb(mx_rows, mx_cols, ans);

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

		bool done = false;
		if (v[i].first != mx_rows) {
			break;
		} else {

			for (int j = 0; j < b.size(); j++) {
				if (b[j].first != mx_cols) {
					break;
				} else {
					if (!ms.count({v[i].second, b[j].second})) {
						done = 1;
						ans = mx_cols + mx_rows;
						break;
					}
				}
			}
		}
		if (done)break;
	}

	cout << ans << endl;

}

int32_t main() {
	IOS;

	solve();

	return 0;
}




Measured memory_bytes: 56152
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs: Vec<i64> = (0..n).map(|_| sc.cin()).collect();
    xs.sort();
    let mut t = 0;
    let mut ac = 0;
    for i in 0..n-1 {
        ac += xs[i];
        if 2 * ac < xs[i + 1] {
            t = i + 1;
        }
    }
    put!(n - t);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 12256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	while(cin>>n,n){
		cin.ignore();
		map<string,int> data;
		data.clear();
		while(n--){
			/*cout <<"popopo"<<endl;
			cout <<endl;*/
			string str;
			getline(cin,str);
			//cout <<str<<endl;
			string tmp="";
			for(int i=0;i <str.length();i++){
				if(str[i]==' '||i==str.length()-1){
					//cout <<tmp<<endl;
					if(i==str.length()-1)tmp+=str[i];
					data[tmp]++;
					tmp ="";
				}else{
					tmp+=str[i];
				}
			}
		}
		char c;
		cin>>c;
		vector<pair<int,string> > d;
		d.clear();
		map<string,int>:: iterator it =data.begin();
		while(it!=data.end()){
			string a =(*it).first;
			int cnt =(*it).second;
			//cout <<a<<endl;
			if(a[0]==c){
				d.push_back(mp(-cnt,a));
			}
			it++;
		}
		sort(d.begin(),d.end());
		bool flag =false;
		for(int i =0;i<d.size()&&i <5;i++){
			flag=true;
			if(i!=0)cout <<" "<<d[i].second;
			else cout <<d[i].second;
		}
		if(flag)cout <<endl;
		else cout <<"NA"<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	string w;

	cin >> w;

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

		for (int j = 0; j < w.size(); j++) {
			if (w[i] == w[j]) cnt++;
		}

		if (cnt % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}

	}

	cout << "Yes" << endl;

}

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

using namespace std;

int main() {
	int n, r = 0;
	string a, b, c;
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i] && a[i] == c[i])
			continue;
		if (a[i] == b[i] || a[i] == c[i] || b[i] == c[i])
			r++;
		else r += 2;
	}
	cout << r << endl;
	return 0;
}


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

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

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

    int n;
    cin >> n;
    string s[n];
    map<string, int> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
        ++m[s[i]];
    }
    for (int i = 0; i < n; ++i)
    {
        if (m[s[i]] >= 2)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 1; i < n; ++i)
    {
        if (s[i][0] != s[i-1][s[i-1].size()-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto A = readln.chomp.to!int;
    auto B = readln.chomp.to!int;
    auto C = readln.chomp.to!int;
    auto D = readln.chomp.to!int;
    writeln(min(A, B) + min(C, D));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    string s;
    cin >> s;
    bool c = false, ans = false;
    rep(i,s.size()){
        if(s[i] == 'C'){
            c = true;
        }else if(s[i] == 'F' && c == true){
            ans = true;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
t = [[0 for _ in range(9)] for l in range(9)]
ans = 0
for i in range(1, N+1):
    if len(str(i)) == 1:
        t[i-1][i-1] += 1
    elif str(i)[-1] != "0":
        t[int(str(i)[0])-1][int(str(i)[-1])-1] += 1
for i in range(1, N+1):
    a = str(i)[0]
    b = str(i)[-1]
    if b == "0":
        continue
    elif a == b:
        ans += t[(int(a)-1)][int(a)-1]
    else:
        ans += t[(int(b)-1)][int(a)-1]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main(void){
    int R[MAX],n;
    
    cin >> n;
    for(int i = 0;i <n ; i++){
        cin >> R[i];
    }
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i = 1;i<n;i++){
        maxv = max(maxv,R[i] - minv);
        minv = min(minv,R[i]);
    }
    cout << maxv << endl;
}



Measured memory_bytes: 3884
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<math.h>
using namespace std;
typedef long long ll;
#define INF 10e+11 + 7
ll Decimal(ll b, ll n){
	if(n == 0)return 0;
	return Decimal(b, n / b) + n % b;
}
int main(){
	ll n, s;
	cin>>n>>s;
	ll ans = INF;
	if(s == 1){
		//ans = min(n, ans);
	}
	if(s == n){
		ans = min(n + 1, ans);
	}
	for(ll i = 2; i <= sqrt(n); i++){
		if(Decimal(i, n) == s){
			ans = min(i, ans);
		}
	}
	for(ll i = sqrt(n); i > 0; i--){
		ll b = (n - s)/(ll)i+1;
		if(b > i){
			if(Decimal(b, n) == s){
				ans = min(b, ans);
			}
		}
	}if(ans != INF){
	cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc153_a
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToIntArray();
            // モンスターの体力
            var h = items[0];
            // サーバルの攻撃で減る体力
            var a = items[1];
            // 攻撃回数
            var cnt = h / a + (h % a > 0 ? 1 : 0);
            Console.WriteLine($"{cnt}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            var items = s.Split(separator);
            var ret = new int[items.Length];
            for (int i = 0; i < items.Length; i++)
            {
                ret[i] = items[i].ToInteger();
            }
            return ret;
        }

    }
}

Measured memory_bytes: 13268
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        String s = sc.next();
        char c = s.charAt(0);
        int ans = 1;
        for (int i = 1; i < n; i++) {
            char mc = s.charAt(i);
            if(mc != c){
                c = mc;
                ans++;
            }
        }

        System.out.println(ans);
    }

    private 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;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; 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() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  char c;
  cin >> c;
  cout << (string("aeiou").find(c) != string::npos ? "vowel" : "consonant") << endl;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val fs = for (_ <- 1 to n) yield {readLine().split(' ').map(_ == "1")}
  val ps = for (_ <- 1 to n) yield {readLine().split(' ').map(_.toInt)}
  val shops = fs.zip(ps).map{case (b, i) => Shop(b, i)}
  case class Shop(isOpen:Seq[Boolean], profit:Seq[Int]){
    def joisinosShopOpen(joisinoIsOpen:Boolean):Shop = {
      if (joisinoIsOpen && isOpen.head) {
        Shop(isOpen.tail, profit.tail)
      }else{
        Shop(isOpen.tail, profit)
      }
    }
  }
  def calMaxProfit(otherShops:Seq[Shop], isOpenAtLeastOnce:Boolean = false):Int = {
    otherShops.head match{
      case Shop(Nil, _) => if (isOpenAtLeastOnce) otherShops.map(_.profit.head).sum else Int.MinValue
      case _ => List(true, false).map(b => calMaxProfit(otherShops.map(_.joisinosShopOpen(b)), isOpenAtLeastOnce | b)).max
    }
  }
  println(calMaxProfit(shops))
}


Measured memory_bytes: 42448
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto M = readln.split[1].to!long;

    long[long] HS = [0: 0];
    long c;
    foreach (a; readln.split.to!(long[])) {
        c = (c + a) % M;
        if (c in HS) {
            ++HS[c];
        } else {
            HS[c] = 0;
        }
    }

    long r;
    foreach (_, n; HS) {
        r += n * (n + 1) / 2;
    }
    writeln(r);
}

Measured memory_bytes: 7376
#include <bits/stdc++.h> 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
    LL N;
    cin>>N;
    if(N<=2){
        cout<<0<<endl;return 0;
    }
    LL maxinum=1;
    for(;maxinum*maxinum<N;maxinum++);
    LL res=0;
    for(LL i=1;i<=maxinum;i++)if(N%i==0&&N/((N/i)-1LL)==N%((N/i)-1LL)){
        res+=((N/i)-1LL);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

struct UnionFind {
	vector<int> par;
	UnionFind(int x) : par(x, -1) {}
	void init(int x) { par.assign(x, -1); }
	int root(int x) {
		if (par[x] <= -1) return x;
		else return root(par[x]);
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	int size(int x) {
		return -par[root(x)];
	}
};
int r[100010];
int main()
{
	int N, M;
	cin >> N >> M;
	UnionFind G(N);
	for (int i = 0; i < M; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		G.merge(x, y);
	}
	for (int i = 0; i < N; i++) {
		r[i] = G.root(i);
	}
	sort(r, r + N);
	int ans = 1;
	for (int i = 1; i < N; i++) {
		if (r[i] != r[i - 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import "fmt"

var A, B string
var dp [][]int

func max(a, b int) int {
	if a > b { return a }
	return b
}

func lcs(m, n int) int {
	dp = make([][]int, m+1)
	dp[0] = make([]int, n+1)
	for i:=1; i<m+1; i++  {
		dp[i] = make([]int, n+1)
		for j:=1; j<n+1; j++ {
			if A[i-1] == B[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1])
			}
		}
	}
	return dp[m][n]
}

func main() {
	_, e := fmt.Scanf("%s", &A)
	if e != nil { return }
	_, e = fmt.Scanf("%s", &B)
	if e != nil { return }
	m,n := len(A), len(B)
	l := lcs(m, n)
	if l == 0 {
		fmt.Println("")
		return
	}
	s := make([]rune, 0)
	i,j := m, n
	for i > 0 && j > 0 {
		if A[i-1] == B[j-1] {
			s = append([]rune{rune(A[i-1])}, s...)
			i--
			j--
		} else if dp[i-1][j] > dp[i][j-1] {
			i--
		} else {
			j--
		}
	}
	fmt.Println(string(s))
}


Measured memory_bytes: 96568
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
const int N=1e6+5;
int n,m,ans,gs;
char a[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();
	scanf("%s",a+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])ans++;
		else gs++;
	}
	if(gs%2==0)cout<<ans+min(m,gs/2)*2;
	else cout<<ans+min(m*2,gs/2*2+1);
}

Measured memory_bytes: 384
s=list(input())

flag=0
cnt1=0
cnt2=0
if ord(s[0])==65 and 65+32<=ord(s[1])<=90+32 and 65+32<=ord(s[-1])<=90+32:
  flag=1
  for i in range(2,len(s)-1):
    if ord(s[i])==67:
      flag+=1
  
print('AC' if flag==2 else 'WA')


Measured memory_bytes: 3060
n,m = map(int,input().split())
ls = []
for i in range(m):
    p,y = map(int,input().split())
    ls.append([p,y,i])
ls.sort(key= lambda x:x[1])
ls.sort(key= lambda x:x[0])
pre = ls[0][0]
cnt = 1
ans = []
for p,y,i in ls:
    if p==pre:
        ans.append(   (str(p).zfill(6) + str(cnt).zfill(6) ,i))
        cnt+=1
    else:
        pre = p
        ans.append((str(p).zfill(6) + str(1).zfill(6),i))
        cnt=2
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)


Measured memory_bytes: 39336
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cmath>
#include <numeric>
#include <stack>
#include <iomanip>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}

int main() {

    int n = inp1;
    vector<ll> h = inp(n);

    rep(i, n) {
        h[i] = h[i] - i;
    }

    auto copy = h;
    sort(allof(copy));

    ll ans = 0LL;

    rep(i, n) {
        // 足して0になる数
        ll target = -h[i] - i * 2;

        ll num = lower_bound(allof(copy), target + 1) - lower_bound(allof(copy), target);
        if (h[i] == target) --num;
        ans += num;
    }

    Cout(ans);

    return 0;
}


Measured memory_bytes: 6428
#include <stdio.h>

int f(int x){ 
 return x * x;
}

int i,c;

int area(int d) {
    int sum = 0;
    for(i=d; i<=600-d;i += d){
        c = d * f(i);
        sum = sum + c;
        
    }
    return sum;
}

int main(void){
    int d;
    while(scanf("%d", &d) != EOF) {
       printf("%d\n", area(d));
    }
    return 0;
}


Measured memory_bytes: 2048
a,b,c,x=$<.map(&:to_i)
ans=0
(a+1).times do |i|
    (b+1).times do |j|
        (c+1).times do |k|
            if i * 500 + j * 100 + k * 50 == x
                ans += 1
            end
        end
    end
end
p ans

Measured memory_bytes: 1788
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int a, b;
    cin >> a >> b;

    int ans = 100000;

    rep(xx, 20000) {
        int tmp_a = int(xx * 1.08) - xx;
        int tmp_b = int(xx * 1.1) - xx;
//        cout << tmp_a << " " << tmp_b << endl;
        if ( tmp_a == a && tmp_b == b) {
            //cout << xx << endl;
            ans = min(ans, xx);
        }
    }

    if (ans == 100000) {
        cout << -1;
    }
    else
    {
        cout << ans;
    }





    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
import math
a,b,n = map(int,input().split())

if (b-1) <= n:
    ans = math.floor(a*(b-1)/b) - (a * math.floor((b-1)/b))
else:
    ans = math.floor(a*n/b) - (a * math.floor(n/b))

print(ans)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200010
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;

int main(){
    ll x;
    cin>>x;
    P ans;
    for(ll a=0;a<=2000;a++){
        for(ll b=-2000;b<=2000;b++){
            if((ll)pow(a,5)-(ll)pow(b,5)==x){
                ans={a,b};
                break;
            }
        }
    }
    OUT(ans.first);
    OUT(ans.second);
    return 0;
}

Measured memory_bytes: 4228
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			int T = 0;
			if(n==0 && x==0) break;
			if(n!=0 && x!=0){
				for(int i=1; i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if((i+j+k)==x) T++;
						}
					}
				}
			}
			System.out.println(T);
		}
	}
}


Measured memory_bytes: 26664
//ABC 132 D Blue and Red Balls

#include <iostream>
typedef long long ll;
using namespace std;

ll MOD=1e9+7;

int dp[2001][2001];

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

    dp[0][0] = 1;
    for(int i=1; i<2001; i++) {
        for(int j=0; j<=i; j++) {
            if(i==j || j==0) dp[i][j] = 1;
            else dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%MOD;
        }
    }

    for(int i=1; i<=K; i++) {
        if(N-K+1<i) cout << '0' << endl;
        else cout << ((ll)dp[N-K+1][i] * (ll)dp[K-1][i-1])%MOD << endl;
    }

    return 0;
}


/*

for(int i=1; i<=k; i++)

n-k+1 C i * k-1 C i-1

*/


Measured memory_bytes: 15104
h, w = map(int,input().split())
s_l = []
s_l.append(['.']*(w+2))
for i in range(1,h+1):
    s_l.append(['.'])
    s_l[i] += list(input())
    s_l[i] += ['.']
s_l.append(['.']*(w+2))

ans = 'Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        if s_l[i][j] == '#':
            if '#' in (s_l[i-1][j], s_l[i+1][j], s_l[i][j-1], s_l[i][j+1]):
                continue
            else:
                ans = 'No'
                break
    if ans == 'No':
        break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 302;

int n;

bool c[N][N][N];
long double dp[N][N][N];

long double rec(int x, int y, int z)
{
    if (c[x][y][z])
        return dp[x][y][z];
    c[x][y][z] = true;
    long double smt = 1.0 * n / (x + y + z);
    if (x)
        dp[x][y][z] += (1.0 * x / (x + y + z)) * (rec(x - 1, y, z) + smt);
    if (y)
        dp[x][y][z] += (1.0 * y / (x + y + z)) * (rec(x + 1, y - 1, z) + smt);
    if (z)
        dp[x][y][z] += (1.0 * z / (x + y + z)) * (rec(x, y + 1, z - 1) + smt);
    return dp[x][y][z];
}

int main()
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(11);
    int x = 0, y = 0, z = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int u;
        cin >> u;
        if (u == 1)
            ++x;
        else if (u == 2)
            ++y;
        else
            ++z;
    }
    cout << rec(x, y, z) << endl;
    return 0;
}


Measured memory_bytes: 454912
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A = Array.new(3) { [] }
A[0] = get_ints
A[1] = get_ints
A[2] = get_ints
N = get_int
B = []
N.times do |i|
  B.push(get_int)
end

def bingo?(arr)
  arr[0].all? { |x| x == 0 } || arr[1].all? { |x| x == 0} || arr[2].all? { |x| x == 0 } ||
    (arr[0][0] == 0 && arr[1][0] == 0 && arr[2][0] == 0) || (arr[0][1] == 0 && arr[1][1] == 0 && arr[2][1] == 0) || (arr[0][2] == 0 && arr[1][2] == 0 && arr[2][2] == 0) ||
    (arr[0][0] == 0 && arr[1][1] == 0 && arr[2][2] == 0) || (arr[2][0] == 0 && arr[1][1] == 0 && arr[0][2] == 0)
end

B.each do |b|
  for i in 0..2
    for j in 0..2
      if A[i][j] == b
        A[i][j] = 0
      end
    end
  end
end

puts bingo?(A) ? 'Yes' : 'No'


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

int main() {
    double n, m;
    cin >> n >> m;

    vector<double> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    double s = accumulate(a.begin(), a.end(), 0);
    rep(i, m) {
        if(s / (4 * m) > a[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3768
#include<iostream>
using namespace std;
int main(){
	int c,n,m,i,j,t,d[103],queue[1000];
	for(;cin>>n>>m&&(n||m);){
		c=0;
		for(i=0;i<103;i++)d[i]=0;
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				cin>>t;
				if(t)d[j+1]++;
			}
		}
		for(i=0;i<=n;i++){
			for(j=m;j>0;j--){
				if(d[j]==i){
					queue[c]=j;
					c++;
				}
			}
		}
		for(i=c-1;i>=0;i--){
			if(i-c+1)cout<<" ";
			cout<<queue[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 868
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=200000;
const int inf=1e9;
const ll mod=1e9+7;

int a[10];

int main()
{
    FasterIO;

    int tc, cs=1, n;

    cin>>n>>tc;
    for(int i=1; i<=n; i++) a[i]=-1;
    while(tc--)
    {
        int x, y; cin>>x>>y;
        if(a[x]!=-1 && a[x]!=y||n>1 && x==1 && y==0)
        {
            cout<<-1<<endl; return 0;
        }
        a[x]=y;
    }
    for(int i=1; i<=n; i++) if(a[i]==-1) a[i]=0;
    if(a[1]==0 && n>1) a[1]=1;
    for(int i=1; i<=n; i++) cout<<a[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
def dis( x1,y1,x2,y2):

	dist = (x1-x2)**2 + (y1-y2)**2
	return dist;

x1,y1,x2,y2 = map(int,input().split())
temp = dis(x1,y1,x2,y2);

if y1!=y2:

	if y1>y2:
		dire = 1;
	else:
		dire=-1;

	num = ( x1-x2 )
	den = ( y2 - y1 )

	L = x2;
	R = 99999999999999;
	flag=0;
	while ( R-L > 1):

		mid = ( L + R )//2;

		x3 = mid;
		y3 = ( num*( x3 - x2 ) + y2*den )//den;

		
		b = dis( x2,y2,x3,y3)

		if b==temp:
			flag=1;
			break;
		elif b > temp:
			R = mid-1;
		else:
			L = mid+1;
	
	if flag==0:
		mid = L;
		x3 = mid;
		y3 = ( num*( x3 - x2 ) + y2*den )//den;

		b = dis( x2,y2,x3,y3)

		if b==temp:
			x3 = L;
		else:
			x3 = R;
	#print(x3)
	#print(slope)
	y3 = ( num*( x3 - x2 ) + y2*den )//den;
	#print(y3)

	if dire == -1:

		x3 = x2 - ( x3-x2)
	y3 = ( num*( x3 - x2 ) + y2*den )//den;
	x4 = x1+x3-x2;
	y4 = y1+y3-y2;

	print( x3,y3,x4,y4);
else:

	x3 = x2;
	if x1>x2:
		dire=-1;
	else:
		dire=1;

	L = y2;
	R = 9999999999999;

	while ( R-L > 1):

		mid = ( L + R )//2;

		y3 = mid;

		b = dis( x2,y2,x3,y3)

		if b==temp:
			flag=1;
			break;
		elif b > temp:
			R = mid-1;
		else:
			L = mid+1;
	
	if flag==0:
		mid = L;
		y3 = mid;

		b = dis( x2,y2,x3,y3)

		if b==temp:
			y3 = L;
		else:
			y3 = R;

	if dire == -1:
		y3 = y2 - (y3-y2);
			
	x4 = x1+x3-x2;
	y4 = y1+y3-y2;

	print( x3,y3,x4,y4);




Measured memory_bytes: 3192
import java.util.*;

public class Main{
  
  public static void main(String[] args){
  
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    
    int num1 = num+num-1;
    int[] list = new int[num1];
    
    list[1] = sc.nextInt();
    int a = list[1];
    list[0] = a;
    
    if(sc.hasNext()){
     for(int i = 2; i < num1-1; i+=2){
        list[i+1] = sc.nextInt();
        int b = list[i+1];
        int c = list[i-1];
         if(b < c){
           list[i] = b;
         }else if(b == c){
           list[i] = b;
         }else{
           list[i] = c;
         }
     }
    }
    
    int d = list[num1-2];
      list[num1-1] = d;
    
 int ans = 0;
  
  for(int i = 0; i < list.length; i +=2){
    ans += list[i];
  }
  
  System.out.println(ans);
  
  }
}


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

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

	int str[26] = {};
	for (int i = 0; i < s.length(); i++) {
		str[s.at(i) - 'a']++;
	}
	string ans = "Yes";
	for (int i = 0; i < 26; i++) {
		if (str[i] % 2 != 0) {
			ans = "No";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
//#define ll long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;

using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int K = 26;
set<int> have[K];
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.length();
    for (int i = 0; i < n; i++) {
        have[s[i] - 'a'].insert(i);
    }
    int ans = -1, cnt = 0;
    for (int i = 0; i < t.length(); i++) {
        int k = t[i] - 'a';
        if (have[k].empty()) {
            cout << -1;
            rr;
        }
        auto it = have[k].upper_bound(ans);
        if (it == have[k].end()) {
            ++cnt;
            ans = *have[k].begin();
        }
        else {
            ans = *it;
        }
    }
    cout << cnt * n + ans + 1 << '\n';
}


Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int r,d,a,x,i;
  cin>>r>>d>>a;
  for(i=0;i<10;i++)
  {
    x=r*a-d;
    cout<<x<<endl;
    a=x;
  }
  return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
#define X first
#define Y second
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
const int maxn=5e5+10;
const ll Inf=1e10;
ll res[maxn];
//vector<ll>res;

//解法一：BFS

// int main(){
// 	ll ans;
// 	int n;
// 	cin>>n;
// 	queue<ll>que;//BFS可以保证是升序的。。。
// 	for(int i=1;i<=9;i++){
// 		que.push(i);
// 	}
// 	while(n--){
// 		ans=que.front();
// 		que.pop();
// 		if(ans%10!=0)que.push(ans*10+ans%10-1);
// 		que.push(ans*10+ans%10);//这一步是一定要做的，这样也可以保证是从小到大的。。。
// 		if(ans%10!=9)que.push(ans*10+ans%10+1);
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

//解法二：DFS
//先以1-9为最高位向下扩展，最大为1e10所以递归的最终条件是大于1e10退出。。。。
int k=0;
//vector<ll>res(maxn,0);
void dfs(ll x){
	if(x>Inf)return;
	res[++k]=x;
	for(ll j=max(ll(0),x%10-1);j<=min(ll(9),x%10+1);j++){
		dfs(x*10+j);//j的取值范围是-1，0，1上下波动。。。
	}
}
int main(){
	int n;
	cin>>n;
	//for(ll i=1;i<=9;i++)dfs(i);
	for(ll x=1;x<=9;x++){dfs(x);}
	sort(res+1,res+k+1);
	//sort(res.begin(),res.end());
	cout<<res[n]<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
N = int(input())
A =  sorted([int(i) for i in input().split()],reverse=True)

ans = 0
for i, a in enumerate(A):
    if i == 0:
        continue
    else:
        ans += A[i//2]
    #print(i,ans)
print(ans)


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

int main()
{
    long long int a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    long long int op1=a*c;
    long long int op2=a*d;
    long long int op3=b*c;
    long long int op4=b*d;
    printf("%lld\n",max({op1,op2,op3,op4}));
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
	ll n;
	cin>>n;
	ll i;ll s=0;
	for(i=1;i<=n;i++)
	{
		if(i%3==0 ||  i%5==0)
		continue;
		else
		s+=i;
	}
	cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 int main (){
	int a, b ;
	cin >>a >>b;
	if(a == b) cout<< "a == b\n" ;
	else if(a <  b) cout<< "a < b\n" ;
	else  cout<<"a > b\n";
	return 0 ;

}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 10000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N;

int main() {
	cin >> N ;
	vector<int> a(N + 1);
	for (int i = 1; i <= N ; i++)
	{
		cin >> a.at(i);
	}
	int cnt = 0;
	for (int i = 1; i <= N ; i++)
	{
		if (a.at(a.at(i)) == i) {
			cnt++;
		}
	}
	cout << cnt / 2 << endl;
}

Measured memory_bytes: 3792
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



int main(void) {
	int n, W;
	vector<int>weight, value;
	vector<vector<int>>dp(1000, vector<int>(10005, 0));


	cin >> n >> W;

	for (int i = 0; i < n; i++) {
		int w, v;
		//cin >> w >> v;
		cin >> v >> w;
		weight.push_back(w);
		value.push_back(v);
	}

	for (int i = 0; i < n; i++) {

		for (int w = 0; w <= W; w++) {
			if (weight[i] <= w) {
				dp[i + 1][w] += max(dp[i][w - weight[i]] + value[i], dp[i][w]);
			}
			else {
				dp[i + 1][w] = dp[i][w];
			}
		}
	}

	/*for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= W + 1; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;*/


	cout << dp[n][W] << endl;



	return 0;
}


Measured memory_bytes: 41800
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int min = x-k+1;
    int max = x+k-1;
    
    for(int i = min; i<=max; ++i){
        cout << i << " ";
    }

    cout << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector <vector<int>> vec(N,vector<int>(2));
  for (int i=0; i<N; i++){
    for(int j=0; j<2; j++)
    cin >> vec.at(i).at(j);
  }
  int M;
  M= N*(N-1)/2;
  vector <vector<int>> sa(M,vector<int>(2));
  for (int i=0; i<N; i++){
    for(int j=0; j<i; j++){
      int a;
        a= (i*(i-1)/2)+j;
      for (int l=0; l<2; l++){
        sa.at(a).at(l)=vec.at(i).at(l)-vec.at(j).at(l);
      }
      for (int l=0; l<2; l++){
        if(sa.at(a).at(0) < 0){
          sa.at(a).at(0) = - sa.at(a).at(0);
          sa.at(a).at(1) = - sa.at(a).at(1);
        }
        if(sa.at(a).at(0) == 0)
          sa.at(a).at(1) = max(-sa.at(a).at(1),sa.at(a).at(1));
      }
    }
  }
  sort(sa.begin(), sa.end());
  int k;
  k=0;
  int i;
  i=0;
  while(i<M){
    int j;
    j=0;
      while(sa.at(i) == sa.at(i+j)){
        k=max(k,j);
        j++;
        if(i+j==M)
          break;
      }
    i=i+j;
   }
  if(N == 1)
    cout << 1;
  else
    cout << N-k-1;
}

Measured memory_bytes: 256
import math

A,B,H,M = map(int,input().split())

Mw = M*6
Hw = H*30 + (0.5)*M
Q = math.cos(math.radians(abs(Mw-Hw)))

C = A**2 + B**2 - 2*A*B*Q
C = math.sqrt(C)
print(float(C))

Measured memory_bytes: 9488
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    char op;
    bool exit = false;
    while (!exit) {
        cin>>a>>op>>b;
        switch (op) {
        case '+': {
            cout << a+b<<endl;
            break;
        }
        case '-': {
            cout <<a-b<<endl;
            break;
        }
        case '*': {
            cout << a*b<<endl;
            break;
        }
        case '/': {
            cout<<a/b<<endl;
            break;
        }
        case '?': {
            exit = true;
            break;
        }
        default:
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3068
n,m=map(int,input().split())
ok=[0]*(n+1)
for _ in range(m):
  l,r=map(int,input().split())
  ok[l-1]+=1
  ok[r]-=1
for i in range(1,n+1):ok[i]+=ok[i-1]
print(ok.count(m))

Measured memory_bytes: 6900
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.random;
import std.range;
import std.functional;
import std.container;
class t
{
    int parent, left, right;
    this()
    {
        parent = left = right = -1;
    }

    int depth;
    int height;
}
void dep(t[] tt, int i, int d = 0)
{
    if (i == -1)
    {
        return;
    }
    tt[i].depth = d;
    dep(tt, tt[i].left, d + 1);
    dep(tt, tt[i].right, d + 1);
}
int hei(t[] tt, int i)
{
    auto a1 = 0, a2 = 0;
    if (tt[i].left != -1)
        a1 = hei(tt, tt[i].left) + 1;
    if (tt[i].right != -1)
        a2 = hei(tt, tt[i].right) + 1;
    tt[i].height = max(a1, a2);
    return tt[i].height;
}
void main()
{
    auto c = readln.strip.to!int;
    auto tt = new t[c];
    foreach (i; 0..c)
        tt[i] = new t();
    foreach (i; 0..c)
    {
        auto a = readln().strip.split(" ").map!(to!int).array;
        if (a[1] != -1)
        {
            tt[a[0]].left = a[1];
            tt[a[1]].parent = a[0];
        }
        if (a[2] != -1)
        {
            tt[a[0]].right = a[2];
            tt[a[2]].parent = a[0];
        }
    }
    foreach (i; 0..c)
    {
        if (tt[i].parent == -1)
        {
            dep(tt, i);
            hei(tt, i);
        }
    }
    foreach (i; 0..c)
    {
        int s = -1;
        if (tt[i].parent != -1)
        {
            if (tt[tt[i].parent].left == i)
            {
                s = tt[tt[i].parent].right;
            }
            else
            {
                s = tt[tt[i].parent].left;
            }
        }
        writef("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, tt[i].parent, s, (tt[i].left != -1 ? 1 : 0) + (tt[i].right != -1 ? 1 : 0), tt[i].depth, tt[i].height);
        if (tt[i].parent == -1)
        {
            writef("root");
        }
        else if (tt[i].left == -1 && tt[i].right == -1)
        {
            writef("leaf");
        }
        else
        {
            writef("internal node");
        }
        writeln();
    }
}



Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define vll vector<ll>
#define here cout<<"I'm here\n";
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele;
}

int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    ll x;
    cin>>x;
    ll ans1=x/500;
    ll ans2=(x-(500*ans1));
    ans2=ans2/5;
    cout<<(ans1*1000)+(ans2*5);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#include <math.h>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
	ll A,B,N;
	cin >> N >> A >> B;
	ll mn,mx;
	mn = A*(N-1)+B;
	mx = A+B*(N-1);
	ll zero = 0;
	ll ans = max(mx-mn+1,zero);
	cout << ans << endl;
}

Measured memory_bytes: 256