akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

def ky2(a,b):
    return pow(a[0]-b[0], 2) + pow(a[1]-b[1], 2)

def main():
    rr = []

    def f(n,m):
        global fr
        a = [LI() for _ in range(n)]
        es = []
        for _ in range(m):
            b,c = LI_()
            es.append([ky2(a[b],a[c]), b, c])
        es.sort(reverse=True)
        r = 0
        uf = UnionFind(n)
        for k,b,c in es:
            if uf.union(b,c):
                continue
            r += pow(k,0.5)

        return '{:0.3f}'.format(r)

    while 1:
        n,m = LI()
        if n == 0 and m == 0:
            break
        rr.append(f(n,m))
        break
        # print('rr', rr[-1])

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 16096
#include<stdio.h>
int main()
{
	int n;
	int x;
	int l[105];
	int d[105];
     int i;
     int t;
	while(~scanf("%d%d",&n,&x)){
		int q=0;
		for(i=1;i<=n;i++)
			scanf("%d",&l[i]);
			d[1]=0;
		for(t=2;t<=n+1;t++){
			d[t]=d[t-1]+l[t-1];
		}
		for(i=1;i<=n+1;i++){
			if(x>=d[i])
			q++;
			else
			break;
		}
		
		printf("%d\n",q);
		
	}
	
	
	
	return 0;
		
		
		
	}
	


Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

for p in range(1,4):
    z=0
    for i in range(n):
        z+=(abs(x[i]-y[i]))**p
    print(f'{z**(1/p):.6f}')

c=[abs(x[i]-y[i]) for i in range(n)]
print(f'{max(c):.6f}')


Measured memory_bytes: 5664
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

H, W, M = map(int, input().split())

rows = [0] * (H + 1)
cols = [0] * (W + 1)

from collections import defaultdict
ng_cols = defaultdict(set)

for _ in range(M):
    h, w = map(int, input().split())
    rows[h] += 1
    cols[w] += 1
    ng_cols[h].add(w)

max_of_rows = max(rows)
max_of_cols = max(cols)
max_rows_index = set()
max_cols_index = set()
for i in range(H + 1):
    if rows[i] == max_of_rows:
        max_rows_index.add(i)
for i in range(W + 1):
    if cols[i] == max_of_cols:
        max_cols_index.add(i)
flag = 0
for i in max_rows_index:
    for j in max_cols_index:
        if j not in ng_cols[i]:
            flag = 1
            break
print(max_of_rows + max_of_cols - 1 + flag)








Measured memory_bytes: 261500
#include <iostream>
#include <string.h>
#include <cstdio> 

#define M 1046527 	//It's a  "prime number".
#define L 14 	//Why?

char H[M][L];

int getChar(char ch)
{
	if( ch=='A' ) return 1;
	else if( ch=='C' ) return 2;
	else if( ch=='G') return 3;
	else if( ch=='T') return 4;
	else return 0;
}

long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for( i=0; i < strlen(str); i++)
	{
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) {return key % M;}
int h2(int key) {return 1 + (key % (M-1));}

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for(i=0; ;i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if ( strlen(H[h]) == 0) return 0; 
	}
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for(i=0; ;i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if ( strlen(H[h]) == 0 )
		{
			strcpy(H[h],str);
			return 0;
		}
	}
	
	return 0;
}


int main() {
	
	int n;
	scanf("%d", &n);
	
	char str[L], com[9];
	for(int i=0; i<M; i++) {H[i][0] = '\0';}
	for(int i=0; i<n; i++)
	{
		scanf("%s %s", com, str);
		if(com[0] == 'i')
		{
			insert(str);
		 } 
		 else if(com[0] == 'f')
		 {
		 	if(find(str)) printf("yes\n");
		 	else printf("no\n");
		 }
	}
	
	return 0;
}


Measured memory_bytes: 17464
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  vector<int>e(3);
  for(int i=0;i<3;i++)cin>>e[i];
  sort(e.begin(),e.end());
  if(e[0]==e[2])puts("Yes");
  else puts("No");
  return 0;
}


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

