akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B81 solver = new B81();
        solver.solve(1, in, out);
        out.close();
    }

    static class B81 {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            for (int i = 1; i <= 9; i++)
                if (n % i == 0 && n / i <= 9) {
                    pw.println("Yes");
                    return;
                }
            pw.println("No");
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}



Measured memory_bytes: 24660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}


void cerrall(const vector<bool>& a){rep(i,a.size()) cerr << i << " " << (a[i]? "True" : "False") << "\n"; cerr << "\n";}
template<class T> void cerrall(const vector<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const set<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const multiset<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T, class U> void cerrall(const vector<pair<T,U>>& a){rep(i,a.size()) cerr << i << " : " << a[i].first << " " << a[i].second << "\n";}
template<class T, class U> void cerrall(const map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}
template<class T, class U> void cerrall(const unordered_map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}

template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}

template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int a,b;cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,K;
  bool ans=false;
  cin>>K>>A>>B;
  
  for(int i=A; i<=B; i++){
    if(i%K==0) {
      ans=true;
      break;
    }
  }
  if(ans) cout<<"OK";
  else cout<<"NG";
}

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

using namespace std;

int main()
{
    int N;
    int l,r;
    int res=0;

    scanf("%d",&N);

    for(int i=0;i<N;i++)
    {
        scanf("%d%d",&l,&r);
        res+=r-l+1;
    }
    
    printf("%d\n",res);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int get_leap_years(int *lys, int begin, int end);
bool is_leap_year(int y);

int main()
{
    int leap_years_list[1000];
    bool first_set = true;

    while (true) {
        int year_begin, year_end;
        //読み込み
        scanf("%d %d", &year_begin, &year_end);

        //終了判定
        if (year_begin == 0 && year_end == 0) {
            break;
        }

        //閏年を計算する
        int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end);

        //セットとセットの間には空行を入れる
        if (first_set) {
            first_set = false;
        } else {
            putchar('\n'); //ちなみにputcharは一文字だけ出力する関数です
        }

        //セットの閏年を出力
        if (leap_years_count == 0) {
            puts("NA"); //putsは単純に与えられた文字列を出力した後改行する関数です
            continue;
        }
        for (int i = 0; i < leap_years_count; i++) {
            printf("%d\n", leap_years_list[i]);
        }
        
    }
}

int get_leap_years(int *lys, int begin, int end)
{
    int count = 0;
    for (int y = begin; y <= end; y++) {
        if (is_leap_year(y)) {
            lys[count++] = y;
        }
    }
    return count;
}

