akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto n = RD;
	auto p = RDR.ARR;

	long ans;
	foreach (i; 1..n-1)
	{
		if (p[i] < p[i-1] && p[i] > p[i+1])
			++ans;
		else if (p[i] > p[i-1] && p[i] < p[i+1])
			++ans;
	}
	

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int 
#define endl '\n'
ll mod=1e9+7;

int main()
{
   FASTio;
    #ifndef ONLINE_JUDGE                    //file start
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
    #endif                                  //file end
    string s;
    cin>>s;
    int i,ans=0;
    int k=0;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='R')
        {
            ans++;
            k=max(k,ans);
        }    
        else
            ans=0;
    }
    cout<<k<<"\n";
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int ,int> P;
#define INF 10000000

int W, H, N;
char map[1010][1010];
int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int d[1010][1010];
int G[10][2];

bool InBox(int x,int y)
{
  return x>=0 && x<W && y>=0 && y<H;
}

int bfs(int k)
{
  P set, goal;
  set.first = G[k][0];
  set.second = G[k][1];
  goal.first = G[k + 1][0];
  goal.second = G[k + 1][1];
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      d[i][j] = INF;

  queue<P> que;
  que.push(P(G[k][0], G[k][1]));
  d[G[k][1]][G[k][0]] = 0;
  while (que.size())
  {
    P p = que.front();
    que.pop();
    
    if (p.first == G[k + 1][0] && p.second == G[k+ 1][1])
      return d[goal.second][goal.first];
    for (int i = 0; i < 4; i++)
    {
      int nx = p.first+dir[i][0];
      int ny = p.second+dir[i][1];

      if (InBox(nx,ny)&&map[ny][nx]!='X'&&d[ny][nx]==INF)
      {
        d[ny][nx] = d[p.second][p.first] +1;
        que.push(P(nx,ny));
        
      }
    }
  }
}

