akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std ;


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ;
	cin >> n ;
	int cnt = 0 ;
	bool ans = false  ; 
	for(int i = 0; i < n ; ++i)
	{
		int u , v; 
		cin >> u >> v ; 
		if(u==v)
			cnt++ ;
		else
			cnt = 0;
		if(cnt == 3 )
			ans = true ; ; 	 		
	}
	if(ans )
		puts("Yes") ; 
	else 
		puts("No") ; 
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int ans = 0;
	rep(i, 0, N) {
		int l, r; cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  char c;
  cin >> c;

  if (c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o'){
  cout << "vowel" << endl;
      }
  else{
  cout << "consonant" << endl;
      }

}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

using P = pair<int, int>;
constexpr int INF = 1001001001;

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

int main(){
    int K;
    cin >> K;
    vector<vector<P>> graph(K);
    for(int i = 1; i < K; ++i){
        int u = (i + 1) % K;
        int v = i * 10 % K;
        graph[i].emplace_back(u, 1);
        graph[i].emplace_back(v, 0);
    }
    vector<int> dist(K, INF);
    dist[1] = 1;
    deque<int> deq;
    deq.push_back(1);
    while(!deq.empty()){
        int from = deq.front();
        deq.pop_front();
        for(auto& e : graph[from]){
            int to = e.first, cost = e.second;
            if(!cost){
                if(chmin(dist[to], dist[from])) deq.push_front(to);
            }
            else{
                if(chmin(dist[to], dist[from] + 1)) deq.push_back(to);
            }
        }
    }
    cout << dist[0] << endl;
}

Measured memory_bytes: 9412
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

ll mod_pow(ll a, ll p)
{
	if (p == 0)return 1;
	else if (p == 1)return a;
	else if (p % 2 == 0)
	{
		ll h = mod_pow(a, p / 2);
		return h * h % mod;
	}
	else return (mod_pow(a, p - 1) * a) % mod;
}