bool is_leap_year(int y)
{
    if (y % 400 == 0) {
        return true; 
    } else if (y % 100 == 0) {
        return false;
    } else {
        return y % 4 == 0;
    }
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int mod = 1000000007;
//long long dp[401][401] ;
vector<vector<long long>> dp(401, vector<long long>(401,-1));
long long a[401];
long long aa[401];
int main() {
  int n;
  cin >> n;
  
  for(int i = 1;i < n+1;i++){
    cin >> a[i];
    dp[i][i] = a[i];
    aa[i] = aa[i-1]+ a[i];
  }
  
  for(int i = 1;i < n;i++){
    dp[i][i+1] = a[i] + a[i+1];
  }
  long long tmp;
  long long res = 0;
  for(int i = 1;i < n; i++){
    //long long tmp = 10000000000;
    for(int j = 1; j < n;j++){
      if(i+j > n){break;}
      for(int k = j; k < j+i;k++){
        tmp = dp[j][k]+dp[k+1][j+i] + aa[j+i]-aa[j-1];
        if(j== k){tmp -= a[j];}
        if(k+1 == j+i){tmp -= a[k+1];}
        if(dp[j][j+i] == -1){
          dp[j][j+i] = tmp;
        }else{
          dp[j][j+i] = min(tmp ,dp[j][j+i]);
        }
        
        
        //cout << j<< " " << k << " " << i+j << " " << dp[j][j+i] << endl; 
      }
      //tmp = min(tmp,dp[j][j+i]);
    }
    //res += tmp;
  }
  //cout << res;
  cout << dp[1][n] << endl;
}


Measured memory_bytes: 1536
A,B=map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
print(len(set(prime_factorize(A))&set(prime_factorize(B)))+1)

Measured memory_bytes: 3064
#include <iostream>
 
using namespace std;
 
int main(){
	int a, b;
  	
  	cin >> a >> b;
  	
  	int maxAns=0;
    int x=a+b, y=a-b, z=a*b;
  	
  	maxAns = max(x, y);
    maxAns = max(maxAns, z);
  
  	cout << maxAns << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) begin(x),end(x)
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	int N;
	set<int> st;
	REP( i, 3 )
	{
		cin >> N;
		st.emplace( N );
	}
	cout << st.size() << endl;
	return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,a=100;
	cin>>x;
	for(ll i=1;i<10000;i++){
		a+=a*0.01;
		if(a>=x){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl;
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); cout << (i>0 ? " ":"") << v[i++]); cout << "\n"; return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(a,k);
    k -= min(a,k);
    if(k > 0){
        k -= min(b,k);
    }
    if(k > 0){
        ans -= min(k,c);
        k -= min(k,c);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 1010;
const int MAXM = 20010;
const int MAXK = 110;
const int MAXQ = 200010;

struct Block {
    int s, w, v;
    Block(int s = 0, int w = 0, int v = 0) : s(s), w(w), v(v) {}
};

bool operator< (Block a, Block b) {
    if (a.s + a.w == b.s + b.w) return a.w < b.w;
    return a.s + a.w < b.s + b.w;
}

int n;
ll dp[MAXN][MAXM];
Block a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i].w >> a[i].s >> a[i].v;
    sort(a+1, a+n+1);
    FOR(i,0,n)
        FOR(j,0,20000) dp[i][j] = -1e18;
    // FOR(i,1,n) {
    //     cout << a[i].s << ' ' << a[i].w << ' ' << a[i].v << endl;
    // }
    dp[0][0] = 0;
    FOR(i,1,n) {
        FOR(j,0,20000) {
            dp[i][j] = dp[i-1][j];
            if (j >= a[i].w && j - a[i].w <= a[i].s) dp[i][j] = max(dp[i][j], dp[i-1][j-a[i].w] + a[i].v);
        }
    }
    ll res = 0;
    FOR(j,0,20000) res = max(res, dp[n][j]);
    cout << res;
    return 0;
}


Measured memory_bytes: 157952
#include <iostream>
#include <algorithm>

using namespace std;

class BubbleSort
{
 public:
  void solve( int n, int a[] );
};

void BubbleSort::solve( int n, int a[] )
{
  int cnt = 0;
  
  for( int i = 0; i < n; i++ )
    {
      for( int j = n - 1; j > i;j-- )
        {
          if( a[j] < a[j-1] )
            {
              swap( a[j], a[j-1] );
              cnt++;
            }
        }
    }
  
  cout << a[0];
  for( int i = 1; i < n; i++ )
    {
      cout << " " << a[i] ;
    }
  cout << endl;
  cout << cnt << endl;
}

int main( void )
{
  int n;
  int a[100];

  BubbleSort *bs = new BubbleSort();

  cin >> n;

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

  bs -> solve( n, a );

  delete bs;

  return 0;
}

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

ll n,h;
ll a[100010],b[100010];

int main() {
    std::cin >> n>>h;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    
    ll result = 0;
    ll a_ijo = distance(b,upper_bound(b,b+n,a[n-1]));

    for (int i = n-1; i >= a_ijo; i--) {
        h -= b[i];
        result++;
        if(h<=0){
            std::cout << result << std::endl;
            return 0;
        }
    }

    std::cout << (ll)(ceil( (h+0.0)/a[n-1] )) + result << std::endl;
}


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

int main() {
  int r,d,x;
  cin >> r >> d >> x;
  rep(i,10){
    x=r*x-d;
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,n) for(ll i=0; i<n; ++i)
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define deb(x) cout<<"For debug : "<<x<<endl;
typedef long long ll;
#define ld long double

void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    For(i,n) cin>>v[i];

    sort(v.begin(),v.end());
    int sum=0;
    For(i,k) sum+=v[i];
    cout<<sum<<endl;
}