int main()
{
  cin >> H >> W >> N;
  for (int y = 0; y < H; y++)
    for (int x = 0; x < W; x++)
    {
      cin >> map[y][x];
      if (map[y][x] == 'S')
      {
        G[0][0] = x;
        G[0][1] = y;
      }
      else if (map[y][x] > '0' && map[y][x] <= '9')
      {
        G[map[y][x] - '0'][0] = x;
        G[map[y][x] - '0'][1] = y;
      }
    }
  int sum = 0;
  for (int i = 0; i < N; i++)
  {

    sum += bfs(i);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 7984
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
	if(a>b)
		swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
	char str[100];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
	sprintf(str,"%s.out",s);
	freopen(str,"w",stdout);
#endif
}
int rd()
{
	int s=0,c;
	while((c=getchar())<'0'||c>'9');
	do
	{
		s=s*10+c-'0';
	}
	while((c=getchar())>='0'&&c<='9');
	return s;
}
int upmin(int &a,int b)
{
	if(b<a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int upmax(int &a,int b)
{
	if(b>a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int n,a[100010],b[100010],c[100010],d[100010];
map<int,int> e;
int f[100010];
int cnt;
int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}
int main()
{
	scanf("%d",&n);
	int s=0;
	int i;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		c[i]=a[i];
		s^=a[i];
	}
	c[n+1]=a[n+1]=s;
	s=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		d[i]=b[i];
		s^=b[i];
	}
	d[n+1]=b[n+1]=s;
	n++;
	sort(c+1,c+n+1);
	sort(d+1,d+n+1);
	for(i=1;i<=n;i++)
		if(c[i]!=d[i])
		{
			printf("-1\n");
			return 0;
		}
	int ans=0;
	for(i=1;i<=n;i++)
		if(a[i]!=b[i]||i==n)
		{
			if(i<n)
				ans++;
			if(!e[a[i]])
				e[a[i]]=++cnt;
			if(!e[b[i]])
				e[b[i]]=++cnt;
		}
	if(!ans)
	{
		printf("0\n");
		return 0;
	}
	for(i=1;i<=cnt;i++)
		f[i]=i;
	for(i=1;i<=n;i++)
		if(a[i]!=b[i])
			f[find(e[a[i]])]=find(e[b[i]]);
	for(i=1;i<=cnt;i++)
		if(find(i)==i)
			ans++;
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 8448
n,m,s,t = map(int,input().split())
uvab = [list(map(int,input().split())) for i in range(m)]
gyen = [[] for i in range(n+1)]
gsnu = [[] for i in range(n+1)]
for u,v,a,b in uvab:
  gyen[u].append((v,a))
  gyen[v].append((u,a))
  gsnu[u].append((v,b))
  gsnu[v].append((u,b))
import heapq as hq
def dijkstra(start,graph):
  dist = [10**18]*(n+1)
  dist[start] = 0
  q = [(0,start)]
  hq.heapify(q)
  while q:
    _,x = hq.heappop(q)
    for y,dd in graph[x]:
      if dist[y] > dist[x]+dd:
        dist[y] = dist[x]+dd
        hq.heappush(q,(dist[y],y))
  return dist
distyen = dijkstra(s,gyen)
distsnu = dijkstra(t,gsnu)
ans = []
for i in range(n,0,-1):
  x = 10**15-(distyen[i]+distsnu[i])
  if i == n:
    ans.append(x)
  else:
    ans.append(max(ans[-1],x))
ans = ans[::-1]
print(*ans,sep="\n")

Measured memory_bytes: 123736
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let s: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end()
            .chars()
            .map(|c| if c == 'R' { 0 } else if c == 'G' { 1 } else { 2 })
            .collect()
    };

    let mut count = vec![vec![0; 3]; n + 1];
    for i in (0..n).rev() {
        for j in 0..3 {
            count[i][j] += count[i + 1][j];
        }
        count[i][s[i]] += 1;
    }

    let mut ans = 0usize;
    for i in 0..(n - 2) {
        for j in (i + 1)..(n - 1) {
            if s[i] == s[j] { continue; }
            ans += count[j + 1][3 - s[i] - s[j]];
            if j - i + j < n && s[j - i + j] == 3 - s[i] - s[j] {
                ans -= 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,a,b; cin >> n >> a >> b;
  rep(cnt,100){
    if(a+1 == b){
      if(cnt%2==0) cout << "Borys";
      else cout << "Alice";
      break;
    }
    if(cnt%2) a++;
    else b--;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3636
x = gets.chomp.to_i

i = 0
while true do
	if(x >= 500)
		x = x - 500
		i += 1
	else
		break
	end
end

j = 0
while true do
	if(x >= 5)
		x = x - 5
		j += 1
	else
		break
	end
end

happy = 1000 * i + 5 * j

puts happy

Measured memory_bytes: 14376
#include <stdio.h>
 
int tri(int a, int b, int c);
 
int angle(int a, int b, int c);
 
int main() {
	
	int N;
	
	int x[200];
	
	int i, j, k;
	
	int res = 0;
	
	if (scanf("%d", &N) != 1) {
		return 1;
	}
	
	for (i = 0; i < N; i++) {
		if (scanf("%d", &x[i]) != 1) {
			return 1;
		}
	}
 
	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			for (k = j + 1; k < N; k++) {
				if (angle(x[i], x[j], x[k])) {
					res++;
				}
			}
		}
	}
 
	printf("%d\n", res);
	return 0;
}

int tri(int a, int b, int c) {
	return a < b && b < c && c > b - a && c < a + b;
}

int angle(int a, int b, int c) {
	return tri(a, b, c) || tri(a, c, b) || tri(b, a, c) || tri(b, c, a) ||
		tri(c, a, b) || tri(c, b, a);
}



Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(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();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    k--;
    cout << a[k];
    return 0;
}

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

#define ioso ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define kholo freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
#define laglo cerr << "Ti : " << clock() * 1.0 / CLOCKS_PER_SEC  << endl;
#define endl '\n';
#define ll long long

int main() {
	ioso; //kholo;
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = (n)/(a+b);
	ans = (ans*a)+ min(a, n-(a+b)*ans);
	cout << ans << endl;
	//laglo;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for i in range(h)]
ans = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            ans = "No"
            for x, y in [(-1, 0), (0, -1), (0, 1), (1, 0)]:
                if  0<=i+x<h and 0<=j+y<w and s[i+x][j+y]=="#":
                    ans = "Yes"
            if ans == "No":
                print(ans)
                exit()
print(ans)

Measured memory_bytes: 39664
fun main(args: Array<String>) {
    readLine()!!
    val hList = readLine()!!.split(" ").map { it.toLong() }.toMutableList()

    for (i in 0 until hList.size - 1) {
        if (hList[i + 1] - hList[i] >= 1 ) hList[i+1] = hList[i+1] - 1

        if ( hList[i] - hList[i + 1] > 0) {
            println("No")
            return
        }
    }

    println("Yes")
}


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
const int N = 1e7 + 5;

int n;
ll ans = 1;
ll divi[N];

void comp() {
	for (int i = 1; i < N; ++i) divi[i] = 1;
	
	for (int i = 2; i <= n; ++i) {
		if (divi[i] != 1) {
			ans += i * divi[i];
			continue;
		}
		for (int j = i; j <= n; j += i) {
			ll tmp = j, cnt = 0;
			while (!(tmp % i)) {
				++cnt;
				tmp /= i;
			}
			divi[j] *= (cnt + 1);
		}
		ans += i * divi[i];
	}
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	comp();
	cout << ans;
}



Measured memory_bytes: 81768
#include <stdio.h>

int main(){
	char c;
	int s = 0;
	for(int i = 0; i < 3; i++){
		scanf("%c", &c);
		if(c == '1')s = s * 10 + 9;
		else s = s * 10 + 1;
	}
	printf("%d\n", s);
	return 0;
}


Measured memory_bytes: 128
import sys
input=sys.stdin.readline
n=int(input())
outs=[[] for i in range(1000000)]
ins=[0]*1000000
for i in range(n):
    a_list=list(map(int,input().split()))
    for j in range(1,n-1):
        x1=min(i,a_list[j-1]-1)
        y1=max(i,a_list[j-1]-1)
        z1=x1*1000+y1
        x2=min(i,a_list[j]-1)
        y2=max(i,a_list[j]-1)
        z2=x2*1000+y2
        outs[z1].append(z2)
        ins[z2]+=1
q=[]
for i in range(n):
    for j in range(i+1,n):
        if ins[1000*i+j]==0:
            q.append(1000*i+j)
res=0
ans=0
while q:
    ans+=1
    v1_list=[]
    while q:
        v1=q.pop()
        res+=1
        v1_list.append(v1)
    for v1 in v1_list:
        for v2 in outs[v1]:
            ins[v2]-=1
            if ins[v2]==0:
                q.append(v2)
if res==n*(n-1)//2:
    print(ans)
else:
    print(-1)





Measured memory_bytes: 129048
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}
#define NUM_MAX 100000
#define DIVISOR 1000000007

int check(int *arr, int num) {
    static int map[NUM_MAX+1];
    int i;
    int flag = 1;
    for(i = 0; i < num; i++) {
        map[arr[i]]++;
    }
    int start = (num%2==0) ? 1 : 2;
    if(num%2 == 1) {
        if(map[0] != 1) flag = 0;
    }
    for(i = start; i < num; i+=2) {
        if(map[i] != 2) flag = 0;
    }
    return flag;
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i;
    int64_t ans = 1;
    if(!check(arr, num)) {
        ans = 0;
    } else {
        for(i = 0; i < num/2; i++) {
            ans = (ans * 2)%DIVISOR;
        }
    }
    printf("%d\n", (int)ans);
}

Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>
#define N 500000
int S[N]={0};
int L[N/2+2]={0};
int R[N/2+2]={0};

long count=0;
void merge(int A[],int left,int mid,int right)
{
	int n1,n2,i,j,k;
	n1=mid-left;
	n2=right-mid;
	for(i=0;i<n1;i++)
	{
		L[i]=A[left+i];
	}
	for(i=0;i<n2;i++)
	{
		R[i]=A[mid+i];
	}
	L[n1]=999999999;
	R[n2]=999999999;
	i=0;
	j=0;
	for(k=left;k<right;k++)
	{
		if(L[i]<=R[j])
		{
			A[k]=L[i];
			i=i+1;
		}
		else
		{
			A[k]=R[j];
			j=j+1;
			count+=(n1-i);
		
		}
	}
	return ;
}

void mergesort(int A[],int left,int right)
{
	int mid;
	if(left+1<right)
	{
		mid=(left+right)/2;
		mergesort(A,left,mid);
		mergesort(A,mid,right);
		merge(A,left,mid,right);
	}
		return ;
}
int main()
{
	int i,n;
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&S[i]);
	}
	mergesort(S,0,n);
	
	printf("%ld\n",count);
	
	return 0;
		
}


Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n;
    cin>>n;
    vector<P>ab(n);
    rep(i,n)cin>>ab[i].second>>ab[i].first;
    sort(ab.begin(),ab.end());
    bool ok=true;
    int time=0;
    rep(i,n){
        P now=ab[i];
        time+=now.second;
        if(now.first<time){
            ok=false;
            break;
        }
    }

    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int WW = Integer.parseInt(sc.next());
    int[] v = new int[N+1];
    int[] w = new int[N+1];
    for(int i=1; i<N+1; i++){
      v[i] = Integer.parseInt(sc.next());
      w[i] = Integer.parseInt(sc.next());
    }

    int[] dp = new int[WW+1];
    dp[0] = 0;

    for (int i=1; i<=N; i++) {
      for (int W=w[i]; W<=WW; W++) {
        if(W-w[i]>=0){
            dp[W] = Math.max(dp[W], dp[W-w[i]] + v[i]);
          }else{
            dp[W] = dp[W-1];
          }
      }
    }
      
    System.out.println(dp[WW]);
  }
}