vector<int>E[100];
int in[100];
bool used[100];
int main() {
	int v, e; scanf("%d%d", &v, &e);
	rep(i, e) {
		int s, t; scanf("%d%d", &s, &t);
		E[s].push_back(t);
		in[t]++;
	}
	queue<int>que;
	rep(i, v) {
		if (!used[i] && !in[i])que.push(i);
		while (!que.empty()) {
			int p = que.front(); que.pop();
			used[p] = true;
			for (int u : E[p]) {
				in[u]--;
				if (!used[u] && !in[u])que.push(u);
			}
		}
	}
	rep(i, v) {
		if (!used[i]) {
			puts("1"); return 0;
		}
	}
	puts("0");
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
#define INF (1ll<<60)
typedef pair<li, li> PI;


vector<li> edge[100100];

li dp[100100];

li dfs(li from) {
	if (dp[from] != -1) {
		return dp[from];
	}
	li next_max = -1;
	for (auto && next : edge[from]) {
		next_max = max(next_max, dfs(next));
	}
	return dp[from] = next_max + 1;
}

int main(void)
{
	li n, m;
	cin >> n >> m;
	rep(i, n) {
		dp[i] = -1;
	}
	rep(i, m) {
		li x, y;
		cin >> x >> y;
		x--;
		y--;
		edge[x].push_back(y);
	}

	rep(i, n) {
		if (dp[i] != -1)continue;
		dfs(i);
	}

	li res = 0;
	rep(i, n) {
		res = max(res, dp[i]);
	}
	cout << res << endl;


	return 0;
}

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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
typedef long long ll;
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	int n,m,k;
	cin>>n>>m>>k;
	vector<ll> v1(n),v2(m);
	for(int i=0;i<n;i++){
		cin>>v1[i];
		if(i) v1[i]+=v1[i-1];
	}
	for(int i=0;i<m;i++){
		cin>>v2[i];
		if(i) v2[i]+=v2[i-1];
	}
	int books=0;
	for(int i=0;i<n;i++){
		if(v1[i]>k){
			break;
		}
		auto it=upper_bound(v2.begin(),v2.end(),k-v1[i]);
		it--;
		int j=it-v2.begin();
		if(j<0){
			books=max(books,i+1);
		}
		else{
			books=max(books,i+1+j+1);
		}

	}
	auto it=upper_bound(v2.begin(),v2.end(),k);
	it--;
	int j=it-v2.begin();
	if(j>0){
		books=max(j+1,books);
	}
	it=upper_bound(v1.begin(),v1.end(),k);
	it--;
	j=it-v1.begin();
	if(j>0){
		books=max(j+1,books);
	}
	cout<<books;
}

Measured memory_bytes: 6348
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(int key,int value){
  return value >= key;
}

int binary_search(vector<int> a,int key){
  int ok = a.size();
  int ng = -1;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  int k = 0;
  bool skip = false;
  rep(i,s.size()){
    if(i != s.size()-1 && s[i] == s[i+1] && !skip){
      i++;
      skip = true;
    }else skip = false;
    ++k;
  }
  print(k);
  return 0;
} 


Measured memory_bytes: 720
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      a: [usize; n],
   }
   let mut x = 0;
   for &a in a.iter().skip(2) {
      x ^= a;
   }

   let s = a[0] + a[1];
   if s < x || (s - x) % 2 == 1 {
      println!("-1");
      return;
   }
   let mut d = (s - x) / 2;
   if d > a[0] || d & x != 0 {
      println!("-1");
      return;
   }
   for i in (0..=42).rev() {
      if (x >> i) & 1 == 1 {
         let c = 1 << i;
         if d + c <= a[0] {
            d += c;
         }
      }
   }
   let ans = a[0] - d;
   if ans == a[0] {
      println!("-1");
   } else {
      println!("{}", ans);
   }
}


Measured memory_bytes: 2180
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
#include <iostream>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
 
#define debug(format, ...) printf(format, __VA_ARGS__);
 
const int N_ = int(1e5) + 10;
 
int N, A[N_], B[N_], C[N_];
ll t1[N_], t2[N_];

int main() {
#ifdef IN_MY_COMPUTER
  freopen("c.in", "r", stdin);
#endif
  scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
  sort(A+1, A+N+1);
  for(int i = 1; i <= N; i++) scanf("%d", &B[i]);
  sort(B+1, B+N+1);
  for(int i = 1; i <= N; i++) scanf("%d", &C[i]);
  sort(C+1, C+N+1);

  for(int i = 1; i <= N; i++) {
    t1[i] = t1[i-1] + lower_bound(A+1, A+N+1, B[i]) - A - 1;
  }
  for(int i = 1; i <= N; i++) {
    t2[i] = t2[i-1] + t1[lower_bound(B+1, B+N+1, C[i]) - B - 1];
  }
  printf("%lld\n", t2[N]);
  return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

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

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

int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll> >a;
    set<ll>st;
    st.insert(-1);
    st.insert(n);
    rep(i,n){
        ll s;
        cin >> s;
        a.push_back(MP(s,i));
    }
    sort(a.begin(),a.end());
    ll sm = 0;
    rep(i,n){
        ll c = a[i].first;
        ll p = a[i].second;
        auto  itr = st.lower_bound(p);
        itr--;
        ll low = *itr;
        auto  itr2 = st.upper_bound(p);
        ll high = *itr2;
        sm += c * (high-p) * (p-low);
        st.insert(p);
    }
    cout << sm << endl;
    return 0;
}

