akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
using namespace std;

struct data{
	int s, t;
};

bool comp(data d1, data d2){
	return d1.s < d2.s;
}

int main(){
	int n;
	while(cin >> n && n){
		vector<data> qd1;
		priority_queue<int, vector<int>, greater<int> > qd2;
		for(int i = 0; i < n; i++){
			string s1, s2;
			cin >> s1 >> s2;
			data d;
			d.s = (s1[0]-'0')*36000 + (s1[1]-'0')*3600 + (s1[3]-'0')*600 + 
				(s1[4]-'0')*60 + (s1[6]-'0')*10 + (s1[7]-'0');
			d.t = (s2[0]-'0')*36000 + (s2[1]-'0')*3600 + (s2[3]-'0')*600 + 
				(s2[4]-'0')*60 + (s2[6]-'0')*10 + (s2[7]-'0');
			qd1.push_back(d);
		}
		sort(qd1.begin(), qd1.end(), comp);
		vector<data>::iterator iter = qd1.begin();
		while(iter != qd1.end()){
			data d = *iter;
			iter++;
			if(qd2.empty()){
				qd2.push(d.t);
			}else{
				int d2 = qd2.top();
				if(d2 <= d.s) qd2.pop();
				qd2.push(d.t);
			}
		}
		cout << qd2.size() << endl;
	}
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 1000000007
int main() {
	int n = ri();
	int64_t k;
	std::cin >> k;
	std::vector<std::vector<int> > mat(n, std::vector<int> (n));
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) mat[i][j] = ri();
	std::vector<int> res(n, 1);
	for (int64_t i = 1; i <= k; i <<= 1) {
		if (k & i) {
			std::vector<int> tmp(n);
			for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) {
				tmp[k] += (int64_t) res[j] * mat[j][k] % MOD;
				if (tmp[k] >= MOD) tmp[k] -= MOD;
			}
			std::swap(res, tmp);
		}
		std::vector<std::vector<int> > tmp(n, std::vector<int> (n));
		for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) for (int l = 0; l < n; l++) {
			tmp[j][l] += (int64_t) mat[j][k] * mat[k][l] % MOD;
			if (tmp[j][l] >= MOD) tmp[j][l] -= MOD;
		}
		std::swap(mat, tmp);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += res[i];
		if (ans >= MOD) ans -= MOD;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int dis;
int n;
queue<int> q;
void visit(int);
void searchQ(int);

int main(){
	dis=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1; //?????¢??¨?????¢??\
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1; //?????????????????????????????????????????????
		}
	}
	visit(0);
	for(i=0;i<n;i++) cout<< i+1 <<" "<<d[i]<<endl;
	return 0;
}

void visit(int a){
	q.push(a);
	d[a]=0;

	while(!q.empty()){
		int i=q.front();
		q.pop();
		searchQ(i);
		
	}
}

void searchQ(int a){//?????\????????¶?????????
	for(int i=0;i<n;i++){
		if(map[a][i]==1 && d[i]==-1){
			q.push(i);
			d[i]=d[a]+1;
		}
	}
}

Measured memory_bytes: 1240
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

typedef Point Vector;

class Circle {
    public:
    double r;
    Point c;

    Circle(double r = 0, Point c = Point()): r(r) {}
};

void print(Point p0, Point p1);

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    Circle k1, k2;
    Point p;
    Point cross0, cross1;
    cin >> p.x >> p.y;
    cin >> k2.c.x >> k2.c.y >> k2.r;

    double dist = ( p - k2.c ).abs();
    double r1 = sqrt( dist*dist - k2.r*k2.r );
    k1.c = p;
    k1.r = r1;

    if ( k1.r < k2.r ) {
        swap(k1.r, k2.r);
        swap(k1.c.x, k2.c.x);
        swap(k1.c.y, k2.c.y);
    }

    double d = ( k1.c - k2.c ).abs();
    
    if ( ( d == k1.r + k2.r ) || ( d == k1.r - k2.r ) ) {
        Vector v1 = k2.c - k1.c;
        v1 = v1 * k1.r / v1.abs();
        cross0 = k1.c + v1;
        print(cross0, cross0);
    }
    else {
        Vector v0 = k2.c - k1.c;
        v0 = v0 * ( k1.r*k1.r - k2.r*k2.r + d*d ) / (2*d) / v0.abs();
        Point x1 = k1.c + v0;
        Vector v1;
        v1.x = v0.y;
        v1.y = - v0.x;
        v1 = v1 * sqrt( k1.r*k1.r - v0.abs()*v0.abs() ) / v1.abs();
        cross0 = x1 + v1;
        cross1 = x1 - v1;
        print(cross0, cross1);
    }

    return 0;
}