int main(){
    optimize();
    ll T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3584
n = int(input().split()[0])
c = list(filter(lambda x:x <= n,map(int,input().split())))

minimum = [ i for i in range(n+1) ]
for i in c:
    minimum[i] = 1

for i in range(2,n+1):
    for j in c:
        if j<=i and minimum[i-j] + 1 < minimum[i]:
            minimum[i] = minimum[i-j]+1

print(minimum[n])

Measured memory_bytes: 9616
A, B, C, K = map(int, input().split())
if K == 0:
  print(0)
elif A >= K:
  print(K)
elif A + B >= K:
  print(A)
elif A + B + C >= K:
  print(A - (K -(A + B)))
elif K == 0:
  print(0)

Measured memory_bytes: 9184
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<long long> a(n),b(n);
    vector<pair<long long,int>> tmp;
    for(int i=0;i<n;++i){
        cin>>a[i]>>b[i];
        tmp.push_back(pair<long long,int>(a[i]+b[i],i));
    }
    sort(tmp.rbegin(),tmp.rend());
    long long res = 0;
    for(int i=0;i<n;++i){
        int k = tmp[i].second;
        if(i%2==0)res += a[k];
        else res -= b[k];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3956
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

int main() {
  int a[3];
  int A,B,C; std::cin >> a[0] >> a[1] >> a[2];
  std::sort(a, (a + 3),  std::greater<>());
  std::cout << 10*a[0] + a[1] + a[2] << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<ll, ll>;
const int mod = 1e9+7;
const LD pi = acos(-1.0);
const LD EPS = 1e-9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const double eps = 1e-9;
struct V {
  double x, y;
  V(double x=0, double y=0): x(x), y(y) {}
  V& operator+=(const V& v) { x += v.x; y += v.y; return *this;}
  V operator+(const V& v) const { return V(*this) += v;}
  V& operator-=(const V& v) { x -= v.x; y -= v.y; return *this;}
  V operator-(const V& v) const { return V(*this) -= v;}
  V& operator*=(double s) { x *= s; y *= s; return *this;}
  V operator*(double s) const { return V(*this) *= s;}
  V& operator/=(double s) { x /= s; y /= s; return *this;}
  V operator/(double s) const { return V(*this) /= s;}
  double dot(const V& v) const { return x*v.x + y*v.y;}
  double cross(const V& v) const { return x*v.y - v.x*y;}
  double norm2() const { return x*x + y*y;}
  double norm() const { return sqrt(norm2());}

  int ort() const { // orthant
    if (abs(x) < eps && abs(y) < eps) return 0;
    if (y > 0) return x>0 ? 1 : 2;
    else return x>0 ? 4 : 3;
  }
  bool operator<(const V& v) const {
    int o = ort(), vo = v.ort();
    if (o != vo) return o < vo;
    return cross(v) > 0;
  }
};
istream& operator>>(istream& is, V& v) {
  is >> v.x >> v.y; return is;
}
ostream& operator<<(ostream& os, const V& v) {
  os<<"("<<v.x<<","<<v.y<<")"; return os;
}

int main(){
    int n; cin >> n;
    vector<V> e(n);
    rep(i,n) cin >> e[i];
    sort(ALL(e));
    D ans = 0;
    rep(i,n){
        int j = i;
        V tmp;
        rep(k,n){
            tmp += e[j];
            chmax(ans, tmp.norm());
            j = (j + 1) % n;
        }
    }
    printf("%.13f\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  vector<vector<int>> data(3,vector<int>(3));
  for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
          cin >> data.at(i).at(j);
      }
  }
  int N;
  cin >> N;
  vector<int> numbers(N);
  for (int i=0;i<N;i++){
      cin >> numbers[i];
  }
  vector<vector<int>> check(3,vector<int>(3));
  for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
          for(int k=0;k<N;k++){
              if(data.at(i).at(j) == numbers[k]){
                  check.at(i).at(j)=1;
              }
          }
      }
  }
  int bingo = 0;
  for(int i=0;i<3;i++){
      if(check.at(i).at(0)+check.at(i).at(1)+check.at(i).at(2)==3){
          bingo=1;
      }
  }
  for(int i=0;i<3;i++){
      if(check.at(0).at(i)+check.at(1).at(i)+check.at(2).at(i)==3){
          bingo=1;
      }
  }
  
      if(check.at(0).at(0)+check.at(1).at(1)+check.at(2).at(2)==3){
          bingo=1;
      }
  
  if(check.at(2).at(0)+check.at(1).at(1)+check.at(0).at(2)==3){
          bingo=1;
      }
  if(bingo==1){
      cout << "Yes" << endl;
  }else if(bingo==0){
      cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int n[100];
int i,j,s,t,x,z;
int sum=0;


i=0;
do{
scanf("%d",&n[i]);
i++;
}while(n[i-1]!=0);

for(i=0;n[i]!=0;i++){
	s=n[i];
	t=n[i]/100+1;
	z=0;
		for(j=1;j<t;j++){
			if(s%j==0) sum+=j;
		}
		for(j=2;j<100;j++){
			if(s%j==0){
				x=s/j;
				if(s%x==0) sum+=x;
			}
		}
    if(sum==n[i]) printf("perfect number\n");
    else if(sum>n[i]) printf("abundant number\n");
    else if(sum<n[i]) printf("deficient number\n");
    sum=0;
}

return 0;
}

Measured memory_bytes: 584
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

ll gcd(ll A, ll B){
  ll M = max(A, B), m = min(A, B);
  while (M % m != 0){
    ll K = M % m;
    M = m; m = K;
  }
  return m;
}

ll lcm(ll A, ll B){
  ll G = gcd(A, B);
  return (A / G) * B;
}

ll count(ll A, ll C, ll D){
  ll ans = A / C + A / D - A / lcm(C, D);
  return A - ans;
}

int main(){
  ll A, B, C, D; cin >> A >> B >> C >> D;

  cout << count(B, C, D) - count(A - 1, C, D) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

class c_bubble
{
private:
    int n;
    long x[100];
    
public:
    void f_bubble();

};

void c_bubble::f_bubble()
{
    int i, j;
    int temp1;
    int c;
    
    cin >> n;
    for ( i = 0; i < n; ++i){
        cin >> x[i];        
    }
    
    c = 0;
    
    for ( i = 0; i < n; ++i){
        for ( j = n-1; j > 0; --j){
            if (x[j] < x[j-1]){
                temp1 = x[j];
                x[j] = x[j-1];
                x[j-1] = temp1;
                c += 1;
            }
        }
    }
    
    for ( i = 0; i < n; ++i){
        cout << x[i];
        if( i == n-1){
            cout << endl;
        }else{
            cout << " ";
        }        
    }
    cout << c << endl;
}

int main(){
    c_bubble bubble01;
    
    bubble01.f_bubble();
    
    return 0;
}

Measured memory_bytes: 3108
import java.util.*;
import java.lang.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    Player[] ply = new Player[18];
	    for(int j = 0; j < 3; j++){
		Player[] tmp = new Player[8];
		for(int i = 0; i < 8; i++)
		    tmp[i] = new Player(sc.nextInt(), sc.nextDouble());
		Arrays.sort(tmp);
		tmp[0].print();
		tmp[1].print();
		System.arraycopy(tmp, 2, ply, j*6, 6);
	    }
	    
	    Arrays.sort(ply);
	    ply[0].print(); 
	    ply[1].print();
	}
    }
    
    public static void main(String[] args){
	new Main();
    }
}