Measured memory_bytes: 13548
import java.util.Scanner;

public class Main{
	public static String calculate(String x, String y){
		StringBuilder ans = new StringBuilder();
		int sur = 0;
		int n = (x.length() > y.length()) ? y.length() : x.length();
		int m = (x.length() > y.length()) ? x.length() : y.length();
		for(int i = 0; i < n; i++){
			int a = Integer.parseInt(Character.toString(x.charAt(x.length()-i-1)));
			int b = Integer.parseInt(Character.toString(y.charAt(y.length()-i-1)));
			int p = (a+b+sur)%10;
			sur = (a+b+sur)/10;
			ans.append(String.valueOf(p));
		}
		String z = (x.length() > y.length()) ? x : y;
		for(int i = n; i < m; i++){
			int a = Integer.parseInt(Character.toString(z.charAt(z.length()-i-1)));
			int p = (a+sur)%10;
			sur = (a+sur)/10;
			ans.append(String.valueOf(p));
		}
		if( sur != 0 ){
			ans.append(sur);
		}
		String result = ans.reverse().toString();
		if( result.length() > 80 ){
			result = "overflow";
		}
		return result;
	}
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		String[] result = new String[N];
		
		for(int i = 0; i < N; i++){
			String x = stdIn.next();
			String y = stdIn.next();
			result[i] = calculate(x, y);
		}
		for(int i = 0; i < N; i++){
			System.out.println(result[i]);
		}
	}
}

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

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

    for(int i = 0; i < n; i++) {
        string data;
        cin >> data;
        int val = 0;
        int count = 0;
        vector<vector<int>> vals(1000);

        for(int j = 0; j < data.size(); j++) {
            if(data[j] == '[') {
                count++;
            }
            else if(data[j] == ']') {
                if(val != 0) {
                    vals[count].push_back((int)(val / 2) + 1);
                    val = 0;
                }
                sort(vals[count].begin(), vals[count].end());
                int sum = 0;
                for(int k = 0; k < (int)(vals[count].size() / 2) + 1; k++) {
                    sum += vals[count][k];
                }
                vals[count-1].push_back(sum);
                vals[count].clear();
                count--;
            }
            else {
                val *= 10;
                val += (int)(data[j] - '0');
            }
        }

        cout << vals[0][0] << endl;;
    }
    return 0;
}


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

#define int long long
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

template <class T = ll> T in() { T x; cin >> x; return (x); }

signed main() {
	ll n,m;
	cin >> n >> m;

	ll res[m];//あまりごとの個数
	ll dis[m];//あまりごとの緩衝材
	ll yoo[100010];//緩衝材

	REP (i,m) {res[i] = 0;dis[i] = 0;}
	REP (i,100010) {yoo[i] = 0;}
	REP (i,n) {ll x = in();res[x%m]++;yoo[x]++;}
	REP (i,100010) {dis[i%m] += (yoo[i] / 2) * 2;}

	ll ans = 0;
	ans += res[0] / 2;

	FOR (i,1,(m-1)/2+1) {
		ll A = i,B = m - i;// res[A] < res[B];
		if (res[A] == res[B]) {ans += res[A];continue;}
		else if (res[A] > res[B]) swap(A,B);
		ans += res[A] + min((res[B] - res[A]),dis[B]) / 2;
	}

	if (m%2 == 0) ans += res[m/2] / 2;
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    int ans;
    for (ans = 1; ans <= 2000; ++ans) {
        int ta = ans * 8 / 100;
        int tb = ans * 10 / 100;
        if (ta == a && tb == b) {
            cout << ans << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: isize = read();

    let mut m = 0;
    let mut ans = 0;
    for _ in 0..n {
        let p = read();
        m = max(m, p);
        ans += p;
    }

    println!("{}", ans - m / 2);
}

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


bool color[8];

int main(){
	int n;
	scanf("%d",&n);
	int grtr = 0;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(x>=1 && x<=399 && !color[0]) color[0] = 1;
		else if(x>=400 && x<=799 && !color[1]) color[1] = 1;
		else if(x>=800 && x<=1199 && !color[2]) color[2] = 1;
		else if(x>=1200 && x<=1599 && !color[3]) color[3] = 1;
		else if(x>=1600 && x<=1999 && !color[4]) color[4] = 1;
		else if(x>=2000 && x<=2399 && !color[5]) color[5] = 1;
		else if(x>=2400 && x<=2799 && !color[6]) color[6] = 1;
		else if(x>=2800 && x<=3199 && !color[7]) color[7] = 1;
		else if(x>=3200) grtr++;
	}

	int mn = 0;
	int mx = 0;
	if(grtr == n) mn = 1;
	for(int i=0;i<8;i++){
		if(color[i]) mn++;
		else if(!color[i] && grtr>0){
		 color[i] = 1;
		 grtr--;
		}
	}
	for(int i=0;i<8;i++) if(color[i]) mx++;
	if(grtr) mx+=grtr;
	cout<<mn<<" "<<mx;

}

Measured memory_bytes: 256
N = int(input())
As = [int(p) for p in input().split()]
Bs = [int(p) for p in input().split()]

count = 0
remain = 0

for a, b in zip(As, Bs + [0]):
    if a >= remain:
        count += remain
        a -= remain
    else:
        count += a
        remain = b
        continue
    if a >= b:
        count += b
        remain = 0
    else:
        count += a
        remain = b - a

print(count)


Measured memory_bytes: 18624
import queue
n,m=map(int,input().split())
a=[[] for i in range(n)]
for i in range(m):
    b,c=map(int,input().split())
    if c!=1:
        a[b-1].append(c)
    if b!=1:
        a[c-1].append(b)
d=[0 for i in range(n)]
qu=queue.Queue()
qu.put(1)
while qu.empty()==False:
    qu1=qu.get()
    for i in range(len(a[qu1-1])):
        if d[a[qu1-1][i]-1]==0:
            d[a[qu1-1][i]-1]=qu1
            qu.put(a[qu1-1][i])
for i in range(1,n):
    if d[i]==0:
        print("No")
        break
else:
    print("Yes")
    for i in range(1,n):
        print(d[i])

Measured memory_bytes: 34620
N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if(j>=weight[i]):
            dp[i+1][j]=max(dp[i][j-weight[i]]+value[i],dp[i][j])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[N][W])