Measured memory_bytes: 26880
N = int(input())
ary = [int(x) for x in input().split(" ")]
ary.sort()
ary.reverse()

alice = 0
bob = 0
for i in range(N):
    tmp = ary.pop(0)
    if i % 2 == 0:
        alice += tmp
    else:
        bob += tmp

print(alice - bob)



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int dp[1009][1009];
char ar[1009][1009];

#define mod 1000000007

int main()
{
    int i,j,k,l,m,n;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cin>>ar[i][j];
        }
    }
    dp[0][0] = 1;
    for(i=1;i<n;i++)
    {
        if(ar[i][0] != '#')dp[i][0] = dp[i-1][0] ;
    }

    for(i=1;i<m;i++)
    {
        if(ar[0][i] != '#')dp[0][i] = dp[0][i-1] ;
    }

    for(i=1;i<n;i++)
    {
        for(j=1;j<m;j++)
        {
            if(ar[i][j] != '#')
            {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
            }

        }
    }

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




Measured memory_bytes: 5120
class Proc:
    def __init__(self, name, time):
        self.name = name
        self.time = time

n, q = list(map(int, input().split()))
queue = []
for i in range(n):
    name, time = list(input().split())
    time = int(time)
    p = Proc(name, time)
    queue.append(p)

now = 0
while queue:
    p = queue.pop(0)
    if p.time <= q:
        now += p.time
        print(p.name, now)
    else:
        p.time -= q
        queue.append(p)
        now += q