class Player implements Comparable{
    public int id;
    public double tm;

    public Player(){
	this.id = 0;
	this.tm = 0;
    }

    public Player(int id, double tm){
	this.id = id;
	this.tm = tm;
    }

    public int compareTo(Object obj){
	Player ply = (Player)obj;

	if(this.tm > ply.tm) return 1;
	if(this.tm < ply.tm) return -1;
	return 0;
    }
    
    public void print(){
	System.out.println(String.valueOf(this.id)+" "+String.valueOf(this.tm));
	return ;
    }
}

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

int main()
{
   int n;
   cin>>n;
   ll arr[n],sum=0,b,c;
   map<ll,ll> mp;
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
       sum+=arr[i];
       mp[arr[i]]++;
   }
   int q;
   cin>>q;
   while(q--)
   {
       cin>>b>>c;
       sum-= mp[b]*b;
       sum+= mp[b]*c;
       mp[c]+= mp[b];
       mp[b]=0;
       cout<<sum<<endl;
   }
    return 0;
}


Measured memory_bytes: 10148
#include<stdio.h>

int main()
{
	int x,y,z,t=0,h=0;
	while(scanf("%d,%d,%d",&x,&y,&z)!=EOF)
	{		
		x*=x;
		y*=y;
		z*=z;

		if(z==(x+y))
		{
			t++;
		}
		else if(x==y)
		{
			h++;
		}
	}
	printf("%d\n%d\n",t,h);
	return 0;
}

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

