akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <string>
#include <cmath>

# define PI 3.14159265358979323846

using namespace std;

int main(void) {
    int n;
    cin >> n;

    int x = n / 1.08;

    if (floor(x * 1.08) == n)
        cout << x << endl;
    else if (floor((x+1) * 1.08) == n)
        cout << x+1 << endl;
    else
        cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
int main(void)
{
    char s[300];

    cin >> s;

    int t;
    int ans;
    int count = 0;
    for (int i = strlen(s)-2; i > 0; i-=2) {
        if (strncmp(s, s+i/2, i/2) == 0) {
            cout << i << endl;
            return 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;


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

Measured memory_bytes: 256
#include<stdio.h>


int main(){
	int a,x,y,n,z;
	while(1){
		scanf("%d",&a);
		if(a==0)
		break;
		for(n=0;n<a;n++){
			scanf("%d %d %d",&x,&y,&z);
			if(x==100||y==100||z==100)
			printf("A\n");
			else if((x+y)/2>=90)
			printf("A\n");
			else if((x+y+z)/3>=80)
			printf("A\n");
			else if((x+y+z)/3>=70)
			printf("B\n");
			else if((x+y+z)/3>=50){
			if(x>=80||y>=80)
			printf("B\n");
			else
			printf("C\n");
			}
			else
			printf("C\n");
		}
		
	}
	return 0;
}

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

using namespace std;

long long gcd(long long a, long long b);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, UCLN, y;
    cin >> n >> UCLN;
    --n;
    while (n--){
        cin >> y;
        UCLN = gcd(UCLN, y);
    }
    cout << UCLN;
    return 0;
}

long long gcd(long long a, long long b){
    while (b){
        long long r = a % b;
        a = b;
        b = r;
    }
    return a;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int H,W; cin >> H >> W;
    map<char,int> m;
    rep(i,H) rep(j,W){
        char c; cin >> c;
        m[c]++;
    }
    int cnt2 = 0, cnt1 = 0;
    for(auto a:m){
        if(a.se%4==1){
            cnt1++;
        } else if(a.se%4==2){
            cnt2++;
        } else if(a.se%4==3){
            cnt1++; cnt2++;
        }
    }
    cnt2*=2;
    if(H%2 && W%2){
        cnt1-=1;
        cnt2-=H+W-2;
    } else if(H%2){
        cnt2-=W;
    } else if(W%2){
        cnt2-=H;
    }
    if(cnt1 == 0 && cnt2 <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int len = h2 * 60 + m2 - h1 * 60 - m1 - k;
    cout << len << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

int main() {
  int64_t N;
  cin >> N;
  // 文字列を取得
  unordered_map<string, int> list;
  for (int64_t i = 0; i < N; ++i) {
    string str;
    cin >> str;
    // ソート
    sort(str.begin(), str.end());
    // ソート後の文字列の検索
    auto it = list.find(str);
    if (it == list.end()) {
      list[str] = 1;
    } else {
      ++it->second;
    }
  }
  int64_t ans = 0;
  for(auto& l : list) {
    if (l.second > 1) {
  	  ans += (int64_t)l.second * (l.second-1)/2;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 10660
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int f[133333],g[133333],a[133333],w[133333],p[133333];
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int n,i,x,y,l,j,cnt=0,ans=0;
	scanf("%d",&n);
//	printf("%d\n",n);
	for(i=1;i<n;i++)
	{
		scanf("%d%d%d",&x,&y,&l);
		x++,y++;
		g[x]^=l,g[y]^=l; 
	}
	for(i=1;i<=n;i++)
	{
		if(a[g[i]]&&g[i])
			ans++;
		a[g[i]]^=1;
	}
//	printf("%d\n",ans);
	for(i=0;i<16;i++)
		if(a[i])
			p[++cnt]=i;//,printf("%d\n",i);
//	printf("%d|",cnt);
	for(i=0;i<(1<<cnt);i++)
	{
		int sum=0;
		for(j=1;j<=cnt;j++)
			if((1<<j-1)&i)
				w[i]^=p[j],sum++;
		if(i)
		f[i]=sum-1;
		if(!w[i])
		{
			for(j=i-1;j;j=(j-1)&i)
			{
				if(!w[j])
					f[i]=min(f[i],f[j]+f[i-j]);
				else
					f[i]=min(f[i],f[j]+f[i-j]+1);
			}
		}
	}
	printf("%d\n",f[(1<<cnt)-1]+ans);
	return 0;
}


Measured memory_bytes: 1152
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = Integer.parseInt(sc.next());
    String str = sc.next();
    boolean flag = false;
    if(number % 2 == 0) {
      String first = str.substring(0, number / 2);
      String end = str.substring(number / 2, number);
      if(first.equals(end)) flag = true;
    }
    if(flag) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,k;cin>>a>>b>>k;
if(k<=a){
  cout<<a-k<<" "<<b<<endl;
}else if(k<=a+b){
  cout<<0<<" "<<b-(k-a)<<endl;
}else{
  cout<<0<<" "<<0<<endl;
}
}

Measured memory_bytes: 256
use std::cmp;

#[allow(dead_code)]
pub struct Scanner<'a> {
    _buf: &'a str,
    iter: ::std::str::SplitWhitespace<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(buf: &'a str) -> Self {
        Scanner {
            _buf: buf,
            iter: buf.split_whitespace(),
        }
    }

    pub fn array<T>(&mut self, n: usize) -> Vec<T>
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.value());
        }
        res
    }

    pub fn value<T>(&mut self) -> T
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.next().chars().collect()
    }

    fn next(&mut self) -> &str {
        self.iter.next().unwrap()
    }
}

struct Solver {
    a: Vec<i64>,
    memo: Vec<Option<i64>>,
}

impl Solver {
    fn new(a: Vec<i64>) -> Self {
        let n = a.len();
        Solver {
            a: a,
            memo: vec![None; n],
        }
    }

    fn f(&mut self, k: i64) -> i64 {
        if k == 0 { return 0; }
        if k == 1 { return cost(self.a[0], self.a[1]); }

        if self.memo[k as usize].is_none() {
            let c1 = self.f(k-1) + cost(self.a[(k-1) as usize], self.a[k as usize]);
            let c2 = self.f(k-2) + cost(self.a[(k-2) as usize], self.a[k as usize]);
            self.memo[k as usize] = Some(cmp::min(c1, c2));
        }
        self.memo[k as usize].unwrap()
    }
}

fn cost(h1: i64, h2: i64) -> i64 {
    (h1-h2).abs()
}

fn main() {
    let mut _input = String::new();
    {
        use ::std::io::Read;
        ::std::io::stdin().read_to_string(&mut _input).unwrap();
    }
    let mut sc = Scanner::new(&_input);

    let n = sc.value::<i64>();
    let a = sc.array::<i64>(n as usize);

    let mut sol = Solver::new(a);
    let ans = sol.f(n-1);

    println!("{}", ans);
}


Measured memory_bytes: 12540
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n, m;
	while (cin >> n >> m&&n&&m) {
		int sumt = 0, sumh = 0;
		vector<int> t, h;
		int a;
		for (int i = 0; i < n; i++) {
			cin >> a;
			t.emplace_back(a);
			sumt += a;
		}
		for (int i = 0; i < m; i++) {
			cin >> a;
			h.emplace_back(a);
			sumh += a;
		}
		int anst = 1000, ansh = 1000;
		for (int i = 0; i < t.size(); i++) {
			for (int j = 0; j < h.size(); j++) {
				if (sumt - t[i] + h[j] == sumh - h[j] + t[i]) {
					if (anst + ansh > t[i] + h[j])anst = t[i], ansh = h[j];
				}
			}
		}
		if (anst == 1000)cout << -1 << endl;
		else cout << anst << " " << ansh << endl;
	}
}