Measured memory_bytes: 17408
#include<stdio.h>
#include<stdlib.h>
#define NIL -1

typedef struct{
  int deg;
  int depth;
  int parent;
  int *child;
  int c_check;
}node;

node *tree;

int main(){
  int num;
  int i, j, n;

  scanf("%d", &n);
  tree = (node*)malloc(sizeof(node)*n);
  for(i=0; i<n; i++){ //初期化
    tree[i].depth = 0;
    tree[i].parent = NIL;
    tree[i].child = 0;
    tree[i].c_check = 0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d", &num);
    scanf("%d", &tree[num].deg);
    if(tree[num].deg != 0){
      tree[num].child = (int*)malloc(sizeof(int)*tree[num].deg);
      tree[num].c_check++;
      for(j=0; j<tree[num].deg; j++){
	scanf("%d", &tree[num].child[j]);
	tree[tree[num].child[j]].parent = num;
	tree[tree[num].child[j]].depth = tree[num].depth + 1;
      }
    } else if(tree[num].deg == 0 && tree[num].parent != NIL){
      tree[num].depth = tree[tree[num].parent].depth + 1;
    }
  }

  for(i=0; i<n; i++){
    printf("node %d: parent = %d, depth = %d, ", i, tree[i].parent, tree[i].depth);
    if(tree[i].depth == 0) printf("root, [");
    else if(tree[i].c_check == 0) printf("leaf, [");
    else printf("internal node, [");

    for(j=0; j<tree[i].deg; j++){
      if(j != 0)printf(", ");
      printf("%d", tree[i].child[j]);
    } printf("]\n");
  }
  return 0;
}



Measured memory_bytes: 5300
import math
def main():
    a,b,h,m = map(int,input().split())
    angle = 180 - abs(180 - abs(m * 6 - (h * 30 + m * 0.5)))
    ans = math.sqrt((a*a + b*b) - (2 * a * b)*math.cos(math.radians(angle)))
    print(round(ans,9))






main()

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

int main()
{
    int n;
    int a[200005],b[200005]={0};
    
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]-1]++;
    }
    for(int i=0;i<n;i++)
    {
        printf("%d\n",b[i]);
    }
    
    
    
    return 0;
}


Measured memory_bytes: 5324
a,b,c,d=map(int,input().split())
while a*c>0:
    cc=c-b
    if cc<=0:
        print("Yes")
        exit()
    else:
        c=cc

    aa=a-d
    if aa<=0:
        print("No")
        exit()
    else:
        a=aa
        


Measured memory_bytes: 61564
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,d,sum,ans=0;
  double num;
  int x[100][100];
  cin>>n>>d;
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      sum=0,num=0;
      if(i!=j){
        for(int k=0;k<d;k++){
          sum += ((x[i][k]-x[j][k])*(x[i][k]-x[j][k]));
        }
        num = sum;
        sum = sqrt(sum);
        if(sum == sqrt(num)){
          ans++;
        }
      }
    }
  }
  cout<<ans/2<<"\n";
  return 0;
}

Measured memory_bytes: 256
N,Y=map(int,input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
                print("{} {} {}".format(i,j,N-i-j))
                exit()  
            
print("{} {} {}".format(-1,-1,-1))
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int P, Q, R;  cin >> P >> Q >> R;

    print(min(min(P+Q, Q+R), R+P));
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 101
#define INFTY 1000000000
#define WHITE 0
#define BLACK 2
#define GRAY 1

int n, M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];

    for(int i=0; i<n; i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }

    d[0]=0;
    color[0]=GRAY;
    while (1) {
        minv=INFTY;
        int u=-1;
        for(int i=0; i<n; i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }

        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > d[u] + M[u][v]){
                    d[v]= d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }


    for(int i=0; i<n; i++){
        printf("%d %d\n",i, d[i] == INFTY ? -1 : d[i] );
    }

}