map<ll, int> prime_factor(ll n)
{
	ll k = n;
	map<ll, int> res;
	for (ll i = 2; i * i <= n; i++)
	{
		while (k % i == 0)
		{
			res[i]++;
			k /= i;
		}
	}
	if (k > 1)res[k]++;
	return res;
}

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

	int n;
	cin >> n;
	vl a(n);
	rep(i, n)cin >> a[i];
	map<ll, int> l_factor;
	rep(i, n)
	{
		auto tmp = prime_factor(a[i]);
		for (auto e : tmp)
		{
			ll prime = e.first;
			int x = e.second;
			chmax(l_factor[prime], x);
		}
	}
	ll l = 1;
	for (auto e : l_factor)
	{
		ll prime = e.first;
		int x = e.second;
		rep(i, x)
		{
			l *= prime;
			l %= mod;
		}
	}
	ll ans = 0;
	rep(i, n)
	{
		ans += (l * mod_pow(a[i], mod - 2)) % mod;
		ans %= mod;
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  int cnt_lr = 0, cnt_rl = 0;
  int hap = 0;
  rep(i,n-1){
    if(s[i]=='L'&&s[i+1]=='R') cnt_lr++;
    if(s[i]=='R'&&s[i+1]=='L') cnt_rl++;
    if(s[i]==s[i+1]) hap++;
  }
  // int cnt = min(k,min(cnt_lr,cnt_rl));
  //
  // cerr << hap SP cnt_lr SP cnt_rl SP cnt << endl;
  int cnt = 0;
  while(cnt<k&&cnt_lr&&cnt_rl){
    hap += 2; cnt++;
    cnt_lr--; cnt_rl--;
  }
  if(cnt<k&&max(cnt_lr,cnt_rl)) hap++;

  // int ans = hap+cnt*2;
  // if((cnt_lr+cnt_rl)&&(!cnt)) ans++;
  // cout << min(n,ans) << endl;
  cout << min(n,hap) << endl;


  return 0;
}


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

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

    int a, b, c;
    cin >> a >> b >> c;
    if((a + b + c) >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdio.h>
int main(){
    
    int n=0,l,i;
    char ch[50];
    scanf("%s",&ch);
    l=strlen(ch);
    for(i=0;i<l;i++){
        if(ch[i]=='o'){
            n++;
        }
    }
    if((15-l+n)>=8){
    printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
s = input()[::-1].replace('CB', 'x')
# print(s)

x = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'x':
        x += 1
    elif s[i] == 'A':
        ans += x
    else:
        x = 0


print(ans)


Measured memory_bytes: 3500
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    static long[] fact = new long[100];
    static int[] coin;
    static int[][] a;
    static int n,m,x;
    static int print = INF;
        public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
         n = sc.nextInt();
         m = sc.nextInt();
         x = sc.nextInt();
        coin = new int[n];
        a = new int[n][m];
        for(int i = 0;i < n;i++){
            coin[i] = sc.nextInt();
            for(int j = 0;j < m;j++){
                a[i][j] = sc.nextInt();
            }
        }
        int[] ary = new int[m];
        dfs(0,ary,0);
        if(print == INF)print = -1;
        System.out.println(print);
    }
    static void dfs(int i,int[] ary,int ans){
        //x超えてるかチェック
        boolean poyo = true;
        for(int s = 0;s < m;s++){
            if(ary[s] < x)poyo = false;
        }
        if(poyo){
            if(print > ans)print = ans;
            return;
        }
        if(i==n)return;
        dfs(i+1,ary,ans);
        int[] tmp = new int[m];
        for(int s = 0;s < m;s++){
            tmp[s] = ary[s]+a[i][s];
        }
        ans+=coin[i];
        dfs(i+1,tmp,ans);
    }
    
}


Measured memory_bytes: 38636
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    elif H==0 or W==0:
        print()
    elif 0<H<=2:
        for i in range(H):
            print("#"*W)
        print()
    else:
        print("#"*W)
        for i in range(1,H-1):
            print(f'{"#"}{"."*(W-2)}{"#"}')
        print("#"*W)
        print()


Measured memory_bytes: 5620
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAXN 200005
#define LL long long
LL inv[MAXN],s[MAXN];
int N;
int n,m,x,y;
LL Pow(LL a,int b)
{
    LL ans=1;
    while(b)
	{
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return ans;
}
void Pre()
{
    s[0]=1;
    for(int i=1; i<=N; i++)
        s[i]=s[i-1]*i%MOD;
    inv[0]=1;
    inv[N]=Pow(s[N],MOD-2);
    for(int i=N-1; i>0; i--)
        inv[i]=inv[i+1]*(i+1)%MOD;
}
LL C(int a,int b)
{
    if(a<0||b<0) return 1;
    return s[a]*inv[b]%MOD*inv[a-b]%MOD;
}
int main()
{

    scanf("%d%d",&n,&m);
    scanf("%d%d",&x,&y);
    N=n+m-2;
    Pre();
    LL ans=0;
    for(int i=y+1;i<=m;i++)
    {
        //cout<<1<<endl;
        ans+=C(n-x+i-2,i-1)*C(x+m-i-1,x-1)%MOD;
        ans%=MOD;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int read(){
	int a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(int x){
	char y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
ll n,K,ans,mod=1e9+7,dp[55][55][2515]={1};
int main(){
	n=read(),K=read();
	if(K%2)return puts("0"),0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
			for(int k=2*j;k<=K;k++)
				dp[i][j][k]=((2*j+1)*dp[i-1][j][k-2*j]+((i-2>=j)?dp[i-1][j+1][k-2*j]*(j+1)*(j+1):0)+(j>0?dp[i-1][j-1][k-2*j]:0))%mod;
	print(dp[n][0][K]);
	return 0;
}

Measured memory_bytes: 26496
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, M, Q, L, R, a[500][500];

int slove(int l, int r) {
	if (l) {
		return a[r][r] - a[l - 1][r] - a[r][l - 1] + a[l - 1][l - 1];
	}
	else {
		return a[r][r];
	}
}

int main(){
	cin >> N >> M >> Q;
	while (M--) {
		cin >> L >> R;
		++a[L - 1][R - 1];
	}
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			a[i][j] += a[i - 1][j];
		}
	}
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			a[j][i] += a[j][i - 1];
		}
	}
	while (Q--) {
		cin >> L >> R;
		cout << slove(L - 1, R - 1) << endl;
	}
	return 0;
}



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

using namespace std;

int main() {
  int e;
  while (true) {
    cin >> e;
    if (e == 0) break;

    int ans = 1e9;
    for (int y = 0; y <= 1000; y++) {
      for (int z = 0; z <= 100; z++) {
        int x = e - y * y - z * z * z;
        if (x < 0) continue;
        ans = min(ans, x + y + z);
      }
    }
    cout << ans << "\n";
  }

  return 0;
}


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

int main(){
	int n;cin>>n;
	string s;cin>>s;
	map<char,int>cnt1,cnt2;
	int mn=0,cur=0;
	for(auto&& u:s)cnt1[u]++;
	for(auto&& u:s){
		if(cnt1[u]>1&&cnt2[u]==0)cur++;
		cnt2[u]++;
		if(cnt1[u]>1&&cnt1[u]==cnt2[u])cur--;
		mn=max(mn,cur);
	}
	cout<<mn<<endl;
}

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

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

  unordered_set<long> ahash;
  long a;
  for (int i=0;i<n;i++){
    cin >> a;
    if (!ahash.emplace(a).second)
      ahash.erase(a);
  }
  
  cout << ahash.size() << endl;
  
  return 0;
}


Measured memory_bytes: 4388
S = str(input())
count = 0
if S == "hi":
    count = 1
if S == "hihi":
    count = 1
if S == "hihihi":
    count = 1
if S == "hihihihi":
    count = 1
if S == "hihihihihi":
    count = 1
if count ==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<stack>

using namespace std;

int main() {
	stack<int> s;
	int n;
	while (cin >> n) {
		if (n) {
			s.push(n);
		}
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}
	return 0;
}

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

int N,Q;
vector<vector<ll> > G(200010);
vector<ll> cost(200010);
vector<bool> visited(200010,false);

void dfs(int v, int pv){
    visited[v] = true;
    if(v != 0)cost[v]+=cost[pv];
    for(auto nv: G[v]){
        if(visited[nv] == false) dfs(nv, v);
    }
}

int main(){
    cin >> N >> Q;
    
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    
    rep(i,Q){
        int a,b; cin >> a >> b;
        a--;
        cost[a] += b;
    }

    dfs(0,0);
    rep(i,N-1) cout << cost[i] << " ";
    cout << cost[N-1] << endl;
}

Measured memory_bytes: 24320
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w, n := iScan(), iScan(), iScan()
	d := make(map[[2]int]int)
	for i := 0; i < n; i++ {
		a, b := iScan(), iScan()
		for j := -1; j <= 1; j++ {
			for k := -1; k <= 1; k++ {
				d[[2]int{a + j, b + k}]++
			}
		}
	}
	ans := make([]int, 10)
	for k, v := range d {
		if 1 < k[0] && k[0] < h && 1 < k[1] && k[1] < w {
			ans[v]++
		}
	}
	fmt.Println((h-2)*(w-2) - sum(ans))
	for _, v := range ans[1:] {
		fmt.Println(v)
	}
}


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