Measured memory_bytes: 119916
n = int(input())
 
exp = 1000
expMin = 100
 
result = min(9, n)
while n >= exp - 1:
  result += (exp - expMin)
  expMin = exp * 10
  exp = exp * 100
  
remainder = n - (expMin - 1)
if remainder >= 0:
  result += remainder
  
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int read();

int n, a[3003];
vector<int> e[3003];
void add(int u, int v) {
    if (a[u] > a[v]) e[u].push_back(v);
    if (a[v] > a[u]) e[v].push_back(u);
}
int p[3003], win[3003];
bool cmp(int u, int v) { return a[u] < a[v]; }

int main() {
    n = read();
    for (int i = 1; i <= n; ++i) a[i] = read(), p[i] = i;
    for (int i = 1; i < n; ++i) add(read(), read());
    sort(p + 1, p + 1 + n, cmp);
    for (int i = 1; i <= n; ++i) {
        int u = p[i];
        for (int v : e[u])
            if (!win[v]) {
                win[u] = 1;
                break;
            }
    }
    for (int u = 1; u <= n; ++u)
        if (win[u]) printf("%d ", u);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}


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

using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int M = 10100001;
int mod = 1e9 + 7;
#define INF 0x3f3f3f3f
	
int main()
{

   // ios::sync_with_stdio(0);
    int a, b;
    while (~scanf("%d%d", &a, &b))
    {
    	vector<int> v;
    	for (int i = a, j = 0; j < 2019 && i <= b; j++, i++)
    		v.push_back(i%2019);
    	int ans = INF;
    	for (int i = 0; i < (int)v.size(); i++)
    		for (int j = 0; j < (int)v.size(); j++) if (i != j)
    			ans = min(ans, v[i]*v[j] % 2019);
    	printf("%d\n", ans);
    }
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <bits/stdc++.h>
#include <algorithm>
#include <cctype>
using namespace std ;

int main(){
    string s ;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" ;
    else cout<< "No" ;
    return  0 ;
    }

    


Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if 0 in a:
    print(0)
    exit()
p = 1
for x in a:
    p *= x
    if p>10**18:
        print(-1)
        exit()
print(p)


Measured memory_bytes: 82916
x = int(input())


if x >= 400 and x <= 599:
    print('8')
if x >= 600 and x <= 799:
    print('7')
if x >= 800 and x <= 999:
    print('6')
if x >= 1000 and x <= 1199:
    print('5')
if x >= 1200 and x <= 1399:
    print('4')
if x >= 1400 and x <= 1599:
    print('3')
if x >= 1600 and x <= 1799:
    print('2')
if x >= 1800 and x <= 1999:
    print('1')





Measured memory_bytes: 9184
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const A = inputList[0].split(" ")[0];
    const B = inputList[0].split(" ")[1];

    console.log(parseInt(A) * parseInt(B));

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll cr=0,cg=0,cb=0;
    for (int i=0;i<n;i++){
        if (s[i]=='R'){
            cr+=1;
        }
        else if (s[i]=='G'){
            cg+=1;
        }
        else{
            cb+=1;
        }
    }
    ll ans1=0;
    for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
            if (s[i]==s[j]){
                continue;
            }
            else{
                int d=j-i;
                if (j+d>=n){
                    continue;
                }
                else{
                    if (s[i]!=s[j] && s[i]!=s[j+d] && s[j]!=s[j+d]){
                        ans1+=1;
                    }
                }
            }
        }
    }
    ll ans=cr*cg*cb;
    cout<<ans-ans1<<endl;

    

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

