akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
using namespace std;

const int INF=0x3f3f3f3f;
int n,m;


struct Stu{
    int x,y;
    int des,dis=INF;
}stu[55];
struct Che{
    int x,y;
}che[55];

int dist(int i,int j){
    return (abs(stu[j].x-che[i].x)+abs(stu[j].y-che[i].y));
}

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++) scanf("%d%d",&stu[i].x,&stu[i].y);
    
    int tem;
    for(int i=0;i<m;i++){
        scanf("%d%d",&che[i].x,&che[i].y);
        for(int j=0;j<n;j++){
            tem=dist(i,j);//cout <<tem<<" dis "<<stu[j].dis<<endl;
            if(tem<stu[j].dis){
                
                stu[j].dis=tem;stu[j].des=i;
            }
        }
        
    }
    for(int i=0;i<n;i++) printf("%d\n",stu[i].des+1);
    return 0;
}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

candidate = p[:X] + q[:Y] + r[:X+Y]
candidate.sort(reverse = True)

print(sum(candidate[:X+Y]))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) for(int i=0;i<n;i++)
using vi=vector<int>;

int main(void){
    int n,m;
    while(cin>>n>>m,n|m){
        vi l;
        l.push_back(stoi(to_string(n+1000000).substr(7-m)));
        rep(i,20){
            string mx,mn;
            mx=mn=to_string(n+1000000).substr(7-m);
            sort(rall(mx));
            sort(all(mn));
            n=stoi(mx)-stoi(mn);
            auto itr=find(all(l),n);
            if(itr==l.end()){
                l.push_back(n);
            }else{
                cout<<(itr-l.begin())<<" "<<n<<" "<<i-(itr-l.begin())+1<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3288
n, m = map(int, input().split())
a = [False] * (n+1)
b = [0] * (n+1)

ac = 0
wa = 0
for i in range(m):
  p,s = input().split()
  p = int(p)
  
  if (not a[p]) and s == "WA":
    b[p] += 1
  elif (not a[p]) and s == "AC":
    ac += 1
    wa += b[p]
    a[p] = True
    
    
print(ac,wa)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main()
{
    fast_cin;
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    int N=0,K;
    cin>>N>>K;
    vector<int> h(N);
    vector<int> dp(N,INT_MAX);
    for(ll i=0;i<N;i++){
        cin>>h[i];
    }

    dp[0]=0;
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=i+K;j++){
            if(j<N){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }


    cout<<dp[N-1]<<"\n";

    return 0;
}

Measured memory_bytes: 3996
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
			System.out.println("Yes");
			return;
		}
		
		System.out.println("No");

	}

}


Measured memory_bytes: 23124
from collections import defaultdict

n = int(input())
li_input = list(map(int, input().split()))

li_ki = li_input[0::2]
d_ki = defaultdict(int)
for ki in li_ki:
    d_ki[ki] += 1


li_gu = li_input[1::2]
d_gu = defaultdict(int)
for gu in li_gu:
    d_gu[gu] += 1

ki_sort = sorted([(k, v) for k,v in d_ki.items()], key=lambda x : x[1], reverse=True)
gu_sort = sorted([(k, v) for k,v in d_gu.items()], key=lambda x : x[1], reverse=True)

ki_cnt = 0
gu_cnt = 0

if ki_sort[0][0] != gu_sort[0][0]:
    print(n - ki_sort[0][1] - gu_sort[0][1])
else:
    ki_1 = ki_sort[0][1]
    ki_2 = ki_sort[1][1] if len(ki_sort) > 1 else 0

    gu_1 = gu_sort[0][1]
    gu_2 = gu_sort[1][1] if len(gu_sort) > 1 else 0

    print(min(n - ki_1 - gu_2, n - ki_2 - gu_1))



Measured memory_bytes: 22336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll Size=1e6+7;
ll parent[1000010];
ll Rank[1000010];
ll SIZE[1000010];
ll mx=0;
ll GCD(ll a,ll b)
{
    return (b == 0) ? a:GCD(b,a%b);
}
ll LCM(ll a,ll b)
{
    return a*b/GCD(a,b);
}
vector<ll>prime;
ll ar[10000010];
void sive()
{
    ll i,j,k;
    for(i=2; i*i<=1e7; i++)
    {
        if(ar[i])
            continue;
        prime.push_back(i);
        for(j=i+i; j<=1e7; j+=i)
            ar[j]=1;
    }
}
int main()
{
    ll n,m;
    ll i,j,k;
    sive();
    ll a,b;
    cin>>n;
    vector<ll>adj[n+10];
    vector<ll>v;
    for(i=0; i<n; i++)
    {
        cin>>a;
        v.push_back(a);
    }
    ll gcd=v[0];
    ll mx=0;
    map<ll,ll>mp;
    for(i=0; i<n; i++)
    {
        a=v[i];
        gcd=GCD(gcd,a);
        for(j=0; j<prime.size()&&prime[j]*prime[j]<=a; j++)
        {
            ll f=0;
            while(a%prime[j]==0)
            {
                f=1;
                a/=prime[j];
            }
            if(f)
            {
                mp[prime[j]]++;
                mx=max(mp[prime[j]],mx);

            }
        }
        if(a>1)
        {
            mp[a]++;
            mx=max(mp[a],mx);
        }
    }
    if(mx<=1)
        cout<<"pairwise coprime"<<endl;
    else if(gcd==1)
        cout<<"setwise coprime"<<endl;
    else
        cout<<"not coprime"<<endl;
    return 0;
}


Measured memory_bytes: 117548
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        mut av: [usize; n]
    };

    let max = 1_000_000;
    let mut table = HashMap::new();
    av.sort();
    let mut res = 0;
    let mut can_div = vec![false; max + 1];
    let mut divs = HashSet::new();
    for a in av {
        *table.entry(a).or_insert(0) += 1;
        if can_div[a] {
            continue;
        }
        divs.insert(a);
        res += 1;
        can_div[a] = true;
        let mut j = a + a;
        while j <= max {
            can_div[j] = true;
            j += a;
        }
    }
    for (a, c) in table {
        if divs.contains(&a) && c > 1 {
            res -= 1;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 12924
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ma, mb;
    cin >> ma >> mb;
    int maxa = 0, maxb = 0;
    vi a(n), b(n), c(n);
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
        maxa = max(maxa, a[i]);
        maxb = max(maxb, b[i]);
    }

    auto num = [&](int i, int j) {
        return i*(n*maxb+1)+j;
    };
    int X = num(maxa*n, maxb*n);
    vi dp(num(maxa*n, maxb*n)+1, INF);
    dp[0] = 0;
    rep(i, n) {
        int numm = num(a[i], b[i]);
        for(int j = X-numm; j >= 0; j--) {
            dp[j+numm] = min(dp[j+numm], dp[j]+c[i]);
        }
    }


    int K = num(ma, mb);
    int ans = INF;
    for(int i = 1; i*ma <= n*maxa and i*mb <= n*maxb; ++i) {
        ans = min(ans, dp[i*K]);
    }

    cout << (ans == INF?-1:ans) << endl;
}

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = 99999999;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int ls[] = {5,7,5,7,7};
    while(1){
        int n,w[40];
        cin >> n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            string s;
            cin >> s;
            w[i] = s.size();
        }
        for(int i=0;i<n;i++){
            int k=0,sum=0;
            for(int j=i;j<n;j++){
                if(sum < ls[k])sum += w[j];
                if(sum>ls[k])break;
                if(sum == ls[k]){
                    k++;
                    sum = 0;
                }
                if(k==5)break;
            }
            if(k==5){
                cout << i+1 << endl;
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n, m, K;
    scanf("%d%d%d", &n, &m, &K);
    For(a, 1, n+1){
        int s = 2*a - n, t = K + a*m - m*n;
        if(s == 0){
            if(t == 0){
                puts("Yes");
                return 0;
            }
        }
        else if(t % s == 0){
            int u = t / s;
            if(0<=u && u<=m){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}

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

const int mxN = 1e5 + 10;
int dp[mxN];

int rec(vector<int>& v, int i, int n) {
	if(i == (n-1)) {
		return dp[n-1] = 0;
	}
	if(dp[i] != -1) return dp[i];
	int ans = INT_MAX;
	if(i + 1 <= n-1)
		ans = min(ans, abs(v[i] - v[i+1]) + rec(v, i+1, n));
	if(i + 2 <= n-1)
		ans = min(ans, abs(v[i] - v[i+2]) + rec(v, i+2, n));
		
	return dp[i] = ans;
}

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	
	for(int i = 0; i < n; i++) {
		cin >> v[i];
	}
	
	memset(dp, -1, sizeof(dp));
	cout << rec(v, 0, n) << "\n";
}


Measured memory_bytes: 11876
#include <vector>
#include <iomanip>
#include <iostream>

using namespace std;
 
int N;
 
vector<vector<int> > square1001Div2;
 
int main()
{
    while(true)
    {
        cin >> N;
         
        if(N == 0) { break; }
     
        square1001Div2 = vector<vector<int> >(N, vector<int>(N, 0));
         
        int ptrx = N / 2, ptry = N / 2 + 1;
         
        for(int rep = 1; rep <= N * N; rep++)
        {
            square1001Div2[ptry][ptrx] = rep;
             
            ptrx = (ptrx + 1) % N;
            ptry = (ptry + 1) % N;
             
            while(square1001Div2[ptry][ptrx] != 0 && rep != N * N)
            {
                ptrx = (ptrx + N - 1) % N;
                ptry = (ptry + 1) % N;
            }
        }
         
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < N; j++)
            {
                cout << setw(4) << square1001Div2[i][j];
            }
             
            cout << endl;
        }
    }
     
    return 0;
}

Measured memory_bytes: 3060
import copy
 
def dfs(A, times):
    if times == N:
        if min(A[1:M+1]) >= X:
            ans[0] = min(A[0], ans[0])
        return
    dfs(copy.copy(A), times+1)
    for i in range(M+1):
        A[i] = A[i] + L[times][i]
    dfs(copy.copy(A), times+1)

N, M, X = map(int, input().split())
L = [0] * (N)
for i in range(N):
    L[i] = [int(x) for x in input().split()]

INF = float('inf')
ans = [INF]
tmp = [0] * (M+1)
dfs(tmp, 0)
if ans[0] == INF:
    ans[0] = -1
print(ans[0])

Measured memory_bytes: 9360
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			int n = in.nextInt(), m = in.nextInt();
			if(n == 0 && m == 0) return;

			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = -in.nextInt();

			Arrays.sort(a);

			int ans = 0;
			for(int i = 0; i < n; i++){
				if((i + 1) % m != 0) ans -= a[i];
			}

			System.out.println(ans);
		}
	}
	
}