int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j]=INFTY;
        }
    }
    int k,c,u,v;
    for(int i=0; i<n; i++){
            scanf("%d %d",&u,&k);
        for(int j=0; j<k; j++){
            scanf("%d %d",&v,&c);
            M[u][v]=c;
        }
    }
    dijkstra();
    return 0;


    }
/*
 与えられた重み付き有向グラフ G = (V, E ) について、単一始点最短経路のコストを 求めるプログラムを作成してください。G の頂点 0 を始点とし、0 から各頂点 v につ いて、最短経路上の辺の重みの総和 d [v] を出力してください。

 入力 最初の行に G の頂点数 n が与えられます。続くn 行で各頂点 u の隣接リストが以下 の形式で与えられます:
 ukv1 c1 v2 c2 ...vk ck
 G の各頂点には0 からn - 1 の番号がふられています。uは頂点の番号であり、k は u の出次数を示します。vi ( i = 1, 2, ...k) は u に隣接する頂点の番号であり、ci は u と vi をつなぐ有向辺の重みを示します。

 出力 各頂点の番号 v と距離 d [v] を1つの空白区切りで順番に出力してください。
   0 から各頂点へは必ず経路が存在する*/

/*
 5
 0 3 2 3 3 1 1 2
 1 2 0 2 3 4
 2 3 0 3 3 1 4 1
 3 4 2 1 0 1 1 4 4 3
 4 2 2 1 3 3
 */

/*
 0 0
 1 2
 2 2
 3 1
 4 3
 */



Measured memory_bytes: 2104
import fractions

while True:
    a, b, c = map(int, input().split())
    if not a:
        break
    d = (b ** 2 - 4 * a * c) ** 0.5
    if isinstance(d, complex) or d - int(d) > 1e-6:
        print('Impossible')
        continue
    num1, num2 = -b + int(d), -b - int(d)
    den = 2 * a
    cmn1, cmn2 = fractions.gcd(num1, den), fractions.gcd(num2, den)
    p, q, r, s = den // cmn1, -num1 // cmn1, den // cmn2, -num2 // cmn2
    if (p, q) < (r, s):
        p, q, r, s = r, s, p, q
    print(p, q, r, s)

Measured memory_bytes: 10300
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

bool check(string s) {
    set<char> se = {'A', 'T', 'G', 'C'};
    for (auto c : s) {
        if (!se.count(c))
            return false;
    }

    return true;
}
int main() {
    string s;
    cin >> s;
    int maxl = 0;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; i + j <= s.size(); j++) {
            string tmp = s.substr(i, j);
            if (check(tmp)) {
                maxl = max(maxl, (int)tmp.size());
            }
        }
    }
    cout << maxl << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <set>
#include <string>

using namespace std;


int n,m;
long long int k;
long long int a[300000];
long long int b[300000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>k;
    long long int sum = 0;
    for(int i=0;i<n;i++) {
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }

    int res = 0;
    int atake = n;
    int btake = 0;
    while(true) {
        
        if(sum<=k) {
            res = max(res, atake + btake);
            if(btake<m) {
                sum+=b[btake];
                btake++;
            }
            else {
                break;
            }
        }
        else {
            if(atake==0) {
                break;
            }
            atake--;
            sum-=a[atake];
        }
    }
   
    std::cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
double a, b;
int main()
{
    cin >> a >> b;
    double x=(a+b) *10 /2;
    int y=(a+b)/2;
    if(x/10-y>=0.5)
    {
        y++;
        cout << y;
    }
    else
    {
        cout << y;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<cassert>
#include<cmath>

using namespace std;

#define N 3
#define N2 9
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};

int MDT[N2][N2];

struct Puzzle{
  int f[N2], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
  int sum = 0;
  for(int i=0 ; i<N2 ; ++i){
    if(pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i]-1];
  }
  return sum;
}

bool isSolved(){
  for(int i=0 ; i<N2 ; ++i) if(state.f[i] != i+1) return false;
  return true;
}

bool dfs(int depth, int prev){
  if(state.MD == 0) return true;
  if(depth + state.MD > limit) return false;

  int sx = state.space/N;
  int sy = state.space%N;
  Puzzle tmp;

  for(int r=0 ; r<4 ; ++r){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx<0 || ty<0|| tx>=N || ty >= N) continue;
    if(max(prev, r)-min(prev, r) == 2) continue;
    tmp = state;

    state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty], state.f[sx*N+sy]);
    state.space = tx*N+ty;
    if(dfs(depth+1, r)){
      path[depth] = r;
      return true;
    }
    state = tmp;
  }
  return false;
}