#define PI 3.1415926535897932

int main() {
  int a,b; double x;
  cin>>a>>b>>x;
  int a2=a*a;
  x/=a2*b;
  cout<<setprecision(12);
  if(x>=0.5){
    cout<<atan((2*b*(1-x))/a)/PI*180;
  }else{
    cout<<atan((double)b/(2*a*x))/PI*180;
  }
}


Measured memory_bytes: 384
#include<stdio.h>
#include <math.h>

int MAX = 100;
int INFTY = 999999;
int WHITE = 0;
int GRAY = 1;
int BLACK = 2;

int n;
int M[100][100];

int prim(int n) {

  int u, minv;
  int d[MAX], p[MAX], color [MAX];

  int i,v;

  int sum = 0;

  d[0]=0;
  
  for (i = 0; i <n; i++ ) {

    if(i!=0) d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;

  }
  
  while ( 1< 2 ) {

    minv = INFTY;

    u = -1;

    for ( i = 0; i < n; i++ ) {
      if ( color[i] != BLACK && minv > d[i]  ) {

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

	if ( d[v] > M[u][v] && u!=-1) {
	 

	  d[v] = M[u][v];
	  p[v] = u;
	  color [v] = GRAY;
	}
      }
    }

    if ( u == -1 ) break;
  }

  for (i = 0; i<n; i++) {
    
    if ( p[i] != -1 ) sum = sum + M[i][p[i]];

  }
  
  return sum;
}


int main() {

  scanf("%d",&n);

  int i,j;

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

    for (j = 0; j<n; j++ ) {
  

      scanf("%d",&e);

      if(e==-1){

	M[i][j]=INFTY;
      }
      else{

	M[i][j]=e;
      }
      
      
    }
  }
  
  printf("%d\n",prim(n));

  return 0;
}



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

#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

