akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================
	

	int M, D;
	cin >> M >> D;

	int ans = 0;
	for (int m = 1; m <= M; m++)
	{
		for (int d = 20; d <= D; d++)
		{
			int d1 = d % 10;
			int d2 = d / 10;

			if (d1 >= 2 && d2 >= 2 && d1 * d2 == m)
			{
				ans++;
			}


		}
	}

	cout << ans << endl;

}





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



int main(){
    int N;
    ll cn=0;
    cin>>N;
    vector<int> l(N);

    rep(i,0,N)cin>>l.at(i);
    sort(l.begin(),l.end());
    for(int i=N-1;i>=2;i--){
        for(int j=i-1;j>=1;j--){
            auto ite=upper_bound(l.begin(),l.end(),(l.at(i)-l.at(j)));
            int len=l.end()-ite;
            if(len-(N-j)<=0)continue;
            cn+=len-(N-j);
        }
    }
    cout<<cn<<endl;

    
}






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

int max_abc(int a, int b, int c)
{
    int m = max(max(a, b), c);
    return m;
}

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

    if(a*b*c==5*7*5)
    {
        cout <<"YES";
    }else{
        cout <<"NO";
    }
}

Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int N,A;
   cin >> N;
   map<int,int> data;
   for (int i=0;i<N;i++) {
       data[i]=0;
   } 
   for (int i=0;i<N-1;i++) {
       cin >> A;
       data[A-1]++;
   }
   for (int i=0;i<N;i++) {
       cout << data[i] << endl;
   }
} 


Measured memory_bytes: 13008
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int A,B; cin >> A >> B;
    if(A+B>9) cout << "error" << endl;
    else cout << A+B << endl;
    return 0;
}

Measured memory_bytes: 256
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let mut xy: Vec<(u64, u64)> = (0..n).map(|_| (sc.read(), sc.read())).collect();
    let max = xy.iter().map(|&(x, y)| cmp::max(x, y)).max().unwrap();
    let min = xy.iter().map(|&(x, y)| cmp::min(x, y)).min().unwrap();
    let max_min = xy.iter().map(|&(x, y)| cmp::max(x, y)).min().unwrap();
    let min_max = xy.iter().map(|&(x, y)| cmp::min(x, y)).max().unwrap();
    let ans1 = (max - max_min) * (min_max - min);

    xy = xy
        .into_iter()
        .map(|(x, y)| (cmp::min(x, y), cmp::max(x, y)))
        .collect();
    xy.sort();
    let mut ans2 = max - min;
    let mut right_min = max;
    let mut max2 = xy[n - 1].0;
    for i in 0..(n - 1) {
        let (_, right) = xy[i];
        right_min = cmp::min(right_min, right);
        max2 = cmp::max(max2, right);
        let min = cmp::min(xy[i + 1].0, right_min);
        ans2 = cmp::min(ans2, max2 - min);
    }

    let ans2 = ans2 * (max - min);
    println!("{}", cmp::min(ans1, ans2));
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int func(int j,int x){
  if(j==1) return 1;
  for(int i=2;i<10;i++){
    if( x < pow(j,i) ){
      //cout << pow(j,i-1) << endl;
      return pow(j,i-1);
    }
  }
}

int main() {
  int x;
  cin >> x;
  int m=0;
  for(int i=0;i<=34;i++){
    if( x < i*i ){
      for(int j=1;j<i;j++){
        m = max(m,func(j,x)); // funcは、jのべき乗数かつX以下で最大のものを返す
      }
      break;
    }
  }
  
  cout << m << endl;
  
  return 0;
  
}

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

using ll = long long;

// 区間の情報を二分木で管理
struct LazySegmentTree{
    // 配列サイズを 2 べきにしたときのサイズ
    int sz;
    // 1-indexed で管理
    vector<ll> data;
    vector<ll> lazy;

    LazySegmentTree(int n){
        sz = 1;
        while(sz < n)   sz <<= 1;
        data.assign(sz << 1, 0);
        lazy.assign(sz << 1, 0);
    }

    void set(int idx, const int& x){
        data[idx + sz] = x;
    }

    // k : セグメント木上のインデックス
    //     (set された配列のどの区間かを表す)
    void build(){
        for(int k = sz - 1; k >= 0; --k){
            data[k] = max(data[k << 1], data[k << 1 | 1]);
        }
    }

    // 子ノードへの伝播
    void propagate(int k){
        if(lazy[k] == 0)    return;

        if(k < sz){
            lazy[k << 1] += lazy[k];
            lazy[k << 1 | 1] += lazy[k];
        }
        data[k] += lazy[k];
        lazy[k] = 0;
    }