void print(Point p0, Point p1) {
    double x0, y0, x1, y1;
    if ( p0.x < p1.x ) {
        x0 = p0.x;
        y0 = p0.y;
        x1 = p1.x;
        y1 = p1.y;
    }
    else if ( p0.x > p1.x ) {
        x0 = p1.x;
        y0 = p1.y;
        x1 = p0.x;
        y1 = p0.y;
    }
    else {
        if ( p0.y < p1.y ){
            x0 = p0.x;
            y0 = p0.y;
            x1 = p1.x;
            y1 = p1.y;
        }
        else{
            x0 = p1.x;
            y0 = p1.y;
            x1 = p0.x;
            y1 = p0.y;
        }
    }
    cout << fixed << setprecision(11) << x0 << " " << y0 << endl << x1 << " " << y1 << endl;
}


Measured memory_bytes: 3316
def d_flipping_signs_dp(N, A):
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 0
    dp[0][1] = -float('inf')
    for i in range(N):
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
    return dp[N][0]

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs_dp(N, A))

Measured memory_bytes: 25600
N,X = map(int, input().split())

A = list(map(int, input().split()))
cnt = 0

for i in range(N-1):
    temp = 0
    if A[i]+A[i+1] <= X:
        continue
    else:
        temp = A[i]+A[i+1]-X
        if A[i+1] < temp:
            A[i+1] = 0
            cnt += A[i+1]
            temp -= A[i+1]
        else:
            A[i+1] -= temp
            cnt += temp
            temp -= A[i+1]

        if A[i]+A[i+1] > X:
            A[i] -= temp
            cnt += temp

print(cnt)

Measured memory_bytes: 19916
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define cf ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define fox(i,j,n) for( i=j;i<n;i++)
#define srtar(a,n) sort(a,a+n)
#define srtvec(v) sort(v.begin(),v.end())
#define fauto(x,t) for(auto x: t)
#define mem(n,x) memset(n, x, sizeof(n))
const double pi=acos(-1);

