akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int bucket[200010];

int main(){
	int n, a;
	scanf("%d", &n);
	for(int i = 0; i < n-1; i++) {
		scanf("%d", &a);
		bucket[a-1]++;
	}
	for(int i = 0; i < n; i++)
		printf("%d\n", bucket[i]);
}


Measured memory_bytes: 4500
#全探索！
N, M = map(int,input().split())
K = []
for i in range(M):
    k =list(map(int,input().split()))
    K.append(k)
p = list(map(int,input().split()))
ans = 0

for i in range(2**N):
    for k in range(M):#kは電球のindex
        a = 0
        b = True
        for j in K[k][1:]:  # このループが一番のポイント
            if (((i >> (j-1) )& 1)):  # 順に右にシフトさせ最下位bitのチェックを行う
                a += 1
        if a%2 != p[k]:
            b = False
            break
    if b:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import numpy as np
import math
n, d = map(int,input().split())
x_l = [ np.array(list(map(int, input().split()))) for _ in range(n)  ]

ans = 0
p = set()
for i,x in enumerate(x_l):
    for j,y in enumerate(x_l):
        if i != j:
            if str(min([i,j]))+'_'+str(max([i,j])) not in p:
                d = math.sqrt(sum((x-y)**2))
                if d.is_integer():
                    ans += 1
                    p.add(str(min([i,j]))+'_'+str(max([i,j])))
print(ans)