// while(in.hasNext()){
		// 	int n = in.nextInt();
		// 	if(n == 0) return;
			
		// }

Measured memory_bytes: 58724
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {

    int n, i, count = 0;
    scanf("%d\n", &n);
    char s[n];
    gets(s);

    for (i = 0; i < n - 2; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            count++;
        }
    }

    printf("%d", count);

    return 0;
}


Measured memory_bytes: 128
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

y = int(input())

print(x[y-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
using pl = pair<ll,ll>;
signed main(){
	ll n; cin>>n;
    vector<pl> vec(n);
	rep(i,0,n){
		ll a,b; cin>>a>>b;
		vec[i].first=a-b;
		vec[i].second=a+b;
	}
	sort(all(vec));
	ll ans=0;
	ll memo=10000000000;
	for(ll i=n-1;i>=0;--i){
		if(vec[i].second>memo)continue;
		ans++;
		memo=vec[i].first;

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

Measured memory_bytes: 4832
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
int dis[N][N];
char str[N][N];
int dx[] = { 0,0,-1,1 };
int dy[] = { 1,-1,0,0 };
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> (str[i] + 1);
		cnt += count(str[i] + 1, str[i] + m + 1, '.');
	}
	queue<pair<int, int>> q;
	q.emplace(1, 1);
	dis[1][1] = 1;
	while (!q.empty())
	{
		int x, y;
		tie(x, y) = q.front();
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int tx = x + dx[i];
			int ty = y + dy[i];
			if (ty < 1 || ty > m) continue;
			if (tx < 1 || tx > n) continue;
			if (str[tx][ty] == '#') continue;
			if (dis[tx][ty]) continue;
			dis[tx][ty] = dis[x][y] + 1;
			q.emplace(tx, ty);
		}
	}
	if (dis[n][m] == 0) puts("-1");
	else printf("%d\n", cnt - dis[n][m]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N,K=2;
  cin>>N;
  vector<int> h(N);

  for(int i=0;i<N;i++){
    cin>>h[i];
  }

  vector<ll> dp(N,1e12);
  dp[0]=0;
  for(int i=1;i<N;i++){
    for(int j=1;j<=K;j++){
      if(i-j<0) break;
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
  }
  cout<<dp[N-1]<<endl;
  return 0;
}




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

vector<int> city(51);

int main() {
  int N, M;
  cin >> N >> M;
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    city.at(a - 1)++;
    city.at(b - 1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << city.at(i) << endl;
  }
  
}

Measured memory_bytes: 256
N = int(input())
ds = list(map(int, input().split()))
# index: 0,...,N-1

ans = 0

for i in range(N-1): # i: 0,...,N-2
    for j in range(i+1,N): # j: i+1,...,N-1
        # print(i,j)
        ans += ds[i] * ds[j]

print(ans)


Measured memory_bytes: 2940
import numpy as np
N,M,X = (int(x) for x in input().split())
Data  = np.zeros((N,M+1),dtype=int)
for Book in range(0,N):
    Data[Book,:] = np.array([int(x) for x in input().split()])

minCost = float('inf')
OK_Flag = 0
for Pt in range(0,pow(2,N)):
    strA  = (list(format(Pt,'0'+str(N)+'b')))
    intA  = np.array([int(x) for x in strA],dtype=bool)
    Price = np.sum(intA.reshape(N,1)*Data,axis=0)
    if (all(Price[1:]>=np.full(M,X))) & (Price[0]<minCost):
        minCost = Price[0]
        OK_Flag = 1

if OK_Flag:
    print(minCost)
else:
    print('-1')

Measured memory_bytes: 27368
#!/usr/bin/env python3
#ABC125 D

n = int(input())
a = list(map(int,input().split()))
cnt = 0
mi = float('inf')
tmp = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
    if mi > abs(a[i]):
        mi = abs(a[i])
        tmp = i
s = list(map(lambda x:abs(x),a))
if cnt % 2:
    print(sum(s)-2*s[tmp])
else:
    print(sum(s))


Measured memory_bytes: 14412
a=input()
k=int(input())
if int(a)<10:
    a=str(int(a)*11)
i=0
x=0
while k>=0:
    if a[i]=='1':
        k-=1
        i+=1
        if k==0:
            x=1
            k=-1
    else: 
        k=-1
print(a[i-x])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int H,W; cin>>H>>W;
    vector<vector<int>> a(H,vector<int>(W));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>a[i][j];

    vector<vector<int>> sum(H+1,vector<int>(W+1));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++){
        sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+a[i][j];
    }
    
    auto solve=[&](int i1,int j1)
    {
        int res=0;
        for(int i2=i1,j2=j1;i1<=H and j1<=W;i1++,j1++){
            while(i2<=H and j2<=W and sum[i2][j2]-sum[i2][j1]-sum[i1][j2]+sum[i1][j1]==0){
                i2++; j2++;
            }
            chmax(res,i2-i1-1);
        }
        return res;
    };

    int ans=0;
    for(int j=0;j<=W;j++) chmax(ans,solve(0,j));
    for(int i=0;i<=H;i++) chmax(ans,solve(i,0));
    ans*=ans;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 33592
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        s: String,
    }
    let sc = s.chars().collect::<Vec<char>>();
    if sc[sc.len() - 1] == 's' {
        println!("{}{}", s, "es");
    } else {
        println!("{}{}", s, "s");
    }
}


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

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

