akhauriyash/Code-Regression huggingface dataset:
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int main() {
    int N;
    ll A,B; cin >> N >> A >> B;
    vecl X(N);
    REP(i,N) cin >> X[i];
    ll ans = 0;
    if(B <= A) ans = B * (N-1);
    else {
        REP(i,N-1) {
            if((X[i+1]-X[i])*A >= B) ans += B;
            else ans += (X[i+1]-X[i])*A;
        }
    }
    cout << ans << endl;
}

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

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

def process(N,W):
  box=[0]*(W+1)
  for i in range(N):
    w,v=map(int,input().split())
    for j in range(W,0,-1):
      idx = j-w
      if idx<0:
        break
      else:
        box[j] = max(box[j],box[idx]+v)
  return box[-1]

print(process(N,W))


Measured memory_bytes: 39792
#include <bits/stdc++.h>
using namespace std;
int n;
int y;
int main()
{
    cin>>n>>y;
    for(long long i=0;i<=n;i++)
    {
        for(long long j=0;j<=n;j++)
        {
            if(i+j>n)continue;
            int z=n-i-j;
            long long x=i*10000,yy=j*5000,xx=z*1000;
            if((x+yy+xx)==y)
            {
                cout<<i<<" "<<j<<" "<<z;return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

LL nwd(LL a, LL b) { return b ? nwd(b, a%b) : a; }

int main()
{
	int T;
	scanf("%d", &T);
	REP(c, T)
	{
		LL A, B, C, D;
		scanf("%lld%lld%lld%lld", &A, &B, &C, &D);

		if (A < B || D < B)
		{
			printf("No\n");
			continue;
		}

		if (C >= B)
		{
			printf("Yes\n");
			continue;
		}

		if (A%B > C)
		{
			printf("No\n");
			continue;
		}

		C -= A%B;

		LL mx = B - A%B;

		LL d = nwd(B, D);
		B /= d;
		D /= d;

		LL ile1 = C / d + 1, ile2 = mx / d - (mx%d == 0 ? 1 : 0);

		if (ile1 <= ile2 && ile1 < B)
			printf("No\n");
		else
			printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 256
//

fun main() {
    aising2020a()
}

fun aising2020a() {
    val (l, r, d) = readLine()!!.split(" ").map {it.toInt()}
    var count = 0
    var k = 1
    while (k * d <= r) {
        if (k * d in l..r) count++
        k++
    }
    println(count)
}


Measured memory_bytes: 36384
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


a, b = MI()
if a + b == 15:
    print('+')
elif a * b == 15:
    print('*')
else:
    print('x')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    int N;
    cin >> N;
    vint P(N);
    vint S;
    REP(i,N){
        cin >> P[i];
        P[i]--;
    }
    int cnt = 0;
    if(P[0] == 0){
        swap(P[0],P[1]);
        cnt++;
    }
    for(int i=1; i<N-1; i++){
        if(P[i] == i){
            if(P[i+1] != i){
                swap(P[i],P[i+1]);
            }else{
                swap(P[i],P[i-1]);
            }
            cnt++;
        }
    }
    if(P[N-1] == N-1){
        swap(P[N-2],P[N-1]);
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3756
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <functional>
#include <string>
#include <iostream>
#include <cctype>
#include <set>
#include <climits>
#include <iomanip>
#include <cassert>

//#include <bits/stdc++.h>

using namespace std;





int main()
{
    float t,x;
    cin >> t >> x;
    cout << t / x << endl;

    return 0;
}



Measured memory_bytes: 256
/*  
    And solitare's the only game in town
    And every road that takes him
    Takes him down
    And by himself it's easy to pretend
    He'll never love again
    _________________________
    _________________________
    984 Hours of Solitude
    Quarantine_Day : 41
*/

#include<bits/stdc++.h>

using namespace std;

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

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<ll>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 200005

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

    int n; cin>>n;
    string s; cin>>s;

    int ans = INT_MIN;

    REP(i, s.size() - 1){
        string a = s.substr(0, i + 1);
        string b = s.substr(i + 1);

        int cnt = 0;
        for(char c = 'a'; c <= 'z'; c++){
            int f1 = (int) a.find(c);
            int f2 = (int) b.find(c);

            if(f1 != -1 && f2 != -1) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 1003;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

char c[10][N];

int r[10][N], x[10];

void solve(){
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> c[i][j];
            c[i][j] -= '0';
        }
    }
    int ans = inf;
    for (int mask = 0; mask < (1 << (n-1)); mask++){
        vector<int> v;
        for (int i = 0; i < n-1; i++){
            if (mask & (1 << i)) v.pb(i);
        }
        int cur = sz(v);
        memset(r, 0, sizeof r);
        v.pb(n-1);
        bool ok = 1;
        for (int i = 0, l = 0; i < n && ok; i++){
            if (v[l] < i)l++;
            for (int j = 0; j < m; j++){
                r[l][j]+= c[i][j];
                if (r[l][j] > k){
                    ok = 0;
                    break;
                }
            }
        }

        if (!ok) continue;

        memset(x, 0, sizeof x);
        for (int j = 0; j < m; j++){
            for (int i = 0; i < sz(v); i++){
                if (x[i] + r[i][j] > k){
                    cur++;
                    memset(x, 0, sizeof x);
                    break;
                }
            }
            for (int i = 0; i < sz(v); i++){
                x[i] += r[i][j];
            }
        }
        ans = min(ans, cur);
    }
    cout << ans;
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    for (int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#define V 300
#define INF 100000000
using namespace std;
typedef pair<int,int> P;

struct edge{
	int to,cap,cost,rev;
};

vector<edge> e[V];
int h[V];
int d[V];
int prv[V];
int pre[V];

int min(int a,int b){return a<b?a:b;}

void add_edge(int from,int to,int cap,int cost){
	e[from].push_back((edge){to,cap,cost,e[to].size()});
	e[to].push_back((edge){from,0,-cost,e[from].size()-1});
}

int mincost(int n,int s,int t,int f){
	int i;
	int res=0;
	for(i=0;i<n;i++)h[i]=0;
	while(f>0){
		priority_queue<P, vector<P>, greater<P> > que;
		for(i=0;i<n;i++)d[i]=INF;
		d[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();que.pop();
			int v=p.second;
			if(d[v]<p.first)continue;
			for(i=0;i<e[v].size();i++){
				edge &g=e[v][i];
				int u=g.to;
				if(g.cap>0&&d[u]>d[v]+g.cost+h[v]-h[u]){
					d[u]=d[v]+g.cost+h[v]-h[u];
					prv[u]=v;
					pre[u]=i;
					que.push(P(d[u],u));
				}
			}
		}
		if(d[t]==INF)return -1;
		for(i=0;i<n;i++)h[i]+=d[i];
		int q=f;
		for(i=t;i!=s;i=prv[i])q=min(q,e[prv[i]][pre[i]].cap);
		f-=q;
		res+=q*h[t];
		for(i=t;i!=s;i=prv[i]){
			edge &g=e[prv[i]][pre[i]];
			g.cap-=q;
			e[i][g.rev].cap+=q;
		}
	}
	return res;
}

int a[100][100];
int b[100][100];
char f[100][100];
vector<P> ans;

int main(){
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&b[i][j]);
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf(" %c",&f[i][j]);
	//0
	//1...n
	//n+1...n*2
	//n*2+1
	for(i=0;i<n;i++){
		int s=0;
		for(j=0;j<n;j++)if(f[i][j]=='o')s+=b[i][j];
		for(j=0;j<n;j++){
			if(f[i][j]=='o')add_edge(i+1,n+j+1,1,s-b[i][j]);
			else add_edge(i+1,n+j+1,1,s+a[i][j]);
		}
	}
	for(i=0;i<n;i++){
		add_edge(0,i+1,1,0);
		add_edge(n+i+1,n*2+1,1,0);
	}
	printf("%d\n",mincost(n*2+2,0,n*2+1,n));
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)if(e[i+1][j].cap==0){
			if(f[i][j]=='o')f[i][j]='+';
			else ans.push_back(P(i,j));
		}
	}
	for(i=0;i<n;i++)for(j=0;j<n;j++)if(f[i][j]=='o')ans.push_back(P(i,j));
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		int x=ans[i].first;
		int y=ans[i].second;
		if(f[x][y]=='o')printf("%d %d erase\n",x+1,y+1);
		if(f[x][y]=='.')printf("%d %d write\n",x+1,y+1);
	}
	return 0;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}


int main(){
//	in_o();
	int64 n;
	cin>>n;
	cout<<n*(n-1)/2;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        long a = sc.nextLong();
        int res = (int) a;
        for (int i = 0; i <= a; i++) {
            int cc = 0;
            int t = i;
            while (t > 0) {
                cc += t % 6;
                t = t / 6;
            }
            t = (int) a - i;
            while (t > 0) {
                cc += t % 9;
                t = t / 9;
            }
            if (res > cc) {
                res = cc;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int l , r , d;
  cin >> l >> r >> d;
  int count = 0;
  for (int i = l; i < r+1; i++) {
  if (i % d == 0){
    count++;
   }
  }
    
    cout << count << endl;
   }

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int m[101][101];
int xyh[100][3];

int main(void){
    int n; cin >> n;
    for(int i = 0;i < 101;i++)for(int j = 0;j < 101;j++)m[i][j] = INF;
    for(int i = 0;i < n;i++){
        int x, y, h; cin >> x >> y >> h;
        for(int i = 0;i < 101;i++)for(int j = 0;j < 101;j++){
            m[i][j] = min(m[i][j], h + abs(i - x) + abs(j - y));
        }
        xyh[i][0] = x;
        xyh[i][1] = y;
        xyh[i][2] = h;
    }
    for(int i = 0;i < 101;i++)for(int j = 0;j < 101;j++){
        for(int k = 0;k < n;k++){
            if(xyh[k][2] == 0){
                if(m[i][j] > abs(i - xyh[k][0]) + abs(j - xyh[k][1]))m[i][j] = 0;
            }else{
                if(m[i][j] != abs(i - xyh[k][0]) + abs(j - xyh[k][1]) + xyh[k][2])m[i][j] = 0;
            }
        }
    }
    int ax, ay, ah = 0;
    for(int i = 0;i < 101;i++)for(int j = 0;j < 101;j++){
        if(m[i][j] > ah){
            ah = m[i][j];
            ax = i;
            ay = j;
        }
    }
    printf("%d %d %d\n", ax, ay, ah);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(void){
    int a, b, c;
    std::cin >> a >> b >> c;
    int cnt = 0;
    if(a == b) cnt++;
    if(a == c) cnt++;
    if(b == c) cnt++;
    if(cnt == 1) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}



Measured memory_bytes: 3604
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i;
	int a[10000];
	long long sum;
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		sum=0;
		for(i=0;i<n-1;i++)	{
			sum=sum+a[i]*(n-1-i);
		}
		printf("%lld\n",sum);
	}
	return 0;
}


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

int main(){
int W,H;
cin>>W>>H;

int x,y,r;
cin>>x>>y>>r;

if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;

return 0;

}


Measured memory_bytes: 3100
n = int(input())
nums = list(map(int, input().split(" ")))
res = 0
even = all(num % 2 == 0 for num in nums)
while even is True:
	nums = [num//2 for num in nums] 
	res = res + 1
	even = all(num % 2 == 0 for num in nums)
print(res)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef long long int ll;

const long long int MOD = 26;

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

	char s[50];
	int cnt = 0;
	while (n > 0)
	{
		n--;
		ll r = n % MOD;
		s[cnt] = 'a' + r;
		// printf("%c\n", 'a' + r);
		n /= MOD;
		cnt++;
	}

	for (int i = cnt - 1; i >= 0; i--)
	{
		printf("%c", s[i]);
	}

	return 0;
}

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

using namespace std;

string s, t;

int main() {
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k) cout << k << endl;
    else if (k <= b) cout << a << endl;
    else cout << a - k + b + a << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    char c;
    cin>>c;
    if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o')
        cout<<"vowel"<<endl;
    else cout<<"consonant"<<endl;
    return 0;
}


Measured memory_bytes: 3600
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var D, N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &D, &N)

	ans := power(100, D)
	for i := 1; i < N; i++ {
		ans = next(ans, D)
	}
	fmt.Println(ans)
}

func next(n, D int) int {
	ret := n + power(100, D)
	if ret%power(100, D+1) == 0 {
		ret = ret + power(100, D)
	}
	return ret
}

func power(a, pow int) int {
	if pow == 0 {
		return 1
	} else if pow == 1 {
		return a
	} else if pow%2 == 0 {
		rt := power(a, pow/2)
		return rt * rt //% MOD
	} else {
		return a * power(a, pow-1) //% MOD
	}
}


Measured memory_bytes: 640
#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>;
const int INF = 1000000007;

int main() {
  int x;
  cin >> x;
  int now = 0;
  int res = 0;
  while (now != 360) {
    now %= 360;
    now += x;
    res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int a,b,x;
  cin >> a >> b;
  x = a + b;
  cout << (x * (x - 1) / 2) - (a * b) << endl;
  return 0;
}


Measured memory_bytes: 3596
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
key = 1


def lcm(a, b):
    return a * b // gcd(a, b)


for a in A:
    key = lcm(key, a)
key -= 1
ans = 0
for a in A:
    ans += key % a
print(ans)


Measured memory_bytes: 5984
N=int(input())
L=[0 for i in range(N+1)]

for i in range(1,N+1):
    for j in range(1,N+1):
        if i*j<=N:
            L[i*j]+=1
cnt=0
for i in range(N+1):
    if i%2!=0 and L[i]==8:
        cnt+=1
print(cnt)
#print(L)

Measured memory_bytes: 64272
s = int(input())
def f(n):
  if n%2:
    return 3*n+1
  else:
    return n/2
L = []
for m in range(1000000):
  if sum(x == s for x in L):
    print(m+1)
    break
  else:
    L.append(s)
    s = f(s)

Measured memory_bytes: 2940
local min=math.min
N=io.read"*n"
M=io.read"*n"

if(N%2==1)then
	for i=1,M do
		print(i,N-i)
	end
else
	if(N%4==2)then
		a=(N-2)/4
		for i=1,min(a,M) do
			print(i,a+a+2-i)
		end
		if(M<=a)then return end
		M=M-a
		for i=1,min(a,M) do
			print(a+a+1+i,a*4+2-i)
		end
	else
		a=N/4
		for i=1,min(a-1,M) do
			print(i,a+a-i)
		end
		if(M<=a-1)then return end
		M=M-a+1
		for i=1,min(a,M) do
			print(a+a-1+i,a*4-i)
		end
	end
end

Measured memory_bytes: 2760
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n,m;
	ll k;
	cin>>n>>m>>k;
	vector<ll> a(n),b(m),p1(n),p2(m);

	for (int i = 0; i < n; i++){
		cin>>a[i];
		if(i == 0) p1[i]= a[i];
		else p1[i] = p1[i-1] + a[i];
	}
	for (int i = 0; i < m; i++){
		cin>>b[i];
		if(i == 0 ) p2[i] = b[i];
		else p2[i] = p2[i-1] + b[i];
	}
	
	int ans = 0;
	for (int i = 0; i < p1.size(); i++){
		if(k-p1[i] < 0) break;
		auto ct = upper_bound(p2.begin(),p2.end(),k -p1[i]);
		if(ct == p2.end()) ans = max(ans,i + m + 1);
		else{
  			int x = ct - p2.begin();
  			ans = max(ans, i + x + 1);
  		}
	}
	auto ct = upper_bound(p2.begin(),p2.end(),k );
	if(ct == p2.end()) ans = max(ans , m);
	else{
		int x = ct - p2.begin();
		ans = max(ans, x);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9532
#include "bits/stdc++.h"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i,a,n) for(i=a;i<n;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

void pre(int* ar,int n,string st){
	int i,cnt = 0;
	ar[0] = cnt;
	For(i,0,n-1){
		string demo = string(st.begin()+i,st.begin()+i+2);
		if(demo == "AC") cnt++;
		//cout<<demo el;
		ar[i+1] = cnt;
	}
	return;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif*/
    int n,q,i;
    string st;
    cin>>n>>q>>st;
    int ar[n];
    pre(ar,n,st);
    //for(int t: ar) cout<<t sp;
    //cout el;
    For(i,0,q){
    	int l,r;
    	cin>>l>>r;
    	r-= 1; l-= 1;
    	//cout<<l sp<< r <<": ";
    	cout<<ar[r] - ar[l] el;
    }
    return 0;
}


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

int main() {
	long long n,m,i,j,i2,j2,jud;
	cin >> n >> m;
	vector<string> a(n),b(m);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	for(i2=0; i2<m; i2++){
		cin >> b[i2];
	}
	for(i=0; i<=n-m; i++){
		for(j=0; j<=n-m; j++){
			jud=0;
			for(i2=0; i2<m && jud==0; i2++){
				for(j2=0; j2<m && jud==0; j2++){
					if(a[i+i2][j+j2]!=b[i2][j2]){
						jud++;
					}
				}
			}
			if(jud==0){
				cout << "Yes"; return 0;
			}
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
M,D = map(int, input().split())
ans = 0
for m in range(1,M+1):
    for d in range(22, D+1):
        d10 = int(str(d)[1])
        d1 = int(str(d)[0])
        if m == d10 * d1 and d10>=2 and d1 >= 2:
            ans += 1
#             print(m, d)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 100000
#define MOD (1.0e9 + 7)

using namespace std;

int main(void)
{
    int n;
    vector<int> p;

    cin>>n;
    for(int i = 1;i <= n;i++)
    {
	int temp;
	cin>>temp;

	p.push_back(temp);
    }

    int counter = 0;
    if(p[0] == 1)
    {
	int temp = p[0];
	p[0] = p[1];
	p[1] = temp;
	counter++;
    }
    if(p[n-1] == n)
    {
	int temp = p[n-1];
	p[n-1] = p[n-2];
	p[n-2] = temp;
	counter++;
    }

    for(int i = 1;i < n-1;i++)
    {
	int index = i+1;
	if(index == p[i])
	{
	    counter++;
	    int temp = p[i];
	    p[i] = p[i+1];
	    p[i+1] = temp;
	}
    }

    cout<<counter<<endl;

    return 0;
}



Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x+r<=H){
        if(y+r<=H){
            if(x-r>=0){
                if(y-r>=0){
                    cout<<"Yes"<<endl;
                }else{
                    cout<<"No"<<endl;
                }
            }else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int32_t main(){
  int32_t n,w; cin>>n>>w;
  vector<int32_t> value(n+1), weight(n+1);
  for(int32_t i=1; i<n+1; ++i) cin>>value[i]>>weight[i];
  vector<vector<int32_t>> dp(n+1,vector<int32_t>(w+1));
  // i=0
  for(int32_t j=0; j<w+1; ++j) dp[0][j]=0;
  for(int32_t i=1; i<n+1; ++i){
    for(int32_t j=0; j<w+1; ++j){
      dp[i][j]=dp[i-1][j];
      if((j-weight[i])>=0) dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
    }
  }
  cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 6824
import math
li = list(map(int,input().split()))
pi = math.pi
a = li[0]
b = li[1]
H_th = li[2] * 30 + li[3]/2
M_th = li[3] * 6
diff = abs(H_th-M_th)
c = a**2 + b**2 -2*a*b*math.cos(diff/180*pi)
print(c**0.5)

Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

bool search(ll n,ll d[],ll k){
    while(n!=0){
        int m = n%10;
        REP(i,k){
            if(d[i]==m)return false;
        }
        n/=10;
    }
    return true;
}

int main(){
    ll N,K;
    ll d[10];
    scanf("%lld %lld\n",&N,&K);
    REP(i,K)scanf("%lld ",&d[i]);

    while(!search(N,d,K)){
        N++;
    }
    printf("%d\n",N);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int m=n;
    while(n)
    {
        sum+=n%10;
        n=n/10;
    }
    if(m%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int a[100005];
	scanf("%d",&n);
		for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int cnt=0,maxx=0;
	for(int i=n-1;i>=1;i--){
		if(a[i]<=a[i-1]) cnt++;
		else{
			maxx=max(cnt,maxx);
			cnt=0;
		}
	}
	maxx=max(maxx,cnt);
	printf("%d",maxx);
	
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int n;
string s;

int imos[300010];

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

    cin >> n >> s;
    
    REP(i, n) {
        imos[i + 1] = imos[i];
        if (s[i] == 'W') {
            imos[i + 1]++;
        }
    }

    int ans = INF;

    REP(i, n) {
        int sum = 0;
        sum += imos[i];
        sum += (n - i - 1) - (imos[n] - imos[i + 1]);
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1812
from itertools import accumulate


def main():
    n, c = map(int, input().split())
    p = [[] for _ in range(c + 1)]
    for _ in range(n):
        *st, cc = map(int, input().split())
        p[cc].append(st)
    all_p = [0] * (10 ** 5 + 10)
    for pp in p:
        if len(pp) == 0:
            continue
        pp.sort()
        last_start, last_end = pp[0]
        for start, end in pp[1:]:
            if start == last_end:
                last_end = end
            else:
                all_p[last_start - 1] += 1
                all_p[last_end] -= 1
                last_start, last_end = start, end
        all_p[last_start - 1] += 1
        all_p[last_end] -= 1
    print(max(accumulate(all_p)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 28608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/900 < b.F.F/900)
		return 1;
	if(a.F.F/900 > b.F.F/900)
		return 0;
	if(a.F.S <= b.F.S)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 450;

ll a[N], b[N];
int inda[N], indb[N];
pli c[N];

void solve()
{
	int n, i, j, cc;
	ll ans = INFLL, val = 0, x;
	bool flag = 1;
	cin >> n;
	fo(i,1,n+1)
	{
		cin >> a[i] >> b[i];
		c[i] = {a[i],i};
		c[i+n] = {b[i],i+n};
	}
	sort(c+1,c+n+n+1);
	fo(i,1,n+1)
	{
		val += c[i].F;
		if((c[1].S <= n) ? (c[i].S > n) : (c[i].S <= n))
			flag = 0;
	}
	if(flag)
	{
		cout << val << '\n';
		return;
	}
	fo(i,1,n+n+1)
	{
		if(c[i].S <= n)
			inda[c[i].S] = i;
		else
			indb[c[i].S-n] = i;
	}
	fo(i,1,n+1)
	{
		cc = 0;
		x = val;
		if(inda[i] > n)
		{
			x += a[i];
			cc++;
		}
		if(indb[i] > n)
		{
			x += b[i];
			cc++;
		}
		j = n;
		while(cc > 0)
		{
			if(c[j].S != i && c[j].S != i+n)
			{
				x -= c[j].F;
				cc--;
			}
			j--;
		}
		ans = min(ans, x);
	}
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	// clk = clock() - clk;
	// cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N,T;cin >> N >> T;
  vector<ll> v(N);
  rep(i,N)cin >> v[i];
  ll min = MAX_LL;
  ll max = 0;
  int num = 0;
  rep(i,N){
    if(v[i]<min)min = v[i];
    else{
      if(v[i]-min > max){
        max = v[i] - min;
        num = 1;
      }else if(v[i]-min == max) ++num;
    }
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	if (N >= 1000)
	{
		cout << "ABD" << endl;
	}
	else
	{
		cout << "ABC" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    string s, t; cin >> s >> t;
    rep(i, s.size()) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char s[5];
	while (cin >> s) {
		if (s[0] == s[1] && s[1] == s[2] || (s[1] == s[2] && s[2] == s[3]))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S=input()
l=len(S)
if S=='keyence':
    print('YES')
    exit()
for i in range(l):
    if i==0:
        for j in range(l-1):
            if S[j+1:]=='keyence':
                print('YES')
                exit()
    else:
        for j in range(i,l):
            if j==l-1:
                if S[:i]=='keyence':
                    print('YES')
                    exit()
            else:
                if S[:i]+S[j+1:]=='keyence':
                    print('YES')
                    exit()
print('NO')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
struct Edge{int to;int id;};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v,int parent_color=-1,int parent=-1){
  int now_color=1;
  for(auto t:g[v]){
    int next_v=t.to;
    int next_id=t.id;
    if(next_v==parent)continue;
    if(now_color==parent_color)now_color++;
    ans[next_id]=now_color;now_color++;
    dfs(next_v,ans[next_id],v);
  }
}
int main(){
  int n;
  cin>>n;
  g.resize(n);
  ans.resize(n-1);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    g[a].push_back(Edge{b,i});
    g[b].push_back(Edge{a,i});
  }
  dfs(0);
  int max_degree=0;
  for(int i=0;i<n;i++){
    max_degree=max(max_degree,int(g[i].size()));
  }
  cout<<max_degree<<endl;
  for(int i=0;i<n-1;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 8960
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
idx=-(-n//2)
ans=0
if n%2:
    for i in range(idx):
        if i==0 or i==idx-1:
            ans+=a[i]
        else:
            ans+=2*a[i]
else:
    for i in range(idx):
        if i==0:
            ans+=a[i]
        else:
            ans+=2*a[i]
print(ans)

Measured memory_bytes: 31540
H, N = map(int, input().split())
lst = []
ctr = 0
ans = [float("inf") for _ in range(H + 1)]
ans[0] = 0

for _ in range(N):
	A, B = map(int, input().split())
	lst.append([A, B])
	lst.sort(key = lambda x : x[0])

for i in range(1, len(ans)):
	for j in range(N):
		ans[i] = min(ans[i], ans[i - min(i, lst[j][0])] + lst[j][1])
	# print(ans)
		
print(ans[-1])

Measured memory_bytes: 43372
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    int sum = 0;
    for (int i=0;i<n-1;++i) {
        for (int j=i+1;j<n;++j) {
            sum += d[i] * d[j];
        }   
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

int f[N];
struct edge{
	int x,nxt;
}e[N];
int h[N],tot;
int n;

void inse(int x,int y){
	e[++tot].x=y;
	e[tot].nxt=h[x];
	h[x]=tot;
}

int t[N],k;

void dfs(int x){
	for(int p=h[x];p;p=e[p].nxt)dfs(e[p].x);
	k=0;
	for(int p=h[x];p;p=e[p].nxt)t[++k]=f[e[p].x];
	sort(t+1,t+1+k);
	fo(i,1,k)f[x]=max(f[x],t[i]+k-i+1);
}

int main(){
	n=get();
	fo(i,2,n){
		int x=get();
		inse(x,i);
	}
	dfs(1);
	printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	string S,T;
	cin >> S >> T;
	cout << T+S << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
int main() {
	int n,x1,x2,y1,y2,z1,z2,w1,w2;
	while (~fscanf(stdin, "%d", &n),n!=0) {
		while (n--) {
			fscanf(stdin, "%d%d%d%d%d%d%d%d", &x1, &y1, &z1, &w1, &x2, &y2, &z2, &w2);
			fprintf(stdout, "%d %d %d %d\n", (x1*x2) - (y1*y2) -(z1*z2) -(w1*w2),
				(x1*y2) + (y1*x2) + (z1*w2) - (w1*z2),
				(x1*z2) - (y1*w2) + (z1*x2) + (w1*y2),
				(x1*w2) + (y1*z2) - (z1*y2) + (w1*x2));
		}
	}
		return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n;
	cin >> n;

	if(n == 1){
		cout << 1.0;
		return 0;
	}
	if(n % 2 == 0){
		cout << 0.5;
	}else{
		cout << ((double)(n / 2 + 1)/(double)(n));
	}


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x, n;
	cin >> x >> n;
	for(int i=0; i<=x; ++i){
		if(2*i+(x-i)*4 == n){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

int main() {
    int a,b,c;
    cin >> a >> b >> c;

    if(c >= a && c <= b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> A(N+1);
    for (int i=0;i<=N;i++) cin >> A[i];
    vector<ll> sum(N+2);
    for (int i=N;i>=0;i--){
        sum[i] = sum[i+1] + A[i];
    }
    vector<ll> Lmax(N+2);
    Lmax[0] = 1LL;
    for (int i=0;i<=N;i++){
        if (A[i] > Lmax[i]) {
            cout << -1 << "\n";
            return 0;
        } else {
            Lmax[i+1] = min(sum[i+1],(Lmax[i]-A[i])*2LL);
        }
    }
    
    ll ans = 0LL;
    for (int i=0;i<=N;i++){
        ans += Lmax[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    ll A,B;
    cin >> A >> B;
    ll outlet = 1,cnt = 0;
    while(outlet < B){
        cnt++;
        outlet -=1;
        outlet += A;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;

class Add_Segment_Tree {
	vector<long long int>v;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
public:
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		v.resize(num, 0);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		b++;
		for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1)ret += v[a++];
			if (b & 1)ret += v[--b];
		}
		return ret;
	}
};

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

	cin >> N;
	M = 0;
	Add_Segment_Tree asg(86400 * 2);
	for (int i = 0; i < N; i++) {
		cin >> K;
		M += K;
		M %= 86400;
		asg.Add(M, 1, false);
		asg.Add(M + 86400, 1, false);
		cin >> K;
		M += K;
	}
	asg.TopDown();
	long long int ans = 0;
	for (int i = 0; i <= 86400; i++) {
		ans = max(ans, asg.Sum(14400 + i, 25200 + i));
	}
	cout << ans << endl;
}

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

namespace ABC86_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str;
            int t, x, y, dx, dy, eo, teo;
            bool f = true;
            int[] current = new int[] { 0, 0 };
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split(' ');
                t = int.Parse(str[0]);
                x = int.Parse(str[1]);
                y = int.Parse(str[2]);
                dx = Math.Abs(x - current[0]);
                dy = Math.Abs(y - current[1]);
                if(dx + dy > t)
                {
                    f = false;
                }
                eo = (dx + dy) % 2;
                teo = t % 2;
                if(eo != teo)
                {
                    f = false;
                }
            }
            if (f)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 15292
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<string.h>
#include<bitset>
#include<set>
using namespace std;

struct S {
	int cost, x, y, o, xh;
	S(int c, int in_x, int in_y, int in_o, int in_xh) : cost(c), x(in_x), y(in_y), o(in_o), xh(in_xh){}
	bool operator<(const S &s) const { 
		if (cost != s.cost)
			return cost < s.cost;
		else
			return o < s.o;
	}
};

const int INF = -1000000000, INF2=10000000;
int w, h, f, m, o, ans;
int stratum[110][110];
int c[11][11][51];
priority_queue<S> pq;

void dijkstra(){
	int move[3] = { 1, -1, 1 };//?´y,?´x,?´x
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		if (a.o == 0) continue;
		if (a.y == h){
			if (-a.cost <= f)
				ans = -a.cost;
			break;
		}
		if (a.o == 1) continue;
		for (int i = 0; i < 3; i++){
			int x = a.x;
			int y = a.y;
			if (i)
				x += move[i];
			else
				 y += move[i];
			int xx = 1<<(w-x);
			xx = xx&a.xh;
			if (!xx || !i){
				if (x <= w && 0 < x&&y <= h){
					if (stratum[y][x] < 0){
						if (a.cost + stratum[y][x] >= -f&&a.cost + stratum[y][x] > c[y][x][a.o - 1]){
							c[y][x][a.o - 1] = a.cost + stratum[y][x];
							if (i)
								pq.push({ c[y][x][a.o - 1], x, y, a.o - 1, a.xh | 1 << (w-x) });
							else
								pq.push({ c[y][x][a.o - 1], x, y, a.o - 1, 1 << (w-x) });
						}
					}
					else if (stratum[y][x] >0){
						int hokyuuu;
						hokyuuu = stratum[y][x] + a.o - 1;
						if (hokyuuu + a.o - 1 >= m)
							hokyuuu = m;
						c[y][x][hokyuuu] = a.cost;
						if (i)
							pq.push({ c[y][x][hokyuuu], x, y, hokyuuu, a.xh | 1 << (w-x) });
						else
							pq.push({ c[y][x][hokyuuu], x, y, hokyuuu, 1 << (w-x) });
					}
					else{
						pq.push({ 0, x, y, o, a.xh | 1 << (w-x) });
					}
				}
			}
			else{
				if (a.cost > c[y][x][a.o - 1] && a.o - 1){
					c[y][x][a.o - 1] = a.cost;
					pq.push({ c[y][x][a.o - 1], x, y, a.o - 1, a.xh });
				}
			}
		}
	}
}


int main(){
	while (cin >> w >> h&&w&&h){
		cin >> f >> m >> o;
		memset(stratum, sizeof(stratum), 0);
		ans=INF2;
		for (int i = 1; i <= 10; i++)
			for (int j = 1; j <= 10; j++)
				fill(c[i][j], c[i][j] + 51, INF);
		while (!pq.empty())
			pq.pop();
		for (int i = 1; i <= h; i++)
			for (int j = 1; j <= w; j++)
				cin >> stratum[i][j];
		pq.push({ 0, 1, 0, o, 1<<(w-1) });
		dijkstra();
		if (ans!=INF2)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1272
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>


int main()
{
	int a, b;
	scanf("%d", &a);
	scanf("%d", &b);
	int c;
	c = a*b;
	int d;
	d = 2 * a + 2 * b;
	printf("%d ",c);
	printf("%d\n", d);

	return 0;
}

Measured memory_bytes: 1024