akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
typedef long long ll;
const long long MOD = 1e9+7;

int main(){
  int n;cin>>n;
  vector<ll> one(61,0);
  
  REP(i,n){
    ll a;cin>>a;
    REP(j,61){
      if(a%2) one.at(j)++;
      a/=2;
    }
  }

  ll ans=0;
  REP(i,61){
    ll tmp=(ll)pow(2,i)%MOD;
    tmp=(tmp*(n-one.at(i)))%MOD;
    tmp=(tmp*one.at(i))%MOD;
    ans=(ans+tmp)%MOD;
  }
  cout<<ans;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
L=[0]*m
R=[0]*m
table=[0]*(n+2)
for i in range(m):
   L[i],R[i]=map(int,input().split())
   table[L[i]]+=1
   table[R[i]+1]-=1
s=[0]*(n+2)#累積和をするリスト
for i in range(1,n+2):
   s[i]=s[i-1]+table[i]
print(s.count(m))

Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ld x;
    cin>>x;
    ll val=100;
    ll t=0;
    while (true)
    {
        if (val>=x)
        {
            cout<<t<<"\n";
            return 0;
        }
        val+=val/100;
        t++;
    }
}


Measured memory_bytes: 3736
#include <iostream>
#include <vector>

using namespace std;

#define MAX_N 51

int N, K, R;
bool angry[MAX_N] = {};

int main() {
	cin >> N >> K;
	vector< vector<int> > boats(K);
	for (int i = 0; i < K; i++) {
		int m; cin >> m;
		boats[i].resize(m);
		for (int j = 0; j < m; j++) cin >> boats[i][j];
	}
	cin >> R;
	for (int i = 0; i < R; i++) {
		int p, q;
		cin >> p >> q;
		for (int j = 0; j < K; j++) {
			bool p_on_boat = false, q_on_boat = false;
			for (int k = 0; k < boats[j].size(); k++) {
				if (boats[j][k] == p) p_on_boat = true;
				else if (boats[j][k] == q) q_on_boat = true;
			}
			if (p_on_boat && q_on_boat) 
				angry[p] = angry[q] = true;
		}
	}

	int cnt = 0;
	for (int i = 1; i <= N; i++) if (angry[i]) cnt++;

	cout << cnt << endl;

	return 0;
}

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

using namespace std;
#define MOD 1000000007
#define X first
#define Y second
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
const int N = 20;
int n, m, d[N];
vector<pii> a[N];

int dem1(int va)
{
    int cnt = 0;
    while (va > 0)
    {
        cnt += (va & 1);
        va /= 2;
    }
    return cnt;
}

bool setup(int j)
{
    for (pii u : a[j]) {
        if (d[u.X] == -1)
        {
            d[u.X] = u.Y;
            if (u.Y == 1)
            {
                if (!setup(u.X)) {
                    return false;
                }
            }
        }
        else if (d[u.X] != u.Y) {
            return false;
        }
    }
    return true;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> m;
        for (int j = 1; j <= m; ++j) {
            int x, y;
            cin >> x >> y;
            a[i].push_back(pii(x, y));
        }
    }
    int lim = (1 << n), record = -1;
    for (int i = 0; i < lim; ++i) {
        int num = dem1(i);
        bool kt = true;
        if (num <= record) continue;
        memset(d, -1, sizeof d);
        for (int j = 1; j <= n && kt; ++j)
            if ((1 << (j - 1)) & i)
            {
                if (d[j] == 1) continue;
                if (d[j] == 0) {
                    kt = false;
                    break;
                }
                if (!setup(j)) {
                    kt = false;
                    break;
                }
            }
            else if (d[j] == 1) kt = false;
        if (kt)
            record = num;
    }
    cout << record;
    return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int sum = a + b + c;
  int max_num = max({a, b, c});
  if (sum == 2 * max_num)
  {
    printYes();
  }
  else
  {
    printNo();
  }
  return 0;
}

Measured memory_bytes: 256
aa=input("").split(" ")
a=[]
for i in range(3):
    a+=[int(aa[i])]
    
    
b=[]
for i in range(a[0]):
    b+=[input("")]