typedef long long Int;

struct edge {Int to, cost;};

vector<vector<edge>> G(100010);
vector<int> cn(100010);

void dfs(Int now, Int par = -1) {
    int n = cn[now];
    for (edge e : G[now]){
        if (e.to == par) continue;
        if (e.cost % 2 == 1) {
            cn[e.to] = (n + 1) % 2;
        }
        else cn[e.to] = n;
        dfs(e.to, now);
    }
    return;
}


int main() {

    Int N;
    cin >> N;
    rep(i,N-1) {
        Int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }

    cn[0] = 0;
    dfs(0);

    rep(i,N) cout << cn[i] << endl;

    return 0;
}


Measured memory_bytes: 10624
w, h, n = map(int, input().split())
st = set()
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    for k in range(x):
      for l in range(h):
        st.add((k, l))
  elif a == 2:
    for k in range(x, w):
      for l in range(h):
        st.add((k, l))
  elif a == 3:
    for k in range(w):
      for l in range(y):
        st.add((k, l))
  elif a == 4:
    for k in range(w):
      for l in range(y, h):
        st.add((k, l))
print(w * h - len(st))

Measured memory_bytes: 9996
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<int ,int> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int s,a,H,W,D,Q,r,l,d[90001],L[100001],R[100001];
  P p,n;
  map<int,P> mp;
  cin >> H >> W >> D;
  REP(i,H)REP(j,W){
    cin >> a;
    mp[a] = P(i,j);
  }
  for(int i = 1;i<=D;i++){
    p = mp[i];
    d[i] = 0;
    s = i;
    while(1){
      if(s+D > H*W)
        break;
      n = mp[s+D];
      d[s+D] = d[s] + abs(p.first-n.first)+abs(p.second-n.second);
      s += D;
      p = n;
    }
  }
  cin >> Q;
  REP(i,Q){
    cin >> L[i] >> R[i];
  }
  REP(i,Q){
    cout << d[R[i]]-d[L[i]] << endl;
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 7936
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
vector<string> dic;
void insert(string s){
    dic.push_back(s);
}
void find(string s){
    for (int i = 0; i < dic.size(); i++)
    {
        if(dic[i]==s){
            cout<<"yes"<<endl;
            return ;
        }
    }
    cout<<"no"<<endl;
}
/* 
int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string order, s;
        cin >> order >> s;
        if(order=="insert"){
            insert(s);
        }else{
            find(s);
        }
    }
}
*/
int main(){
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++)
    {
        string order, s;
        cin >> order >> s;
        if(order=="insert"){
            st.insert(s);
        }else{
            if(st.find(s)!=st.end()){
                cout<<"yes"<<endl;
            }else{
                cout<<"no"<<endl;
            }
        }
    }
    
}