string iterative_deeping(Puzzle in){
  in.MD = getAllMD(in);

  for(limit = in.MD ; limit<=LIMIT ; ++limit){
    state = in;
    if(dfs(0, -100)){
      string ans = "";
      for(int i=0 ; i<limit ; ++i) ans += dir[path[i]];
      return ans;
    }
  }
  return "unsolvable";
}

int main(){
  for(int i=0 ; i<N2 ; ++i){
    for(int j=0 ; j<N2 ; ++j){
      MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);
    }
  }
  Puzzle in;
  for(int i=0 ; i<N2 ; ++i){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deeping(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}

int main(){
	char s[5];
	cin>>s;
	int a=int(s[0])-48;
	int b=int(s[1])-48;
	int c=int(s[2])-48;
	int d=int(s[3])-48;
	rep(i,2){
		
		rep(j,2){
			
			rep(k,2){
				int x=a;
				if(i==0){
					x+=b;
				}else{
					x-=b;
				}
				if(j==0){
					x+=c;
				}else{
					x-=c;
				}
				if(k==0){
					x+=d;
				}else{
					x-=d;
				}
				if(x==7){
					cout<<a;
					if(i==0){
						cout<<"+";
					}else{
						cout<<"-";
					}
					cout<<b;
					if(j==0){
						cout<<"+";
					}else{
						cout<<"-";
					}
					cout<<c;
					if(k==0){
						cout<<"+";
					}else{
						cout<<"-";
					}
					cout<<d<<"=7"<<endl;
					return 0;
				}
			}
		}
	}

}


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

int main(){
  string S;

  cin >> S;

  for (int i = 0; i < S.size(); i++){
    if (S[i] == '?') S[i] = 'D';
    cout << S[i];
  }
  cout << endl;

  return 0;

}


Measured memory_bytes: 3756
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	int md[12] = {0, 31, 59, 90,120,151,181,212,243,273,304,334};
	int y2, m2, d2;
	int y1, m1, d1;

	while (true)
	{
		scanf("%d%d%d%d%d%d", &y1, &m1, &d1, &y2, &m2, &d2);
		if (y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0)
			break;

		int yt = y2 - 1;
		int days2 = yt * 365 + md[m2 - 1] + d2 + (yt / 4 - yt / 100 + yt / 400);
		if (m2 >= 3 && y2 % 4 == 0 && (y2 % 100 != 0 || y2 % 400 == 0))
			days2++;

		yt = y1 - 1;
		int days1 = yt * 365 + md[m1 - 1] + d1 + (yt / 4 - yt / 100 + yt / 400);
		if (m1 >= 3 && y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0))
			days1++;

		printf("%d\n", days2 - days1);
	}

	return 0;
}

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


int a[10005], b[10005];
int dp[10005]; 


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int h, n;
	cin >> h >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i] >> b[i];

	for (int i = 1; i <= h; ++i)
		dp[i] = 2e9;

	for (int i = 1; i <= n; ++i){
		//cout << "### " << i << "###\n";
		for (int j = 0; j <= h; ++j){
		//	cout << "dp[" << min(j+a[i],h) << "] = " << dp[min(j+a[i],h)] << " v " << dp[j] + b[i] << "\n";
			dp[min(j+a[i],h)] = min(dp[min(j+a[i],h)],dp[j]+b[i]);
		}
	}
	cout << dp[h] << "\n";
}

Measured memory_bytes: 256
N = int(input())
t = [list(map(int,input().split())) for _ in range(N)]
x,k,y = 0,0,0
for i in range(N):
    if (abs(t[i][1] - x) + abs(t[i][2] - y) > t[i][0] - k 
       or (abs(t[i][1] - x) + abs(t[i][2] - y))%2 != (t[i][0] - k)%2):
       print("No")
       exit()
    x = t[i][1]
    y = t[i][2]
    k = t[i][0]
print("Yes")

Measured memory_bytes: 27020
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, As):
    import math
    primes = [0] * (max(As) + 1)
    pairwise_flg = True
    for x in As:
        i = 2
        while x != 1:
            if x % i == 0:
                if primes[i] != 0:
                    pairwise_flg = False
                    break
                primes[i] = 1
                while x % i == 0:
                    x = x // i
            else:
                i += 1
                if i > math.sqrt(x):
                    if primes[x] != 0:
                        pairwise_flg = False
                    else:
                        primes[x] = 1
                    break
        if not pairwise_flg:
            break
    if pairwise_flg:
        print('pairwise coprime')
        return

    tmp = math.gcd(As[0], As[1])
    for A in As:
        tmp = math.gcd(tmp, A)
    if tmp == 1:
        print('setwise coprime')
        return

    print('not coprime')