c=[]
for i in range(a[0]):
    d=[]
    for k in b[i]:
        if (k=="."):
            d+=[0]
        else:
            d+=[1]
    c+=[d]
def count(n,m):
    s=0
    for i in range(a[0]):
        for k in range(a[1]):
            if (c[i][k]==1 and n[i]==1 and m[k]==1):
                s+=1
    return s
ss=0
for ii in range(2**a[0]):
    for kk in range(2**a[1]):
        d=ii
        e=kk
        n=[]
        m=[]
        for iii in range(a[0]):
            n+=[d%2]
            d=int((d/2))
        for kkk in range(a[1]):
            m+=[e%2]
            e=int(e/2)
        if (count(n,m)==a[2]):
            ss+=1
print(ss)
                
        
    
            



Measured memory_bytes: 9280
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	
	if(a%2==0||b%2==0)
	{
		printf("Even");
	}
	else
	{
		printf("Odd");
	}
	
	return 0;
}

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

int main() {

  long long int n, p, a, b, c, d, e, f, s, m;

  string l;

  while( true ) {

    cin >> n;

    if ( n == 0 ) break;

    vector< pair< double, string > > list;

    for ( long long int i = 0; i < n; i++ ) {

      cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;

      long long int k = f * s * m - p;

      list.push_back( make_pair( -1.00 * k / ( a + b + c + ( d + e ) * m ), l ) );

    }

    sort( list.begin(), list.end() );

    for ( long long int i = 0; i < n; i++ ) {

      cout << list[i].second << endl;

    }

    cout << "#" << endl;

  }

  return 0;

}

Measured memory_bytes: 1220
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e3 + 5;
int a[maxn];
int n, m;
set<int>s;