int main()
{
    ll n, s=0, t, i ;
    cin >> n ;
    s=s+(n/500)*1000;
    n=n-(n/500)*500;
    s=s+(n/5)*5;
    cout << s;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cmath>
#include <deque>
#include <bitset>
#define ll long long
#define PI 3.1415926535897932384626433832795
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;
string S;


int coba(string x, char c){
	int r = 0;

	while(true){
		string tmp = "";
		int N = x.length();
		if (N == 0) break;
		bool ok = 1;
		for (int i=1;i<N;i++) 
			if (x[i] != x[i-1]) ok = 0;

		if (ok) break;
		for (int i=1;i<N;i++){
			if (x[i] == c || x[i-1] == c) tmp.push_back(c);
			else tmp.push_back(x[i]);
		}
		x = tmp;
		r++;
	}

	return r;
}

int main(){
   std::ios::sync_with_stdio(false); 
   cin>>S;
   int res = 9999;
   for (char c= 'a'; c <= 'z'; c++){
   		res = min(res,coba(S, c) );
   }
   cout<<res<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

bool compare(int h, int w, int hh, int ww) {  // h, w: Input   hh, ww: search
    int input_rect = h*h + w*w;
    int cmp_rect = hh*hh + ww*ww;

    if(input_rect < cmp_rect) {
        return true;
    }

    if(cmp_rect == input_rect && hh > h) {
        return true;
    }

    return false;
}


int main() {

    while(1) {
        int h, w;
        int ret_h = 151, ret_w = 151;

        cin >> h >> w;
        if(w == 0 && h == 0) {
            break;
        }

        for(int i = 1; i < 151; i++) {
            for(int j = i + 1; j < 151; j++) {
                if (compare(h, w, i, j)) {
                    if (compare(i, j, ret_h, ret_w)) {
                        ret_h = i;
                        ret_w = j;
                    }
                }
            }
        }

        cout << ret_h << " " << ret_w << "\n";
    }
    return 0;

}




Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main () {
	io_optimized
	int n,m,a;
	while(cin>>n>>m)
	{
		while(m--)
		{
			cin>>a;
			n-=a;
		}
		cout<<(n<=0?"Yes\n":"No\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b)
		printf("a < b\n");
	if(a>b)
		printf("a > b\n");
	if(a==b)
		printf("a == b\n");
	return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    string s;

    cin>>s;
    int n=s.size();
    int ans=INF;
    map<char,int> m;

    for(int i=0;i<n;i++){
        char c = s[i];
        if(m[c]<1){
            m[c]++;
         int count =0;
         int maxl=-1;
          rep(j,n){
          if(s[j]!=c){
              count++;
          }else{
              maxl =  max(maxl,count);
              count=0;
          }
         }

         maxl=max(maxl,count);
         if(maxl!=-1)ans=min(ans,maxl);
        }
    }



    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
#define pb push_back
#define int long long

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	string ans = "No";
	if (n%10 == 7) ans = "Yes\n";
	n /= 10;
	if (n%10 == 7) ans = "Yes\n";
	n /= 10;
	if (n%10 == 7) ans = "Yes\n";
	n /= 10;
	cout << ans << '\n';
}

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

typedef long long ll;

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

	vector<int> R;
	for(int i=10000; i<100000; i++){
		string s = to_string(i);
		string r = s;
		reverse(r.begin(),r.end());
		if(s==r) R.push_back(i);
	}
	int ans = 0;
	for(int u : R){
		if(u>=a && u<=b)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
T = readline() #println("Input: ",split(tmp))
N = parse(Int128, T)
#println("NUM: $N")
A=zeros(N)
B=zeros(N)
for i in 1:N
    A[i],B[i]= parse.(Int128,split(readline()))
end
#println(A,B)

#ma = med(A,B,N)

as = sort(A)
bs = sort(B)
if N % 2 != 0
    ma = bs[div(N+1,2)] - as[div(N+1,2)] + 1
else
    ma = (bs[div(N,2)] + bs[div(N,2)+1]) - (as[div(N,2)] + as[div(N,2)+1]) + 1
end
#println(as,bs)
#println("median min: $ma")
println(Int128(ma))

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int n,k;
    string s;

    cin >> n >> k >> s;

    int i=0,j=0,res=0;

    while(j<n){
        while(j<n && s[j]=='1')
            j++;
        res=max(res,j-i);
        while(j<n && s[j]=='0')
            j++;
        k--;
        if(k<0){
            while(i<n && s[i]=='1')
                i++;
            while(i<n && s[i]=='0')
                i++;
        }
        res=max(res,j-i);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	static int[] L = new int[2001];
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String str = br.readLine();
		
		int[] map = new int[1001];
		String[] word = str.split("\\s+");
		 L = new int[N];
		for(int i=0;i<N;i++){
			L[i] = Integer.parseInt(word[i]);
			map[L[i]]++;
		}
		Arrays.sort(L);
		
//		N*(N-1)*(N-2)/6;
// [b,a+b];有多少个值
	//	a+b  > c 肯定构成  三角
		
		int M = L[N-1]+L[N-1];
		List<Node> list = new ArrayList<Node>();
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				Node node = new Node(i, j);
				list.add(node);
			}
		}
		
		int res = 0;
		
		for(int i=0,size=list.size();i<size;i++){
			Node node = list.get(i);
			int sum = node.sum;
			int maxIndex = node.index2;
			
			for(int j=maxIndex+1;j<N;j++){
				if(   L[j] <  sum ){
					res ++;
				}
			}
		}
		System.out.println(res);
	}
/**
 * a+b 结果。。。。。。。。这么多个值V{index1,index2,a,b,sum};     {1,5,1,1,2} 
 * c<a+b的有sum中再从index2+1中到N搜索   
 */
		
		private static class Node {
			int index1;
			int index2;
			int a;
			int b;
			int sum;
			
			public Node(int index1,int index2){
				this.index1 = index1;
				this.index2 = index2;
				this.a = L[index1];
				this.b = L[index2];
				this.sum = this.a + this.b;
			}
		}
	
		
		
		
}

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

bool range_base (pair<long long, long long> i, pair<long long, long long>j) {
    return (i.first + i.second < j.first + j.second);
    }
int main(){
    int n;cin>>n;
    vector<pair<long long, long long>> robots(n);
    for(int i=0;i<n;i++){
        long long x, l;
        cin>>x>>l;
        robots[i] = make_pair(x, l);
    }
    sort(robots.begin(), robots.end(), range_base);
    long long acc = 0;
    pair<long long, long long> latest_robot = robots[0];
    acc++;
    if (n == 1){
        cout << acc << endl;
        return 0;
    }

    for (int i=1;i<n;i++){
        if (latest_robot.first + latest_robot.second <= robots[i].first - robots[i].second){
            acc++;
            latest_robot = robots[i];
        }
    }
    cout << acc << endl;
    return 0;

}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;


int main() {

	int n, m;

	cin >> n >> m;
	int s[5], c[5];

	for (int i = 0; i < m; i++) {
		cin >> s[i] >> c[i];
	}

	bool is_exist=true;

	for (int i =0 ; i < m; i++) {
		if (n != 1 && s[i] == 1 && c[i] == 0)is_exist = false;
	}
	for (int i = 0; i < m-1; i++) {
		for (int j = i + 1; j < m; j++) {
			if (s[i] == s[j]) {
				if (c[i] != c[j])is_exist = false;
			}
		}
	}

	if (is_exist) {

		if (n == 1) {
			int a1 = 0;
			for (int i = 0; i < m; i++) {
				a1 = c[i];
			}
			cout << a1 << endl;
		}
		else if (n == 2) {
			int a1 = 1;
			int a2 = 0;
			for (int i = 0; i < m; i++) {
				if (s[i] == 1)a1 = c[i];
				if (s[i] == 2)a2 = c[i];

			}

			cout << a1 * 10 + a2 << endl;

		}
		else {
			int a1 = 1;
			int a2 = 0;
			int a3 = 0;
			for (int i = 0; i < m; i++) {
				if (s[i] == 1)a1 = c[i];
				if (s[i] == 2)a2 = c[i];
				if (s[i] == 3)a3 = c[i];

			}
			cout << a1 * 100 + a2 * 10 + a3 << endl;
		}
	}
	else {
		cout << -1 << endl;
	}
	

	return 0;

}

Measured memory_bytes: 256
N, K = map(int, input().split())
V = list(map(int, input().split()))
M = min(N, K)
ans = 0
for p in range(M+1):
  for q in range(M-p+1):
    left = []
    right = []
    if p > 0:
      left = V[:p]
    if q > 0:
      right = V[-q:]
    have = sorted((left+right).copy())
    if len(have) > 0:
      for i in range(min(len(have),K-p-q+1)):
        if have[i] > 0:
          break
      ans = max(sum(have[i:]),ans)
print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a;
  cin >> a;
  if(a<105){
    cout <<0;
  }else if(a<135){
    cout <<1;
  }else if(a<165){
    cout <<2;
  }else if(a<189){
    cout <<3;
  }else if(a<195){
    cout <<4;
  }else{
    cout <<5;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>
#define FOR(arg, ini, end) for(int arg = ini; arg < end; arg++)


using namespace std;
int main(int argc, const char * argv[]) {
    
    string a[3];
    cin >> a[0] >> a[1] >> a[2];

    int i=0;
    int id[3] = {0, 0, 0};
    while( a[i].size() != id[i] ) {
        id[i]++;
        i = a[i][id[i]-1] - 'a';
    }

    string s="ABC";
    cout << s[i] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import math
N, M = map(int, input().split())

A = np.array(list(map(int, input().split())), np.int64)

cnt = 0
while True:
	num_E = np.count_nonzero(A % 2 == 0) 
	if 0 < num_E < N:
		print(0)
		sys.exit()
	elif num_E == 0:
		cnt -= 1
		break
	else:
		cnt += 1
		A //= 2

def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a%b)
lcm = A[0]
for i in range(1,N):
	tmp_gcd = gcd(lcm, A[i])
	lcm *= A[i]//tmp_gcd
	if lcm > M:
		print(0)
		sys.exit()
M = math.floor(M/(2**cnt))

ans = 1 + (M-lcm)//(2*lcm)
print(ans)

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 200001

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, d;
    cin >> n >> d;
    vvi pnt(n, vi(d));
    REP(i, 0, n)
        REP(j, 0, d)
            cin >> pnt[i][j];
    ll a = 0, s, x;
    REP(i, 0, n-1) {
        REP(j, i+1, n) {
            s = 0;
            REP(k, 0, d)
                s += (pnt[i][k] - pnt[j][k]) * (pnt[i][k] - pnt[j][k]);
            x = sqrt(s);
            if (x * x == s)
                a++;
        }
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    ll a,b,c,A,B,C;
    cin>>a>>b>>c>>A>>B;
    
    if(a+b>c+c){
        C=min(A,B);
        cout<<min(c*max(A,B)*2,c*C*2+max((A-C)*a,(B-C)*b))<<endl;
    }
    else cout<<a*A+b*B<<endl;

    return 0;
}


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

#define MAX 100

int main() {
  int n;
  int A[MAX];
  int tmp;
  int swap_num = 0;
  bool flag = true;

  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    if(n < 1 && n > 100) {
      printf("Error: out of range.");
        return -1;
    }
  }

  while(flag == true) {
    flag = false;
    for(int i = n - 1; i > 0; i--) {
      if(A[i] < A[i - 1]) {
        tmp = A[i];
        A[i] = A[i - 1];
        A[i - 1] = tmp;
        swap_num += 1;
        flag = true;
      }
    }
    /* printf("%d", A[0]); */
    /* for(int i = 1; i < n; i++) { */
    /*   printf(" %d", A[i]); */
    /* } */
    /* printf("\n"); */
  }

  printf("%d", A[0]);
  for(int i = 1; i < n; i++) {
    printf(" %d", A[i]);
  }
  printf("\n");
  printf("%d\n", swap_num);
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,t,q,x[100001],y[100001],p,z;
vector<int>v;
main(){
	cin>>n>>t>>q;
	v.push_back(-1e19);
	r(i,n){
		scanf("%lld%lld",&x[i],&y[i]);
		if(i&&y[i]!=y[i-1])v.push_back((x[i]+x[i-1])/2);
	}
	v.push_back(1e19);
	r(i,q){
		scanf("%lld",&p);p--;
		if(y[p]==1){
			z=*lower_bound(v.begin(),v.end(),x[p]);
			if(t+x[p]<z)cout<<t+x[p]<<endl;
			else cout<<z<<endl;
		}
		else{
			z=*(lower_bound(v.begin(),v.end(),x[p])-1);
			if(x[p]-t>z)cout<<x[p]-t<<endl;
			else cout<<z<<endl;
		}
	}
}

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

using namespace std;

#define io freopen("test.txt", "r", stdin);
#define fast ios_base::sync_with_stdio(0);cin.tie(0);


#define ull unsigned long long int
#define lli long long int
#define li long int
#define ld long double

#define cout(x) cout<<x<<" "
#define coutn(x) cout<<x<<endl
#define newline cout<<endl

#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define ar array

#define pii pair<int,int>
#define pll pair<lli,lli>
#define pps pair<pair<int,int>, string>

const int MOD=1000000007;
const lli INF=1e18;
const int MX=100001;
const int N=1000000;

int n;

void solve(){
    cin>>n;
    vector<int>v(n);

    for(int i=0;i<n;i++) cin>>v[i];

    int ans[N];

    ans[0]=0;
    for(int i=1;i<n;i++){
        int a=(i-1>=0)?ans[i-1]+abs(v[i]-v[i-1]):INT_MAX;
        int b=(i-2>=0)?ans[i-2]+abs(v[i]-v[i-2]):INT_MAX;
        ans[i]=min(a,b);
    }

    cout<<ans[n-1]<<"\n";
}

int main(){
    fast
    // #ifndef godzqa
    //     io
    // #endif

    lli t=1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 4040
#include<iostream>

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

    int i,ans=0;
    if(a*c<=b)
    {
        cout<<c<<endl;
    }
    else
    {
        for(i=1; i<=c; i++)
        {
            if(a*i<=b)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
istream& operator>>(istream& input, vector<int>& v) {
	for (int& i : v) input >> i;
	return input;
}
int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> A(N), B(N), C(N - 1);
	cin >> A >> B >> C;
	for (int i = 0; i < N; i++) {
		ans += B[A[i] - 1];
		if (i > 0 && A[i] == A[i - 1] + 1) ans += C[A[i - 1] - 1];
	}
	cout << ans << endl;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int d = max({a,b,c});
    int ans = a + b + c + d*9;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
def divisor(x):
    div = []
    for i in range(1,int(x**0.5)+1):
        if x%i == 0:
            div.append(i)
            if x != i**2: div.append(x//i)
    
    return div

MOD = 1000000000 + 7

n,k = map(int,input().split())

count = [0] * k

for i in range(k):
    count[i] = pow(k//(i+1),n,MOD)
    
for i in range(k,0,-1):
    for j in divisor(i):
        if j<i:
            count[j-1] -= count[i-1]
            count[j-1] %= MOD

ans = 0
for i in range(k):
    ans += (i+1)*count[i]
    ans %= MOD
    
print(ans)

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

int main( int argc, char *argv[] )
{
int a[ 10 ];

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

	cin >> a[ 0 ];
	cin >> a[ 1 ];
	cin >> a[ 2 ];
	sort( a, a + 3 );

	if( a[ 0 ] == 5 && a[ 1 ] == 5 && a[ 2 ] == 7 )
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.Bool (bool)

main :: IO ()
main = solve <$> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve [a, b, c, d] = bool "No" "Yes" $ f a d >= f c b
  where
    f x y = (x + y - 1) `div` y


Measured memory_bytes: 3888
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#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;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    ll a, b, x, y;
    cin >> a >> b >> x >> y;
    cout << db((a * b) / db(2)) << " " << ((!(a & 1) and x == a / 2) and (!(b & 1) and y == b / 2) ? 1 : 0) << "\n";
}


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

//League Match Score Sheet
public class Main{

	static class T implements Comparable<T>{
		int k;
		int s;
		String n;
		public T(int k, String n, int s) {
			this.k = k;
			this.s = s;
			this.n = n;
		}
		public int compareTo(T o) {
			return s==o.s?k-o.k:o.s-s;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean f = true;
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			if(!f)System.out.println();
			f = false;
			PriorityQueue<T> q = new PriorityQueue<T>();
			for(int i=0;i<n;i++)q.add(new T(i,sc.next(),sc.nextInt()*3+sc.nextInt()*0+sc.nextInt()));
			while(!q.isEmpty()){
				T t = q.poll();
				System.out.println(t.n+","+t.s);
			}
		}
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static final int FIRST_NUMBER = 0;
    public static final int SECOND_NUMBER = 1;

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

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	// ?¨?????????°
	int vertical = Integer.parseInt(br.readLine());

	int horizontal = Integer.parseInt(br.readLine());

	List<int[]> changeRequests = new ArrayList<>();
	for (int i = 0; i < horizontal; i++) {
	    String[] changeRequestStr = br.readLine().split(",");
	    int[] changeRequest = new int[2];
	    changeRequest[FIRST_NUMBER] = Integer.parseInt(changeRequestStr[FIRST_NUMBER]);
	    changeRequest[SECOND_NUMBER] = Integer.parseInt(changeRequestStr[SECOND_NUMBER]);
	    changeRequests.add(changeRequest);
	}

	int[] outputArray = getDrawedArray(changeRequests, vertical, horizontal);

	for (int i = 1; i < outputArray.length; i++) {
	    System.out.println(outputArray[i]);
	}

    }

    /**
     *
     * @param changeRequests
     * @param vertical
     * @param horizontal
     */
    private static int[] getDrawedArray(List<int[]> changeRequests, int vertical, int horizontal) {
	int[] outputArray = new int[vertical + 1];
	for (int i = 1; i < outputArray.length; i++) {
	    outputArray[i] = i;
	}

	for (int[] changeRequest : changeRequests) {
	    int mediator = 0;
	    mediator = outputArray[changeRequest[FIRST_NUMBER]];
	    outputArray[changeRequest[FIRST_NUMBER]] = outputArray[changeRequest[SECOND_NUMBER]];
	    outputArray[changeRequest[SECOND_NUMBER]] = mediator;

	}

	return outputArray;

    }

}

Measured memory_bytes: 24376
#include <iostream>
using namespace std;
int main(){
  int s[30],b;

  for(int i = 0 ; i < 30 ; i++ )s[i] = 1;
  for(int i = 0 ; i < 28 ; i++ ){
    cin >> b;
    s[b-1] = 0;
}
  for(int i = 0 ; i < 30 ; i++ ){

       if(s[i] == 1)cout << i+1 << endl;
}

}

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

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

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

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;

int n, v[25], c[25];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,0,n-1) cin >> v[i];
    FOR(i,0,n-1) cin >> c[i];
    int res = 0;
    FOR(mask,0,(1<<n)-1) {
        int val = 0, cost = 0;
        FOR(i,0,n-1)
            if (mask & (1 << i)) {
                val += v[i];
                cost += c[i];
            }
        res = max(res, val - cost);
    }
    cout << res;
    return 0; 
}

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

using namespace std;

void print_vec(vector<int> &vec) {
    for (int j = 0; j < vec.size(); j++) {
        if (j != 0) cout << " ";
        cout << vec[j];
    }
    cout << endl;
}

int main() {
    int N;

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

    print_vec(A);
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        print_vec(A);
    }

    return 0;
}



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

const long long maxn = 2e5 + 10;

long long n;
long long ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
}

void solve(){
    while(n){
        ans++;
        n >>= 1;
    }
    ans = (1ll << ans) - 1;
}

void out(){
    cout << ans;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long n = scanner.nextLong();
			long m = scanner.nextLong();
			System.out.println((m > 2 * n) ? (m - 2 * n) / 4 + n : m / 2);
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main()
{
    string s;
    cin >> s;
    int s_len = s.size();
    for(int i=s_len-1;i>=0;i--){
        if(s[i]=='?'){
            if(i!=s_len-1){
                if(s[i+1]=='D') s.replace(i, 1, "D");
                else s.replace(i, 1, "D");
            }else{
                s.replace(i, 1, "D");
            }
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF (1LL<<60)
#define MOD 1000000007

int N;
int A[100000];
bool sign[100000];

long long dp[100001][3];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) {
    if (i > 0) {
      char c;
      cin >> c;
      sign[i] = c == '-';
    }
    cin >> A[i];
  }

  rep(i, N) {
    rep(j, 3) dp[i][j] = -INF;
  }
  dp[0][0] = 0;
  rep(i, N) {
    rep(d, 3) {
      if (dp[i][d] == -INF) continue;
      int nd = d;
      if (sign[i]) {
        nd++;
        if (nd == 3) nd = 1;
      }
      int b = (nd % 2 == 0) ? 1 : -1;
      dp[i+1][nd] = max(dp[i+1][nd], dp[i][d] + 1LL*b*A[i]);
    }

    dp[i+1][1] = max(dp[i+1][1], dp[i+1][2]);
    dp[i+1][0] = max(dp[i+1][0], dp[i+1][1]);
  }
  cout << dp[N][0] << "\n";
  return 0;
}


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

int main() {
  int n;
  cin>>n;
  ll a[100005];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  sort(a,a+n);
  int x[100005],y[100005];
  int i=0;
  int tmp1,tmp2;
  if (a[n-2]>=0) {
    x[0]=a[0];
    y[0]=a[n-2];
    for (i=1; i<n-2; i++) {
      if (a[n-2-i]<0) break;
      x[i]=x[i-1]-y[i-1];
      y[i]=a[n-2-i];
    }
    tmp1=x[i-1]-y[i-1];
  }
  else tmp1=a[0];
  if (i<n-2) {
    x[i]=a[n-1];
    y[i]=a[n-2-i];
    i++;
    for (; i<n-2; i++) {
      x[i]=x[i-1]-y[i-1];
      y[i]=a[n-2-i];
    }
    tmp2=x[n-3]-y[n-3];
  }
  else tmp2=a[n-1];
  x[n-2]=tmp2;
  y[n-2]=tmp1;

  cout<<x[n-2]-y[n-2]<<endl;
  for (int i=0; i<n-1; i++) {
    cout<<x[i]<<' '<<y[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3456
#include<cstdio>
using namespace std;
int N,S;
int main(){
	scanf("%d",&N);
	S=0;
	int n=N;
	while(n!=0){
		S+=(n%10);
		n/=10;
	}
	if(N/S*S==N)	printf("Yes");
	else	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define inf int(1e9)
#define half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;

string s;

void solve() {
    unordered_map<char, int> mp;
    rep(i, s.length()) mp[s[i]] = i + 1;
    if (s.length() == 26) {
        repr(i, s.length()) {
            for (char j = 'a'; j <= 'z'; ++j) {
                if (j > s[i] && mp[j] > mp[s[i]]) {
                    s[i] = j;
                    cout << s.substr(0, i + 1) << endl;
                    return;
                }
            }
            if (i == 0) cout << "-1" << endl;
        }
    } else {
        for (char j = 'a'; j <= 'z'; ++j) {
            if (mp[j] == 0) {
                cout << s + j << endl;
                return;
            }
        }
    }
}

int main() {
    cin >> s;
    solve();
    return 0;
}

Measured memory_bytes: 256
// frog1
// bottom-up approach
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
using namespace std;
int main()
{
	ll n,val1,val2;
	cin>>n;
	vector<ll> height(n,0);
	vector<ll> dp(n);
	for(ll i=0;i<n;i++)
	{
		cin>>height[i];
	}
	
	dp[0]=0;
	dp[1]=abs(height[1]-height[0]);
	for(ll i=2;i<n;i++)
	{
		val1=abs(height[i]-height[i-1])+dp[i-1];
		val2=abs(height[i]-height[i-2])+dp[i-2];
		dp[i]=min(val1,val2);
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
n, k = gets.split.map(&:to_i)
target = gets.split.map(&:to_i)
target.unshift 0 # ダミー

mod_info = Array.new(n+1, -1)

now = 1
mod = 0
mod_info[now] = mod

loop_start = 0
loop_size = nil

k.times do
  now = target[now]
  mod += 1
  if mod_info[now] == -1
    mod_info[now] = mod
  else
    loop_start = mod_info[now]
    loop_size = mod - loop_start
    break
  end
end

if loop_size.nil?
  last_mod = k
elsif mod != 0
  last_mod = (k - loop_start) % loop_size + loop_start
end

last = mod_info.find_index(last_mod)
puts last


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

using namespace std;

typedef long long ll;
const int MAX = 100005;
const int MOD = 1000000007;

#define F first
#define S second

void solve()
{
	ll a,b,t,x;
	cin>>a>>b>>t;
	ll ans=0;
	x=a;
	while(x<=t)
	{
		ans+=b;
		x+=a;

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 256
def d_lucky_pin():
    N = int(input())
    S = input()

    # 暗証番号を全探索 (PyPy で 400ms 程度)
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_index = 0
        current_searching = pin[current_index]

        for ch in S:
            if ch == current_searching:
                current_index += 1
                if current_index == 3:
                    ans += 1
                    break
                current_searching = pin[current_index]
    return ans

print(d_lucky_pin())

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==-1) printf("root, ");
  else if(T[u].l==-1) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6392
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const double PI = acos(-1);
const ll MOD = 1e9+7;
const ll MAXN = 2 * 1e3;

vi jalan[MAXN];
ll cap[MAXN][MAXN], val[MAXN], par[MAXN];
ll s, t, f, n, m;
ll res[MAXN][MAXN];

bool bfs(ll skrg) {
	bool vis[MAXN];
	memset(vis, 0, sizeof(vis));

	queue<ll> q;
	q.push(skrg);
	vis[skrg] = 1;
	par[skrg] = -1;

	while (!q.empty()) {
		ll cur = q.front();
		q.pop();

		for (ll i = 0; i < jalan[cur].size(); i++) {
			ll ttg = jalan[cur][i];
			if (!vis[ttg] && res[cur][ttg] > 0) {
				q.push(ttg);
				par[ttg] = cur;
				vis[ttg] = 1;
			}
		}
	}

	return vis[t];
}

int main(){
	cin >> n;
	s = 0; t = n + 1;
	ll tot = 0;
	for (ll i = 1; i <= n; i++) {
		ll x;
		cin >> x;

		if (x > 0) {
			jalan[i].pb(t);
			jalan[t].pb(i);
			cap[i][t] = x;
			tot += x;
		}
		else {
			jalan[s].pb(i);
			jalan[i].pb(s);
			cap[s][i] = -1 * x;

		}
	}

	for (ll i = 1; i <= n; i++) {
		for (ll j = 2*i; j <= n; j+=i) {
			jalan[i].pb(j);
			jalan[j].pb(i);
			cap[i][j] = INT_MAX;
		}
	}	


	for (ll i = 0; i <= n + 1; i++) {
		for (ll j = 0; j <= n + 1; j++) {
			res[i][j] = cap[i][j];
		}
	}
	
	ll mf = 0;

	while (bfs(s)) {
		ll p = INT_MAX;
		for (ll i = t; i != s; i = par[i]) {
			ll j = par[i];
			p = min(p, res[j][i]);
		}
		for (ll i = t; i != s; i = par[i]) {
			ll j = par[i];
			res[j][i] -= p;
			res[i][j] += p;
		}

		mf += p;
	}

	cout << tot - mf << endl;

}

Measured memory_bytes: 4488
#include <algorithm>
#include <iostream>
#include <vector>

constexpr int INF = 10000000;

int main() {
  int n, ma, mb;
  std::cin >> n >> ma >> mb;
  std::vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i] >> b[i] >> c[i];
  }
  std::vector<std::vector<std::vector<int>>> t(
      401, std::vector<std::vector<int>>(401, std::vector<int>(2, INF)));
  t[0][0][0] = 0;

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < 401; i++) {
      for (int j = 0; j < 401; j++) {
        int idx = k % 2;
        int idx2 = (k + 1) % 2;
        if (i - b[k] >= 0 && j - a[k] >= 0) {
          t[i][j][idx2] =
              std::min(t[i][j][idx], t[i - b[k]][j - a[k]][idx] + c[k]);
        } else {
          t[i][j][idx2] = t[i][j][idx];
        }
      }
    }
  }
  int ans = INF;
  for (int i = 1; i < 401; i++) {
    for (int j = 1; j < 401; j++) {
      if (i * ma == j * mb) {
        ans = std::min(ans, t[i][j][n % 2]);
      }
    }
  }
  std::cout << ((ans == INF) ? -1 : ans) << std::endl;
}

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

void heapify (int arr[], int idx, int max)
{
    int largest = idx;
    int l = 2 * idx + 1;
    int r = 2 * idx + 2;

    if (l < max && arr[l] > arr[largest])
        largest = l;
    
    if (r < max && arr[r] > arr[largest])
        largest = r;
    
    if (largest != idx) {
        swap (arr[idx], arr[largest]);

        heapify(arr, max, largest);
    }
}

void heapSort (int arr[], int n)
{
    for (int i = n / 2 - 1; i >= 0; i--)
        heapify(arr, i , n);
    
    for (int i = n - 1; i >= 0; i--){
        swap(arr[0], arr[i]);
        heapify(arr, 0, i);
    }
}

int main(){
    int n;
    int m;
    cin >> n >> m;
    
    vector<int> vec(m);
    for(int i = 0; i < m; ++i){
        cin >> vec.at(i);
    }

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

    vector<int> vecdiff(m-1);
    for(int j = 0; j < m - 1; ++j){
        vecdiff.at(j) = vec.at(j + 1) - vec.at(j);
    }

    sort(vecdiff.begin(), vecdiff.end());
    int mDiffn = m - n;
    if (mDiffn < 0) mDiffn = 0;
    int mvmin = 0;
    for(int k = 0; k < mDiffn; ++k){
        mvmin += vecdiff[k];
    }
    cout << mvmin << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 998244353 
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cout<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}


vector<pii> p;
ll dp[101][100005];
int main(){
      sync;
      ll n,w;
      cin>>n>>w;
      for(ll i=1; i<=n; i++){
            ll w,v;
            cin>>w>>v;
            p.pb({v,w}); 
      }
      
      for(int i=0;i<n;i++){
      	 for(int j=0;j<=w;j++){
      	 	   if(i==0){
      	 	   	   dp[i][j]=(p[i].sd>j?0:p[i].ft);continue;
      	 	   }
               dp[i][j]=dp[i-1][j];
               if(p[i].sd<=j) dp[i][j]=max(dp[i][j],dp[i-1][j-p[i].sd]+p[i].ft);
      	 }
      }

      cout<<dp[n-1][w]<<endl;
} 



Measured memory_bytes: 78464
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,x,t;cin>>n>>x>>t;
  cout<<(ll)ceil((double)n/x)*t<<endl;
  return 0;
}


Measured memory_bytes: 3724
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
   string s, t;
   cin >> s >> t;
   int cnt = 0;
   if (s[0] == t[0])
   {
      cnt++;
   }
   if (s[1] == t[1])
   {
      cnt++;
   }
   if(s[2] == t[2])
   {
      cnt++;
   }
   cout << cnt << endl;
   
   return 0;
}


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

# define ll long long

int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) { int a; cin >> a; h[i] = a; }
	vector<int> dp(n, 1000000);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	int i;
	for (i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define int64 long long

int main() {
	int h1, h2, m1, m2, k;
	std::cin >> h1 >> m1 >> h2 >> m2;
	m1 += h1 * 60, m2 += h2 * 60;
	std::cin >> k;
	std::cout << std::max(m2 - k - m1, 0);
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
int a[200000];
int dp[200000];
int main(){
	int i;
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	dp[1] = 0;
	dp[2] = abs(a[2]-a[1]);
	for(i = 3; i <= n; i++){
		dp[i] = min(abs(a[i]-a[i-1])+dp[i-1], abs(a[i]-a[i-2])+dp[i-2]);
	}
	printf("%d", dp[n]);
	return 0;
}

Measured memory_bytes: 1024