Measured memory_bytes: 32148
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

const int upTo = 2e5 + 5;
int f[upTo];
int p2[2][upTo];
int md[2];
int tot[2];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	for (char c : s) md[0] += (c == '1');
	--md[0]; md[1] = md[0]+2;

	if (md[0] == 0) ++md[0];
	p2[0][0] = 1 % md[0];
	p2[1][0] = 1 % md[1];
	for (int x = 1; x < upTo; ++x) {
		f[x] = 1 + f[x % __builtin_popcount(x)];
		p2[0][x] = (2*p2[0][x-1])%md[0];
		p2[1][x] = (2*p2[1][x-1])%md[1];
	}
	for (int i = 0; i < n; ++i) {
		if (s[i] == '1') {
			tot[0] = (tot[0]+p2[0][n-1-i])%md[0];
			tot[1] = (tot[1]+p2[1][n-1-i])%md[1];
		}
	}
	for (int i = 0; i < n; ++i) {
		if (s[i] == '0') {
			int x = (tot[1]+p2[1][n-1-i])%md[1];
			cout << 1+f[x] << "\n";
		} else {
			if (md[1] == 2) { cout << "0\n"; continue; }
			int x = (tot[0]-p2[0][n-1-i]+md[0])%md[0];
			cout << 1+f[x] << "\n";
		}
	}
}