Measured memory_bytes: 26996
#include <cstdio>
const int Maxn=100000;
int a[Maxn+5];
int main(){
	int h,n,sum=0;
	scanf("%d%d",&h,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum>=h){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    long X, K, D;
    cin >> X >> K >> D;
    long result;
    long minimum_candidate1;
    long minimum_candidate2;

    X = abs(X);

    if (X / D >= K) {
        result = X - K * D;
    } else {
        minimum_candidate1 = X % D;
        minimum_candidate2 = abs(minimum_candidate1 - D);

        if ((K - (X / D)) % 2 == 0) {
            result = minimum_candidate1;
        } else {
            result = minimum_candidate2;
        }
    }



    std::cout << result << std::endl;
    
}

Measured memory_bytes: 3172
from math import sqrt

N, D = map(int, input().split())

X = []
for i in range(N):
    x_line = list(map(int, input().split()))
    X.append(x_line)

count = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        droot = sqrt(float(dist))
        if droot.is_integer():
            count += 1

print(count)

Measured memory_bytes: 38384
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

X = I()

while 1:
    flag = True
    for i in range(2,int(X**0.5+1)):
        if X%i==0:
            flag = False
            break
    if flag:
        break
    else:
        X += 1

print(X)

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

typedef long long ll;

ll dp[101][4][2];

int main() {
	string N;
	cin>>N;
	ll K;
	cin>>K;
	dp[0][0][0]=1;
	for(ll i=0;i<N.size();i++){
      for(ll k=0;k<=3;k++){
        ll temp=N[i]-'0';//現在の桁              
        for(ll j=0;j<10;j++){
				if(j==0){
					if(j==temp){
                      //次の桁も現在の桁も0なのでkは変わらない
						dp[i+1][k][0]+=dp[i][k][0];
                    }
					else if(j<temp){
						dp[i+1][k][1]+=dp[i][k][0];
					}
					dp[i+1][k][1]+=dp[i][k][1];
				}
              
				else{
                  if(k==3) continue;
					if(j==temp){
						dp[i+1][k+1][0]+=dp[i][k][0];
					}
					else if(j<temp){
						dp[i+1][k+1][1]+=dp[i][k][0];
					}
					dp[i+1][k+1][1]+=dp[i][k][1];					
				}
              
			}
		}
	}
	cout << dp[N.size()][K][0]+dp[N.size()][K][1];
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll A[2000010],B[2000010];
void init(){
    A[0]=1;
    rep(i,2000001) A[i+1]=A[i]*(i+1)%mod;
    rep(i,2000002) B[i]=inv(A[i]);
}
ll nCk(ll n,ll k){
    return A[n]*B[k]%mod*B[n-k]%mod;
}
ll r1,r2,c1,c2;
ll frc(ll r,ll c){
    if(r>c) swap(r,c);
    if(r<0) return 0;
    return (frc(r-1,c)+nCk(r+c+1,c))%mod;
}
int main(){
    cin>>r1>>c1>>r2>>c2;
    init();
    cout<<(frc(c2,r2)-frc(c1-1,r2)-frc(c2,r1-1)+frc(c1-1,r1-1)+mod)%mod;
}


Measured memory_bytes: 62720
import java.util.*;
public class Main {

    public static void main(String[] args){
        Main main = new Main();
        main.input();
        main.solve();
        main.output();
    }

    int N; // 1<=N<=1000000
    long result;

    private void input() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
    }

    private void solve() {
        if (N == 1) {
            result = 0;
            return;
        }
        Calc c = new Calc();
        c.n = 2;
        c.num_all = 100;
        c.num_outof0 = 81;
        c.num_outof0and9 = 64;
        c.num_include0 = 19;
        c.num_include0and9 = 2;
        while (true) {
            if (c.n == N) { break; }
            c = c.next();
            // System.out.println(c.num_include0and9);
        }
        result = c.num_include0and9 % 1000000007;
    }

    private void output() {
        System.out.println(result);
    }
}

class Calc {
    int n;
    long num_all;
    long num_outof0;
    long num_outof0and9;
    long num_include0;
    long num_include0and9;

    public Calc next() {
        Calc c = new Calc();
        c.n = this.n+1;
        c.num_all = this.num_all*10 % 1000000007;
        c.num_outof0 = this.num_outof0*9 % 1000000007;
        c.num_outof0and9 = this.num_outof0and9*8 % 1000000007;
        c.num_include0 = (this.num_include0*10 + this.num_outof0) % 1000000007;
        c.num_include0and9 = (c.num_outof0and9 + c.num_include0*2 - c.num_all) % 1000000007;
        if (c.num_include0and9 < 0) {
            c.num_include0and9 += 1000000007;
        }
        return c;
    }
}

Measured memory_bytes: 52264
#include <bits/stdc++.h>
using namespace std;
#define N 40
#define M 405
int n,ma,mb,a[N],b[N],c[N],dp[M][M],ans=10000000,ans2;
int main(){
	cin>>n>>ma>>mb;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
			dp[i][j]=ans;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<N;i++){
		for(int j=M;j-a[i]>=0;j--){
			for(int k=M;k-b[i]>=0;k--){
				dp[j][k]=min(dp[j][k],dp[j-a[i]][k-b[i]]+c[i]);
			}
		}
	}
	ans2=ans;
	for(int i=1;i<=400;i++){
		for(int j=1;j<=400;j++){
			if(i*mb==j*ma)
				ans=min(ans,dp[i][j]);
		}
	}
	if(ans==ans2)cout<<"-1\n";
	else cout<<ans<<endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int r;
  cin>>r;
  cout<<r*r;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define pq priority_queue
using namespace std;
int n;
int l(int x)
{
    if(x==1)
        return 2*n-1;
    else
        return x-1;
}
int r(int x)
{
    if(x==2*n-1)
        return 1;
    else
        return x+1;
}
int main()
{
    int now,k,gg=1;
    cin>>n>>k;
    now=n;
    if(k==1 || k==2*n-1)
        printf("No\n");
    else
    {
        printf("Yes\n");
        while(now<k)
        {
            now++;
            gg=r(gg);
        }
        while(now>k)
        {
            now--;
            gg=l(gg);
        }
        for(int i=1;i<2*n;i++)
        {
            printf("%d\n",gg);
            gg=r(gg);
        }
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>> n;
    cin.ignore();
    string str[n];
    set <string> set1;
    for(int i=0; i<n; i++)
    {
        getline(cin,str[i]);
        set1.insert(str[i]);
    }
    cout<< set1.size()<<endl;
}

Measured memory_bytes: 25372
use proconio::input;

fn main() {
  input! {
    h: usize,
    w: usize,
    mut rows: [String;h]
  }

  let mut columns: Vec<Vec<usize>> = vec![];
  let mut scores: Vec<Vec<usize>> = vec![];
  for row in rows {
    let mut score_row = vec![0;w];
    let mut count = 0;
    let mut index = 0;
    let chars = row.chars().collect::<Vec<char>>();
    for i in 0..w {
      match chars[i] {
        '.' => { count += 1; },
        '#' => { count = 0; },
        _ => panic!("nya-n")
      };
      score_row[i] = count;
    }
    let mut insert_v = 0;
    let mut result = vec![0;score_row.len()];
    score_row.reverse();
    for (i, v) in score_row.iter().enumerate() {
      let v = *v;
      if v == 0 {
        insert_v = 0;
      } else {
        insert_v = std::cmp::max(insert_v, v);
      };
      result[i] = insert_v;
    }
    columns.push(result);
    scores.push(score_row);
  }
   
  let mut rows = scores;
  for c in 0..w {
    let mut count = 0;
    for r in 0..h {
      let v = rows[r][c];
      let v = if v > 0 {
        count += 1;
      } else {
        count = 0;
      };
      rows[r][c] = count;
    }
    
    let mut r = h-1;
    let mut insert_val = 0;
    loop {
      let v = rows[r][c];
      let v = if v == 0 {
        insert_val = 0;
      } else {
        insert_val = std::cmp::max(insert_val, v);
      };
      rows[r][c] = insert_val;
      
      if r == 0 { break };
      r -= 1;
    }
  }
 
  let mut max = 0;
  for r in 0..h {
    for c in 0..w {
      max = std::cmp::max(max, columns[r][c] + rows[r][c]);
    }
  }
  
  if max == 0 {
    println!("0");
  } else {
    println!("{}", max - 1);
  }
}

Measured memory_bytes: 68652
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

vvi g;
vl misum, masum, cnt, d;
string s;

void dfs(int v, int p) {
  cnt[v] = s[v];
  ll ma = 0; 
  for (int nv : g[v]) if (nv != p) {
    dfs(nv, v);
    misum[nv] += cnt[nv];
    masum[nv] += cnt[nv];
    masum[v] += masum[nv];
    ma = max(ma, masum[nv] + misum[nv]);
    cnt[v] += cnt[nv];
  }
  if (ma <= masum[v]) {
    misum[v] = masum[v] % 2;
    d[v] = masum[v] / 2;
  } else {
    misum[v] = ma - masum[v];
  }
//  cerr << v + 1 << ' ' << misum[v] << ' ' << masum[v] << endl;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n >> s;
  g.resize(n);
  for (int i = 0; i < n; ++i) s[i] -= '0';
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  const ll MAX = 1e18;
  ll res = MAX;
  for (int s = 0; s < n; ++s) {
    misum.assign(n, 0);
    masum.assign(n, 0);
    cnt.assign(n, 0);
    d.assign(n, 0);
    dfs(s, s);
//    cerr << "s:" << s + 1 << ' ' << misum[s] << ' ' << masum[s] << endl;
    if (misum[s] == 0) {
      res = min(res, d[s]);
    }
  }
  if (res == MAX) res = -1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

n,k=map(int,input().split())
l=[[] for _ in range(n)]
ans=k
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1; b-=1
    l[a].append(b)
    l[b].append(a)

mod=10**9+7
fact=[1]
fact_inv=[1]
for i in range(10**5+1):#<< Nの最大値
    new_fact=fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))

def mod_p(n,k,mod):
    if n-k<0:
        print(0)
        exit()
    return fact[n]*fact_inv[n-k]%mod

def dfs(v,p):
    ans2=1
    for a in l[v]:
        if a==p:
            continue
        ans2*=dfs(a,v)
        ans2%=mod
    return mod_p(k-2,len(l[v])-1,mod)*ans2%mod

ans*=mod_p(k-1,len(l[0]),mod)

for a in l[0]:
    ans*=dfs(a,0)

print(ans%mod)


Measured memory_bytes: 95320
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    ll n, p;
    cin >> n >> p;
    ll k = p;
    vector<ll> prime(sqrt(p)+10,0);
    if(n==1){
        cout << p << endl;
        return 0;
    }
    for (ll i = 2; i <= sqrt(p);i++){
        if(p%i==0){
            while(1){
                prime[i]++;
                p /= i;
                if(p%i!=0){
                    break;
                }
            }
        }
    }
    ll sum = 1;
 //   cout << sqrt(p) << endl;
    for (int i = 2; i <= sqrt(k);i++){
       // cout <<i<<" "<< prime[i] << " ";
        if(prime[i]/n>=1){
            sum*=pow(i,(prime[i]/n));
        }
    }
  //  cout << endl;
    cout << sum << endl;
}