if __name__ == '__main__':
    N = int(input())
    As = [int(i) for i in input().split()]
    # # test
    # import random
    # N = 10 ** 6
    # As = [random.randint(1, 10 ** 6) for _ in range(N)]
    solve(N, As)



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;






ll solve(ll cap, vector<vector<ll>> a) {
    vector<ll> dp(cap+1, 0);

    for (int i=1; i<=cap; i++) {
	dp[i]=dp[i-1];
	for (auto item: a) {
	    ll weight = item[0];
	    ll reward = item[1];
	    if (i-weight>=0) {
		dp[i] = max(dp[i], reward+dp[i-weight]);
	    }
	}
    }

    return dp[cap];
}


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


    ll n;
    ll ga,sa,ba;
    ll gb,sb,bb;

    cin>>n;
    cin>>ga>>sa>>ba;
    cin>>gb>>sb>>bb;

    vector<vector<ll>> a = {{ga,gb},{sa,sb},{ba,bb}};
    vector<vector<ll>> v;
    for (auto p: a) {
	if (p[1]>p[0]) {
	    v.push_back({p[0],p[1]-p[0]});
	}
    }
    n += solve(n, v);
	
    
    a = {{gb,ga},{sb,sa},{bb,ba}};
    v.clear();
    for (auto p: a) {
	if (p[1]>p[0]) {
	    v.push_back({p[0],p[1]-p[0]});
	}
    }
    n += solve(n, v);
    cout<<n<<endl;

    
    return 0;
}


Measured memory_bytes: 198448
N = int(input())
words = {}
max_count = 1
for i in range(N):
    new = input()
    if new in words:
        words[new] += 1
        if words[new] > max_count:
            max_count = words[new]
    else:
        words[new] = 1
ans = []
for word in words:
    if words[word] == max_count:
        ans.append(word)
        
ans.sort()

for elem in ans:
    print(elem)

Measured memory_bytes: 32096
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct edge{int to,cost;};
typedef pair<int,int> P;

signed main (){
    int n,m,R;cin>>n>>m>>R;
    vector<int> r(R);
    rep(i,0,R){cin>>r[i];r[i]--;}
    sort(r.begin(),r.end());
    vector<vector<int>> d(n,vector<int>(n,LINF));
    rep(i,0,n)d[i][i]=0;
    rep(i,0,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        d[a][b]=c;
        d[b][a]=c;
    }

    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,n){
                d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }
    int ans=LINF;
    do{
        int subans=0;
        rep(i,1,R){
            subans+=d[r[i-1]][r[i]];
        }
        ans=min(ans,subans);
    }while(next_permutation(all(r)));
    printf("%lld\n",ans);
    // int v[]={2,3,1};
    // do{
    //     rep(i,0,3)cout<<v[i]<<" ";
    //     cout<<endl;
    // }while(next_permutation(v,v+3));
    
    

    
}
/*
1-21-2
*/


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

using namespace std;

typedef long long ll;
typedef pair < int,int> pii;
typedef pair < double,double> pt;

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

vector < int > v[N];
vector < pii > v2;

int lan[N],dub[N],root,bst,n;

void findroot(int x,int lst){
    dub[x] = dub[lst] + 1;
    v2.push_back(make_pair(dub[x], x));
    if(dub[x] > dub[bst])
        bst = x;
    for(int i = 0;i<v[x].size();i++)
        if(v[x][i] != lst)
            findroot(v[x][i], x);
}

void findlan(int x,int lst){
    lan[x] = 0;
    int lncnt = 0,a = 0,b = 0;
    for(int i = 0;i<v[x].size();i++){
        if(v[x][i] == lst) continue;
        findlan(v[x][i], x);
        a += lan[v[x][i]];b++;
    }
    if(a == 1 && b == 1) lan[x] = 1;
    if(b == 0) lan[x] = 1;
}

int solve(int x,int lst){
    int lncnt = 0,ret = 0;
    for(int i = 0;i<v[x].size();i++){
        if(v[x][i] == lst) continue;
        if(lan[v[x][i]]) lncnt++;
        else ret += solve(v[x][i], x);
    }
    if(lncnt) lncnt--;
    return ret + lncnt;
}

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n-1;i++){
        int x,y;scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    findroot(0, 0);
    int sol = n;
    sort(v2.rbegin(),v2.rend());
    for(int k = 0;k<min(50, n);k++){
        int root = v2[k].second;
        findlan(root, root);
        if(lan[root]) {sol = 1;}
        else sol = min( solve(root, root) + 1, sol);
    }
    printf("%d\n", sol);
}



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

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1e7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/




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

    int h1, m1, h2, m2, k;
    cin>>h1>>m1>>h2>>m2>>k;
    cout<<60*(h2-h1) + (m2-m1) - k;



}