int main() {
	while (scanf("%d %d", &n, &m)) {
		s.clear();
		if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		int max = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if(i!=j) s.insert(a[i] + a[j]);
			}
		}
		//set<int>::iterator it = s.upper_bound(m);
		bool flag = false;
		for (set<int>::iterator it = --s.end(); it != s.begin(); it--) {
			if (*it <= m) {
				printf("%d\n", *it);
				flag = true;
				break;
			}
		}
		if (!flag) {
			if (*s.begin() <= m) printf("%d\n", *s.begin());
			else printf("NONE\n");
		}
	}
	return 0;
}


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

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

    int N, x,flag;
    vector<int> a;
    flag = 0;
    cin>>N;
    for(int i = 0; i<N; i++)
    {
        cin>>x;
        a.push_back(x);
    }

    for(int i=0; i<N; i++)
    {
        if((a.at(i) % 2 == 0))
        {
            if((a.at(i) % 3 == 0 || a.at(i) % 5 == 0))
            {
                continue;
            }
            else
            {
                flag = 1;
            }
            
        }
    }

    if(flag == 0)
    {
        cout<<"APPROVED"<<endl;
    }
    else
    {
        cout<<"DENIED"<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    string s[n];
    for(int i = 0;i<n;i++) cin>>s[i];
    char matu = s[0][s[0].length()-1];
    for(int i = 1;i<n;i++){
      if(matu ==s[i][0]){
      	 matu = s[i][s[i].length()-1];
      }
      else{
         cout<<"No";
         return 0;
      }
    }
    sort(s,s+n);
    for(int i =0;i<n-1;i++){
       if(s[i] == s[i+1]){
         cout<<"No";
         return 0;
       }
    }
    cout<<"Yes";
    return 0; 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define ll long long
#define M 1000000007
#define N 105
#define K 100010
using namespace std;

ll n,k,a[N],cnt[K],dp[N][K];

int main()
{
    cin>>n>>k; FOR(i,1,n+1) cin>>a[i];
    dp[0][0]=1;
    FOR(i,1,n+1)
    {
        memset(cnt,0,sizeof(cnt));
        FOR(j,0,k+1) cnt[j]=dp[i-1][j];
        FOR(j,1,k+1) cnt[j]=(cnt[j]+cnt[j-1])%M;
        FOR(j,0,k+1) dp[i][j]=(j<=a[i])?cnt[j]:(cnt[j]-cnt[j-a[i]-1]+M)%M;
    }
    cout<<dp[n][k]<<'\n';

    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=1e5+10;
int a[N];
int main()
{
	int n;init(n);
	for(int i=1;i<=n;++i) init(a[i]);
	if(n&1) puts("0");
	else {
		sort(a+1,a+1+n);
		int mid=(n>>1);
		printf("%d\n",a[mid+1]-a[mid]);
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int h,a;
	cin >> h >> a;
	int ans = h/a;
	if(h%a!=0) ans++;

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    int N, K;
    cin >> N >> K;
    vi A(N);
    map<int, int> cnt;
    rep(i, N) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    vector<pii> B;
    each(c, cnt)B.emplace_back(c.second, c.first);
    sort(B.rbegin(),B.rend());
    int ans = 0;
    while (sz(B) > K) {
        ans += B.back().first;
        B.pop_back();
    }
    cout << ans << endl;
}


Measured memory_bytes: 12660
#include<bits/stdc++.h>
    #define F first
    #define S second
    using ll = long long;
    const ll mod = 1000000007;
    const ll infi = 1000000000000000;
    const ll md = 998244353;
    using namespace std;
    using vl = vector<ll>;
    using pll =  pair<ll,ll>;

    void solve(){
        double n,e,o;
        cin>>n;
        e = (int)n/2;
        o = n- e;
        double ans = o/n;
        printf("%0.6lf",ans);
    }
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //int n;cin>>n; for(int i=0;i<n;i++)
        solve();
        return 0;
    } 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	ll n,t,m = 10000000000,r = -10000000000;
	cin >> n;
	for(ll i = 0;i < n;i++) {
		cin >> t;
		r = max(r,t - m);
		m = min(m,t);
	}
	cout << r << endl;
}



Measured memory_bytes: 3104
def upper_bound(ar, val):
    low = 0
    high = len(ar)
    while low < high:
        mid = (low + high) >> 1
        if val >= ar[mid]:
            low = mid + 1
        else:
            high = mid
    return low


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
count = [0] * n
greater_a = [0] * n
for i in range(n):
    greater_a[i] = upper_bound(b, a[i])
    count[i] = n - upper_bound(c, b[i])
prefix = [0] * n
prefix[n - 1] = count[n - 1]
for k in range(n - 2, -1, -1):
    prefix[k] = prefix[k + 1] + count[k]
total = 0
for k in range(n):
    if greater_a[k] < n:
        total += prefix[greater_a[k]]
print(total)


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S; cin >> S;
  
  //main
  if(S=="AAA"||S=="BBB"){
    cout << "No" << endl; 
  }else{
    cout << "Yes" << endl; 
  }
  
  // output
  //cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    rep(i,N-K) {
        cout << (A[i] < A[i+K] ? "Yes" : "No") << ln;
    }
}


Measured memory_bytes: 4732
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int temp(int a,int b)
{
	return a>b;
}
int main()
{
	int x=0,sum11=0,sum22=0,n,a[5111];
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	sort(a+1,a+n+1,temp);
	for(int i=1;i<=n;i++)
	{
		if(x%2==1)
		  sum11+=a[i];
		else sum22+=a[i];
		x++;
	}
	cout<<abs(sum11-sum22)<<endl;
}

Measured memory_bytes: 256
import sys

sign = '+-'

def main():
    a, b, c, d = list(sys.stdin.readline().rstrip())

    for i in sign:
        for j in sign:
            for k in sign:
                left = a + i + b + j + c + k + d
                if eval(left) == 7:
                    print(left+'=7')
                    sys.exit()

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
const int N_MAX = 8;
int N;
int M;
bool edge[N_MAX][N_MAX];
bool visited[N_MAX];
int ans = 0;
void dfs (int v) {
    bool end = true;
    for (int i = 0; i < N; i++) {
        if (!visited[i]) end = false;
    }
    if (end) ans++;

    for (int i = 0; i < N; i++) {
        if (edge[v][i] && !visited[i]) {
            visited[i] = true;
            dfs(i);
            visited[i] = false;
        }
    }
}
int main (void) {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            edge[i][j] = false;
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a][b] = true;
        edge[b][a] = true;
    }

    for (int i = 0; i < N; i++) visited[i] = false;
    visited[0] = true;
    dfs(0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <climits>
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

int N;
int a[100100];
int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    int b;
    cin >> b;
    a[b]++;
  }
  int ans = 0;
  for(int i=1;i<=100000;i++){
    if(a[i] > 1) ans += a[i] - 1;
  }
  cout << N-((ans+1)/2)*2 << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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 REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  REP(i,m) cin >> l[i] >> r[i];
  
  int rmin = r[0],lmax = l[0];
  REP(i,m){
    if(r[i] <= rmin){
      rmin = r[i];
    }
    if(l[i] >= lmax){
      lmax = l[i];
    }
  }

  cout << max(rmin - lmax + 1,(long long)0)<< endl;

  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[101010];