Measured memory_bytes: 8064
time = []
for _ in range(5):
    time.append(int(input()))

mod = []
for i in time:
    mod.append(i % 10)

mod = [i for i in mod if i != 0]

for i in range(len(mod)):
    mod[i] = 10 - mod[i]

if len(mod) == 0:
    add = 0
else:
    add = sum(mod) - max(mod)

print(sum(time) + add)

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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int x, a, b;
  cin >> x >> a >>b;
  if (b <= a) {
    cout << "delicious\n";
  } else if (b - a < x + 1) {
    cout << "safe\n";
  } else {
    cout << "dangerous\n";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0,g=0,h=0, count = 0;
	char ac,uc[100000];
	string manji,gage;
	cin >> a>>b>>c;
	if (a <= c && b >= c  ) {
		cout << "Yes" << endl;
		return 0;
	}
	
	else { cout << "No" << endl; }

	return 0;
}

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

int main(){
  int N,dan=1;
  cin >> N;
  vector <int> moti(N);
  for (int i=0;i<N;i++){
    cin >> moti.at(i);
  }
  sort(moti.begin(),moti.end());
  reverse(moti.begin(),moti.end());
  
  for(int i=1;i<N;i++){
    if(moti.at(i)<moti.at(i-1))
      dan++;
  }
  cout << dan<<endl;
}

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