Measured memory_bytes: 3616
#include <stdio.h>

int main(void) {
    int n, a, b, res=0;
    scanf("%d %d %d", &n, &a, &b);

    for (int i = 0; i <= n; i++) {
        int t = 0;
        for (int j = i; j != 0;) {
            if (j < 10) {
                t += j;
            } else {
                t += j % 10;
            }
            j = j / 10;
        }
        if ((t >= a) && (t <= b)) {
            res += i;
        }
    }

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

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007

int main(void) {
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) {
      char a;
      cin >> a;
      A[i][j] = a;
    }
  }

  vector<vector<ll>> dp(H, vector<ll>(W));
  dp[0][0] = 1;
  for (int j = 1; j < W; j++) {
    if (A[0][j] == '#') {
      dp[0][j] = 0;
    } else {
      dp[0][j] = dp[0][j - 1];
    }
  }
  for (int i = 1; i < H; i++) {
    if (A[i][0] == '#') {
      dp[i][0] = 0;
    } else {
      dp[i][0] = dp[i - 1][0];
    }
  }

  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (A[i][j] == '#') {
        dp[i][j] = 0;
      } else {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
      }
    }
  }
  cout << dp[H - 1][W - 1] << endl;
  return 0;
}

Measured memory_bytes: 9088
import itertools
N = int(input())
# A = list(range(1,N+1))
# mx = 0
# for ls in itertools.permutations(A, N):
#     #print (ls)
#     sm = sum([n%(i+1) for i,n in enumerate(ls)])
#     #print (sm)
#     mx = max(sm,mx)
# print (mx)
print (N*(N-1)//2)


Measured memory_bytes: 3060
import numpy as np

H, W = map(int, input().split())
G = np.zeros((H+2, W+2))

for i in range(1, H+1):
    s = input()
    for j in range(1, W+1):
        if s[j-1] == "#":
            G[i, j] = 1

check = True

for i in range(H):
    for j in range(W):
        if G[i+1, j+1] == 0:
            continue

        up    = G[i  , j+1]
        right = G[i+1, j+2]
        down  = G[i+2, j+1]
        left  = G[i+1, j]
        if up + right + down + left == 0:
            check = False
            break

if check:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14296
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	string s;
	cin >> s;

	int cnt = 1;
	bool seq = false;
	for (int i = 1; i < (int)s.size(); i++) {

		if (!seq && s[i] == s[i - 1]) {
			if (i != s.size() - 1) cnt++;
			i++;
			seq = true;
		}
		else {
			cnt++;
			seq = false;
		}
	}


	cout << cnt << "\n";

	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<ll> mat_mul(int n, vector<ll>& a, vector<ll>& b, ll mod) {
  vector<ll> ret(n*n);
  rep(i, n) {
    rep(j, n) {
      rep(k, n) {
        ret[i*n+j] += a[i*n+k]*b[k*n+j];
        ret[i*n+j] %= mod;
      }
    }
  }
  return ret;
}


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

  int n; cin >> n;
  ll k; cin >> k;

  vector<ll> mat(n*n);
  vector<ll> orig(n*n);

  rep(i, n*n) {
    cin >> orig[i];
  }

  rep(i, n) {
    mat[i*n+i] = 1;
  }

  while(k > 0) {
    if (k & 1) mat = mat_mul(n, mat, orig, mod);
    orig = mat_mul(n, orig, orig, mod); k >>= 1;
  }

  ll ans = 0;
  rep(i, n*n) {
    //debug(i); debugln(mat[i]);
    ans += mat[i];
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
use std::io::*;
fn main() {
 let s=std::io::stdin();
 for l in s.lock().lines(){
  let l = l.unwrap();
  let mut t=l.split_whitespace();
  let a=t.next().unwrap().parse::<i32>().unwrap();
  let b=t.next().unwrap().to_string();
  let c=t.next().unwrap().parse::<i32>().unwrap();
  let x=match &*b{
   "+"=>a+c,
   "-"=>a-c,
   "*"=>a*c,
   "/"=>a/c,
   _ => break
  };
  println!("{}",x);
 }
}


Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
// --------------------------------------------------</TEMPLATE>--------------------------------------------------


void solve()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    ll pre[n];
    pre[0]=arr[0];
    for(int i=1;i<n;i++)
        pre[i]=max(pre[i-1],arr[i]);
    ll ans=0;
    for(ll i=0;i<n;i++)
        ans+=(pre[i]-arr[i]);
    cout<<ans<<endl;
}

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


Measured memory_bytes: 6732