Measured memory_bytes: 6080
#import sys
#N = int(input())
K, X = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]

T = [str(i) for i in range(X - (K-1), X + K) if i >= -1000000 and i <= 10000000]
print(' '.join(T))


#sys.exit()

Measured memory_bytes: 2940
#include<stdio.h>

int main()
{
  int n = 0,S[10000],q = 0,T[500],i = 0,j = 0,k = 0,l = 0,C = 0;
  
  scanf("%d",&n);
  for(i = 0;i < n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);
  for(j =0;j < q;j++)
    {
      scanf("%d",&T[j]);
    }
  
  for(k = 0;k < q;k++)
    {
      for(l = 0;l < n;l++)
	{
	  if( S[l] == T[k]){
	      C++;
	      break;
	    }
	}
      
    }
  printf("%d\n",C);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)

// for debug macro
bool global_debug_flag = false;
#define DEBUG(val) \
  if (global_debug_flag) cout << #val << " = " << val << endl

// dp[max_keta][tight_flag 基本は2値][condition_flag ここで条件をカウント]
int dp[100005][2][105];
long mod = 1000000007;
// 前提：globalにメモ化のdp配列が定義されていること(かつ-1で初期化されていること)
// このtemplateは各桁の和がDになるものを集めてくる。
long rec(string &s, int D, int keta = 0, bool tight = true, int sum = 0) {
  if (keta == s.size()) {
    // sumが条件を満たした場合(sum == D)に1を返してカウント扱い。
    // 満たさなかったら0を返却。
    return sum % D == 0;
  }

  int x = s[keta] - '0';
  int r = tight ? x : 9;
  long res = 0;
  // -1で初期化しているので、すでに値が求められていた場合は即返す。
  if (dp[keta][tight][sum] != -1) {
    return dp[keta][tight][sum];
  } else {
    for (int i = 0; i <= r; i++) {
      // 下位桁に渡す。ここでsumの値を調整して条件に合うやつを集めてくる
      res += rec(s, D, keta + 1, tight && i == r, (sum + i) % D) % mod;
      res %= mod;
    }
  }

  dp[keta][tight][sum] = res;
  return res;
}