Measured memory_bytes: 3080
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    plus = []
    minus = []
    for _ in range(n):
        x, y = map(int, input().split())
        plus.append(x + y)
        minus.append(x - y)
    plus.sort()
    minus.sort()
    ans = max(plus[-1] - plus[0], minus[-1] - minus[0])
    print(ans)

main()

Measured memory_bytes: 25528
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)-v.begin()
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n) upper_bound(v.begin(),v.end(),n)//-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a);
		}
		b>>=1;
		a=(a*a);
	}
	return ans;
}//prefixsums
void frooty()
{
	l a;
	cin>>a;
	l num=a+(a*a)+(a*a*a);
	cout<<num<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
//	cin>>q;
	while(q--)
	{
		frooty();
	}
}

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

int main() {
    int N, x;
    cin >> N;
    x = 0;
    // cout << N << endl;
    
    for (int i = 1; i < N; i++){
        string S;
        cin >> S;
        
        if (S == "Y"){
            x++;
        }
        //cout << S;
    }
    
    if (x > 0){
        cout << "Four" << endl;
    }
    else {
        cout << "Three" << endl;
    }
    
}

Measured memory_bytes: 256
import sys
n=input()
house=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
for i in range(4):
    for j in range(3):
        for k in range(10):
            house[i][j].append(0)
for i in range(n):
    b,f,r,v=map(int,raw_input().split())
    house[b-1][f-1][r-1]+=v