vector<int> E[101010];

int dfs(int cur) {
	vector<int> V;
	
	FORR(e,E[cur]) {
		V.push_back(dfs(e));
	}
	sort(ALL(V));
	reverse(ALL(V));
	int ma=0,i;
	FOR(i,V.size()) ma=max(ma,V[i]+i);
	return ma+1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=2;i<=N;i++) {
		cin>>P[i];
		E[P[i]].push_back(i);
	}
	cout<<dfs(1)-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 13952
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

int ext_gcd(int a, int b, int &x, int &y){
    int d = a;
    if(b == 0){
        x = 1; y = 0;
    } else {
        d = ext_gcd(b, a%b, y, x);
        y -= (a/b) * x;
    }

    return d;
}

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

    int a, b;
    int x, y;
    cin >> a >> b;
    ext_gcd(a, b, x, y);
    cout << x << " " << y << "\n";
    return 0;
}

Measured memory_bytes: 3228
import java.util.*;
 
public class Main {
    private static final Scanner scn = new Scanner(System.in);
     
    public static void main(String[] args) {
        int[] num = new int[6];
        for(int i = 0; i < 6; i++) {
            num[i] = scn.nextInt();
        }
        Dice dice = new Dice(num);
        dice.move(scn.next());
        System.out.println(dice.show(Dice.TOP));
    }
}
 
class Dice {
    private int[] num_;
    public static final int
      TOP = 0, SOUTH = 1, EAST = 2,
      WEST = 3, NORTH = 4, BOTTOM = 5;
    
    public Dice(int... ary) {
        int[] num = new int[6];
        for(int i = 0; i < 6; i++) {
            num[i] = ary[i];
        }
        num_ = num;
    }
     
    public int show(int side) {
        return num_[side];
    }
     
    public void move(String str) {
        char[] ary = str.toCharArray();
        for(char elm : ary) {
            move(elm);
        }
    }
     
    public void move(char dir) {
        if(dir == 'S') {
            toSouth();
        } else if(dir == 'E') {
            toEast();
        } else if(dir == 'W') {
            toWest();
        } else if(dir == 'N') {
            toNorth();
        }
    }
     
    private void toSouth() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[NORTH];
        num_[NORTH]  = num_[BOTTOM];
        num_[BOTTOM] = num_[SOUTH];
        num_[SOUTH]  = tmp;
    }
     
    private void toEast() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[WEST];
        num_[WEST]   = num_[BOTTOM];
        num_[BOTTOM] = num_[EAST];
        num_[EAST]   = tmp;
    }
     
    private void toWest() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[EAST];
        num_[EAST]   = num_[BOTTOM];
        num_[BOTTOM] = num_[WEST];
        num_[WEST]   = tmp;
    }
     
    private void toNorth() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[SOUTH];
        num_[SOUTH]  = num_[BOTTOM];
        num_[BOTTOM] = num_[NORTH];
        num_[NORTH]  = tmp;
    }
}

Measured memory_bytes: 26412
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

template<typename T> vector<pair<T, LL>> cc(vector<T> v) {
	vector<pair<T, LL>> a;
	inc(i, v.size()) {
		if(i == 0 || v[i] != v[i - 1]) { a.EB(v[i], 1); } else { a.back().SE++; }
	}
	return a;
}

string s;