int     main() {
	int N;
	long K;
	cin >>N >>K;
	int S=0;
	vector<int> A(N);
	for (int i=0; i<N; i++) {
		cin >> A.at(i);
		S += A.at(i);
	}
	vector<int> B(0);
	for (int i=1; i<=sqrt(S); i++) {
		if (0==S%i) {
			B.push_back(i);
			B.push_back(S/i);
		}
	}
	sort(B.begin(), B.end());
	B.erase(unique(B.begin(), B.end()), B.end());
	//
	int j=B.size();
	vector<int> M(N);
	while (true) {
		j--;
		if (j<0) break;
		int BB=B.at(j);
		for (int i=0; i<N; i++) {
			M.at(i)=A.at(i)%BB;
		}
		sort(M.begin(), M.end());
		int L=0;
		int R=N-1;
		long KKK=0;
		int SSS=0;
		if (0<M.at(R)) {
			SSS +=M.at(L)-(BB-M.at(R));
			KKK +=M.at(L);
			while (R-L>1) {
				if (SSS<0) {
					L++;
					SSS += M.at(L);
					KKK += M.at(L);
				} else {
					R--;
					SSS -= BB-M.at(R);
				}
			}
		}
		if (KKK<=K) {
			cout <<BB <<endl;
			return 0;
		}
	}
	return 0;
};


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

int main(){
	int n, m;

	cin >> n >> m;
	vector<int> a(n);
	for(int i=0; i < n; i++){
		cin >> a[i];
	}
	int sum = 0;
	for(int i=0; i < n; i++){
		sum += a.at(i);
	}
	int cnt = 0;
	for(int i=0; i < n; i++){
		if(sum <= 4 * m * a.at(i))
			cnt++;
	}
	if(cnt >= m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int main(){
	int a,b;
	cin>>a>>b;
	if(a<b)cout<<0<<endl;
	else cout<<10<<endl;
}


Measured memory_bytes: 256
#pragma warning(disable:4996) 

#include <algorithm>
#include <bitset>
// #include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr ll LL2_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = { { typeid(int), "%d" },
{ typeid(ll), "%lld" },
{ typeid(double), "%lf" },
{ typeid(char), "%c" } };

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
// static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
	 //INFILE();

	int n, count = 0;
	cin >> n;
	string s = to_string(n);

	for (char c : s) {
		if (c == '2')
		{
			count++;
		}
	}

	cout << count << endl;
	return 0;
}

template <class T> static void scan(vector<T> &v) {
	auto tFormat = scanType[typeid(T)];
	for (T &n : v) {
		scanf(tFormat, &n);
	}
}