signed main(){

  int a, b, r, x, tmp;

    cin >> a >> b ;
   x = a * b;

if(a<b){
    tmp = a;
    a = b;
    b = tmp;
}
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
cout <<x/b; 
  return 0;



             }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.size()==26){
		string t=s;
		if(!next_permutation(t.begin(),t.end()))cout<<-1<<endl;
		else{
			for(int n=0;n<s.size();n++){
				if(s[n]!=t[n]){
					cout<<t.substr(0,n+1)<<endl;
					break;
				}
			}
		}
	}else{
		for(char c='a';c<='z';c++){
			if(all_of(s.begin(),s.end(),[&](char e){
				return e!=c;
			})){
				cout<<s<<c<<endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 256
n=int(input())
s=[]
for i in range(n):
    s.append(str(input()))
m=int(input())
t=[]
for i in range(m):
    t.append(str(input()))

ln=s+t
ans=[]
for i in range(len(ln)):
    ctr=0
    test=ln[i]
    for k in range(n):
        if s[k]==test:
            ctr+=1
    for j in range(m):
        if t[j]==test:
            ctr-=1
    ans.append(ctr)

if max(ans)>=0:
    print(max(ans))  
else:
    print(0)


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

int g(int a, int b) {
  if (a <= b && b % a == 0)
    return a;
  else if (a > b && a % b == 0)
    return b;
  else if (a <= b && b % a != 0)
    return g(a, b % a);
  else if (a > b && a % b != 0)
    return g(a % b, b);
}

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

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

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

  int min = a[n - 1];
  for (int i = 0; i < n - 1; i++) {
    if (min > g(a[i], a[i + 1])) min = g(a[i], a[i + 1]);
  }

  cout << min << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    string S,T; cin>>S>>T;
    int res = 0;
    for(int i = 0; i < S.size(); i++)if(S[i]!=T[i])res++;
    cout<<res<<endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

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

  if (A + B >= 24) cout << A + B - 24 << endl;
  else cout << A + B << endl;
  
  return 0;
}


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

int main(){
    int64_t K, N, ans;
    cin >> K;
    N = 7;
    ans = -1;
    for(int i = 0; i < 1000000; i++){
        if(N % K == 0){
            ans = i + 1;
            break;
        }
        else
            N = (N * 10 + 7) % K;
      
    }
    cout << ans << endl;
}

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

const int mod = 998244353;


int main(){

    
    long long n;
    long long ans = 1;
    std::map<long long,long long> um;
    std::cin>>n;
    for(long long i=0;i<n;i++){
        long long tmp;
        std::cin>>tmp;
        um[tmp]++;
        if(i && !tmp)ans = 0;//頂点2~で1との距離が0の場合
        if(!i && tmp)ans = 0;//頂点1が0で無い場合
    }

	int prev = -1, cnt = 1;
	for (auto i : um) {
		if (i.first != prev + 1) ans = 0;
		prev = i.first;
		for (int j = 0; j < i.second; j++) ans = ans * cnt % 998244353;
		cnt = i.second;
	}

    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 6528
N, M, X = map(int, input().split())
CA = [0]*N
for i in range(N):
    CA[i] = list(map(int, input().split()))

INF = 10**7
ans = INF
for t in range(2**N):
    tmp = 0
    check = [X]*M
    for i in range(N):
        if (t >> i) & 1 == 1:
            tmp += CA[i][0]
            for j in range(M):
                check[j] -= CA[i][j+1]
    for ch in check:
        if ch > 0:
            break
    else:
        if tmp < ans:
            ans = tmp

if ans == INF:
    print(-1)
else:
    print(ans)


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int w,h,n;

int main(){
  cin >> w>>h>>n;
  int l_x=0,h_x=w,l_y=0,h_y=h;
  REP(i,n){
    int x,y,a;
    cin >> x>>y>>a;
    if(a==1){
      l_x = max(l_x,x);
    }else if(a==2){
      h_x = min(h_x,x);
    }else if(a==3){
      l_y = max(l_y,y);
    }else{
      h_y = min(h_y,y);
    }
  }
  cout << max(0,(h_x-l_x)) * max(0,(h_y-l_y)) << endl;
}


Measured memory_bytes: 256
//This template belongs to Juan Carlo Vieri
#include <bits/stdc++.h>
using namespace std;

typedef int_fast64_t ll;
typedef long double ld;
typedef int_fast64_t intt;
typedef int_fast64_t tmp_m;
#define deb(x) cout << #x << ' ' << x << endl
#define rep(i, cmp1, cmp2) for (tmp_m i = cmp1; i < cmp2; ++i)
#define repp(i, cmp1, cmp2) for (tmp_m i = cmp1; i >= cmp2; --i)
#define pb push_back
#define st stack
#define pa pair
#define vc vector
#define qu queue
#define pq priority_queue
#define fr first
#define sc second
#define mp map
const ld pi = acos(-1.0);
const intt mod = 1e9 + 7;

struct pr {
  intt x;
  intt y;
  intt dst;
  pr() {}
  pr(intt x, intt y, intt dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst < cmp2.dst;
    if (x != cmp2.x) return x < cmp2.x;
    return y < cmp2.y;
  }
  inline bool operator==(const pr& cmp2) const {
    return (cmp2.dst == dst) && (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst > cmp2.dst;
    if (x != cmp2.x) return x > cmp2.x;
    return y > cmp2.y;
  }
};

struct point {
  intt x;
  intt y;
  point() {}
  point(intt x, intt y) : x(x), y(y) {}
  inline bool operator<(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x < x;
    return cmp2.y < y;
  }
  inline bool operator==(const point& cmp2) const {
    return (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x > x;
    return cmp2.y > y;
  }
};

class prHash {
 public:
  size_t operator()(const pr& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y)) ^
           (hash<intt>()(cmp1.dst));
  }
};

class pointHash {
 public:
  size_t operator()(const point& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y));
  }
};

inline bool spoint(const point& cmp1, const point& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

inline bool spr(const pr& cmp1, const pr& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.dst != cmp2.dst) return cmp1.dst < cmp2.dst;
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

intt vis[200005];

void solve() {
  intt n, k;
  cin >> n >> k;
  vc<intt> arr(n);
  rep(i, 0, n) {
    cin >> arr[i];
    --arr[i];
  }
  vc<intt> path;
  intt cur = 0;
  while (1) {
    if (vis[cur])break;
    path.pb(cur);
    vis[cur] = 1;
    cur = arr[cur];
  }
  intt indx = 0;
  rep(i, 0, (intt)path.size()) {
    if (cur == path[i]) {
      indx = i;
      break;
    }
  }
  // deb(indx);
  // deb(cur);
  // for(auto i : path)cout << i << endl;
  if(k < indx){
    cout << path[k] + 1 << endl;
    return;
  }
  cout << path[(k - indx) % (path.size() - indx) + indx] + 1 << endl;
}

void init() {
  // remove if interactive
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  // memset(dp, -1, sizeof dp);
}

int main() {
  init();
  solve();
  return 0;
}


Measured memory_bytes: 8372
n, m, l = gets.split(" ").map(&:to_i)

a = Array.new(n).map{Array.new(m+1, 0)}
b = Array.new(m+1).map{Array.new(l, 0)}
c = Array.new(n).map{Array.new(l, 0)}

n.times { |d|
  a[d] = gets.split.map(&:to_i)
}

m.times { |e|
  b[e] = gets.split.map(&:to_i)
}

for i in 0..n-1
  for j in 0..l-1
    for k in 0..m-1
      c[i][j] += a[i][k] * b[k][j]
    end
  end
end

n.times { |l|
  puts c[l].join(" ")
} 

Measured memory_bytes: 9388
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long

using namespace std;

typedef long long ll;

int A[200010], n;

ll F[200010][3];

signed main() {
    scanf("%lld", &n);
    ll tot = 0;
    for(int i = 1; i <= n; i++) scanf("%lld", &A[i]), tot += A[i];
    for(int i = 1; i <= n; i++)
        if(!A[i]) {
            F[i][0] = max(-2ll, F[i - 1][0] - 2);
            F[i][1] = max(-1ll, max(F[i - 1][0] - 1, F[i - 1][1] - 1));
            F[i][2] = max(F[i - 1][1] - 2, F[i - 1][2] - 2);
        } else if(A[i] % 2 == 0) {
            F[i][0] = max(A[i], F[i - 1][0] + A[i]);
            F[i][1] = max(A[i] - 1, max(F[i - 1][0] + A[i] - 1, F[i - 1][1] + A[i] - 1));
            F[i][2] = max(F[i - 1][1] + A[i], F[i - 1][2] + A[i]);
        } else {
            F[i][0] = max(A[i] - 1, F[i - 1][0] + A[i] - 1);
            F[i][1] = max(A[i], max(F[i - 1][0] + A[i], F[i - 1][1] + A[i]));
            F[i][2] = max(F[i - 1][1] + A[i] - 1, F[i - 1][2] + A[i] - 1);
        }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
        ans = max(ans, max(F[i][0], max(F[i][1], F[i][2])));
    printf("%lld\n", tot - ans);
    return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
using namespace std;
void printArray(int a[],int n){
    for(int i=0;i<n;i++){
        cout << a[i];
        if(i<n-1){
            cout << " ";
        }
    }
    cout << endl;
}
void insertSort(int a[],int n){
    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;
        printArray(a,n);
    }
}
int main(){
    int n;
    cin >> n;
    int a[n];
    if(n>=1 && n<=100){
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        printArray(a,n);
        insertSort(a,n);
    }else{
        return 0;
    }
    return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORTR(x) sort(ALLR(x))
#define SORT(x) sort(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<char> VC;
typedef vector<VC> VVC;
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 <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}


/////////////////////SUMに；；；；；；；；
void Main()
{
	ll N;
	string result="No";
	cin>>N;
	VI L(N);
	REP(i, N) cin >> L[i];
	SORTR(L);

	ll maxLen=L[0];
	ll other=SUM(L)	-L[0];
	if(maxLen<other) result="Yes";

	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(n);i++)
#define fori(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;


// 3 1 2 2 1
// 1 1 2 2 3
// (1 1) 2 2 3 need = nsm - sm


int main(){
	double n;
	cin>>n;
	//cout<<(float)((n/3)*(n/3)*(n/3));
	printf("%0.9f", (n/3)*(n/3)*(n/3));
	return 0;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  if(a!=b&&a!=c&&b==c){cout<<"Yes"<<endl;}
  else if(a==b&&a!=c&&b!=c){cout<<"Yes"<<endl;}
  else if(a!=b&&a==c&&b!=c){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
        int count = 0;
        int money = 0;
        int sum_count = 0;
        int sum_money = 0;
        int n = 0;
        double aved =0.0;
        int avei = 0.0;
        while(scanf("%d,%d", &money, &count) != EOF)
        {
                sum_money = sum_money + money * count;
                sum_count = sum_count + count;
                n++;
        }

        avei = sum_count / n;
        aved = (double)sum_count / n;

        if(aved - avei >= 0.5)
        {
                avei++;
        }
        else
        {
                avei=avei;
        }

        printf("%d\n", sum_money);
        printf("%d\n", avei);

        return 0;
}

Measured memory_bytes: 592
using System;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var sct = 0;
        for(var i = 0; i < str.Length; i++)
            if (str[i] == 'S')
                sct++;
            else if (sct > 0)
                sct--;
        WriteLine(sct * 2);
    }
}


Measured memory_bytes: 11616
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	int  T[N];
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	int M;
	cin >> M;
	int P[M], X[M];
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> X[i];
	}
	for (int i = 0; i < M; i++) {
		long long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += T[i];
		}
		cout << sum - T[P[i]-1] + X[i] << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    long int ans;
    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    } else if (n == 2)
    {
        cout << 1 << endl;
        return 0;
    }
    
    
    ans = (long int)(n - 1) * (n) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	int A,B;
	char S[30];
	char T[30];
	char U[30];

	scanf("%s %s",S,T);
	scanf("%d %d",&A,&B);
	scanf("%s",U);
	if(strcmp(S,U)==0)
	{
		A--;
		printf("%d %d", A,B);
	}
	else 
	{
		B--;
		printf("%d %d", A,B);
	}