int main() {
	cin >> s;
	int n = SI(s);
	vector<int> v;
	inc(i, n) { v.PB(s[i] == 'R' ? +1 : -1); }
	
	auto w = cc(v);
	vector<int> ans(n);
	int p = 0;
	inc(i, SI(w)) {
		if(i % 2 != 0) { continue; }
		
		p += w[i].SE;
		ans[p - 1] = ce(w[i].SE, 2) + fl(w[i + 1].SE, 2);
		ans[p    ] = fl(w[i].SE, 2) + ce(w[i + 1].SE, 2);
		p += w[i + 1].SE;
	}
	
	inc(i, n) { cout << ans[i] << (i == n - 1 ? "\n" : " "); }
	
	return 0;
}


Measured memory_bytes: 3380
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n;
    int a[100010];
    int ans = 0;

    cin >> n;

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

    for (int i = 0; i < n; i++) {
        if (i+1 == a[i]) {
            ans++;
            if (i+2 == a[i+1]) {
                i++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int main()
{
    int N;
    int X[200000];
    int Y[200000];

    scanf("%d", &N);

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &X[i]);
        Y[i] = X[i];
    }

    sort(X, X + N);

    for (int i = 0; i < N; i++)
    {
        if (Y[i] <= X[N/2 - 1])
            printf("%d\n", X[N/2]);
        else
            printf("%d\n", X[N/2 - 1]);
    }
}



Measured memory_bytes: 3712
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        if (a < b && b < c) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26152
import sys
sys.setrecursionlimit(10**7)

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

ans = []
def f(i, anum, alen, bnum, blen, cnum, clen):
    if i == n:
        if alen * blen * clen == 0:
            return
        mp = abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1)
        ans.append(mp)
    else:
        f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
        f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
        f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
        f(i+1, anum, alen, bnum, blen, cnum, clen)

f(0, 0, 0, 0, 0, 0, 0)

res = float('inf')
for i in ans:
    res = min(res, i)

print(res)

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

using namespace std;

#define ll long long 
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define SIZE 1005