    // [a, b) の各要素に対して x を一様加算
    ll update(int a, int b, const ll& x, int k = 1, int l = 0, int r = -1){
        if(r == -1) r = sz;
        
        propagate(k);

        // 更新する範囲が今見ている区間内にない
        if(b <= l || r <= a)    return data[k];

        // 更新する区間が今見ている区間を内包している
        else if(a <= l && r <= b){
            lazy[k] += x;
            propagate(k);
            return data[k];     // 子ノードの更新は遅延させる
        }

        else{
            return data[k] = max(update(a, b, x, k << 1, l, (l + r) >> 1),
                                update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    // [a, b) における最大値を取得
    ll query(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r == -1) r = sz;
        
        propagate(k);
        
        if(b <= l || r <= a)    return 0;
        else if(a <= l && r <= b)   return data[k];
        else{
            return max(query(a, b, k << 1, l, (l + r) >> 1),
                        query(a, b, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    ll operator[](const int& idx){
        return query(idx, idx + 1);
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> table(n + 1);
    for(int i = 0; i < m; ++i){
        int l, r, a;
        cin >> l >> r >> a;
        table[r].emplace_back(l, a);
    }
    LazySegmentTree dp(n + 1);
    for(int i = 1; i <= n; ++i){
        dp.update(i, i + 1, dp.query(0, i));
        for(auto p : table[i]){
            int l = p.first, a = p.second;
            dp.update(l, i + 1, a);
        }
    }
    cout << dp.query(0, n + 1) << endl;
}

Measured memory_bytes: 19328
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    string ans = "APPROVED";
    rep(i, 0, n) if (a[i] % 2 == 0 && !(a[i] % 3 == 0 || a[i] % 5 == 0)) ans = "DENIED";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N (int)2e5
#define fi first
#define se second
#define mp make_pair
#define pb push_back
int n,m,memo[N];
vector <int> adj[N];

int dp(int u) {
    if (adj[u].size() == 0) return 0;
    int &sol = memo[u];
    if (sol != -1) return sol;
    int keep = INT_MIN;
    for (int v : adj[u]) {
        keep = max(
            keep ,
            dp(v) + 1
        );
    }
    return sol = keep;
}

int main() {
    scanf("%d%d" , &n , &m);
    for (int i = 1 ; i <= m ; i++) {
        int u,v; scanf("%d%d" , &u , &v);
        adj[u].pb(v);
    }
    memset (memo , -1 , sizeof memo);
    int sol = INT_MIN;
    for (int u = 1 ; u <= n ; u++)
        sol = max(sol , dp(u));
    printf("%d\n" , sol);
}


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

int main(){
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for(int i = 0; i < h; i++)
	{
		cin >> s[i];		
	}
	
	vector<int> dx = {1, 1, 1, 0, 0, -1, -1, -1};
	vector<int> dy = {1, 0, -1, 1, -1, 1, 0, -1};
	
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{	
			if(s[i][j] == '#') cout << '#';
			else{
				int cnt =  0;
				for(int k = 0; k < 8; k++)
				{
					if(i+dx[k] >= 0 && i+dx[k] < h && j+dy[k] >= 0 && j+dy[k] < w){
						if(s[i+dx[k]][j+dy[k]] == '#') cnt++;
					}
				}
				cout << cnt;
			}
		}
		cout << endl;
		
	}
	

	return 0;
}

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

using namespace std;


int main(){
    long long N, a[100000], xored = 0, bit_cnt[40] = {};
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        xored ^= a[i];
        for(int j = 0; j < 40; j++){
            bit_cnt[j] += (((a[i]^(a[i]-1))+1) >> j) & 1;
        }
    }

    long long ans = 0;
    for(int j = 40-1; j >= 0; j--){
        //printf("%d: %lld\n", j, bit_cnt[j]);
        if((xored >> j) & 1 != 0 && bit_cnt[j+1] != 0){
            ans ++;
            for(int i = 0; i <= j; i++){
                xored ^= (1 << i);
            }
        }
    }
    if(xored == 0){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char s[1000005];
int main() {
	cin>>s+1;
	int n = strlen(s + 1);
	if (s[1] == 'A') {
		if(s[2] == 'C' || (s[2] < 'a' || s[2] > 'z') || s[n] == 'C' || s[n] < 'a' || s[n] > 'z'){
			cout<<"WA"<<endl;
			return 0;
		}
		int count = 0;
		for(int i = 3; i <= n - 1; i++) {
			if (s[i] == 'C') {
				count++;
			}
		}
		if(count == 1){
			for(int i = 3; i <= n - 1; i++){
				if((s[i] < 'a' || s[i] > 'z') && s[i] != 'C') {
					cout<<"WA"<<endl;
					return 0;
				}
			}
			cout<<"AC"<<endl;
			return 0;
			
		} else {
			cout<<"WA"<<endl;
			return 0;
		}
	}
	cout<<"WA"<<endl;
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#define MAX 1002001
#define EDGE 1002
using namespace std;

int p[MAX], h[EDGE + 2][EDGE + 2], visit[EDGE + 2][EDGE + 2], lastcave[EDGE + 2][EDGE + 2];

int max(int a, int b, int c){
	return max(max(a, b), max(b, c));
}



int main()
{
	//洞窟の作成
	int nowx, nowy, d, size, sizecounter;
	nowx = (EDGE - 1) / 2;
	nowy = (EDGE + 1) / 2;
	d = 0;
	size = 1;
	sizecounter = 0;
	for (int i = 0; i <= MAX; i++){
		h[nowy][nowx] = i;
		if (d == 0){
			nowx++;
		}
		else if (d == 1){
			nowy--;
		}
		else if (d == 2){
			nowx--;
		}
		else if (d == 3){
			nowy++;
		}
		if (sizecounter == size){
			sizecounter = 0;
			d = (d + 1) % 4;
			if (d == 0 || d == 2){
				size++;
			}
		}
		sizecounter++;
	}

	//素数の判定用配列を作成
	fill(p, p + MAX, 1);
	p[1] = 0;
	for (int i = 2; i <= MAX; i++){
		int sqrti = (int)sqrt(i);
		for (int j = 2; j <= sqrti; j++){
			if (i % j == 0){
				p[i] = 0;
				break;
			}
		}
	}

	//入力
	int m, n;
	while (cin >> m >> n, m || n){

		//初期化
		int goalcave = 0;
		int cavecounter = 0;
		for (int i = 0; i < EDGE + 2; i++){
			for (int j = 0; j < EDGE + 2; j++){
				visit[i][j] = 0;
				lastcave[i][j] = 0;
			}
		}


		//脱出する直前の洞窟のyを求める．
		bool flag = false;
		for (int i = EDGE + 1; i > 0; i--){
			for (int j = 0; j < EDGE + 2; j++){
				if (0 < h[i][j] && h[i][j] <= m){
					goalcave = i;
					flag = true;
					break;
				}
			}
			if (flag)
				break;
		}

		//下から順に計算
		for (int i = goalcave; i > 0; i--){
			for (int j = 0; j < EDGE + 2; j++){
				if (0 < h[i][j] && h[i][j] <= m){

					//visitを求める
					if (p[h[i][j]]){
						visit[i][j] = max(visit[i + 1][j - 1], visit[i + 1][j], visit[i + 1][j + 1]) + 1;
					}else{
						visit[i][j] = max(visit[i + 1][j - 1], visit[i + 1][j], visit[i + 1][j + 1]);
					}

					//lastcaveを求める
					if (visit[i + 1][j - 1] > visit[i + 1][j] && visit[i + 1][j - 1] > visit[i + 1][j + 1]){
						lastcave[i][j] = lastcave[i + 1][j - 1];
					}
					else if (visit[i + 1][j] > visit[i + 1][j - 1] && visit[i + 1][j] > visit[i + 1][j + 1]){
						lastcave[i][j] = lastcave[i + 1][j];
					}
					else if (visit[i + 1][j + 1] > visit[i + 1][j - 1] && visit[i + 1][j + 1] > visit[i + 1][j]){
						lastcave[i][j] = lastcave[i + 1][j + 1];
					}
					else if (visit[i + 1][j - 1] == visit[i + 1][j] && visit[i + 1][j - 1] > visit[i + 1][j + 1]){
						lastcave[i][j] = max(lastcave[i + 1][j - 1], lastcave[i + 1][j]);
					}
					else if (visit[i + 1][j] == visit[i + 1][j + 1] && visit[i + 1][j] > visit[i + 1][j - 1]){
						lastcave[i][j] = max(lastcave[i + 1][j], lastcave[i + 1][j + 1]);
					}
					else if (visit[i + 1][j + 1] == visit[i + 1][j - 1] && visit[i + 1][j + 1] > visit[i + 1][j]){
						lastcave[i][j] = max(lastcave[i + 1][j + 1], lastcave[i + 1][j - 1]);
					}
					else{
						lastcave[i][j] = max(lastcave[i + 1][j + 1], lastcave[i + 1][j], lastcave[i + 1][j - 1]);
					}
					if (p[h[i][j]] && lastcave[i][j] == 0){
						lastcave[i][j] = h[i][j];
					}

				}

				//出力
				if (h[i][j] == n){
					cout << visit[i][j] << " " << lastcave[i][j] << endl;
					break;
				}
				
			}
		}
	}
	return 0;
}

Measured memory_bytes: 16888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  int nn = n;
  vector<P> ans;
  for(int i = 2;i <= sqrt(n);i++){
    if(n % i == 0){
      int num = 1;
      n /= i;
      while(n % i == 0){
        num++;
        n /= i;
      }
      ans.push_back(P(i,num));
    }
  }
  if(n != 1) ans.push_back(P(n,1));
  int ansans = 0;
  rep(i,0,ans.size()){
    int num = 1;
    while(ans[i].second>=num){
      ansans++;
      ans[i].second -= num;
      num++;
    }
  }
  cout << ansans << endl;
}

Measured memory_bytes: 3724
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b=I()
if a >= 13:
    print(b)
elif a >= 6:
    print(b//2)
else:
    print(0)


Measured memory_bytes: 10388
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0]*(M+1) for i in range(N+1)]

for i in range(N):
  for j in range(M):
    if S[i] == T[j]:
      dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] + 1) % MOD
    else:
      dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD

print((dp[N][M] + 1) % MOD)

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int main()
{
    _upgrade
    string s; cin >> s;
    for(int i = 0; i + 1 < sz(s); i++)
    {
        if(s.substr(i, 2) == "AC")
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  priority_queue<int> que;
  rep(i,n){
    int tmp;
    cin >> tmp;
    que.push(tmp);
  }
  int a,b;
  b=0;
  a = que.top();
  que.pop();
  while(!que.empty()){
    b += que.top();
    que.pop();
  }
  string ans;
  if(a<b) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}


ll com(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    ll h,w; cin >> h >> w;
    char c[h][w];
    rep(i,h){
        rep(j,w) cin >> c[i][j];
    }
    for(ll i=0; i<h; i++){
        rep(j,w) cout << c[i][j];
        cout << endl;
        rep(j,w) cout << c[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N; cin >> N;
  vector<int> MY(N);
  int count=0;
  for(int i=0;i<N;i++){
    cin >> MY.at(i);
  }
  for(int i=0;i<N;i++){
    count+=MY.at(i);
  }
  cout << count-N << endl;
}

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

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var xy = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (sx, sy, tx, ty) = (xy[0], xy[1], xy[2], xy[3]);
            var answer = "";
            var dx = tx - sx;
            var dy = ty - sy;
            answer += new string(Enumerable.Repeat('U', dy).ToArray());
            answer += new string(Enumerable.Repeat('R', dx).ToArray());
            answer += new string(Enumerable.Repeat('D', dy).ToArray());
            answer += new string(Enumerable.Repeat('L', dx).ToArray());
            answer += "L";
            answer += new string(Enumerable.Repeat('U', dy + 1).ToArray());
            answer += new string(Enumerable.Repeat('R', dx + 1).ToArray());
            answer += "D";
            answer += "R";
            answer += new string(Enumerable.Repeat('D', dy + 1).ToArray());
            answer += new string(Enumerable.Repeat('L', dx + 1).ToArray());
            answer += "U";

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28340
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;
  bool ok = true;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 != 0 && S.at(i) == 'R') {
      ok = false;
      break;
    }
    else if (i % 2 == 0 && S.at(i) == 'L') {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3600
unittest
{
	assert( [ "10 4" ].parse.expand.solve == 3 );
	assert( [ "1 10000" ].parse.expand.solve == 1 );
	assert( [ "10000 1" ].parse.expand.solve == 10000 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ha = input.front.split.to!( long[] );
	return tuple( ha[ 0 ], ha[ 1 ] );
}

auto solve( long h, long a )
{
	return ( h + a - 1 ) / a;
}


Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

ll a[N], b[N];
vector<int> pos[N];
vector<pii> all;

int main() {
	fast_cin();
	int n; cin >> n;
	ll sum_a = 0, sum_b = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i];
		sum_a += a[i];
		sum_b += b[i];
		all.pb({a[i], i});
		all.pb({b[i], i});
	}
	sort(all.begin(), all.end());
	ll ans = min(sum_a, sum_b);
	ll temp = 0;
	for (int i = 0; i < n; ++i) {
		temp += all[i].first;
	}
	for (int i = 0; i < 2 * n; ++i) {
		pos[all[i].second].pb(i);
	}
	for (int i = 1; i <= n; ++i) {
		ll cand = temp, p = n - 1;
		for (int j = 0; j < 2; ++j) {
			if (pos[i][j] <= p) {
				cand -= all[pos[i][j]].first;
				cand += all[++p].first;
			}
		}
		ans = min(ans, cand);
	}
	cout << ans << endl;
}

Measured memory_bytes: 8816
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, M; LL C; cin >> N >> M >> C;
		vector<LL> B(M); rep(i, M) cin >> B[i];
		UL ans = 0;
		rep(i, N) {
			LL sum = C;
			rep(i, M) {
				LL a; cin >> a;
				sum += a * B[i];
			}
			if (sum > 0) ans++;
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h1,m1,h2,m2,k = inpl()
if m1 > m2:
    m2 += 60
    h2 -= 1
print((h2-h1)*60+(m2-m1)-k)


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

using namespace std;

int main(){
                //  0     1     2     3     4     5     6      7    8     9
    string c[10]={"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
    int n;cin>>n;
    int one=n%10;
    cout << c[one]<<endl;
}


Measured memory_bytes: 3568
S = input()
L = len(S)
# RLのブロックに分割
i = 0
Data = []
while i < L:
    l = 0
    r = 0
    while i < L and S[i] == 'R':
        r += 1
        i += 1
    while i < L and S[i] == 'L':
        l += 1
        i += 1
    Data.append([r,l])

for d in Data:
    r = d[0]
    l = d[1]
# R....RL (R:ｎ個)
# 右端の Rの箇所に 　　　R:奇数 n//2 + 1 R:偶数 n//2 
#        Lの箇所にのこり        n//2            n//2
# RL...L  (L:ｎ個)
# 左端の Lの箇所に 　　　R:奇数 n//2 + 1 R:偶数 n//2 
#        Rの箇所にのこり        n//2            n//2
# RL...L  (L:ｎ個)
#ほかは0
    rp = 0
    lp = 0
    if r % 2 == 0:
        rp += r//2
        lp += r//2
    else:
        rp += r//2 +1
        lp += r//2
    if l % 2 == 0:
        lp += l//2
        rp += l//2
    else:
        lp += l//2 +1
        rp += l//2 

    for i in range(r-1):
        print( '0', end = ' ')
    print( rp, end = ' ')
    print( lp, end = ' ')
    for i in range(l-1):
        print( '0', end = ' ')


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n,m;
    vector<int> cnt;
    Problem(LL n, LL m):n(n),m(m),cnt(n){};

    void solve(){
        for(int i=0; i<m; ++i){
            int s,t;
            cin >> s >> t;
            --s;--t;
            ++cnt[s];++cnt[t];
        }
        bool ans=true;
        for(int i=0; i<n; ++i){
           if(cnt[i]%2==1)ans=false;
        }
        cout << (ans?"YES":"NO") <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0,m;
    cin >> n >> m;
    Problem p(n,m);
    p.solve();
    return 0;
}



Measured memory_bytes: 640
#include<iostream>
using namespace std;
 
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(x-r >= 0 && y-r >= 0 && x+r <= W && y+r <= H){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
     
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int n;
    scanf("%d", &n);
    vector<int> v(n-1,MOD);
    rep(i,n-1) scanf("%d", &v.at(i));
    intt ans=0;
    ans+=v.at(0);
    rep(i,n-2) {
        ans+=min(v.at(i), v.at(i+1));
    }
    ans+=v.at(n-2);
    printf("%lld\n", ans);
}

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

long long a,b,x;
    
long long f(long long n){
    
    if(n >= 0)return n/x + 1;
    else return 0;
    
    
    
}


int main(void){
    

    cin >> a >> b >> x;
    cout << f(b) - f(a - 1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long lint;
typedef complex<double> point;

template<typename Key, typename Value>
using hash_map = cc_hash_table<Key, Value>;
template<typename T, typename Cmp = less<T>>
using oset = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 0x3f3f3f3f;
const lint INFL = 0x3f3f3f3f3f3f3f3fLL;
const double E = 1e-9, pi = 2 * acos(0);

template<typename T, typename U> void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if (x < y) x = y; }

const int SIGMA = 26;

bool solve(int testNumber) {
	string str;
	if (!(cin >> str)) {
		return false;
	}
	unordered_map<int, int> least;
	least[0] = 0;
	int mask = 0;
	for (char c: str) {
		c -= 'a';
		mask ^= 1 << c;
		int ans = least.count(mask) ? least[mask] : INF;
		for (int i = 0; i < SIGMA; i++) {
			int nmask = mask ^ (1 << i);
			if (least.count(nmask)) {
				amin(ans, least[nmask]);
			}
		}
		if (!least.count(mask)) {
			least[mask] = INF;
		}
		amin(least[mask], ++ans);
	}
	int ans = max(least[mask], 1);
	printf("%d\n", ans);
	return true;
}

void init(const char *in = nullptr, const char *out = nullptr) {
	if (in) freopen(in, "r", stdin);
	if (out) freopen(out, "w", stdout);
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	init();
	for (int i=1; solve(i); i++);
	return 0;
}

Measured memory_bytes: 8668
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define Sort(a) sort((a).begin(),(a).end())
#define Reverse(a) reverse((a).begin(),(a).end())
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;
signed main(){
    int n;
    cin >> n;
    vec(a,n);
    vec(b,n);
    REP(i,n){
        cin >> a[i];
    }
    b[1] = abs(a[1]-a[0]);
    FOR(i,2,n){
        b[i] = min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
    }
    cout << b[n-1] << endl;


    return 0;
}

Measured memory_bytes: 1792
import heapq
n,m = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)

while m > 0:
    x = heapq.heappop(A)*(-1)
    x //= 2
    A.append(-x)
    m -= 1
print(abs(sum(list(A))))

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

typedef long long int ll;
typedef vector<int> vi; 
typedef pair<int,int> pi; 
typedef vector<ll> vll; 


#define F first;
#define S second;
#define PB push_back;
#define MP make_pair;
#define rep(i, a, b) for (int i=a; i<b; i++)

int main(){
	ll n,t;
	cin >>n>>t;
    ll arr[n][2];
    ll min = 999999;
	rep(i,0,n){
		cin>> arr[i][0]>>arr[i][1];
        if(arr[i][1]<=t){
            if(arr[i][0]<min){
                min = arr[i][0];
            }
        }
    }
    if(min==999999){
        cout << "TLE";
    }
    else{
        cout<<min;
    }


	return 0;
}

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

using namespace std;

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

    int res=0;
    int temp=0;
    for(int i=0;i<N;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if (x==y) temp++;
        else temp=0;
        res=max(res,temp);
    }

    if (res>=3) puts("Yes");
    else puts("No");


    return 0;
}

Measured memory_bytes: 1664
#binary_tree_restore
class Node
  attr_accessor :myname,:parent,:left,:right

  def initialize(n)
    @myname = n
    @parent = nil
    @left   = nil
    @right  = nil
  end

  def add_left(child)
      self.left    = child
      child.parent = self
  end

  def add_right(child)
      self.right    = child
      child.parent = self
  end

  def postorder(flag)
    if(left != nil && left != -1)
      left.postorder(0)
    end
    if(right!= nil && left != -1)
      right.postorder(0)
    end
    printf("%d",self.myname)
    printf(" ") if flag == 0
  end

end


n = STDIN.gets.split[0].to_i
$tree=Array.new(n+1){|i| Node.new(i)}
$pre =Array.new(n)
$in_ =Array.new(n)


s = STDIN.gets.split
0.upto(n-1){|i|
  $pre[i] = s[i].to_i
}

s = STDIN.gets.split
0.upto(n-1){|i|
  $in_[i]  = s[i].to_i
}

$pre_cnt=0
def get_pre_order
  ret=$pre[$pre_cnt]
  $pre_cnt += 1
  ret
end

def make_tree(array)
  root = get_pre_order

=begin
  printf("root=%d|",root)
  for n in array
    printf("%d ",n)
  end
  printf("[%d]\n",array.length)
=end

  if(array.length == 1)
    $tree[root].left = -1
    $tree[root].right= -1
  else
    pos=array.index(root)
    if(pos==0)
      $tree[root].left = nil
    else
      left_node = make_tree(array[0...pos])
      left_node.parent = $tree[root]
      $tree[root].left = left_node
    end
    if(pos == array.length-1)
      $tree[root].right= nil
    else
      right_node = make_tree(array[pos+1...$tree.length])
      right_node.parent = $tree[root]
      $tree[root].right  = right_node
    end
  end
  $tree[root]
end

make_tree($in_)
$tree[$pre[0]].postorder(1)
printf("\n")

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

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

    int ans(0);
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3580
import sys

numBridge = 0
visited = set()

def singletonSet(x):
    r = set()
    r.add(x)
    return r

def dfs(start, stack):
#    print("dfs: stack = {}".format(stack))
    global numBridge
#    print("added {} to visited".format(start))
    visited.add(start)
    tree[start] = []
    for v in nbr[start]:
#        print("checking {}->{}".format(start, v))
        if v in done[start]:
            pass
        else:
            done[v].add(start)
            tree[start].append(v)
            if v in visited:
#                print("visited {}->{}".format(start, v))
                loop[start].add(v)
                while not v in stack:
                    w = revtree[v]
                    loop[w].add(v)
                    v = w
                t = v
#                print("common top is {}".format(t))
                v = start
                while v != t:
                    w = revtree[v]
                    loop[w].add(v)
                    v = w
            else:
                revtree[v] = start
                dfs(v, stack.union(singletonSet(start)))

def count():
    c = 0
    for p in range(1, n + 1):
#        print("tree[{}] = {}".format(p, tree[p]))
#        print("loop[{}] = {}".format(p, loop[p]))
        c += len(tree[p]) - len(loop[p])
    return c

f = sys.stdin
n, m = map(int, next(f).rstrip().split(' '))
nbr     = [[]    for _ in range(n + 1)]
tree    = [[]    for _ in range(n + 1)]
done    = [set() for _ in range(n + 1)]
revtree = [None  for _ in range(n + 1)]
loop    = [set() for _ in range(n + 1)]
for line in f:
    (p, q) = map(int, line.rstrip().split(' '))
#    print("p, q = {}, {}".format(p, q))
    nbr[p].append(q)
    nbr[q].append(p)

dfs(1, set())
print(count())



Measured memory_bytes: 3188
fn main() {
    proconio::input! {
        n: usize,
    }
    let mut ans = 0;
    for i in 1..=n {
        if i % 3 == 0 || i % 5 == 0 {
            continue;
        }
        ans += i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
a[9][9][11],b,f,r,v,n;
main(){for(scanf("%d",&n);n--;scanf("%d%d%d%d",&b,&f,&r,&v),a[b][f][r]+=v);for(b=0;b++<4;b>3?exit(0):puts("####################"))for(f=0;f++<3;puts(""))for(r=0;r++<10;printf(" %d",a[b][f][r]));}

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

inline long long read()
{
	long long x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

typedef long long ll;
const int MAXN = 1000005;
ll p[MAXN],q[MAXN];
ll n,cnt,cntp,cntq;

inline void sol(ll n)
{
	if(!n) return;
	if(~n&1) q[++cntq]=cnt++,sol(n-1);
	else p[++cntp]=cnt++,sol(n>>1);
}

int main(int argc, char const *argv[])
{
	n=read(); sol(n); printf("%lld\n", cnt+100);
	for(ll i=1; i<=cntq; ++i) printf("%lld ", cnt-q[i]);
	for(ll i=cntp; i; --i) printf("%lld ", cnt-p[i]);
	for(ll i=1; i<=100; ++i) printf("%lld ", i);
	return 0;
}

Measured memory_bytes: 3760
use std::cmp::min;

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let hwk: Vec<usize> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
    let (h, w, k) = (hwk[0], hwk[1], hwk[2]);
    let mut map = vec![vec![0; w]; h];
    for y in 0..h {
        line = String::new();
        std::io::stdin().read_line(&mut line);
        let line_bytes = line.as_bytes();
        for x in 0..w {
            if line_bytes[x] == 0x31 {
                map[y][x] = 1usize;
            } else {
                map[y][x] = 0usize;
            }
        }
    }
    // Split
    let mut ans = h * w * 2;
    for h_split in 0..(1 << (h - 1)) {
        let mut fail = false;
        let mut sum = vec![0; h];
        let mut cur_ans = 0;
        for x in 0..w {
            let mut cur = vec![0; h];
            cur[0] = map[0][x];
            for y in 0..h - 1 {
                if (h_split >> y & 1) > 0 {
                    cur[y + 1] = map[y + 1][x]
                } else {
                    cur[y + 1] = map[y + 1][x] + cur[y];
                }
            }
            if *(cur.iter().max().unwrap()) > k {
                fail = true;
                break;
            }
            let mut split_x = false;
            for y in 0..h {
                if cur[y] + sum[y] > k {
                    split_x = true;
                    break;
                }
            }

            for y in 0..h {
                if split_x {
                    sum[y] = cur[y]
                } else {
                    sum[y] += cur[y]
                }
            }
            if split_x { cur_ans += 1 }
        }

        for y in 0..h - 1 {
            if (h_split >> y & 1) > 0 {
                cur_ans += 1
            }
        }
        if  !fail {
            ans = min(ans, cur_ans);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;

    vector<int> r(n);
    REP(i, n) {
        int tmp; cin >> tmp;
        r[i] = tmp - 1;
    }

    int cnt = 0;
    REP(i, n)
        if (i == r[r[i]]) cnt++;

    cout << cnt / 2 << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    int first=b[n-1];
    int second=b[n-2];
    // for(int i=n-2;i>=0;i--){
    //     if(b[i]!=first){
    //         second=b[i];
    //         break;
    //     }
    // }
    for(int i=0;i<n;i++){
        if(a[i]==first){
            cout<<second<<endl;
        }else{
            cout<<first<<endl;
        }
    }
    
    return 0;
    
}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;

int n, m;
ll dp[1005][1005];
char mat[1005][1005];


int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> mat[i][j];
        }
    }    

    
    for (int r = 0; r < n; ++r) {
        for (int c = 0; c < m; ++c) {
            if ( r == 0 && c == 0 ) {
                dp[r][c] = 1;
                continue;
            }

            if ( r - 1 >= 0 && mat[r][c] == '.' ) dp[r][c] = dp[r - 1][c] % mod;
            if ( c - 1 >= 0 && mat[r][c] == '.' ) dp[r][c] += dp[r][c - 1] % mod;
        }
    }

    cout << dp[n - 1][m - 1] % mod << endl;
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int K;
    cin >> K;

    ll sum = 0;
    ll mul = 1;
    REP(i, K) {
        sum += (7 * (mul % K));
        sum %= K;
        if (sum == 0) {
            cout << i + 1 << endl;
            return 0;
        }
        mul = (mul * 10) % K;
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3644
n = gets.to_i
t_list = gets.split(' ').map(&:to_i)
v_list = gets.split(' ').map(&:to_i)

t_list.map!.with_index{|t, i| i == 0 ? t : (t + t_list[i-1]) }
tv_list = t_list.zip(v_list)
t_list.unshift(0)
v_list.push(0)
lim_list = t_list.zip(v_list).map{|t, v| t + v}

v = 0
t = 0
sum = 0
tv_list.each.with_index do | (t_lim, v_lim), i|
  t1 = v_lim - v + t #現在の時間の制限速度に引っかかる時
  t2 = (lim_list[(i+1)..n].min - v + t)/2.0 #将来の制限速度に引っかかる時
  t0 = [t1, t2, t_lim].min
  dt = t0 - t
  sum += (v*2 + dt) * dt / 2.0
  t  = t0
  v += dt
  case t0
  when t1
    t2 = lim_list[(i+1)..n].min - v
    if t2 < t_lim
      dt = t2 - t
      sum += dt * v
      dt = t_lim - t2
      sum += (v*2 - dt) * dt / 2.0
      v -= dt
    else
      dt = t_lim - t
      sum += dt * v
    end
  when t2
    dt = t_lim - t
    sum += (v*2 - dt) * dt / 2.0
    v -= dt
  end
  t = t_lim
end
puts sum.to_s

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
//ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
//ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){

  int n,m;
  cin >> n >> m;

  vector< vector<ll> > dp(n+1,vector<ll>(m+1,0));
  vector<ll> s(n),t(m);

  /*
    2dimBITを使えば
    cnt[i][j] := sのi文字目とtのj文字目が最後になるときの個数
    とすると
    s[i]==t[j]:
      cnt[i][j] = sum(cnt[x][y]|x<i,y<j) + 1;
    s[i]!=t[j]:
      cnt[i][j] = 0;
    とするとO(NM(logNlogM))でできる
    ans = sum(cnt)


    dp[i][j] := sはi文字目までtはj文字目まで見た時の個数
    ans = dp[n][m]
    2dimBITの時はans=sum(cnt)だった。今回はdp[i][j]をdp[n][m]まで伝搬させてる？？
    dp[i+1][j+1] = (伝搬されてきたやつ) + (sのi文字目とtのj文字目が最後になるときの個数)
    (伝搬されてきたやつ) = dp[i+1][j] + dp[i][j+1] - dp[i][j]
    (sのi文字目とtのj文字目が最後になるときの個数) = dp[i][j]
    O(NM)

    s[i]!=t[j]の時:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j];
    s[i]==t[j]の時:
      dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1];
  */

  for(auto &&x:s)cin>>x;
  for(auto &&x:t)cin>>x;
  for(int i=0;i<n+1;i++)dp[i][0] = 1;
  for(int j=0;j<m+1;j++)dp[0][j] = 1;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      dp[i+1][j+1] += dp[i][j+1];
      dp[i+1][j+1] += dp[i+1][j];
      if(s[i]!=t[j]){
        dp[i+1][j+1] += MOD - dp[i][j];
      }
      dp[i+1][j+1] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 31616
#include<stdio.h>
int main(){
  int n,d[10][11];
  int i,s,j;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      s=0;
      for(j=0;j<n;j++){
	scanf("%d",&d[i][j]);
	s+=d[i][j];
	printf("%5d",d[i][j]);
      }
      printf("%5d\n",s);
      d[i][j]=s;
    }
    for(i=0;i<=n;i++){
      s=0;
      for(j=0;j<n;j++){
	s+=d[j][i];
      }
      printf("%5d",s);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 616
#include <algorithm>
#include <cstdio>

using namespace std;

#define MAXN 100000
int N;
pair<int, int> data[MAXN];

int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; ++i) {
    int a; scanf("%d", &a);
    data[i] = make_pair(a, i);
  }
  sort(data, data + N);
  int res = 0;
  for(int i = 0; i < N; i += 2) {
    if(data[i].second % 2 == 1) ++res;
  }
  printf("%d\n", res);
  return 0;
}


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

bool IsPrime(int n) {
    for(int i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            return false;
        }
    }
    return true;
}

int main(void){
   int count = 0, n;
   cin >> n; 
   for(int i = 0; i < n; i++) {
       int p;
       cin >> p;
       if(IsPrime(p)){	
       	count ++;
 }
   }
   cout << count << endl;
   return 0;
}


Measured memory_bytes: 3064
// A - Changing a Character

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

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

	string S;
	cin >> S;

	S[K-1] = tolower(S[K-1]);

	cout << S << endl;

	return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

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

    cout << (abs(x - a) < abs(x - b) ? "A" : "B");
}


Measured memory_bytes: 256