#define mod 1000000007
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

int main(){
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	//scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		puts((n%10 == n/100)?"Yes":"No");
	}
	return 0;	
}

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

int main() {
int N;
  cin>>N;
  vector<int>S(N);
  int A=0;
  for(int i=0; i<N; i++){
    cin>>S.at(i);
    if((i+1)!=S.at(i))
      A++;
  }
  if(A==0||A==2)
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

a, b, c, d = map(int, input().strip().split())
res = a * c
res2 = b * d
res3 = a * d
res4 = b * c
if res < res2:
    res = res2
if res < res3:
    res = res3
if res < res4:
    res = res4
print(res)






Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
long long dp[1000][1000];
int main(){
  int H,W;
  cin>>H>>W;
  string a[1000];
  for(int i=0;i<H;i++){
    cin>>a[i];
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      dp[i][j]=0;
      if(a[i][j]=='.'){
        if(i==0&&j==0){
          dp[i][j]=1;
        }
        if(i==0&&j!=0){
          dp[i][j]=dp[i][j-1];
        }
        if(i!=0&&j==0){
          dp[i][j]=dp[i-1][j];
        }
        if(i!=0&&j!=0){
          dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
        }
      }
    }
  }
  cout<<dp[H-1][W-1]<<endl;
  return 0;
}

/*long long dp[101][100001];
int main(){
int N;
long long W;
cin>>N>>W;
long long w[101],v[101];
for(int i=1;i<N+1;i++){
cin>>w[i]>>v[i];
}
  for(int i=0;i<N+1;i++){
    for(int value=0;value<100001;value++){
      dp[i][value]=9999999999;
    }
  }
  dp[0][0]=0;
for(int i=1;i<N+1;i++){
for(int value=1;value<100001;value++){
if(value>v[i]){
dp[i][value]=min(dp[i-1][value-v[i]]+w[i],dp[i-1][value]);
}
else{
dp[i][value]=min(dp[i-1][value],w[i]);
}
}
}
int answer=0;
for(int value=1;value<100001;value++){
if(dp[N][value]<=W){
answer=max(answer,value);
}
}
cout<<answer<<endl;

}*/

/*long long dp[101][100001];
int main(){
int N,W;
cin>>N>>W;
long long w[101],v[101];
for(int i=1;i<N+1;i++){
cin>>w[i]>>v[i];
}
dp[0][0]=0;
for(int i=1;i<N+1;i++){
for(int wei=1;wei<W+1;wei++){
if(wei>=w[i]){
dp[i][wei]=max(dp[i-1][wei-w[i]]+v[i],dp[i-1][wei]);
}
else{
dp[i][wei]=dp[i-1][wei];
}
}
}
cout<<dp[N][W]<<endl;
}*/




Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);

ll n,a[100001],m,x,i,b[100001];

int main()
{
	ll n,m;
	cin>>n>>m;
	ll p=n*(n-1)/2;
	ll q=m*(m-1)/2;
	cout<<p+q<<"\n";
} 

Measured memory_bytes: 256
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
P.sort(key=lambda x:x[2])
a, b, c = P[-1]

for px in range(101):
    for py in range(101):
        H = abs(px - a) + abs(py - b) + c
        if all(h == max(H - abs(x - px) - abs(y - py), 0) for x, y, h in P):
            print(px, py, H)
            break