int main()
{
	//IOS
	string ch;
	cin >> ch;
	int coun = 0;
	int len = ch.size();
	for(int i = 0; i < len/2; i++)
	{
		if(ch[i] != ch[len-i-1]) coun++;
	}
	cout << coun << endl;
	return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    ABC = sorted(il())
    print(ABC[0] + ABC[1] + ABC[2] * 10)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10208
#include <stdio.h>

int main(int argc, char argv[]){
    int input1 = 0;
    int cake = 0;
    int donut = 0;

    scanf("%d%d%d", &input1, &cake, &donut);

    int input2 = 0;

    input2 = input1 - cake;
    
    int input3 = 0;

    input3 = input2 % donut;

    printf("%d\n", input3);

    return 0;

}

Measured memory_bytes: 128
#include <stdio.h>

int bi_search(int *S, int val, int min, int max) {
  while (min < max) {
	int mid = (min + max) / 2;
	if (S[mid] == val)
	  return 1;
	else if (val < S[mid])
	  max = mid;
	else
	  min = mid + 1;
  }
  return 0;
}

int main() {
  int n, q;
  scanf("%d", &n);
  int S[n];
  for (int i = 0; i < n; i++) {
	scanf("%d", S + i);
  }

  scanf("%d", &q);
  int T[q];
  int count = 0;
  for (int i = 0; i < q; i++) {
	scanf("%d", T + i);
  }

  for (int i = 0; i < q; i++) {
	if (bi_search(S, T[i], 0, n))
	  //if (bi_search(S, T[i], 0, n - 1))
	  count++;
  }

  printf("%d\n", count);
}



Measured memory_bytes: 2268
input_lines = gets.chop.split("").map(&:to_s)
input_lines2 = gets.chop.split("").map(&:to_s)

count = 0
for i in 0...input_lines.size
    if input_lines[i] == input_lines2[i]
        count = count + 1 
    end
end
puts count

Measured memory_bytes: 1788
// copied from https://atcoder.jp/contests/abc154/submissions/10014975
#include<bits/stdc++.h>

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

using namespace std;

int dp[101][4][2];
// dp[i][j][k]
// i個までの桁を見ている時
// j個の非ゼロを使い
// k:0なら今の所Nと一致
// k:1ならすでにN以下が確定している

int main(){
  string s;cin>>s;
  int n=s.size();
  int K;cin>>K;
  dp[0][0][0]=1;
  rep(i,n)rep(j, 4)rep(k, 2){
    int nd = s[i]-'0';
    rep(d, 10){
      int ni = i+1, nj=j, nk=k;
      // 非ゼロなら次の遷移先のjの値を増やす
      if(d != 0) nj++;
      // 今の時点で使用済み非ゼロがK個よりも多ければ遷移しない
      if(nj > K )continue;
      // k==0:今の所nと一致している時
      if(k==0){
        // ループ中の桁がnの今着目している桁よりも大きければ、Nより大きくなるのは確定なのでノー遷移
        if(d>nd)continue;
        // ループ中の桁がnの今着目している桁よりも小さいなら、Nより小さくなるのは確定なのでkの値を1にして遷移させる
        if(d<nd)nk=1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  int result = dp[n][K][0] + dp[n][K][1];
  cout<<result;

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
  p,y=map(int,input().split())
  a[i]=[p,y,i]
a.sort()
p=a[0][0]
y=1
for i in range(m):
  if a[i][0]==p:
    a[i][1]=y
    y+=1
  else:
    p=a[i][0]
    y=1
    a[i][1]=y
    y+=1
a.sort(key=lambda x: x[2])
for i,j,k in a:
  print(str(i).zfill(6)+str(j).zfill(6))

Measured memory_bytes: 25396
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

static const double eps = 10e-6;

class intersect_triangle{
private:
	double dst[3];
	double orig[3], dir[3];
	double vert0[3],vert1[3],vert2[3];

	double dot(double v1[3],double v2[3]){
		return v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
	}
	void cross(double dest[3],double v1[3],double v2[3]){
		dest[0] = v1[1]*v2[2]-v1[2]*v2[1];
		dest[1] = v1[2]*v2[0]-v1[0]*v2[2];
		dest[2] = v1[0]*v2[1]-v1[1]*v2[0];
	}

	void sub(double dest[3],double v1[3], double v2[3]){
		dest[0] = v1[0]-v2[0];
		dest[1] = v1[1]-v2[1];
		dest[2] = v1[2]-v2[2];
	}
public:
	intersect_triangle(double xp1,double yp1,double xp2,double yp2,double xp3,double yp3,
		double xk,double yk){
		vert0[0] = xp1;
		vert0[1] = yp1;
		vert0[2] = 0;

		vert1[0] = xp2;
		vert1[1] = yp2;
		vert1[2] = 0;

		vert2[0] = xp3;
		vert2[1] = yp3;
		vert2[2] = 0;

		orig[0] = xk;
		orig[1] = yk;
		orig[2] = -1;

		dst[0] = xk;
		dst[1] = yk;
		dst[2] = 1;

		double len = sqrt(pow(dst[0]-orig[0],2.0)+pow(dst[1]-orig[1],2.0)+pow(dst[2]-orig[2],2.0));
		dir[0] = (dst[0]-orig[0])/len;
		dir[1] = (dst[1]-orig[1])/len;
		dir[2] = (dst[2]-orig[2])/len;
	}

	bool is_intersect(){
		double edge1[3],edge2[3],tvec[3],pvec[3],qvec[3];
		double det,inv_det,t=0,v=0,u=0;

		sub(edge1,vert1,vert0);
		sub(edge2,vert2,vert0);

		cross(pvec,dir,edge2);

		det=dot(edge1,pvec);

		if(det > -eps && det < eps) return false;

		inv_det = 1.0/det;

		sub(tvec,orig,vert0);

		u=dot(tvec,pvec)*inv_det;
		if(u < 0.0 || u > 1.0) return false;

		cross(qvec,tvec,edge1);

		v=dot(dir,qvec) * inv_det;
		if(v < 0.0 || u+v > 1.0) return false;

		t = dot(edge2,qvec) * inv_det;

		return true;

	}
};

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

	for(int i=0;i<n;i++){
		double xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
			&xp1,&yp1,&xp2,&yp2,&xp3,&yp3,&xk,&yk,&xs,&ys);
		intersect_triangle inter_t1(xp1,yp1,xp2,yp2,xp3,yp3,xk,yk);
		intersect_triangle inter_t2(xp1,yp1,xp2,yp2,xp3,yp3,xs,ys);
		printf("%s\n",(inter_t1.is_intersect() && inter_t2.is_intersect()) 
			|| (!inter_t1.is_intersect() && !inter_t2.is_intersect())
			? "NG" : "OK");
	}
}

Measured memory_bytes: 0
n = gets.to_i
price = [600,800,1000,1200,1400,1600]
until n == 0
all_cost = 0
n.times do
    x = gets.split(" ").map{|k| k.to_i }
    size = x[0] + x[1] + x[2]
    weight = x[3]
    cost1 = 0
    cost2 = 0
    qq = 0
    if size <= 60
        cost1 = price[0]
    elsif size <= 80
        cost1 = price[1]
    elsif size <= 100
        cost1 = price[2]
    elsif size <= 120
        cost1 = price[3]
    elsif size <= 140
        cost1 = price[4]
    elsif size <= 160
        cost1 = price[5]
    elsif size > 160
        qq = 1
    end

    if weight <= 2
        cost2 = price[0]
    elsif weight <= 5
        cost2 = price[1]
    elsif weight <= 10
        cost2 = price[2]
    elsif weight <= 15
        cost2 = price[3]
    elsif weight <= 20
        cost2 = price[4]
    elsif weight <= 25
        cost2 = price[5]
    elsif weight > 25
        qq = 1
    end
    if qq == 1
        all_cost += 0
    else
        if cost1 <= cost2
            all_cost += cost2
        else
            all_cost += cost1
        end
    end

end
puts all_cost
n = gets.to_i
end


Measured memory_bytes: 7040
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
typedef unsigned long long int ulli;

int main() {
    int n;
    cin >> n;
    ulli res = 0;
    ulli resa[9][9];
    for (int j = 0; j < 9; j++) {
        for (int k = 0; k < 9; k++) {
            resa[j][k] = 0;
        }
    }
    for (int i = 1; i < n + 1; i++) {
        string si = to_string(i);
        int sil = si.length();
        int j = si[0] - '1';
        int k = si[sil - 1] - '1';
        if (k == -1)continue;
        resa[j][k]++;
    }
    for (int j = 0; j < 9; j++) {
        for (int k = 0; k < 9; k++) {
            if (resa[j][k] == 0) {
                continue;
            }
            res += (resa[j][k]) * (resa[k][j]);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3756
#112_C
N=int(input())
pyramid=[]
for i in range(N):
    x,y,h=map(int,input().split())
    pyramid.append((x,y,h))
pyramid=sorted(pyramid,key=lambda x:x[2])[::-1]

Ans=[]
#全探索
for cx in range(0,101):
    for cy in range(0,101):
        flg=True
        H=pyramid[0][2]+abs(cx-pyramid[0][0])+abs(cy-pyramid[0][1])
        for i in range(1,N):
            h=max(H-abs(cx-pyramid[i][0])-abs(cy-pyramid[i][1]),0)
            if h!=pyramid[i][2]:
                flg=False
        if flg:
            Ans=[cx,cy,H]
            break
print(*Ans)

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

static const int N = 100;

int main() {
  int n, p[N+1], m[N+1][N+1];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i-1] >> p[i];
  }

  // 同じindex、つまり行列1個の場合はコスト0
  for (int i = 1; i <= n; i++) m[i][i] = 0;
  // 計算する行列積の長さでループ
  for (int l = 2; l <= n; l++) {
    // 計算し始める行列の始点をずらす
    for (int i = 1; i <= n -l + 1; i++ ) {
      int j = i + l - 1;
      // 1 の 21bit左シフト。要するにinfty
      m[i][j] = (1 << 21);
      for (int k = i; k <= j - 1; k++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}




Measured memory_bytes: 3160
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
          String str = br.readLine();

          if(str.equals("ABC")){
            System.out.println("ARC");
          }else if(str.equals("ARC")){
            System.out.println("ABC");
          }

      }
    }
}

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

int main() {
  int N,n;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;++i){
    cin >> S[i];
  }

  int i,j;
  int c;
  i = 0;
  j = 1;
  c = 0;
  sort(S.begin(),S.end());
  //for(int i=0;i<N;++i) cout<<S[i]<<endl;
  while(true){
    while(S[i]==S[j]){
      c++;
      j++;
    }
    if(j>=N) break;
    i = j;
    j = i+1;
  }
  
  cout<<N-c<<endl;
      
}

Measured memory_bytes: 9556
n, m = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(m))

for i in range(10**n):
  k = str(i)
  if len(str(i)) == n:
    if all(str(i)[s-1] == str(c) for s, c in sc):
      print(i)
      exit()
print(-1)

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

int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<ll> AC(N, K-Q );
  REP(i,Q) {
    int ain;
    cin >> ain;
    ain--;
    AC[ain]++;
  }
  REP(i,N) {
    if ( AC[i] > 0 ) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l



int main() {

	int h, w, H, W;
	cin >> H >> W >> h >> w;
	int ans = H * W - h * W - H * w + h * w;
	cout << ans << endl;


}

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

int longest_path(stack<int> &s, vector<vector<int>> &e, int start, int n);
void dfs(const vector<vector<int>> &e, int node, vector<bool> &visited, stack<int> &s) {
	visited[node] = true;
	for(auto n : e[node]) {
		if (visited[n]) continue;
		dfs(e, n, visited, s);
	}
	s.push(node);
}


int main() {
	int n,m;
	cin >> n >>m;
	int f, t;
	vector<vector<int>> e(n+1);
	
	for (int i = 0; i < m; i++) {
		cin >> f >> t;
		e[f].push_back(t);
	}
	
	stack<int> s;
	vector<bool> visited(n + 1, false);
	for (int i = 1; i <= n; i++) {
	    if (visited[i]) continue;
	    dfs(e, i, visited, s);
	}
	
	int maxi = -INF;
	//for (int i = 1; i <= n; i++) {
		//stack<int> ss(s);
		maxi = max(maxi, longest_path(s, e, 1,  n));
	//}
	cout << maxi << endl;
}

int longest_path(stack<int> &s, vector<vector<int>> &e, int start, int n) {
	vector<int> dist(n+1, 0);
	while(!s.empty()) {
		int u = s.top();
		s.pop();
		for(auto v : e[u]) {
			dist[v] = max(dist[v], dist[u] + 1);
		}
	}
	
    return *max_element(dist.begin(), dist.end());
}

Measured memory_bytes: 9984
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
 
#define INF 1e9
#define LINF 1e18
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
  int n;
  string s;
  cin >> n >> s;
  int res = 0;
  rep(i, 10){
    rep(j, 10){
      rep(k, 10){
        int sz = s.size();
        int a[3] = {i, j, k};
        int now = 0;
        rep(m, sz){
          if(s[m] - '0' == a[now])now++;
          if(now >= 3)break;
        }
        if(now == 3)res++;
      }
    }
  }
  cout << res << endl;
}
 

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

using namespace std;

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

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

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

    vector<int> c(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i];
    }

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

    for (int i = 0; i < n - 1; ++i) {
        if (a[i] + 1 == a[i + 1])
            ans += c[a[i]];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=5e5+10;
int p[maxn],a[maxn],d[maxn];
ll dp[maxn],sum[maxn];
int main(){
	int n=read();
	d[0]=read();
	REP(i,1,n){
		a[i]=read();
		d[i]=min(abs(d[i-1]-a[i]),d[i-1]);
	}
	dp[n+1]=1;
	DREP(i,n,1) if(a[i]==1){
		dp[i]=2;
		DREP(j,i-1,1){
			if(dp[j+1]*2<=a[j]) dp[j]=dp[j+1];
			else dp[j]=dp[j+1]+a[j];
		}
		break;
	}
	else dp[i]=1;
	int q=read();
	while(q--){
		int x=read();
		if(d[x-1]>=dp[x+1]) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 12160
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){
    vll SA(N+1, 0), SB(M+1, 0);
    REP(i, N) SA[i+1] = SA[i] + A[i];
    REP(i, M) SB[i+1] = SB[i] + B[i];
    ll ans = 0;
    REP(i, N+1){
        if(SA[i] > K) break;
        ll tmp = i;

        tmp += (upper_bound(ALL(SB), K - SA[i]) - SB.begin()) - 1;
        chmax(ans, tmp);
    }
    cout<<ans<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9252