for i in range(4):
    for j in range(3):
        for k in range(10):
            sys.stdout.write(' %d'%house[i][j][k])
        print('')
    if i!=3:
        print('#'*20)

Measured memory_bytes: 6368
#!/usr/bin/env python3

h, w = list(map(int, input().split()))

ss = [list(str(input())) for _ in range(h)]

dp = [[100*100 for _ in range(w)] for i in range(h)]  # dp[h][w]

if ss[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
# print(dp)

for h_tmp in range(0, h):
    for w_tmp in range(0, w):
        if w_tmp > 0:
            # print(dp[h_tmp][w_tmp-1])
            if ss[h_tmp][w_tmp-1] == "." and ss[h_tmp][w_tmp] == "#":
                dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp][w_tmp-1]+1)
            else:
                dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp][w_tmp-1])
        if h_tmp > 0:
            # print(dp[h_tmp][w_tmp-1])
            if ss[h_tmp-1][w_tmp] == "." and ss[h_tmp][w_tmp] == "#":
                dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp-1][w_tmp]+1)
            else:
                dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp-1][w_tmp])

# print(dp)
print(dp[-1][-1])


Measured memory_bytes: 3188
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
b=[0]*2**n
for i in range(2**n):
  tr=bin(i)[2:].zfill(n)
  cnt=0
  for j in range(n):
    if tr[j]=='1':
      cnt+=a[j]
  b[i]=cnt
for i in m:
  if i in b:
      print('yes')
  else:
      print('no')


Measured memory_bytes: 42964
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N,A,B,C,D = list(map(int, input().split()))
        S = np.asarray(list(str(input())))
    else:
        pass

    scount = 0
    dcount = 0
    swapok = False
    #print(S[A:D])
    for i in range(A,max(C,D)):
        s = S[i]
        if s == "#":
            dcount = 0
            scount += 1
            if scount == 2:
                print("No")
                exit()
        else:
            scount = 0
            if D > i > B-3:
                dcount += 1
                if dcount == 3:
                    swapok = True
    
    if (C>D) & (not swapok):
        if (S[D-2] == ".") & (S[D] == "."):
            print("Yes")
        else:
            print("No")
    else:
        print("Yes")

if __name__ =='__main__':
    main()

Measured memory_bytes: 22404
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
string w[100];
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin>>n>>m;
	rep(i, 0, n) cin>>w[i];
	rep(i, 0, n) rep(j, 0, m)
	{
		int cnt = 0;
		if (w[i][j] == '#') continue;
		rep(k, 0, 8)
		{
			int nx = i+dx[k], ny = j+dy[k];
			if (0 <= nx && nx < n && 0 <= ny && ny < m && w[nx][ny] == '#') cnt++;
		}
		w[i][j] = '0'+cnt;
	}
	rep(i, 0, n) cout<<w[i]<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 256
/*
 * omg.cpp
 *
 *  Created on: 2019/06/03
 *      Author: J01003
 */
#include<iostream>
using namespace std;
int main(){
	int x=0,y=0;
	cin>>x>>y;
	x=x*3;
	y=y+x;
	x=0;
	while(1){
		if(y>=2){
			y=y-2;
			x++;
		}else{
			break;
		}
	}
	cout<<x<<endl;
	return 0;
}


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