static void scan(vector<string> &v, bool isWord) {
	if (isWord) {
		for (auto &n : v) {
			cin >> n;
		}
		return;
	}

	int i = 0, size = static_cast<int>(v.size());
	string s;
	getline(cin, s);

	if (s.size() != 0) {
		i++;
		v[0] = s;
	}

	for (; i < size; ++i) {
		getline(cin, v[i]);
	}
}

//static boost::dynamic_bitset<> scan(char trueValue) {
//	string s;
//	getline(cin, s);
//
//	if (s.size() == 0) {
//		getline(cin, s);
//	}
//
//	for_each(begin(s), end(s),
//		[trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
//	return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
//}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = 0; i < K; i++)
  {
    if (i % 2 == 0)
    {
      if (A % 2 == 1)
        A--;
      B += A / 2;
      A /= 2;
    }
    else
    {
      if (B % 2 == 1)
        B--;
      A += B / 2;
      B /= 2;
    }
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x) \
    cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;
const int MAX = 1e6;
vector<int> m[MAX + 1];
int v[MAX], divisors[MAX + 1];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &v[i]);
    for (int i = 2; i <= MAX; i++) {
        if (!divisors[i]) {
            for (int j = i; j <= MAX; j += i) {
                divisors[j] = i;
            }
        }
    }
    bool pair_wise_coprime = true;
    bool gcd_is_one = true;

    for (int i = 0; i < n; i++) {
        int x = v[i];
        int cur = x;
        set<int> q;
        while (cur != 1) {
            q.insert(divisors[cur]);
            cur /= divisors[cur];
        }
        for (int div : q) {
            auto &curr_map = m[div];
            curr_map.push_back(x);
            if (curr_map.size() > 1) pair_wise_coprime = false;
            if (curr_map.size() == n) gcd_is_one = false;
        }
    }
    if (pair_wise_coprime) {
        puts("pairwise coprime");
        return 0;
    }
    if (gcd_is_one) {
        puts("setwise coprime");
        return 0;
    }
    puts("not coprime");
}


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

int main( int argc, char *argv[] )
{
int N;
int K;
int i;
int x;
int iSum;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> K;

	iSum = 0;
	for( i = 0; i < N; i++ )
	{
		cin >> x;
		if( 2 * x >= K )
			iSum += 2 * ( K - x );
		else
			iSum += 2 * x;
	}

	cout << iSum << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		mp[x]++;
	}
	cout << endl;
	while (m--) {
		int b, c;
		cin >> b >> c;
		while (!mp.empty()) {
			int x, m; tie(x, m) = *mp.begin();
			if (x > c) break;
			if (m > b) {
				mp[x] -= b;
				mp[c] += b;
				b = 0;
				break;
			} else {
				mp.erase(x);
				mp[c] += m;
				b -= m;
			}
		}
	}
	long long ret = 0;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		ret += (long long)it->first * it->second;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 7040
#include <stdio.h>
#include <math.h>
#include <stdlib.h>



int main(void)
{
	long int n;
long int fk=0;
	int mc=0,i,j,k,tl=0,x;
	int a[100];
	
	scanf("%lu",&n);
	
	//3141592653589793
	//printf("n%lu\n",n);
       	k=floor(log10(n))+1;
	

	//printf("k%d\n",k);
	for(i=k;i>=1;i--){
		a[i]=floor((n-fk)/pow(10,i-1));
		//printf("ai%d\n",a[i]);
		x=tl+a[i]-1+9*(i-1);
		if (x>mc) mc=x;
		tl+=a[i];
		fk+=a[i]*pow(10,i-1);
	}
	if(tl>mc){mc=tl;}
	printf("%d\n",mc);
	
	return 0;
}