return 0;
}

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

vector<int> seen;

void dfs(int v, const vector<vector<int>> &G, vector<int> &cnt) {
    seen[v] = 1;
    for (int nv : G.at(v)) {
        if (seen.at(nv)) continue;
        cnt.at(nv) += cnt.at(v);
        dfs(nv, G, cnt);
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> G(N);
    for (int i = 0, a, b; i < N - 1 && cin >> a >> b; i++) {
        G.at(--a).push_back(--b);
        G.at(b).push_back(a);
    }
    vector<int> cnt(N);
    for (int i = 0, p, x; cin >> p >> x; i++) {
     cnt.at(--p) += x;
    }
    
    seen.resize(N);
    dfs(0, G, cnt);
    
    for (int i : cnt) cout << i << "\n";
}

Measured memory_bytes: 27392
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        System.out.println(s.substring(0, 1) + (s.length() - 2) + s.substring(s.length() - 1, s.length()));
    }
}

Measured memory_bytes: 21076
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main2(): 
    N, W = LI()
    things = []
    for i in range(N):
        things.append(LI())

    knapsack_dp = [[0 for _ in range(W+1)] for _ in range(N)]

    for i, wv in enumerate(things):  # 10**2
        w, v = wv
        if i == 0:
            for weight in range(W+1):  # 10**5
                knapsack_dp[i][weight] = 0 if weight < w else v
        else:
            for weight in range(W+1):
                if weight-w < 0:
                    knapsack_dp[i][weight] = knapsack_dp[i-1][weight]
                else:
                    knapsack_dp[i][weight] = max(knapsack_dp[i-1][weight], knapsack_dp[i-1][weight-w]+v)

    print(knapsack_dp[N-1][W])