int main() {
  memset(dp, -1, sizeof(dp));
  string s;
  cin >> s;
  int d;
  cin >> d;
  cout << (rec(s, d) - 1 + mod) % mod << endl;
}

Measured memory_bytes: 83456
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      string n;
      cin >> n;
      string s="ABC";
      s+=n;
      cout << s << endl;
      return 0;}

Measured memory_bytes: 256
/****************************
*  Developer : joshi08
*  Date  :  14-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a,lli b) {lli i,p=1; for(i=0;i<b;i++){p*=a;} return p;}

using namespace std;

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

	lli x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;
	
	if(x1==0)
		cout<<1;
	else
	if(x2==0)
		cout<<2;
	else
	if(x3==0)
		cout<<3;
	else
	if(x4==0)
		cout<<4;
	else
	if(x5==0)
		cout<<5;

    return 0;
}



Measured memory_bytes: 3668
// https://atcoder.jp/contests/abc149/tasks/abc149_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <int_fast64_t max_N> struct Prime {
    bool sieve[max_N];
    constexpr Prime() : sieve() {
        for (int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for (int_fast64_t i = 2; i < max_N; ++i) {
            for (int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X;
    cin >> X;
    constexpr auto p = Prime<100010>();
    FOR(i, X, 100010) {
        if (p.sieve[i]) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e6+10;
char s[maxn],t[maxn];
int q[maxn],l=1,r;
int main(){
	int n=read(),ans=0;
	scanf("%s%s",s+1,t+1);
	if(!strcmp(s+1,t+1)) return printf("0\n"),0;
	for(int i=n,j=n;i>=1;--i) if(i==1 || t[i]!=t[i-1]){
		chkmin(j,i);
		while(j && s[j]!=t[i]) --j;
		if(!j) return printf("-1\n"),0;
		while(l<=r && q[l]-r+l>i) ++l;
		q[++r]=j;
		if(i!=j) chkmax(ans,r-l+1);
	}
	printf("%d\n",ans+1);
	return 0;
}


Measured memory_bytes: 6144
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b / a, c) << endl;
}

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

#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, mn, mx = -linf;

signed main() {
	cin >> n >> a;
	mn = a;
	rep(i,n-1) {
		cin >> a;
		chmax(mx, a-mn);
		chmin(mn, a);
	}
	cout << mx << ln;
}


Measured memory_bytes: 3220
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string s[3];
  REP(i,3)cin>>s[i];
  REP(i,3)cout<<s[i][0];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない



int main() {

	int ans1 = 0, ans2 = 0;
	ll x, y;
	cin >> x >> y;

	if (x * 2 <= y) {
		cout << x + (y - 2 * x) / 4 << endl;
	}
	else {
		cout << (y - (y % 2)) / 2 << endl;
	}

	return 0;
}


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

int main(){
  int n, ans=0;
  cin >> n;
  vector<int> v(n), c(n);
  for(int i=0; i<n;i++){
    cin >> v[i];
  }
  for(int i=0; i<n;i++){
    cin >> c[i];
  }
  for(int i=0; i<n;i++){
    if(v[i]-c[i]>0){
      ans += v[i]-c[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int count_watering(vector<int> h) {
	int N = h.size();
	int count = 0;
	vector<vector<int>> garden;
	vector<int> part_gdn;

	//cout << "water " << N << endl;
	//for (int hh: h) {
	//	cout << hh << " ";
	//}
	//cout << endl;

	if (N == 0) {
		return 0;
	}
	else if (N == 1) {
		return h[0];
	}
	else {
		int min_h = 100;
		REP(i, N) {
			min_h = min(min_h, h[i]);
		}
		count += min_h;
		REP(i, N) {
			h[i] -= min_h;
			if (h[i] == 0 && part_gdn.size() != 0) {
				garden.push_back(part_gdn);
				part_gdn.clear();
				part_gdn.shrink_to_fit();
			}
			else if (h[i] != 0) {
				part_gdn.push_back(h[i]);
			}
		}
		if (part_gdn.size() != 0) {
			garden.push_back(part_gdn);
			part_gdn.clear();
			part_gdn.shrink_to_fit();
		}

		//for(vector<int> gdn: garden) {
		//	for(int hh: gdn) {
		//		cout << hh << " ";
		//	}
		//	cout <<endl;
		//}

		for(vector<int> gdn: garden) {
			count += count_watering(gdn);
		}

		return count;
	}

}

int main() {
	int N;
	cin >> N;
	vector<int> h(N);

	REP(i, N) {
		cin >> h[i];
	}

	cout << count_watering(h) << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int i,j,counta=0,countb=0,bx;
    string str;
bool bo=false;
void duce();
int main(){
    for(i=1;;i++){
            getline(cin,str);
        if(str[0]=='0'){
            break;
        }
            for(j=1;j<str.size();j++){
           // if(counta==10 && countb==10){
            //    duce();
              //  bo=true;
                //break;
            //}
            if(str[j]=='A'){
                counta++;
            }
            else if(str[j]=='B'){
                countb++;
            }
        }
        if(bo){
            bo=false;
        }
        else if(counta<countb){
            countb++;
        }
        else if(counta>countb){
            counta++;
        }
        cout<<counta<<" "<<countb<<endl;
        counta=0;
        countb=0;
    }
    return 0;
}
void duce(){
    counta=0;countb=0;
        for(;j<str.size();j++){
            if(str[j]=='A'){
                counta++;
            }
            else{
                countb++;
            }
        }
    
    return;
}

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

typedef long long int64;
const int
	MAX = 1e5 + 5,
	C = 1e5;
int n, a[MAX], freq[2 * MAX];

int64 f(int x) {
	for(int i = 0; i < 2 * MAX; i++)
		freq[i] = 0;

	int64 ans = 0, tot = 0;
	int s = 0;

	freq[C] = 1;
	
	for(int i = 1; i <= n; i++) {
		int v = (a[i] <= x) ? 1 : -1;

		s += v;

		if(v == -1)
			ans -= freq[s + C];

		else ans += freq[s - 1 + C];

		freq[s + C]++;
		tot += ans;
	}

	return tot;
}

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

	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	int64 M = f(1e9);

	int st = 1, nd = 1e9, ans = 1e9;

	while(st <= nd) {
		int mid = (st + nd) >> 1;

		if(f(mid) >= M / 2 + 1) {
			ans = min(ans, mid);
			nd = mid - 1;
		}

		else st = mid + 1;
	}

	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int ans=0;
  std::vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n;i++)if(v[v[i]-1]-1==i)ans++;
  cout<<ans/2<<endl;
}


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

int X;

int main() {
    cin >> X;

    int ans = X;
    int yakusu = 100;
    while (yakusu > 2) {
        yakusu = 0;
        for (int i = 1; i <= ans; i++) { 
            if ((ans % i) == 0) { 
                yakusu++;
            }
        }
        ans++;
    }
    cout << ans-1 << endl;
}


Measured memory_bytes: 256
#x = int(input())
#A = list(map(int, input().split()))
#n, x, t = map(int, input().split())
n = input()
list_num = list(n)
list_num = [int(n) for n in list_num]
ans = sum(list_num)
#print(list_num)
if ans % 9 == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 12496
H, W, N = map(int, open(0).read().split())

if( N % max(H, W) == 0):
  print(int(N/max(H, W)))
elif ( N < max(H, W)*int( round(int(N/max(H, W) +0.50)) ) ):
  print(round(N/max(H, W)))
else:
  print(round(N/max(H, W)) + 1)

Measured memory_bytes: 3064
N = int(input())
arm_range = []
for _ in range(N):
    X,L = map(int,input().split())
    arm_range.append([X+L,X-L])

arm_range = sorted(arm_range)

limit = arm_range[0][0]
ans = 1

for i in range(1,N):
    if arm_range[i][1] >= limit:
        ans += 1
        limit = arm_range[i][0] 

print(ans)

Measured memory_bytes: 21648
// https://atcoder.jp/contests/abc138/tasks/abc138_b
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    string s;
    cin >> a;
    cin >> s;
    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red\n";
    }
    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int S, W;
    cin >> S >> W;

    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	while (1) {
		int N; cin >> N;
		if (!N)return 0;
		string S; cin >> S;
		VI ans(N, 0);
		int ba = 0;
		REP(i, S.size()) {
			int now = i % N;
			if (S[i] == 'S') {
				ba += ans[now] + 1;
				ans[now] = 0;
			}
			if (S[i] == 'L') {
				ans[now] += ba + 1;
				ba = 0;
			}
			if (S[i] == 'M') {
				ans[now]++;
			}

		}


		SORT(ans);
		fore(i, ans)cout << i << " ";
		cout << ba << endl;
	}

	return 0;
}




Measured memory_bytes: 3152
//59
#include<iostream>

using namespace std;

int main(){
  char s[7*1001];
  cin>>s;
  char p=0;
  int l=0;
  char r;
  int rl=-1;
  for(int i=0;s[i];i+=(p=='e')?3:7){
    if(p==s[i]){
      l=0;
    }
    l++;
    p=s[i];
    if(l>rl){
      rl=l;
      r=p;
    }
  }
  cout<<((r=='e')?"egg":"chicken")<<endl;
  return 0;
}

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

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

const int MAX = 1e7 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, M;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll f(int cnt){
    return COM(N - 1 + cnt, cnt);
}

int main(){
    cin >> N >> M;

    map<int, int> m;
    int x = 2;
    while(M >= x * x){
        if(M % x){
            x++;
        } else {
            m[x]++;
            M /= x;
        }
    }
    if(M != 1) m[M]++;

    COMinit();

    ll ans = 1;
    for(auto i : m){
        int cnt = i.second;
        ans = ans * f(cnt);
        ans %= MOD;
    }

    cout << ans << endl;
}

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

int main(){
  vector<int> eratos(200+1, 0);
  for(int i=2; i<=200; i++)
    if(eratos[i] == 0){
      eratos[i] = i;
      for(int j=2; i*j<=200; j++)
        if(eratos[i*j] == 0)  eratos[i*j] = i;
    }

  int n;  cin >> n;
  int ans = 0;
  for(int i=3; i<=n; i+=2){
    int yaku = 1, nowi = i;
    do{
      int cnt = 0, d = eratos[nowi];
      while(nowi%d == 0){
        nowi /= d;
        cnt++;
      }
      yaku *= (cnt+1);
    }while(nowi != 1);
    if(yaku == 8)  ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,flag1=0;
    char ara[101];
    cin>>ara;

    for(i=1;i<=strlen(ara);i++)
    {
        if(i%2!=0)
        {
            if(ara[i-1]=='R'||ara[i-1]=='U'||ara[i-1]=='D')
            {
                flag1++;
            }
        }
    }
      for(i=1;i<=strlen(ara);i++)
    {
        if(i%2==0)
        {
            if(ara[i-1]=='L'||ara[i-1]=='U'||ara[i-1]=='D')
            {
                flag1++;
            }
        }
    }



    if(flag1==strlen(ara))
    {
        cout<<"Yes\n";
    }
    else
        cout<<"No\n";

}


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

int main(void){
    int n, m = 1e9 + 7; long long ans = 1; cin >> n;
    vector<int> a(n), c(n + 1, 0);
    for (int i = 0; i < n; i++) {cin >> a[i]; a[i]++;}
    c[0] = 3;
    for (int x: a){
        (ans *= c[x - 1] - c[x]) %= m;
        c[x]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>

#define MAX 9999999;

int min(int, int);

int main(){
  int n, i, j, l, k;
  int p[100+1], m[100+1][100+1];

  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1; i<=n; i++) m[i][i]=0;

  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      m[i][j]=MAX;
      for(k=i; k<=j-1; k++){
        m[i][j]=min(m[i][j], m[i][k] + m[k+1][j] + (p[i-1]*p[k]*p[j]));
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}

int min(int a, int b){
  if(a>b) return b;
  else return a;
}

Measured memory_bytes: 636