int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double mmax=a*a*b;

    double r = 180.0/M_PI;
    double ans;

    if(x>mmax/2){
        double save=mmax-x;
        double len = (2*save)/(a*a);
        double tt=len/a;
        ans=atan(tt);
        ans*=r;

    }
    else{
        double len = (2*x)/(a*b);
        double tt = b/len;
        ans=atan(tt);
        ans*=r;
    }

    printf("%.16lf\n",ans);
}

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

int main()
{
  int W,N,v,w,i,j;
  int cnt=0,maxv,maxw;
  vector< vector<int> > dp;
  while(cin>>W>>N,W){
    vector< vector<int> > dp(N+2,vector<int>(W+1));
    for(i=1;i<=N;i++){
      scanf("%d,%d",&v,&w);
      for(j=0;j<=W;j++){
	if(j>=w && dp[i-1][j] < dp[i-1][j-w]+v)dp[i][j]=dp[i-1][j-w]+v;
	else dp[i][j]=dp[i-1][j];
      }
    }
    maxv=maxw=0;
    for(j=0;j<=W;j++){
      if(maxv<dp[N][j]){maxv=dp[N][j];maxw=j;}
    }
    printf("Case %d:\n%d\n%d\n",++cnt,maxv,maxw);
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s; cin >> s;
    ll ans = 0, cnt = 0, n = s.size();
    REP(i, n) {
        char te = i >= (n+1)/2 ? 'p' : 'g';
        if (s[i] == 'p') --ans;
        if (te == 'p') ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
module Main(main) where

import           Data.List (intercalate, sortBy)

-- | solve
-- (行数, 市名, 点数)
--
-- >>> solve [(1, "khabarovsk", 20), (2, "moscow", 10), (3, "kazan", 50), (4, "kazan", 35), (5, "moscow", 60), (6, "khabarovsk", 40)]
-- [3,4,6,1,5,2]
--
-- >>> solve [(1, "yakutsk", 10), (2, "yakutsk", 20), (3, "yakutsk", 30), (4, "yakutsk", 40), (5, "yakutsk", 50), (6, "yakutsk", 60), (7, "yakutsk", 70), (8, "yakutsk", 80), (9, "yakutsk", 90), (10, "yakutsk", 100)]
-- [10,9,8,7,6,5,4,3,2,1]
--
--
--
solve :: [(Int, String, Int)] -> [Int]
solve = map fst' . sortBy predicate


predicate :: (Int, String, Int) -> (Int, String, Int) -> Ordering
predicate (_, aname, apoint) (_, bname, bpoint) = case aname `compare` bname of
        EQ  -> (flip compare) apoint bpoint
        res -> res

fst' (a, _, _) = a


genTuple :: [[String]] -> [(Int, String ,Int)]
genTuple = zipWith (\n [s, p] -> (n, s, read p)) [1..]


main :: IO ()
main = do
    getLine
    input <- map words . lines <$> getContents
    let ts = genTuple input
        res = solve ts
    putStrLn . intercalate "\n" . map show $ res


Measured memory_bytes: 1020
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]

max_A=max(AB)[0]
DP=[0]+[float("inf")]*(h+max_A)
for i in range(h+1):
    if DP[i]==float("inf"):continue
    for a,b in AB:
        t=DP[i]+b
        if t<DP[i+a]:
            DP[i+a]=t

print(min(DP[h:]))

Measured memory_bytes: 42844
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N; map<ll, int>mp;
  rep(i, N){
    ll a; cin >> a; mp[a]++;
  }
  vector<ll> tmp, pmt;
  for(auto k: mp){
    if(k.second>=2) tmp.push_back(k.first);
    if(k.second>=4) pmt.push_back(k.first);
  }
  sort(tmp.begin(), tmp.end(), greater<>());
  sort(pmt.begin(), pmt.end(), greater<>());
  if(pmt.size()>0 && tmp.size()>=2){
    cout << max(pmt[0]*pmt[0], tmp[0]*tmp[1]) << endl; return 0;
  }
  if(pmt.size()){
    cout << pmt[0]*pmt[0] << endl; return 0;
  }
  else if(tmp.size()>=2){
    cout << tmp[0]*tmp[1] << endl; return 0;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 6528
/*A - Blackjack*/

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int ans = 0;
	int n;

	for (int i = 0; i < 3; ++i)
	{
		cin >> n;
		ans += n;
	}

	if(ans >= 22)
		cout << "bust";
	else
		cout << "win";

	return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B, X;
    cin >> A >> B >> X;
    if(A <= X && A+B >= X) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define SHOWVEC(v, n) for(int _i = 0; _i < n; _i++) cerr << v[_i] << ' '; cerr << endl;

using namespace std;
typedef long long ll;

int main()
{
  int N; cin >> N;
  map<string, ll> mp;
  REP(i, N) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto e : mp) {
    ll num = e.second;
    ans += num * (num - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 11136
#include <stdio.h>

int main(void)
{
        int n,i;
        double s,c;

        scanf("%d",&n);

        int a[n];

        for(i=0;i<n;i++)
                scanf("%d",&a[i]);

        for(i=0;i<n;i++){
                s=s+1/(double)a[i];
        }

        c=1/s;

        printf("%lf",c);

        return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

const M = 13

func main() {
	var s string
	fmt.Scan(&s)

	dp := make([][]int64, len(s)+1)
	dp[0] = make([]int64, M)
	dp[0][0] = 1

	md := int64(1000000000 + 7)

	remUnit := 1

	for i := 0; i < len(s); i++ {
		// 左の桁から計算しても同じだが、小さい桁からやる方が直感的。
		idx := len(s) - i - 1
		r := s[idx]

		dp[i+1] = make([]int64, M)

		if r == '?' {
			for q := 0; q <= 9; q++ {
				rem := (q * remUnit) % M
				for di, prev := range dp[i] {
					k := (di + rem) % M
					dp[i+1][k] = (dp[i+1][k] + prev) % md
				}
			}
		} else {
			d := int(r) - '0'
			rem := (d * remUnit) % M
			for di, prev := range dp[i] {
				k := (di + rem) % M
				dp[i+1][k] = prev
			}
		}

		remUnit = (remUnit * 10 % M) % M
	}

	fmt.Println(dp[len(s)][5])
}


Measured memory_bytes: 14592
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <numeric> // accumulate

using namespace std;

int main() {
  int N;
  int x;
  vector <int> v;

  cin >> N >> x;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    v.push_back(num);
  }
  sort(v.begin(), v.end());

  int rest = x;
  int count = 0;
  for (auto it = v.begin(); it != v.end(); it++){
    // この人にも配れるようであれば配って、人数をインクリメント
    if (rest >= *it) {
      rest -= *it;
      count++;
    }
  }
  // お菓子があまってて全員にくばっちゃってたら一人押し付けて犠牲になってもらう
  // 全員にくばってなければ、残りの人に押し付ければよいので特にインクリメントしない
  if (rest > 0 && count == N) {
    count = N - 1;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>

using namespace std;
using ll = long long;

ll N;
vector<ll> A;

void input() {
    cin >> N;
    A.resize(N);
    for (auto& a : A) cin >> a;
}

ll solve() {
    ll cminus = 0;
    for (auto& a : A) if (a < 0) {
        cminus++;
        a = -a;
    }
    sort(A.begin(), A.end());
    ll ans = 0;
    for (auto a : A) ans += a;
    if (cminus % 2)
        ans -= A[0]*2;
    return ans;
}

int main() {
    input();
    cout << solve() << endl;
//    solve();

    return 0;
}



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

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

    bool flag = false;
    for(int i=0; i<n-2; i++){
        if(a[i][0]!=a[i][1]) continue;
        if(a[i+1][0]!=a[i+1][1]) continue;
        if(a[i+2][0]!=a[i+2][1]) continue;
        flag = true;
        break;
    }
    if(flag){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  bool ans = true;
  if(w>=v)ans = false;
  ll sub = abs(a - b);
  ll s = v - w;
  if(s*t<sub)ans = false;
  if(ans){
    print("YES");
  }
  else{
    print("NO");
  }
}

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

int main() { 
    long long int n, a, b, ans = 0;;
    cin >> n >> a >> b;
    if(n <= a) {
        cout << n << '\n';
    } else {
        ans = n/(a+b)*a + min(n%(a+b), a);
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int maisu = a % 1000 == 0 ? a / 1000 : a / 1000 + 1;
    
    System.out.println(1000 * maisu - a);
  }
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

//今回は辺がメインなので直接操作できる構造体を定義
struct Edge
{
    int to, id;
};

//v→現在の頂点、p→現在の頂点の親、c→親から現在の辺の色
void dfs(vector<vector<Edge>> &G, vector<int> &ans, int v, int c, int p)
{
    int k = 1;
    for (auto e : G[v])
    {
        if (e.to == p)
            continue;
        if (k == c)
            k++;
        ans[e.id] = k;
        k++;
        dfs(G, ans, e.to, ans[e.id], v);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<Edge>> G(n);
    vector<int> ans(n - 1);

    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--; //0インデックスに
        G[a].push_back((Edge){b, i});
        G[b].push_back((Edge){a, i});
    }

    dfs(G, ans, 0, -1, -1);
    int mx = 0;
    rep(i, n) mx = max(mx, (int)G[i].size());
    cout << mx << endl;
    rep(i, n - 1) cout << ans[i] << endl;
}

//ポインタ渡し？だと引数が多くなりがちで面倒かも
//グローバル変数とてグラフと答えを用意してmainでresizeのがわかりやすい

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,i;cin>>N>>M;i=M/N;
  while(M%i)i--;
  cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // 累積和
    vector<ll> Ac(N);
    Ac[0] = A[0];
    FOR(i, 1, N){
        Ac[i] = Ac[i-1] + A[i];
    }

    // 数える
    map<ll, ll> mp;
    mp[0]++;
    FOR(i, 0, N){
        mp[Ac[i]]++;
    }

    ll sum = 0;
    for(auto p : mp){
        ll count = p.second;
        if(count==2){
            sum++;
        }
        else if(count > 2){
            // nC2
            sum += count * (count-1) / 2;
        }
    }

    p(sum);
    
    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int W = scanner.nextInt();
        int H = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int r = scanner.nextInt();
        
       if((x-r)<0){
           System.out.println("No");
       }else if((y-r)<0){
           System.out.println("No");
       }else if((x+r) > W){
           System.out.println("No");
       }else if((y+r) > H){
           System.out.println("No");
       }else{
           System.out.println("Yes");
       }
       
    }
}



Measured memory_bytes: 26308
(n,m,c) = list(map(int,input().split()))
b = list(map(int,input().split()))
a = []
for i in range(n):
  a.append(list(map(int,input().split())))

ans = 0
count = 0
for i in range(n):
  for index in range(m):
    ans += a[i][index]*b[index]
  if ans + c > 0:
    count += 1
  else:
    next
  ans = 0
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

#define MAX 100005
int a[MAX];
map<int,int> mp;

void fin(){
  cout<<0<<en;
}

signed main(){
  int n; cin>>n;
  for(int i=0; i<n; i++){
    cin>>a[i];
    mp[a[i]]++;
  }
  
  for(int i=(n%2) ? 0:1; i<n; i+=2){
    if(i==0){
      if(mp[0]!=1){
        fin();
        RE;
      }
      else continue;
    }
    if(mp[i]!=2){
      fin();
      RE;
    }
  }
  
  int ans=1;
  if(n%2){
    n=(n-1)/2;
    for(int i=0; i<n; i++) ans=ans*2%MOD;
  }else{
    n=n/2;
    for(int i=0; i<n; i++) ans=ans*2%MOD;
  }
  cout<<ans<<en;
}


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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k<=a){
        cout << k << "\n";
    }

    else if(k<= a+b){
        cout << a << "\n";
    }

    else{
        cout << a - (k-a-b) << "\n";
    }


    return 0;
}

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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 998244353

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    ll ans=0;
    ll i,j,k,k1;
    cin>>k1;

    fr(i,1,k1+1)
    {
        fr(j,1,k1+1)
        {
            fr(k,1,k1+1)
                ans+=__gcd(__gcd(i,j),k);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
def main():
    n = int(raw_input())
    a = [int(raw_input()) for _ in xrange(n)]
    #p = []
    plen = 0
    maxa = 0
    for amt in a:
        minp = maxa + 1
        items = (amt - 1) / minp
        #print amt, minp, items
        #p.extend([minp] * items)
        plen += items
        if items > 0:
            #p[-1] += (amt - 1) % minp
            rem = 1
        else:
            rem = amt
        maxa = max(maxa, rem)
    #print len(p)
    #for pi in p:
    #    print pi
    print plen
main()


Measured memory_bytes: 5764
#include <stdio.h>
#include <float.h>
typedef long long ll;

int main()
{
    ll n, k;
    double ans = 0;

    scanf("%lld %lld", &n, &k);

    for (ll i = 1; i <= n; i++) {
        double round_ans = 1.0 / (double)n;
        ll point = i;

        while (point < k) {
            point *= 2;
            round_ans *= 0.5;
        }

        ans += round_ans;
    }

    printf("%.*lf\n", DBL_DIG, ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x)  cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

using namespace std;
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<pr> VP;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};

template<typename T>
int diff(vector<T> &a,vector<T> &b) {
	int la = a.size();
	int lb = b.size();
	int inf = numeric_limits<int>::max() - 10;
	vector<vector<int>> dp(la+1,vector<int>(lb+1,inf));
	REP(i,lb+1) dp[0][i] = i;
	REP(i,la+1) dp[i][0] = i;
	REP(i,la) {
		REP(j,lb) {
			if (a[i] == b[j]) dp[i+1][j+1] = dp[i][j];
			dp[i+1][j+1] = min({dp[i+1][j]+1,dp[i][j+1]+1,dp[i][j]+1,dp[i+1][j+1]});
		}
	}
	return dp[la][lb];
}
int main(void) {
	string s1,s2;
	cin >> s1 >> s2;
	vector<char> A(s1.size()),B(s2.size());
	REP(i,s1.size()) A[i] = s1[i];
	REP(i,s2.size()) B[i] = s2[i];
	cout << diff<char>(A,B) << endl;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 1e5+5;
int n, a[maxn], pre[maxn], suf[maxn];

int main(){
	scanf("%d", &n);
	for(int i = 1; i<=n; i++) scanf("%d", &a[i]);
	for(int i = 1; i<=n; i++) pre[i] = __gcd(a[i], pre[i-1]);
	for(int i = n; i>=1; i--) suf[i] = __gcd(a[i], suf[i+1]);
	int ans = -1;
	for(int i = 1; i<=n; i++) ans = max(ans, __gcd(pre[i-1], suf[i+1]));
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	X := make([]int, N)
	for i := 0; i < N; i++ {
		X[i] = nextInt()
	}

	min := int(1e18)
	var temp int
	for i := 1; i <= 100; i++ {
		temp = 0
		for j := 0; j < N; j++ {
			temp += int(math.Pow(float64(X[j]-i), 2.0))
		}
		if temp < min {
			min = temp
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 640
fun main(args: Array<String>) {
    val S = readString()

    println(
        if (
            S.isRev()
            && S.substring(0 until S.length/2).isRev()
            && S.substring((S.length+1)/2 until S.length).isRev()
        )
            "Yes"
    else "No"
    )
}
fun String.isRev() = this == reversed()

fun readString() = readLine()!!

Measured memory_bytes: 33668
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

struct Edge {
    int to, cost;
    Edge(int t, int c)
         : to(t), cost(c){}
};
vector<vector<Edge>> edges;
int memo[800][801][2];
int dfs(int cur, int before, int need_to_back) {
    int& res = memo[cur][before][need_to_back];
    if(res != -1) return res;
    res = 0;
    if(need_to_back) {
        for(const Edge& e : edges[cur]) {
            if(e.to == before) continue;
            int cos = dfs(e.to, cur, 1);
            res += cos;
            if(cos == 0) res += e.cost;
            else res += e.cost * 3;
        }
    }else {
        vector<pint> costs;
        for(const Edge& e : edges[cur]) {
            if(e.to == before) continue;
            int cos[2];
            rep(i, 2) {
                cos[i] = dfs(e.to, cur, i);
                if(cos[i] == 0) cos[i] += e.cost;
                else cos[i] +=  e.cost * (i + 2);
            }
            costs.push_back(pint(cos[1] - cos[0], cos[0]));
        }
        sort(costs.begin(), costs.end(), greater<pint>());
        rep(i, costs.size()) {
            int sa, cos; tie(sa, cos) = costs[i];
            if(i == 0) res += cos;
            else res += sa + cos;
        }
    }
    return res;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N;
    while(cin >> N && N) {
        edges.assign(N, vector<Edge>());
        vector<int> num(N);
        REP(i, 1, N) cin >> num[i];
        REP(i, 1, N) {
            int c; cin >> c;
            --num[i];
            edges[num[i]].push_back(Edge(i, c));
            edges[i].push_back(Edge(num[i], c));
        }
        
        int ans = INF;
        memset(memo, -1, sizeof(memo));
        rep(i, N) {
            ans = min(ans, dfs(i, N, 0));
 //           cout << ans << endl;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8344
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	foreach (line; stdin.byLine) {
		auto date = line.split.map!(to!int);

		if (date[0] > 1989 || (date[0] == 1989 && (date[1] > 1 || (date[1] == 1 && date[2] >= 8)))) write("heisei ", date[0]-1988," ");
		else if (date[0] > 1926 || (date[0] == 1926 && (date[1] > 12 || (date[1] == 12 && date[2] >= 25)))) write("showa ", date[0]-1925," ");
		else if (date[0] > 1912 || (date[0] == 1912 && (date[1] > 7 || (date[1] == 7 && date[2] >= 30)))) write("taisho ", date[0]-1911," ");
		else if (date[0] > 1868 || (date[0] == 1868 && (date[1] > 9 || (date[1] == 9 && date[2] >= 8)))) write("meiji ", date[0]-1867," ");
		else {
			writeln("pre-meiji");
			continue;
		}
		writeln(date[1], " ", date[2]);
	}
}

Measured memory_bytes: 1088
#include<algorithm>
#include<iostream>
#include<vector>
#include<utility>

typedef std::pair<int,int> P;

bool compare( const P& lhs, const P& rhs )
{
	if( lhs.first != rhs.first )
		return lhs.first > rhs.first;

	return lhs.second < rhs.second;
}

int main()
{
	int n;
	std::cin >> n;
	
	std::vector<P> vec;
	while( n-- )
	{
		int a, v;
		std::cin >> a >> v;
		vec.push_back( std::make_pair( v, a ) );
	}

	std::sort( vec.begin(), vec.end(), compare );

	std::cout << vec[0].second << " " << vec[0].first << std::endl;

	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, k; string s;
    cin >> n >> s >> k;
    k--;
    rep(i, n) if (s[i] != s[k]) s[i] = '*';
    cout << s << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(container , s ) for(auto x : container ){cout << x << s;} cout<<endl;
#define one(x) cerr<<#x<<" : "<<x<<endl;
#define two(x,y) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;
signed main()
{
    int tc , n , i , j;
    int a , b , c;
    cin >> a >> b >> c;
    swap(a , b);
    swap(a , c);
    cout<<a << " "<<b <<" "<<c <<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


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

int main() {
	ll N, M; cin >> N >> M;
	string S, T; cin >> S >> T;

	ll gcd = GCD(N, M);
	ll lca = N * M / gcd;
	ll sstep = N / gcd;
	ll tstep = M / gcd;
	int scur = 0;
	int tcur = 0;
	while (scur < S.size()) {
		if (S[scur] != T[tcur]) {
			cout << -1 << endl;
			return 0;
		}


		scur += sstep;
		tcur += tstep;
	}

	cout << lca << endl;





	return 0;
}


Measured memory_bytes: 512
/*
 *  Author : Tatsuhiro Hashimoto
 *  Created : Thu Jun 11 19:34:37 JST 2020
 */
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define FSP(n, v) cout << fixed << setprecision(n) << (v) << endl;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define iMAX 2147483647;
#define lMAX 9223372036854775807;
#define llMAX 18446744073709551615;
#define SORT(v) sort((v).begin(), (v).end());
#define REV(v) reverse((v).begin(), (v).end());
static inline ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b);}
static inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

ld ans = 0.0;

void solve() {
    int N; cin >> N;
    vector<int> A(N, 0);
    ll lcm_v = 0, c_sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (i == 0) lcm_v = A[i];
        else lcm_v = lcm(lcm_v, A[i]);
    }
    for (int i = 0; i < N; ++i) {
        c_sum += lcm_v / A[i];
    }
    ans = (long double)(lcm_v / (c_sum * 1.0));
}

signed main() {
    prepare
    solve();
    FSP(6, ans)
}

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

int main(void){
    long long n, x, p[51], sub[51], sou[51];
    cin >> n >> x;
    long long cnt=0;
    p[0] = 1;
    p[1] = 3;
    sub[0] = 1;
    sub[1] = 2;
    sou[0] = 1;
    sou[1] = 5;
    for(int i=2;i<=n;++i){
        p[i] = p[i-1]*2+1;
        sub[i] = p[i-1]+1;
        sou[i] = sou[i-1]*2+3;
    }
    while(n>=0){
        if((sou[n]+1)/2 <= x){
            cnt+=sub[n];
            x -= (sou[n]+1)/2;
        }else{
            --x;
        }
        if(n > 1 && x<=n-1) break;
        --n;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
module UnionFind_Potential

implicit none
integer,allocatable,dimension(:)::par
!parentより
integer,allocatable,dimension(:)::diff_weight

contains

recursive function root(x) result(res)
  integer :: x,res,r
  r=par(x)
  if(par(r) /= r)then
    r = root(par(x))
    diff_weight(x)=diff_weight(x)+diff_weight(par(x))
    par(x)=r
  endif
  res = r
end function

subroutine unite(x,y,w)
  !x+w=yとなるように繋げます
  integer :: x,y,w,rx,ry,rw
  !rx,ryはそれぞれの根っこ
  !rwはrxとryの差分です
  
  rx = root(x);ry = root(y)
  
  !rx + weight(x) +w=ry+weight(y)から
  rw = w + weight(x)-weight(y)
  
  if(rx /= ry)then
    par(ry) = rx
    diff_weight(ry)=rw
  endif
end subroutine

function weight(x)
  integer::x,weight
  weight=root(x)
  weight=diff_weight(x)
end function

function diff(x,y)
  integer::x,y,diff
  diff=weight(y)-weight(x)
end function
end module UnionFind_Potential

use UnionFind_Potential

integer n,m
integer l,r,d
read*,n,m
allocate(par(n),diff_weight(n))

!初期化
do i=1,n
  par(i)=i
end do
diff_weight=0

do i=1,m
  read*,l,r,d
  
  if(root(l)==root(r))then
    if(diff(l,r)/=d)then
      print"(A)","No"
      STOP
    end if
   else    
    call unite(l,r,d)
  endif
end do

print"(A)","Yes"

end  

Measured memory_bytes: 1024