def main():
    N, W = LI()
    things = []
    for i in range(N):
        things.append(LI())

    knapsack_dp = [[0 for _ in range(W+1)] for _ in range(N)]

    # knapsack_dp[考慮した品物][その重さピッタリの重さ] = 価値 とする。
    for i, wv in enumerate(things):  # 10**2
        w, v = wv
        if i == 0:
            for weight in range(W+1):  # 10**5
                knapsack_dp[i][weight] = 0 if weight != w else v
        else:
            for weight in range(W+1):
                if weight-w < 0:
                    knapsack_dp[i][weight] = knapsack_dp[i-1][weight]
                else:
                    knapsack_dp[i][weight] = max(knapsack_dp[i-1][weight], knapsack_dp[i-1][weight-w]+v)

    print(max(knapsack_dp[N-1]))

main()

Measured memory_bytes: 170632
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
 
 
public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		
		
		int N = Integer.parseInt(sc.next());
		//int Q = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		int ans = (N-2)*180;		
		System.out.println(ans);
		
		
		
	}
	
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	  cin.tie(NULL);
	  cout.tie(NULL);
    char s[101];
    int i,len,c=0;
    cin>>s;
    len=strlen(s);
    for(i=0;i<len;i++){
      if(i%2==0 && s[i]=='L'){
        c++;
        break;
      }
      else if (i%2!=0 && s[i]=='R'){
        c++;
        break;
      }
    }
    if(c==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

const int v_size = 100;
const int e_size = 10000;
int v, e;
int s[e_size];
int t[e_size];
int_t d[e_size];

bool input() {
  if (cin >> v >> e) {
    rep (i, e) cin >> s[i] >> t[i] >> d[i];
    return true;
  }
  return false;
}

const int_t inf = numeric_limits<int_t>::max();
int_t g[v_size][v_size];

void solve() {
  rep (i, v_size) fill(g[i], g[i]+v, inf);
  rep (i, v_size) g[i][i] = 0;
  rep (i, e) g[s[i]][t[i]] = d[i];

  for (int k = 0; k < v; ++k) {
    for (int i = 0; i < v; ++i) {
      for (int j = 0; j < v; ++j) {
        if (g[i][k] == inf || g[k][j] == inf) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  rep (i, v) {
    if (g[i][i] != 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return;
    }
  }

  rep (i, v) {
    rep (j, v) {
      if (j > 0) cout << " ";
      if (g[i][j] == inf) {
        cout << "INF";
      } else {
        cout << g[i][j];
      }
    }
    cout << endl;
  }
}

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



Measured memory_bytes: 3348