Measured memory_bytes: 128
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
					/*多倍長整数/cpp_intで宣言
					#include <boost/multiprecision/cpp_int.hpp>

					using namespace boost::multiprecision;
					*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	vector<bool> a(n);
	vector<int> b(n);
	int p;
	string s;
	rep(i, m) {
		cin >> p >> s;
		if (!a[p - 1]) {
			if (s == "AC")a[p - 1] = true;
			else ++b[p - 1];
		}
	}
	int wa = 0;
	rep(i, n) {
		wa += a[i] * b[i];
	}
	printf("%d\n%d\n", accumulate(all(a), 0), wa);

	Please AC;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

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

  bool ng = (a[0] != 0);
  FOR(i, 1, n) {
    if (a[i] - a[i - 1] >= 2)
      ng = true;
  }

  if (ng) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  FOR(i, 1, n) {
    if (a[i - 1] < a[i]) {
      ans++;
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
from collections import Counter


def solve(N, K, As):
    c = Counter(As)
    if len(c) <= K:
        return 0
    m = sorted([(v, k) for (k, v) in c.items()], reverse=True)
    return sum([n[0] for n in m[K:]])


if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, K, As))


Measured memory_bytes: 41104
#include<bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t x,int64_t y){
if(x==0 || y==0)
  return max(x,y);
  else if(x<y)
    return gcd(x,y%x);
  else if(y<x)
    return gcd(y,x%y);
  else
    return x;
}
int64_t lcm(int64_t x,int64_t y){
return ((x*y)/gcd(x,y));

}
int main(){
int64_t A,B,C,D;
  cin>>A>>B>>C>>D;
  int64_t b=B-B/C-B/D+B/lcm(C,D);
  A--;
  int64_t a=A-A/C-A/D+A/lcm(C,D);
  int64_t ans=b-a;
  cout<<ans<<endl;
  
   return 0;
}

Measured memory_bytes: 256
import decimal,math
from collections import Counter,defaultdict
from fractions import gcd
from bisect import bisect_right,bisect_left
decimal.getcontext().prec = 10
N=int(raw_input())
s=raw_input()
if(N<3200):
	print "red"
else:
	print s	
# f=map(int,raw_input().split())

Measured memory_bytes: 34792
#include<iostream>

using namespace std;

int main(){
    int N;
    cin>>N;
    long long sum1=0,sum2=0;
    long long ans1=0,ans2=0;
    //1は遇を２は奇を正に

    for(int i=0;i<N;++i){
        long tmp=0;
        cin>>tmp;
        sum1+=tmp;
        sum2+=tmp;
        if(i%2==0){
            if (sum1<=0) {
                ans1+=abs(sum1-1);
                sum1=1;
            }
            if(sum2>=0){
                ans2+=abs(sum2+1);
                sum2=-1;
            }
        }else{
            if (sum1>=0) {
                ans1+=abs(sum1+1);
                sum1=-1;
            }
            if(sum2<=0){
                ans2+=abs(sum2-1);
                sum2=1;
            }
        }
    }

    cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		int sum = 0;
		for(int i = 0; i < list.size(); i++) {
			for(int j = i + 1; j < list.size(); j++) {
				sum += list.get(i) * list.get(j);
			}
		}
		System.out.println(sum);

	}

}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
    long long x,p=100,ans=0;
    scanf("%lld",&x);
    while(p<x)
    {
        p+=p/100;
        ans++;
    }
    printf("%lld\n",ans);
    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

string T;
const int maxn = 2e5 + 5;
int suf[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> T;
    int n = T.length();
    int cnt = 0;
    for(int i = 0;i < n;i++){
        cnt += (T[i] == '1');
    }
    ll ans = 0;
    for(int i = 1; i <= cnt;i++){
        ans += (i + 1) / 2;
    }
    int zero = n - cnt;
    cnt = 0;
    vector<int> v;
    for(int i = 0;i < n;i++){
        if(T[i] == '1'){
            cnt++;
        }else{
            ans += 1LL * cnt / 2 * zero;
            if(cnt & 1){
                v.push_back(1);
            }
            cnt = 0;
            v.push_back(0);
        }
    }
    ans += 1LL * cnt / 2 * zero;
    if(cnt & 1){
        v.push_back(1);
    }
    int m = v.size();
    suf[m] = 0;
    for(int i = m - 1;i >= 0;i--){
        suf[i] = suf[i + 1] + (v[i] == 0);
    }
    cnt = 0;
    for(int i = 0;i < m;i++){
        if(v[i] == 1){
            if(i & 1){
                ans += cnt / 2 + suf[i + 1];
            }else{
                ans += (cnt + 1) / 2 + suf[i + 1];
            }
        }else{
            cnt++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int N, K;

int main() {
    cin >> N >> K;
    bool ans[N];
    memset(ans, true, sizeof(ans));
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int A;
            cin >> A;
            ans[A-1] = false;
        }
    }

    int aaa = 0;
    for (int i = 0; i < N; i++) {
        if (ans[i]) aaa++;
    }

    cout << aaa << endl;

    return 0;
}


Measured memory_bytes: 3620
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let N = Number(input[0].split(' ')[0])
	let M = Number(input[0].split(' ')[1])
	if(N > M / 2) {
		let ccMaxCount = Math.floor(M / 2)
		console.log(Math.min(ccMaxCount, N))
	} else {
		console.log(Math.floor((N * 2 + M) / 4))
	}
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
vector<int> lp(N + 1);
vector<int> mp(N + 1);
int maxcnt = 0;
bool pairWise = true;
void init_seive () {
  vector<int> pr;
  for (int i=2; i<=N; ++i) {
    if (lp[i] == 0) {
        lp[i] = i;
        pr.push_back (i);
    }
    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
  }
}

void factorise(int x) {
  while (x != 1) {
    int s = lp[x];
    if (mp[s] >= 1) pairWise = false;
    mp[s]++; maxcnt = max(maxcnt, mp[s]);
    while (s == lp[x]) x /= s;
  }
}

int main (void) {
  init_seive();
  int n; cin >> n;
  int a[n]; for (int& ai: a) {
    cin >> ai;
    factorise(ai);
  }
  if (pairWise) cout << "pairwise coprime" << '\n';
  else if (maxcnt < n) cout << "setwise coprime" << '\n';
  else cout << "not coprime" << '\n';
}

Measured memory_bytes: 14992
#pragma optimization_level 3
#pragma GCC optimize("Ofast")   //Comment optimisations for an interatcive problem - use endl
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
#define  x                     first                 
#define  y                     second                
 
const ll   N     =  5005;
const ll   mod   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
#define maxBits 22
#define maxMask (1<<maxBits)
 
ll n,vis[N][N],a[N];
 
ll rem(int f,int i,int j){
    if(vis[i][j] != 0) return vis[i][j];
    if(i > j) return 0;
    if(f == 0)
        vis[i][j] = min(rem(1,i+1,j),rem(1,i,j-1));
    else
        vis[i][j] = max(a[i]+rem(0,i+1,j),a[j]+rem(0,i,j-1));
    return vis[i][j];
}
 
int main(){
    fastio;
    cin>>n;
    ll s = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
      	s += a[i];
    }
    ll x = rem(1,0,n-1);
    cout<<2*x-s<<endl;
}

Measured memory_bytes: 118528
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string S;
	cin >> S;
	if(S == "ABC") cout << "ARC";
	else cout << "ABC";
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int ans=1,n,k;
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	  if (ans>k) ans+=k;
	  else ans+=ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> l(n);
    rep(i,n)cin>>l[i];
    ll ans=0;
    sort(l.begin(),l.end());
    for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++){
        int x=l[i]+l[j];
        int a = lower_bound(l.begin(),l.end(),x)-l.begin();
        int b = j+1;
        ans+=a-b;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#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>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
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)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



int h, n;

int main() {

	cin >> h >> n;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		h -= tmp;
	}

	if (h <= 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	set<char> p;
	for (int i = 0; i < 4; i ++) p.insert(s[i]);
	if (((s[0] == s[1] && s[2] == s[3]) || (s[0] == s[2] && s[1] == s[3]) || (s[0] == s[3] && s[1] == s[2])) && p.size() != 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] p = sc.nextIntArray(n);
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (p[i] != i + 1) count++;
    }
    System.out.println(count == 0 || count == 2 ? "YES" : "NO");
  }
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i=0; i<N; i++) cin >> vec.at(i);
  
  int s=0;
  for (int i=0; i<1000000; i++) {
    for (int j=0; j<N; j++) {
      if (vec.at(j)==i+1) {
        s+=1;
        break;
      }
    }
    //ここに条件を付けたい
  }
  
  cout << s << endl;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> C(26,1);
  for(int i = 0; i < N; ++i){
    ++C[S[i]-'a'];
  }
  long long mod = 1e9 + 7, ans = 1;
  for(int i = 0; i < 26; ++i) ans *= C[i], ans %= mod;
  ans -= 1;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n - 1); i >= 0; --i)
#define D(n, retu)                                                             \
  REP(i, n) { cin >> retu[i]; }
#define mod 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
//#define INF 931931114518101
using namespace std;
typedef pair<ll, ll> P;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
#define yo 100001
//------------------変数-----------------------//
ll a, b, c, n;
map<ll, ll> r;
//-------------------関数----------------------//

int main() {
  cin >> a >> b >> c;
  r[a]++;
  r[b]++;
  r[c]++;
  if (r[a] == 1) {
    cout << a << endl;
  } else if (r[b] == 1) {
    cout << b << endl;
  } else {
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define int long long int
#define mod 1000000007
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;


signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // int t = 1;
    // cin >> t;
    // while (t--) {
        int n, x, t;
        cin>>n>>x>>t;
        int ans = 0;
        ans = n/x;
        if(n%x != 0){
            ans++;
        }
        cout<<ans*t<<endl;
    // }
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int main()
{
    std::ios::sync_with_stdio(false);
    ll x;
    while(cin>>x)
    {
        ll t,ans=0;
        if(x%11)
        {
            t=x%11;
            if(t>6)
                ans+=2;
            else
                ans++;
        }
        ans+=x/11*2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   int n = s.size();
   int ans = 0;
   rep(i, 0, n) {
      int j = n - 1 - i;
      if (i < j && s[i] != s[j]) ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	int ans = 0;
	int max_H = 0;
	for (int i=0; i<N; ++i) {
		int H;
		cin >> H;
		if (H >= max_H) {
			ans++;
		}
		max_H = max(H, max_H);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws Exception {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");
        int a = Integer.parseInt(strArr[0]);
        int b = Integer.parseInt(strArr[1]);
        int c = Integer.parseInt(strArr[2]);
        if (a < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24328
#include<stdio.h>
int main(){
  int i,j,minj,n,tmp,A[100],count = 0;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  for(i = 0 ; i < n ; i++){
    minj = i;
    for(j = i ; j < n ; j++){
      if(A[j] < A[minj]) {
	minj = j;
      }
    }
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    if(i != minj)count++;
  }
  for(i = 0 ; i < n ; i++){
    if(i == n - 1)printf("%d",A[i]);
    else printf("%d ",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2128
let rec seq a b = if a > b then [] else a :: seq (a+1) b
let (>>=) x f = List.map f x |> List.concat
let () =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
  let stat =
    ['M'; 'A'; 'R'; 'C'; 'H'] |> List.map (fun ch ->
      Array.fold_left (fun x s -> if s.[0] = ch then x+1 else x) 0 a)
    |> Array.of_list
  in
  (seq 0 4 >>= fun i ->
   seq (i+1) 4 >>= fun j ->
   seq (j+1) 4 >>= fun k -> [stat.(i) * stat.(j) * stat.(k)])
  |> List.fold_left (+) 0
  |> Printf.printf "%d\n"

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

#define int long long

using namespace std;
const int N = 3000;

int n, ans(0);
int a[N], cnt[N];

signed main(void)
{
	scanf("%lld", &n);
	for (int i=1;i<=n;++i) 
	{
		scanf("%lld", a+i);
		cnt[a[i]] ++;
	}
	for (int i=1;i<N;++i)
	    cnt[i] += cnt[i-1];
	for (int i=1;i<=n;++i)
	    for (int j=i+1;j<=n;++j)
	    {
	        ans += cnt[a[i]+a[j]-1]-cnt[max(a[i]-a[j],a[j]-a[i])];
	        ans -= (a[i] < a[i] + a[j] && a[i] > max(a[i]-a[j],a[j]-a[i]));
	        ans -= (a[j] < a[i] + a[j] && a[j] > max(a[i]-a[j],a[j]-a[i]));
	    }
	cout<<ans / 3<<endl;
	return 0; 
}

Measured memory_bytes: 256
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    // let n = read_line().into_bytes();
    let n = read_line();
    println!("ABC{}", n);

}


Measured memory_bytes: 4352