int main(){
	int dp[100][100]={0};
	int n,ans=-10000;
	cin>>n;
	for(int i=0;i<n;i++){
		int a,s[101]={0};
		for(int j=0;j<n;j++){
			cin>>a;
			s[j+1]=s[j]+a;
		}
		for(int j=0;j<n;j++){
			for(int k=j;k<n;k++){
				dp[j][k]=max(0,dp[j][k])+s[k+1]-s[j];
				ans=max(ans,dp[j][k]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void solve() {
		IOS;
		int n;
		cin >> n;
		vector<int> a(n);
		REP(i, n-1) {
			cin >> a[i + 1];
			a[i + 1]--;
		}
		vector<int> res(n,0);
		FOR(i, 1, n) {
			res[a[i]]++;
		}
		REP(i, n) {
			put(res[i]);
		}
	}

} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 4768
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int a,b,c,d;

cin >> a >> b >> c >> d;

if(a < c){
int t = a;
a = c;
c = t;
}

if(a - c <= d){
cout << "Yes" << endl; return 0;
}

if(b - c <= d && a - b <= d) {
cout << "Yes" << endl; return 0;
}


cout << "No" << endl; 
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }

vector<ll> Eratosthenes(const ll N){
    vector<bool> is_prime( N + 1 );
    for(ll i = 0; i <= N; i++ ){
        is_prime[i] = true;
    }
    vector<ll> P;
    for(ll i = 2; i <= N; i++ ){
        if(is_prime[i]){
            for(ll j = 2 * i; j <= N; j += i ){
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> P = Eratosthenes(n);
    vector<ll> a(n+1, 1), b(n+1);

    for (auto num : P){ //素数ごとに計算
        for (ll i=num; i<=n; i += num){
            ll res = i;
            ll count = 1;
            while (res%num == 0){
                res /= num;
                count++;
            }
            if (a[i]==1) a[i] = count;
            else a[i] *= count;
        }
    }
    b[1] = 1;
    rep2(i, 2, n+1){
        b[i] += b[i-1] + i*a[i];
    }
    cout << b[n] << endl;
}

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

int main(){
  int A, B;
  string op;
  cin >> A >> op >> B;

  int res;
  if(op == "+"){
    res = A + B;
  } else if(op == "-"){
    res = A - B;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
typedef struct {double x,y;}Point;
void koch(int n,Point a,Point b) {
  if(n == 0){
    return;
  }
  Point s,t,u;
  double th = M_PI * 60.0/180.0;
  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x-s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x-s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1,a ,s);
  printf("%.8f %.8f\n",s.x, s.y);
  koch(n - 1, s ,u);
  printf("%.8f %.8f\n",u.x, u.y);
  koch(n - 1,u ,t);
  printf("%.8f %.8f\n",t.x, t.y);
  koch(n - 1,t ,b);
}
int main(){
  Point a, b;
  int n;
  scanf("%d",&n);
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
  printf("%.8f %.8f\n",a.x, a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x, b.y);
  return 0;
}



Measured memory_bytes: 2128
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

a = sys.stdin.readline().strip()
arr = list(map(int, sys.stdin.readline().strip().split()))
mod = 10**18

ans = arr[0]
for i in range(1, len(arr)):
    ans *= arr[i]
    if ans > mod:
        ans = -1
        break

if 0 in arr:
    ans = 0

print(ans)


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

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

    int X;
    cin >> X;

    int r = X % 100;
    int cnt = 0;

    while(1) {
        if(r < 5) break;
        r -= 5;
        cnt++;
    }

    while(1) {
        if(r < 4) break;
        r -= 4;
        cnt++;
    }

    while(1) {
        if(r < 3) break;
        r -= 3;
        cnt++;
    }

    while(1) {
        if(r < 2) break;
        r -= 2;
        cnt++;
    }

    while(1) {
        if(r < 1) break;
        r -= 1;
        cnt++;
    }

    if(cnt > X / 100) cout << "0";
    else cout << "1";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int a, b;
  cin >> a >> b;
  string s, t;
  rep(i, b) s.push_back((char)(a + '0'));
  rep(i, a) t.push_back((char)(b + '0'));
  cout << (s < t ? s : t) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	ll n; cin >> n;

	ll ans = (n / 11) * 2;
	ll amari = n % 11;
	
	if (amari > 0)ans++;
	if (amari > 6)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 2000010;

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) cin >> a[i];
    int sum = 0;
    REP(i,n) sum += a[i];

    bitset<N> dp;
    dp = 1;
    REP(i,n){
        dp |= dp << a[i];
    }

    FOR(x,(sum+1)/2,sum){
        if (dp[x]){
            cout << x << endl;
            return 0;
        }
    }


    return 0;
}


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

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define debug(x) cout << #x << ": " << x << endl
using ll = long long;
//#define int ll

//**********

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int x[1000010], y[1000010];
    double angle[110][110] = {};
    double max[110] = {};
    
    REP(i,n){
        cin >> x[i] >> y[i];
        angle[i][i] = {-1000.0};
    }
    
    REP(i,n){
        max[i]=0;
        REP(k,n){
            // iからみたkの角度
            if(k==i) continue;
            if(x[k]==x[i] && y[k]>y[i]) angle[i][k] = M_PI/2;
            else if(x[k]==x[i] && y[k]<y[i]) angle[i][k] = -M_PI/2;
            else angle[i][k] = atan2((y[k]-y[i]),(x[k]-x[i]));
            }
        sort(angle[i],angle[i]+n,greater<double>());
        
        REP(k,n-1){
            if(k==n-2){
                if(angle[i][k]-angle[i][0]+M_PI*2 > max[i] + M_PI){
                    max[i] = angle[i][k]-angle[i][0]+M_PI;
                }
            }else if(angle[i][k]-angle[i][k+1] > max[i] + M_PI){
                max[i] = angle[i][k]-angle[i][k+1]-M_PI;
            }
        }
    }
    
    REP(i,n){
        printf("%f\n",max[i]/M_PI/2);
    }
    
    return 0;
    
}





Measured memory_bytes: 2560
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i).map { |x| x - 1 }


def f(n, k, a)
  t = Array.new(a.size, -1)
  cnt = 0
  now = 0
  prev = 0
  loop do
    if t[now] == -1
      t[now] = cnt
      cnt += 1
      prev = now
      now = a[now]
      if cnt == k
        puts now + 1
        return
      end
    else
      k1 = k - t[now]
      m = cnt - t[now]
      k2 = k1 % m

      loop do
        if k2 == 0
          puts now + 1
          return
        end
        k2 -= 1
        now = a[now]
      end
    end
  end
end

f(n, k, a)


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

using namespace std;

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

    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < N; ++i) {
        cout << S[i] << T[i];
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
ll pow(ll x,ll n,ll mod){
  ll res=1;
  if(n>0){
    res=pow(x,n/2,mod);
    if(n%2==0){
      res=(res*res)%mod;
    }else{
      res=(((res*res)%mod)*x)%mod;
    }
  }
  return res;
}
//
ll inv(ll n,ll mod){
  return pow(n,mod-2,mod);
}
//
ll kai[300001];
ll gya[300001];
ll nck[300001];
int main(){
  ll N,A,B,K;
  cin>>N>>A>>B>>K;
  kai[N]=N;
  ROF(i,1,N){
   (kai[i]=kai[i+1]*i)%=mod;
  }
  gya[1]=inv(1,mod);
  FOR(i,2,N+1){
   (gya[i]=gya[i-1]*inv(i,mod))%=mod;
  }
  FOR(i,1,N){
    (nck[i]=kai[N+1-i]*gya[i])%=mod;
  }
  nck[0]=1;
  nck[N]=1;
  ll ans=0;
  FOR(i,0,N+1){
    if((K-A*i)%B==0&&(K-A*i)/B>=0&&(K-A*i)/B<=N){
      (ans+=nck[i]*nck[(K-A*i)/B])%=mod;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int o, e;
	o = 0;
	e = 0;

	for (int i = 1; i <= K; i++) {
		if (i % 2) o++;
		else e++;
	}

	cout << o * e << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

lli data[30][30];

lli flag[30][30];

int main()
{
	lli h,w;
	cin>>h>>w;

	lli ansSi,ansSj,ansGi,ansGj;
	lli ansL = 0;

	REP(i,0,h){
		REP(j,0,w){
			char tmp;
			cin>>tmp;
			if(tmp=='.')data[i][j]=0;
			else data[i][j]=1;
		}
	}

	//all check!

	REP(si,0,h)REP(sj,0,w){
		REP(i,0,30)REP(j,0,30)flag[i][j]=-1;

		if(data[si][sj])continue;
		queue<lli> qi,qj;
		qi.push(si);
		qj.push(sj);
		flag[si][sj]=0;

		while(qi.size()){
			lli topI = qi.front();
			lli topJ = qj.front();
			lli topL = flag[topI][topJ];
			if(DEBUG)cout<<"topI="<<topI<<" topJ="<<topJ<<"topL="<<topL<<endl;
			qi.pop();
			qj.pop();

			lli dx[4]= {-1,0,1,0};
			lli dy[4]= {0,1,0,-1};
			REP(dd,0,4){
				lli nextI = topI + dy[dd];
				lli nextJ = topJ + dx[dd];
				if(nextI <0 || nextI >= h || nextJ <0 || nextJ >= w)continue;
				if(flag[nextI][nextJ]!=-1)continue;
				if(data[nextI][nextJ]==1)continue;
				flag[nextI][nextJ] = topL + 1;
				qi.push(nextI);
				qj.push(nextJ);
			}
		}

		REP(gi,0,h){
			REP(gj,0,w){
				if(data[gi][gj])continue;
				if(ansL < flag[gi][gj]){
					ansSi = si;
					ansSj = sj;
					ansGi = gi;
					ansGj = gj;
					ansL = flag[gi][gj];
				}
			}
		}

	}
	cout<<ansL<<endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;
int K;

template <class T>
void printVector(const vector<T>& v) {
    for (auto value : v) {
        cout << value << " ";
    }
    cout << endl;
}

// https :  // drken1215.hatenablog.com/entry/2020/04/05/150900
void dfs(vector<ll>& A, ll val, int digit) {
    A.push_back(val);
    if (digit == 10) {
        return;
    }
    // 各項の値は val-1 ... val+1
    for (ll v = -1; v <= 1; ++v) {
        ll tail = (val % 10) + v;
        if (0 > tail || tail > 9) continue;
        ll nval = val * 10 + tail;
        dfs(A, nval, digit + 1);
    }
}

int main() {
    vector<ll> A;
    cin >> K;

    reps(val, 9) { dfs(A, val, 1); }

    sort(A.begin(), A.end());
    cout << A[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 4928
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,m;
    cin >> n >> m;
    vector<pair<long long, long long>> a;
    for(int i = 0;i < n;i++){
        pair<long long, long long> p;
        cin >> p.first >> p.second;
        a.push_back(p);
    }

    sort(a.begin(),a.end());
    long long d = 0,ans = 0;
    while(m--){
        if(a[d].second == 0){d++;m++;continue;}
        ans += a[d].first;
        a[d].second--;
    }
    cout << ans << endl;
}

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

int main()
{
	int money = 100000;
	int n;
	cin >> n;
	while (n--)
	{
		money *= 1.05;
		if (money % 1000 != 0)
		{
			money += 1000 - (money % 1000);
		}
	}
	cout << money << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long n;
  cin>>n;
  long sum=0;
  for(long i=0;i<=n;i++){
    if(i%3==0 or i%5==0){
      continue;
    }
    sum+=i;
  }
  cout<< sum <<endl;
 return 0; 
}


Measured memory_bytes: 3540
import itertools

n = int(input())
num_list = input().split()

mod_base = 10 ** 9 + 7

num_list = [int(x) for x in num_list]

sum_list = []
sum_tmp = sum(num_list)
for i in range(len(num_list)):
    sum_list.append(sum_tmp)
    sum_tmp -= num_list[i]

all_sum = 0
for index, num in enumerate(num_list):
    if index + 1 >= len(num_list):
        break
    all_sum += num * sum_list[index+1]

print(all_sum % mod_base)

Measured memory_bytes: 31332
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_N 100000

int dp[MAX_N];

signed main(){
	int n,k;
	cin >> n >> k;
	int h[n];
	REP(i,n){
		cin >> h[i];
	}
	REP(i,n){
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= k; j++){
			if(i - j < 0){
				continue;
			}
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

const int N_MAX = 100000;

int N, K;
int a[N_MAX];

vector<int> rG[N_MAX];
int dist[N_MAX];
pair<int, int> dv[N_MAX];
int ans;

void rdfs(int v, int d) {
  dist[v] = d;
  REP(i, rG[v].size()) {
    rdfs(rG[v][i], d + 1);
  }
}

void dfs(int v, int d) {
  if (dist[v] <= d) return;
  dist[v] = d;
  if (d == 1) {
    if (a[v] != 0) {
      a[v] = 0;
      ans++;
    }
    return;
  }
  dfs(a[v], d - 1);
}

void solve() {
  ans = 0;
  if (a[0] != 0) {
    a[0] = 0;
    ans++;
  }

  FOR(i, 1, N - 1) rG[a[i]].push_back(i);
  rdfs(0, 0);

  REP(i, N) dv[i] = make_pair(dist[i], i);
  sort(dv, dv + N);

  for (int i = N - 1; i >= 0; i--) {
    int v = dv[i].second;
    if (dist[v] > K) dfs(v, K);
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) {
    scanf("%d", a + i);
    a[i]--;
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 11904
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main(){
  int n,s,save;
  cin>>n;
  map<int,int> path;
  map<int,int> data;
  for(int i=1;i<n+1;i++){
    cin>>s;
    data[i]=s;
  }
  save=data[1];
  path[1]=1;
  path[save]=1;
  s=1;
  
   while(true){
    if(save==2){
      cout<<s<<endl;
      break;
    }
    save=data[save];
     
    if(path.find(save)!=path.end()){
      cout<<-1;
      break;
    }
    
    path[save]=1;
    s+=1;
  }
}

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

int main() {
    int n, a[26], b[26];
    string s[55];
    scanf("%d", &n);

    for (int i = 0; i < 26; i++) a[i] = 55;

    for  (int i = 0; i < n; i++) {
        cin >> s[i];   
        for (int j = 0; j < 26; j++) b[j] = 0;
        for (int j = 0; j < s[i].size(); j++) {
            b[s[i][j] - 'a']++;
        }
        for (int j = 0; j < 26; j++) a[j] = min(a[j], b[j]);
    }

    for (int i = 0; i < 26; i++) {
        while (a[i] > 0) {
            char c = 'a' + i;
            printf("%c", c);
            a[i]--;
        }
    }
    printf("%c", '\n');
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SOR(vec) sort((vec).begin(),(vec).end())
using namespace std;
int n,m,pa1[12],pa2[12];
string grid[12],sorg[12];
bool ac(int id1,int id2){
	for(int it=0;it<n;it++)
		if(grid[it][id1]!=grid[pa1[it]][id2]) return false;
	return true;
}
void dfs1(int cur,int rem){
	if(cur==m) cout<<"YES"<<endl,exit(0);
	else if(pa2[cur]!=-1) dfs1(cur+1,rem);
	else{
		for(int nxt=cur+1;nxt<m;nxt++)
			if(pa2[nxt]==-1&&ac(cur,nxt))
				pa2[nxt]=cur,pa2[cur]=nxt,dfs1(cur+1,rem),pa2[nxt]=pa2[cur]=-1;
		if(rem) pa2[cur]=cur,dfs1(cur+1,0),pa2[cur]=-1;
	}
}
void dfs2(int cur,int rem){
	if(cur==n) dfs1(0,(m%2));
	else if(pa1[cur]!=-1) dfs2(cur+1,rem);
	else{
		for(int nxt=cur+1;nxt<n;nxt++)
			if(pa1[nxt]==-1&&sorg[cur]==sorg[nxt])
				pa1[nxt]=cur,pa1[cur]=nxt,dfs2(cur+1,rem),pa1[nxt]=pa1[cur]=-1;
		if(rem) pa1[cur]=cur,dfs2(cur+1,0),pa1[cur]=-1;
	}
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	memset(pa1,-1,sizeof(pa1));
	memset(pa2,-1,sizeof(pa2));
	for(int i=0;i<n;i++) cin>>grid[i];
	for(int i=0;i<n;i++) sorg[i]=grid[i],SOR(sorg[i]);
	dfs2(0,(n%2));
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
// Kevin Mathew T
// Birla Institute of Technology, Mesra
// LinkedIn - https://www.linkedin.com/in/KevinMathewT/
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define F first
#define S second
#define fi(a, b) for(ll i=(a);i<=b;i++)
#define fj(a, b) for(ll j=(a);j<=b;j++)
#define fid(a, b) for(ll i=(a);i>=b;i--)
#define fjd(a, b) for(ll j=(a);j>=b;j--)

// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> // for less 
// #include <iostream> 
// using namespace __gnu_pbds; 
// using namespace std; 
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) : Value at kth index in sorted array. 
// order_of_key(k) : Index of the value k.

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    os << "]";
	return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, unordered_map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}


const ll N = 200010, M = 1e9 + 7;
ll n, a[N];
vector<ll> T[N];

void solve(){
	cin >> n;
	fi(2, n) {
		cin >> a[i];
		T[i].push_back(a[i]);
		T[a[i]].push_back(i);
	}

	cout << T[1].size() << "\n";
	fi(2, n) cout << T[i].size() - 1 << "\n";
}

int main(){
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	// ll T;
	// cin >> T;
	// while(T--)
		solve();

	return 0;
}

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

const int INF = 0x3f3f3f3f;
int tim, n, e, t1, t2, start[100005], nd[100005];
vector <int> v[100005];
bool c, vis[100005];

void dfs(int node) {
	vis[node] = 1;
	start[node] = tim++;
	for (int i : v[node]) {
		if (start[i] != INF && nd[i] == INF) {
			c = 1;
			break;
		}
		if (!vis[i]) {
			dfs(i);
		}
	}
	nd[node] = tim;
}

int main() {
	cin >> n >> e;
	for (int i = 0; i < e; i++) {
		cin >> t1 >> t2;
		v[t1].push_back(t2);
	}
	for (int i = 0; i < n; i++) start[i] = INF, nd[i] = INF;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) dfs(i);
	}
	if (c) cout << 1 << endl;
	else cout << 0 << endl;
}



Measured memory_bytes: 5512
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();

		int u = 10;
		int[][] mat = new int[u][u];
		for (int i = 0; i < u; i++) {
			Arrays.fill(mat[i], -1);
		}
		for (int i = 0; i < u; i++) {
			for (int j = 0; j < u; j++) {
				mat[i][j] = in.nextInt();
			}
		}
		int[] wall = new int[h*w];
		for (int i = 0; i < h*w; i++) {
			wall[i] = in.nextInt();
		}

		// solve
		int[] transCost = new int[10];

		for (int fromNode = 0; fromNode < 10; fromNode++) {
			if (fromNode == 1) {
				continue;
			}
			Set<Integer> x = new HashSet<>();
			Set<Integer> y = new HashSet<>();
			boolean[] visit = new boolean[u];
			for (int i = 0; i < u; i++) {
				if (fromNode == i) {
					continue;
				}
				y.add(i);
			}
			int[] nodeCost = new int[u];
			Arrays.fill(nodeCost, Integer.MAX_VALUE);
			x.add(fromNode);
			nodeCost[fromNode] = 0;
			visit[fromNode] = true;

			while (!y.isEmpty()) {
				int min = Integer.MAX_VALUE;
				int v = -1;
				for (int from : x) {
					for (int to = 0; to < u; to++) {
						int visitCost = mat[from][to] + nodeCost[from];
						// toのノードが最小コストで訪問済でない場合
						if (mat[from][to] != -1 && !visit[to] && visitCost <= nodeCost[to]) {
							nodeCost[to] = visitCost;
							if (nodeCost[to] < min) {
								min = nodeCost[to];
								v = to;
							}
						}
					}
				}
				x.add(v);
				y.remove(v);
				visit[v] = true;
			}
			transCost[fromNode] = nodeCost[1];
		}

		int ans = 0;
		for (int wa : wall) {
			if (wa == -1 || wa == 1) {
				continue;
			}
			ans += transCost[wa];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 47000
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;

#define lli long long int
#define REP(i,n)for(int i=0;i<n;i++)
#define LIM 1000000007
 
int main(){

	lli n;
	string s;

	cin>>n;
	cin>>s;
	vector<lli> a(27,0);
	REP(i,n)a[s.at(i)-'a']++;
	
	lli sum=1;

	REP(i,27){
		sum *= (a[i]+1);
		sum %= LIM;
	}
	cout<<sum-1<<endl;

	return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
to = [0] * (N+1)
E = [set() for i in range(N+1)]
for i in range(N+M-1):
    A, B = map(int, input().split())
    E[A].add(B)
    #E.append([A, B])
    to[B] += 1
A = [0] * (N+1)
for root, t in enumerate(to[1:], 1):
    if t==0:
        break
Open = {root}

while len(Open)>0:

    root = Open.pop()

    for r in E[root]:
        #print(r)
        to[r]-=1
        if to[r]==0:
            A[r]=root
            Open.add(r)
for a in A[1:]:
    print(a)


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

int main(){
  string S;
  cin>>S;
  int ss=S.size();
  int ans=ss;
  char c=S[ss/2];
  for(int i=ss/2;i<ss;i++){
    if(S[ss-1-i]!=c||S[i]!=c){
      ans=i;break;
    }
  }
  cout<<ans<<endl;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    int priceA, priceB;
    int priceA_min, priceA_max, priceB_min, priceB_max;
    priceA_min = ceil(double(A / 0.08));
    priceA_max = floor(double((A + 1) / 0.08));
    priceB_min = ceil(double(B / 0.1));
    priceB_max = floor(double((B + 1) / 0.1));
    //min以上max未満で被っている最小の金額が答え
    //cout << priceA_min << " " << priceA_max << " " << priceB_min << " " << priceB_max << endl;
    //10%の範囲に8%が存在してる？
    for(int i = priceB_min; i < priceB_max; i++){
        if( i >= priceA_min && i < priceA_max){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
 
public class Main {
	private	static	BufferedReader	br = null;
	private	static	TeamCmp			tc = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
		tc = new TeamCmp();
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		Team[]	team = null;
		int		cnt  = 0;

		while ((team = parseTeam()) != null) {
			if (cnt++ > 0) {
				System.out.println("");
			}

			for (int i = 0; i < team.length; i++) {
				System.out.println(String.format("%s,%d", team[i].nm, team[i].pt));
			}
		}
	}

	private static Team[] parseTeam() {
		Team[]	team = null;
		int		cnt  = parseNum();

		if (cnt > 0) {
			String	stdin = null;

			team = new Team[cnt];
			for (int i = 0; i < team.length; i++) {
				team[i] = new Team();
				if ((stdin = parseStdin()) != null) {
					String[]	lines = stdin.split(" ");

					team[i].nm = lines[0];
					team[i].no = i+1;
					team[i].pt = Integer.parseInt(lines[1])*3+Integer.parseInt(lines[3]);
				}
			}
			Arrays.sort(team, tc);
		}

		return team;
	}

	private static int parseNum() {
		int		num = 0;
		String	str = null;

		if ((str = parseStdin()) != null) {
			num = Integer.parseInt(str);
		}

		return num;
	}

	private static String parseStdin() {
		String  stdin = null;

		try {
			String  tmp = br.readLine();
			if (tmp != null) {
				if (!tmp.isEmpty()) stdin = tmp;
			}
		}
		catch (IOException e) {}

		return stdin;
	}
}

class Team {
	public	String	nm = null;
	public	int		no = 0;
	public	int		pt = 0;
}

class TeamCmp implements Comparator<Team> {
   public int compare(Team tm1, Team tm2) {
       return (tm2.pt != tm1.pt) ? tm2.pt - tm1.pt : tm1.no - tm2.no;
   }
}

Measured memory_bytes: 19156