Measured memory_bytes: 3064
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp;
  writeln("2018" ~ s[4..$]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int N, M;
int p[100010], y[100010];
vector<int> yd[100010];

int main() {
    cin >> N >> M;
    rep(i, M) {
        cin >> p[i] >> y[i];
        yd[p[i]].push_back(y[i]);
    }
    rep(i, N) sort(yd[i+1].begin(), yd[i+1].end());
    rep(i, M) {
        printf("%06d", p[i]);
        printf("%06ld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i])-yd[p[i]].begin()+1);
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;

const int INF = 1e9;
int a;
string s;

int main() {
  cin >> a >> s;
  if (a < 3200) s = "red";
  cout << s << endl;
  return 0;
}


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

int main() {
  long long n;
  cin >> n;
  map<long long, int> mp;
  long long tmp = n;
  vector<long long> ans;
  int flag = 0;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      mp[i]++;
      flag = 1;
    }
  }
  if (n != 1) mp[n]++;

  // if (flag == 0 && tmp != 1) mp[tmp]++;
  for (const auto& [key, value] : mp) {
    for (int i = 1; i <= value; i++) {
      ans.push_back(pow(key, i));
    }
  }
  sort(ans.begin(), ans.end());
  int num = 0;
  for (int i = 0; i < ans.size(); i++) {
    if (tmp % ans.at(i) == 0) {
      num++;
      tmp /= ans.at(i);
    }
  }
  cout << num;

  return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

// Mod int
const int mod = 1000000007;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
typedef vector<vm> vvm;
//

int main(){

  string num;
  int K;
  cin >> num >> K;
  int n = num.size();
  mint dp[n+10][2][K];
  memset(dp,0,sizeof(dp));

  dp[0][0][0] = 1;
  rep(i,n){
    rep(j,2){
      rep(k,K){
        ll border;
        if(j == 1) border = 9;
        else border = (int)(num[i] - '0');
        rep(digit,border+1){
          //cout << "dp[" << i+1<< "][" << (j||(digit<border))<< "][" << (k+digit)%K << "] += dp[" << i << "][" << j << "][" << k << "] = " <<  dp[i][j][k] << endl;
          dp[i+1][j||(digit<border)][(k+digit)%K] += dp[i][j][k];
        }
      }
    }
  }

  mint ans = 0;
  rep(i,2) ans += dp[n][i][0];
  cout << ans-1 << endl;

  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define MP make_pair
#define ull unsigned long long int
#define F first
#define S second
#define put insert
#define pb push_back
#define rsortV(arr) sort(arr.begin(),arr.end(),greater<int>())
#define sortV(arr) sort(arr.begin(),arr.end())
#define sortA(arr,n) sort(arr,arr+n)
#define rsortA(arr,n) sort(arr,arr+n,greater<int>())
#define arrInput(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define rev(arr) reverse(arr.begin(), arr.end())
#define all(x) (x).begin(), (x).end()
ll MOD = 1e9+7;
int main() {
    fastio
    // int t;
    // cin>>t;
    // while(t--) {
    string s;
    cin>>s;
    vector<ll> arr(10,0);
    for(char c : s) {
        arr[c-'0'] = (arr[c-'0']+1)%9;
    }
    ll sum = 0;
    for(ll i=0;i<10;i++)
        sum += (i*arr[i])%9;
    cout<<((sum%9==0)?"Yes":"No");
    // }
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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() {
    int N, M;
    cin >> N >> M;
    int p[N];
    for(int i = 0; i < N; i++) cin >> p[i];
    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        tree.unite(x, y);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(tree.same(i, p[i] - 1)) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int dp[1010][1010];
int main()
{
	int n;
	while (true) {
		cin >> n; 
		if (n == 0) break;
		vector<string> masu(n);
		for (int i = 0; i < n; ++i) cin >> masu[i];

		int res = 0;
		for (int i = 0; i < n; ++i) dp[i][0] = masu[i][0] == '.';
		for (int j = 0; j < n; ++j) dp[0][j] = masu[0][j] == '.';
		for (int i = 1; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (masu[i][j] == '.') {
					dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1]))+1;
				}
				else {
					dp[i][j] = 0;
				}
				res = max(res, dp[i][j]);
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 2012
def ifPrine(n):
    if n <= 1:
        return True
    elif n == 2 or n == 3:
        return False
    else:
        i = 2
        while i*i <= n:
            if n % i == 0:
                return True
            else:
                i += 1
    return False

x = int(input())
q = 0
while q < 100000:
    if ifPrine(x+q) == False:
        print(x+q)
        break
    else:
        q += 1
        

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	int N;
	long total;
	int l, r, i;

	scanf("%d", &N);

	total = 0;
	for(i=0; i<N; i++){
		scanf("%d %d", &l, &r);
		total += (r - l + 1);
	}

	printf("%ld", total);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::pair;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q;
ull a, b, c, x, y;
ull K, L, N, M;

int main()
{
	cin >> x >> a >> b;
	if ((x - a)*(x - a) < (x - b)*(x - b))cout << "A\n";
	else cout << "B\n";
	return 0;
}


Measured memory_bytes: 256
N = int(input())
T, A = tuple(map(int, input().split()))
H = list(map(int, input().split()))

listT = []
for i in range(N):
    listT.append(abs(A-(T - H[i] * 0.006)))

m = min(listT)
mi =listT.index(m) + 1

print(mi)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#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 MOD 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
using namespace std;
typedef pair<ll, ll> P;
typedef pair<ll, P> TP;

ll n, k, white[2100][2100], black[2100][2100];

void imos(ll grid[2100][2100]) {
  FOR(i, 1, k + 1) {
    FOR(j, 1, k + 1) { grid[i][j] += grid[i][j - 1]; }
  }
  FOR(i, 1, k + 1) {
    FOR(j, 1, k + 1) { grid[j][i] += grid[j - 1][i]; }
  }
}

ll imoscnt(ll lx, ll ly, ll rx, ll ry, ll grid[2100][2100]) {
  return grid[rx][ry] - grid[rx][ly] - grid[lx][ry] + grid[lx][ly];
}

int main() {
  cin >> n >> k;
  REP(i, n) {
    ll x, y;
    char c;
    cin >> x >> y >> c;
    x %= 2 * k, y %= 2 * k;

    ll b = (c == 'W');
    if (x >= k)
      x -= k, b = !b;
    if (y >= k)
      y -= k, b = !b;

    ll(*p)[2100] = (b ? white : black);
    p[x + 1][y + 1]++;
  }

  imos(white);
  imos(black);

  ll maxi = 0;
  REP(i, k + 2) {
    REP(j, k + 2) {
      ll cnt = 0;
      cnt += imoscnt(0, 0, i, j, white) + imoscnt(i, j, k, k, white);
      cnt += imoscnt(i, 0, k, j, black) + imoscnt(0, j, i, k, black);
      maxi = max({maxi, n - cnt, cnt});
    }
  }
  return !printf("%lld\n", maxi);
}


Measured memory_bytes: 36480
#pragma comment(linker, "/STACK:10240000,10240000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 2e5 + 7;

int n;
long long a[maxn], b[maxn];

void sort(long long *a, long long md) {
    int pos = n;
    for (int i = 0; i < n; i ++) {
        if (pos == n && a[i] >= md) pos = i;
        a[i] = a[i] & (md - 1);
    }
    inplace_merge(a, a + pos, a + n);
}

bool solve(long long limit) {
    long long ans = 0;
    int that = n - 1;
    for (int i = 0; i < n; i ++) {
        while (that >= 0 && a[i] + b[that] >= limit) that --;
        ans += n - 1 - that;
    }
    return ans & 1;
}
int main() {
    int T, cas = 0;
        cin >> n;
        for (int i = 0; i < n; i ++) {
            scanf("%I64d", a + i);
        }
        for (int i = 0; i < n; i ++) {
            scanf("%I64d", b + i);
        }
        sort(a, a + n);
        sort(b, b + n);
        long long ans = 0;
        for (int i = 61; i >= 0; i --) {
            sort(a, (long long)2 << i);
            sort(b, (long long)2 << i);
            long long res =
                solve((long long)1 << i) ^
                solve((long long)2 << i) ^
                solve((long long)3 << i);
            ans |= res << i;
        }
        printf("%I64d\n", ans);
    return 0;
}


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

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

    int n;
    cin >> n;
    vector<double> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    double t = 0;
    for(int i = 0; i < n; i++){
        t += 1 / A[i];
    }

    double ans = 1 / t;
    cout << fixed << std::setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        int n;

        n = Int32.Parse(Console.ReadLine());

        float totalOdd = n / 2;
        if (n % 2 != 0)
            totalOdd++;

        float probability = totalOdd / n;

        Console.WriteLine(probability);
    }
}




Measured memory_bytes: 13140
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(n * n * n)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1772
S = input()
T = input()
l = len(T)
min = l
max = 0
count = len(S) - l + 1
i = 0
while (i < count):
    c = 0
    for j in range(l):
        if S[i + j] == T[j]:
            c += 1
    if max < c:
        max = c
        min = l - max
    i += 1
print(min)


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n+1);
    for(int i = 2; i <= n; i++)
    {
        int d;
        cin >> d;
        a[d].push_back(i);
    }
    vector<int> dp(n+1);

    function<int(int)> dfs = [&](int v)
    {
        if(a[v].empty())
        {
            return dp[v] = 0;
        }
        vector<int> tmp;
        for(int child : a[v])
        {
            tmp.push_back(dfs(child));
        }
        if(tmp.size() == 1)
        {
            return dp[v] = tmp[0] + 1;
        }
        sort(tmp.begin(), tmp.end());
        int count = a[v].size();
        int high = 1;
        for(int i = 0; i < a[v].size(); i++)
        {
            high = max(high, tmp[i] + count);
            count--;
        }
        return dp[v] = high;
    };
    dfs(1);
    cout << dp[1] << endl;
}


Measured memory_bytes: 17024
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

h = Hash.new(0)
a.each do |num|
  h[num] += 1
end

ans = 0
h.keys.each do |k|
  v = h[k]
  ans += v * (v-1) / 2
end

# p ['ans', ans]
a.each do |num|
  v = h[num]
  diff = v * (v-1) / 2 - (v-1) * (v-2) / 2
  puts ans - diff
end


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


S = input()

first = S[:2]
last = S[2:]

fmf = False
lmf = False

if (
    "01" in first
    or "02" in first
    or "03" in first
    or "04" in first
    or "05" in first
    or "06" in first
    or "07" in first
    or "08" in first
    or "09" in first
    or "10" in first
    or "11" in first
    or "12" in first):
    fmf = True

if (
    "01" in last
    or "02" in last
    or "03" in last
    or "04" in last
    or "05" in last
    or "06" in last
    or "07" in last
    or "08" in last
    or "09" in last
    or "10" in last
    or "11" in last
    or "12" in last):
    lmf = True

if fmf:
    if lmf:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if lmf:
        print("YYMM")
    else:
        print("NA")



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int> >;

 
 
int main(){
  int N; cin >> N;
  vector<int> b(N);
  for(int i=0; i<N; i++) cin >> b[i];
  int ans = 1000000000;
  for(int i=1; i<100; i++){
    int sum=0;
    for(int j=0; j<N; j++){
      sum += (b[j]-i)*(b[j]-i);
    }
 
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}

int main()
{
	int n=read();
	int res=0;
	for(rint i=1;i<=n;++i) {int x=read();if(x%2==1) res=1;}
	if(res) cout<<"first";
	else cout<<"second";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
 
int main() {

    ll h;
    cin>>h;

    ll co;
    
    rep(i,10000) {
        if(h<(ll)pow(2,i)) {
            co=i;
            break;
        }
    }

    ll ans=0;
    rep(i,co) {
        ans+=(ll)pow(2,i);
    }

    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s = RD!string;
	foreach (i, c; s)
	{
		if (i % 2 == 0)
			write(c);
	}

	writeln();
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 508
#include<bits/stdc++.h>
                     
int main()
{
    int n;
    std::cin>>n;
    std::vector<int> a(n);
    std::vector<std::vector<std::pair<int,bool>>> f(n);
    for(int i=0;i<n;i++){
        std::cin>>a[i];
        f[i].resize(a[i]);
        for(int j=0;j<a[i];j++){
            int a,b;
            std::cin>>a>>b;
            a--;
            f[i][j] =  {a,b==1};
        }
    }

    //bit全探索
    int min = 0;
    for(int bit=0;bit<(1<<n);bit++){
        bool flag = true;
        int cnt = 0;
        std::vector<bool> chack(n);
        //評価
        for(int i=0;i<n;i++){
            if( bit & (1<<i)){
                chack[i] = true;
                cnt++;
                //std::cout<<i<<" ";
            }
        }
        //証言について
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                //もし矛盾があったら
                for(auto j : f[i]){
                    if(chack[j.first] != j.second)flag = false;
                }
            }
        }
        //std::cout<<" :"<<flag<<std::endl;
        cnt = (flag ? cnt : 0);
        min = std::max(cnt,min);
    }
    std::cout<<min<<std::endl;
}


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

int main()
{
    int A, P;
    cin >> A >> P;

    cout << ( 3 * A + P) / 2 << endl;
    
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bla
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int min = 1234567890;
            for (int i = 1; i < n; i++)
            {
                min = Math.Min(min, dsum(i) + dsum(n - i));
            }
            Console.WriteLine(min);
        }

        static int dsum(int n)
        {
            int sum = 0;
            while(n != 0)
            {
                sum += n % 10;
                n /= 10;
            }
            return sum;
        }
    }
}

Measured memory_bytes: 11092