akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(j) for j in input().split(" ")]

sum_v = 0

for i in range(n):
    sum_v += min(a[i], b[i])
    if b[i] - a[i] > 0:
        sum_v += min(b[i] - a[i], a[i+1])
        a[i+1] = max(a[i+1] - (b[i] - a[i]), 0)
        

#sum_v += min(b[n-1] - a[n-1], a[n])

print(sum_v)
    

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

int main()
{
  string S;
  cin >> S;
  if (S.length() == 3)
  {
    for (int i = S.length() - 1; i >= 0; i--)
    {
      cout << S[i];
    }
    cout << endl;
  }
  else if (S.length() == 2)
  {
      for (int i = 0; i < S.length(); i++)
      {
        cout << S[i];
      }
      cout << endl;
  }
  return 0;
}

Measured memory_bytes: 760
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1018
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  while(cin>>n){
    vector<int> v(n,0);
    vector<int> a(n,0);
    for(int i=0;i<n;++i){
      cin>>v[i];
    }
    sort(v.begin(), v.end());
    for(int i=0;i<a.size();++i){
      if(i>0) a[i] = v[i] + a[i-1];
      else if(i==0) a[i] = v[i];
    }
    int ans=0;
    for(int i=0;i<a.size();++i){
      ans += a[i];
    }
    cout<<ans<<endl;
  }
  
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
 
int main(){
    int n,m;cin>>n>>m;
    vector<vector<int>> s(m);
    rep(i,m){
        int k;cin>>k;
        for(int j=0;j<k;++j){
            int a;cin>>a;
            s[i].push_back(a-1);
        }
    }
    vector<int> p(m);
    rep(i,m) cin>>p[i];
    ////////////////
    int ans =0;
    for(int bit=0;bit<(1<<n);++bit){
        bool ok = true;
        for(int j=0;j<m;++j){/////////////電球について
            int count = 0;
            for(int k=0;k<s[j].size();k++){
                int num = s[j][k];
                if((bit>>num)&1)count++;/////電球iに繋がっているスイッチ
            }
        if(count%2!=p[j]){ok=false;break;}
        }
        if(ok)ans+=1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int x, t; cin >> x >> t;
	cout << ((x - t) >= 0 ? x - t : 0) << endl;
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b;
    cin >> a >> b ;
    
    //*
    if(a + b > 9 ){
        cout << "error" << endl;
    } else {
        cout << a + b << endl;
    }
    //*/
    
    //cout << a.at(0) - 'a' + 'A' << b.at(0) - 'a' + 'A' << c.at(0) - 'a' + 'A' << endl;

    return 0; 
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>

using namespace std;


int main()
{
	while (1)
	{
		int ans = 1, k, ue = 1, migi = 3, hidari = 2;

		cin >> k;
		if (k == 0)break;
		while (k--)
		{
			string a;
			int s, d;
			cin >> a;
			if (a == "North")
			{
				s = ue;
				ue = hidari;
				hidari = 7 - s;
			}
			else if (a == "East")
			{
				s = ue;
				ue = 7 - migi;
				migi = s;
			}
			else if (a == "West")
			{
				s = ue;
				ue = migi;
				migi = 7 - s;
			}
			else if (a == "South")
			{
				s = ue;
				ue = 7 - hidari;
				hidari = s;
			}
			else if (a == "Left")
			{
				s = migi;
				migi = hidari;
				hidari = 7 - s;
			}
			else if (a == "Right")
			{
				s = hidari;
				hidari = migi;
				migi = 7 - s;
			}
			ans += ue;
		}
		cout << ans << endl;






	}

	return 0;
}

Measured memory_bytes: 1212
n = gets.to_i

happiness = []

left   = n
pointT = 0
pointA = 0

n.times do |i|
  a, b = gets.split.map(&:to_i)
  happiness << [a, b, a + b, i]
end

happiness = happiness.sort_by{|ary| ary[2]}.reverse

loop do
  if left > 0
    pointT += happiness.shift[0]
    left -= 1
  else
    break
  end

  if left > 0
    pointA += happiness.shift[1]
    left -= 1
  else
    break
  end
end

puts pointT - pointA


Measured memory_bytes: 17272
N=int(input())
#print#(N)

D={}
for i in range(1,N+1):
    I=str(i)
    if (I[-1],I[0]) not in D:
        D[(I[-1],I[0])]=1
    else:
        D[(I[-1],I[0])]+=1
#print(D)
ans=0
for j in range(1,N+1):
    J=str(j)
    if (J[0],J[-1]) in D:
        ans+=D[(J[0],J[-1])]
print(ans)

Measured memory_bytes: 41836
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> q.at(i);
  }
  vector<int> v(n);
  iota(v.begin(), v.end(), 1);
  int pc=0;
  int qc=0;
  int count=0;
  do{
    if(p==v)
    pc=count;
    if(q==v)
    qc=count;
    count++;
  }while(next_permutation(v.begin(),v.end()));
  cout << abs(pc-qc) << endl;
}

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

int factor[1001];

void primeFactorize(int n) {
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            factor[i]++;
            n /= i;
        }
    }
    if (n != 1) factor[n]++;
}

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

    const int mod = 1000000007;
    long long res = 1;
    for (int i = 1; i <= N; i++)
        primeFactorize(i);

    for (int i = 0; i < 1001; i++) {
        if (factor[i]) {
            res *= factor[i] + 1;
            res %= mod;
        }
    }
    cout << res << endl;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var wrong_answer = new wrong_answer();
        wrong_answer.Solve();
    }
}

public class wrong_answer
{
    const int INF = 1 << 29;
    const long INFL = 1L << 60;
    const int MOD = 1000000007;
    const int MOD2 = 998244353;

    myinout IO = new myinout();






    public void Solve()
    {

        var o = IO.intm;
        var n = o[0];
        var p = IO.intm;
        var dp = new int[n+1];
        for (int i = 0; i < n+1;++i)dp[i] = INF;
        int ans = 0;
        for (int i = 0; i < n;++i){
            dp[i + 1] = Math.Min(dp[i], p[i]);
        }
        for (int i = 0; i < n;++i){
            if(p[i]<=dp[i])ans++;
        }
        IO.wri(ans);
    }




}






public static class Math2
{
    public static long pow(long i, long n, long MOD = 1000000007)
    {
        long res = 1;
        while (n > 0)
        {
            if ((n & 1) != 0) res = res * i % MOD;
            i = i * i % MOD;
            n >>= 1;
        }
        return res;
    }

    public static long gcd(long i, long y)
    {
        while (y != 0)
        {
            var r = i % y;
            i = y;
            y = r;
        }
        return i;
    }

    public static long lcm(long i, long y)
    {
        return i * y / gcd(i, y);
    }

    public static Dictionary<long, int> primefactorization(long N)
    {

        var ret = new Dictionary<long, int>();

        for (long i = 2; i * i <= N; ++i)
        {
            int cnt = 0;
            while (N % i == 0)
            {
                cnt++;
                N /= i;
            }
            if (cnt != 0) ret[i] = cnt;

        }
        if (N >= 2) ret[N] = 1;

        return ret;

    }

    public static List<long> divisorenumrate(long N)
    {
        var ret = new List<long>();

        for (long i = 1; i * i <= N; ++i)
        {

            if (N % i == 0)
            {
                ret.Add(i);
                ret.Add(N / i);
            }

        }

        return ret;

    }

    public static void swap<T>(ref T a, ref T b)
    {
        var i = a;
        a = b;
        b = i;
    }

}

class myinout
{
    //in
    public string str => Console.ReadLine();

    public string[] strm => str.Split(' ');

    public long[] longm => strm.Select(long.Parse).ToArray();
    public int[] intm => strm.Select(int.Parse).ToArray();
    public char[] charm => str.ToArray();
    public double[] doublem => strm.Select(double.Parse).ToArray();
    public long long1 => longm[0];
    public int int1 => intm[0];
    public char char1 => charm[0];
    public double double1 => doublem[0];



    //out
    public void wri<T>(T i)
    {
        Console.WriteLine(i);
    }
    public void wri<T>(T[] i)
    {
        Console.WriteLine(string.Join(" ", i));
    }

    public void yn(bool i)
    {
        if (i) wri("Yes");
        else wri("No");
    }

}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, j, n, m, k, d, a, ans;
int sunuke[101];

int main() {
    scanf(" %d %d", &n, &k);
    init(sunuke, 101, 0);
    rep(0,k) {
        scanf(" %d", &d);
        repj(0, d) {
            scanf(" %d", &a);
            sunuke[a] = 1;
        }
    }
    ans = 0;
    rep(1, n+1) if (sunuke[i] == 0) ans++;

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

Measured memory_bytes: 3824
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
struct card
{
	char suit;
	int value;
};
int n;
struct card a[110],A[110],C[110];
int isstable()
{
	int i;
	for(i=1;i<=n;i++)
		if(a[i].suit!=A[i].suit)
			return 1;
	return 0;
}
struct card a[110],A[110],C[110];
void swap(int x,int y,char z)
{
	struct card t;
	if(z=='a')
	{
		t=a[x];
		a[x]=a[y];
		a[y]=t;
	}
	if(z=='A')
	{
		t=A[x];
		A[x]=A[y];
		A[y]=t;
	}
	return;
}
void bubblesort()
{
	int i,j;
	for(i=1;i<=n-1;i++)
		for(j=n;j>=i+1;j--)
			if(a[j].value<a[j-1].value)
				swap(j-1,j,'a');
	return;
}
void selectionsort()
{
	int i,j,min;
	for(i=1;i<=n;i++)
	{
		min=i;
		for(j=i;j<=n;j++)
			if(A[j].value<A[min].value)
				min=j;
		if(i!=min)
			swap(i,min,'A');
	}
	return;
}
int main()
{
	int i;
	 
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		getchar();
		scanf("%c%d",&a[i].suit,&a[i].value);
		A[i]=a[i];
		C[i]=a[i];
	}

	bubblesort();
	for(i=1;i<=n-1;i++)
		printf("%c%d ",a[i].suit,a[i].value);
	printf("%c%d\n",a[i].suit,a[i].value);
	printf("Stable\n");

	selectionsort();
	for(i=1;i<=n-1;i++)
		printf("%c%d ",A[i].suit,A[i].value);
	printf("%c%d\n",A[i].suit,A[i].value);
	if(isstable())
		printf("Not stable\n");
	else
		printf("Stable\n");
	return 0;
}


Measured memory_bytes: 2144
import java.util.*;
public class Main{
    public static long gcd(long a, long b){
        while(true){
            if(a == 0) return b;
            b %= a;
            if(b == 0) return a;
            a %= b;
        }
    }
    public static long lcm(long a, long b){
        if(gcd(a,b)>0){
            return a/gcd(a,b)*b;
        }else{
            return 0;
        }
    }

    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long t = 0;
        long ans = 1;
        for(int i=0; i<n; i++){
            t = sc.nextLong();
            ans = lcm(ans, t);
        }
        System.out.println(ans);
    }
}


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

using namespace std;
using ll = long long;

void solve(){
	int n,k;
	ll ans=0;
	cin >> n >> k;
	vector<int> monster(n);
	for(int i=0;i<n;++i){
		cin >> monster[i];
	}
	sort(monster.begin(),monster.end());
	for(int i=0;i<n-k;++i)
		ans+=monster[i];
	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){ 
		solve();
	}
	return 0;
}

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

char s[20];

int main(){
    scanf("%s",s);
    int n = strlen(s);
    if(n&1)
        printf("No\n");
    else{
        bool failed = false;
        for(int i = 0; i<n; i+=2){
            if(s[i]!='h'||s[i+1]!='i')
                failed = true;
        }
        if(failed)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 256
cov = {1 => 2, 2 => 3, 3 => 1}

loop do
  a = []
  a << gets.to_i
  break if a[0] == 0
  4.times do
    a << gets.to_i
  end
  b = a.uniq
  a.each do |item|
    if b.size == 2
      puts (b.include? cov[item]) ? 1 : 2
    else
      puts 3
    end
  end
end

Measured memory_bytes: 6088
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <bitset>
#include <cmath>

#define MY_SIZE_MAX 100001
#define MY_VALUE_MAX 100001

using namespace std;

void GetPrimeList( vector<int>& out, int target )
{
	if( MY_SIZE_MAX <= target ){ return; }
	bitset<MY_SIZE_MAX> check(0);
	const int nMax = target + 1;
	for( int n = 2; n <= nMax; ++n )
	{
		if( check[n] ){ continue; }
		check[n] = true;
		out.push_back( n );
		for( int m = n * 2; m <= target; m += n )
		{
			check[m] = true;
		}
	}
}


int main()
{
	vector<int> prime;
	GetPrimeList( prime, 55555 );

	int n;
	cin >> n;

	vector<int> ans;
	for( int m = 0; m < prime.size(); ++m )
	{
		if( prime[m] % 5 != 1 ){ continue; }
		ans.push_back( prime[m] );
	}

	for( int m = 0; m < n; ++m )
	{
		if( m != 0 ){ cout << " "; }
		cout << ans[m];
	}
	return 0;
}

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

int main(){
	long long unsigned int a, b, r, gcd, lcm, x, y;

	while(cin >> a >> b){
		r = 1;
		x = a;
		y = b;
		while(r = x % y){
			x = y;
			y = r;
		}
		gcd = y;
		lcm = a * b / gcd;

		cout << gcd << " " << lcm << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let N = get!(i64);
    let (S, P): (Vec<_>, Vec<_>) = get!(String, i64; N).into_iter().unzip();

    let mut iSP = (1..(N + 1)).zip(S.iter().zip(P.iter()))
        .collect::<Vec<_>>();
    iSP.sort_by_key(|&(_, sp)| (sp.0, -sp.1));

    // 出力
    for (i, _) in iSP {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
import sys
import math
MOD = 10 ** 9 + 7

input = sys.stdin.readline
n,a,b = map(int,input().split())
x1 = 1

a = min(a,n-a)
b = min(b,n-b)
if a > b:
    a,b = b,a

for i in range(n-a+1,n+1):
    x1 = x1 * i % MOD
x11 = 1
for i in range(1,a+1):
    x11 = x11 * i % MOD
x1 = x1 * pow(x11,MOD-2,MOD) % MOD

x2 = x1
for i in range(n-b+1,n-a+1):
    x2 = x2 * i % MOD
x21 = 1
for i in range(a+1,b+1):
    x21 = x21 * i % MOD
x2 = x2 * pow(x21,MOD-2,MOD) % MOD

t = []
nn = n
while nn > 0:
    t.append(nn % 2)
    nn //= 2
x0 = 1
for i in range(len(t)):
    x0 = x0 ** 2
    x0 = x0 % MOD
    if t[len(t)-i-1] == 1:
        x0 *= 2
        x0 = x0 % MOD
print ((x0 - x1 - x2 - 1) % MOD)




Measured memory_bytes: 39152
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": # "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n;){
		double weight,height;
		scanf(",%lf,%lf",&weight,&height);
		if(weight/pow(height,2)+1e-10>25)
			cout<<n<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

using namespace std;

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

	a = n / 10;
	b = n % 10;

	if (a == 9 || b == 9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;

  std::vector<int> p;

  for (size_t i = 0; i < n; i++) {
    int tmp;
    std::cin >> tmp;
    p.push_back(tmp);
  }

  std::sort(p.begin(), p.end(), std::greater<int>());

  int sum = 0;
  sum += p.at(0)/2;
  for (size_t i = 1; i < p.size(); i++) {
    sum += p.at(i);
  }

  std::cout << sum << '\n';
  
  return 0;
}

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

int main() {
	string x, y;
	int a, b, c;
	cin >> x >> a;
	for (int i = 0; i < a; i++) {
	    cin >> y >> b >> c;
	    if (y == "print") {
	        for (int o = b; o <= c; o++) {
	            cout << x[o];
	        }
	        cout << endl;
	    }else if (y == "replace") {
	        string z; cin >> z;
	        for (int o = b; o <= c; o++) {
	            x[o] = z[o - b];
	        }
	    } else if (y == "reverse") {
	        string z = x;
	        for (int o = b; o < c + 1; o++) {
	            x[o] = z[c + b - o];
	        }
	    }
	}
}


Measured memory_bytes: 3164
/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
    // lastIndex(where:)
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
      	for i in stride(from: count - 1, through: 0, by: -1) {
          	if predicate(self[i]) {
              	return i
            }
        }
      	return nil
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
    // max()
    func max() -> Element? {
        guard self.count > 0 else { return nil }
        return self.reduce(self.first!) { return Swift.max($0, $1) }
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}

/// end

let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let M = input[1]

var edges = Array(repeating: [Int](), count: N + 1)

for _ in 0 ..< M {
    let edge = readLine()!.split(separator: " ").map { Int($0)! }
    let sourceNode = edge[0]
    let destinationNode = edge[1]
    edges[sourceNode].append(destinationNode)
}

var dp = Array(repeating: Int.min, count: N + 1)

func memorization(startNode: Int) -> Int {
    guard dp[startNode] == Int.min else { return dp[startNode] }

    var result = 0
    for destinationNode in edges[startNode] {
        result = max(result, memorization(destinationNode) + 1)
    }
    dp[startNode] = result
    return result
}

var result = 0
for i in stride(from: 1, through: N, by: 1) {
    result = max(result, memorization(i))
}
print(result)


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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()


int main() {
    string s;
    cin >> s;
    unordered_map<char,int> M;
    for(int i=0;i<s.size();i++){
        M[s[i]]++;
    }

    bool ok = true;
    if(M.size()!=2) ok = false;
    for(auto m:M){
        if(m.second!=2)ok=false;
    }
    
    if(ok)cout<< "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}



Measured memory_bytes: 256
num = input()

onenum = int(num[len(num)-1])


hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if onenum in hon:
  print("hon")
elif onenum in pon:
  print("pon")
elif onenum in bon:
  print("bon")





Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    vector<int> tree[n];
    rep(i,n-1){
        int a,b;  cin >> a >> b;
        a--; b--;
        tree[a].pb(b); tree[b].pb(a);
    }
    queue<int> q;
    vector<bool> vis(n,0);
    vector<bool> col(n);
    q.push(0);
    vis[0]=0; col[0]=0;
    while(!q.empty()){
        int v=q.front(); q.pop();
        for(int u:tree[v]){
            if(vis[u]) continue;
            if(col[v]) col[u]=0;
            else col[u]=1;
            vis[u]=1;  q.push(u);
        }
    }
    int cnt=0;
    rep(i,n) if(col[i]) cnt++;
    vector<int> ans(n);
    if(cnt<=n/3){
        //cout << "One" << endl;
        rep(i,n){
            if(col[i]) ans[i]=0;
            else ans[i]=-1;
        }
    }else if(n-cnt<=n/3){
        //cout << "Two" << endl;
        rep(i,n){
            if(col[i]) ans[i]=-1;
            else ans[i]=0;
        }
    }else{
        //cout << "Three" << endl;
        int x=0,y=0;
        rep(i,n){
            if(col[i]){
                if(3*x+1<=n){
                    ans[i]=1;
                    x++;
                }else ans[i]=-1;
            }
            else{
                if(3*y+2<=n){
                    ans[i]=2;
                    y++;
                }else ans[i]=-1;
            }
        }
    }
    int a=1,b=0,c=0;
    rep(i,n){
        if(ans[i]==0&&3*a<=n){
            ans[i]+=3*a;
            a++;
        }else if(ans[i]==1&&(3*b+1)<=n){
            ans[i]+=3*b;
            b++;
        }else if(ans[i]==2&&(3*c+2)<=n){
            ans[i]+=3*c;
            c++;
        }
    }
    rep(i,n){
        if(ans[i]==-1){
            if(3*a<=n){
                ans[i]=3*a;
                a++;
            }else if(3*b+1<=n){
                ans[i]=3*b+1;
                b++;
            }else{
                ans[i]=3*c+2;
                c++;
            }
        }
    }
    rep(i,n) cout << ans[i] << '\n';
}



Measured memory_bytes: 14580
#include <bits/stdc++.h>
using namespace std;
// TODO: whileの処理の仕方を覚える
int main() {
  int N;
  int t;
  int c = 0;
  cin >> N;
  t = N;
  while( t > 0) {
    c += t % 10;
    t = t / 10;
  }
  if ( N % c == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    
    sort(RALL(a));

    ll res = 0;
    for(int i = 1; i < n; i++) {
        res += a[i/2];
    }

    cout << res << endl;

    return 0;
}   

Measured memory_bytes: 4828
#include <stdio.h>
#define N 1000002
int main()
{

    int a;

    int n[200001];
    //int ki[N];
    int data[N];
    int max;

    scanf("%d", &a);

    for (int i = 0; i <= N; i++)
    {
        data[i] = 0; //で初期化
        //ki[i] = 0;
    }

    for (int i = 0; i < a; i++)
    {
        scanf("%d", &n[i]);
        if(n[i]==0){
            printf("0\n");
            return 0;
        }
        if (data[n[i]] != 2)//割り切れるものがまだない。
        {
            if(data[n[i]]==1){
                data[n[i]] = 2;//二回以上
            }
            else if (data[n[i]] == 0){//初回
                if(max<=n[i])
                    max = n[i];

                data[n[i]] = 1;
                for (int j = 2; j * n[i] <= N; j++)
                {
                    data[n[i] * j] = 2;
                }
            }
        }
    }
/*
    for (int i = 0; i < a; i++)
    {
        scanf("%d", &n[i]);
        if (data[n[i]] != 2)
        {
            if (data[n[i]] == 1)
            {
                data[n[i]] == 2; //二回以上
            }
            if (data[n[i]] == 0)
            {
                data[n[i]] = 1;
                for (int j = 2; j * n[i] <= N; j++)
                {
                    data[n[i] * j] = 2;
                }
            }
        }
    }

*/
    int count = 0;
    for (int i = 1; i <= max; i++)
    {
        if (data[i] == 1)
        {
            count++;
        }
    }

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

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

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

	int answer = 0;

	// 3桁である成約より111~999しかない
	for(int want = 111; want <= 999; want += 111) {
		if(want >= N) {
			answer = want;
			break;
		}
	}

	std::cout << answer << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,K;cin>>N>>K;
  vector<int> arr(N);
  REP(i,0,N)cin>>arr[i];
  sort(ALL(arr));
  if(arr[N-1]<K){
    print("IMPOSSIBLE");
    re 0;
  }
  int g=arr[0];
  REP(i,1,N)g=gcd(g,arr[i]);
  if(K%g==0)print("POSSIBLE");
  else print("IMPOSSIBLE");

}


Measured memory_bytes: 1024
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  int dx = c - a, dy = d - b;
  int px, py;
  for (int i = 0; i < 2; i++)
  {
    px = c - dy;
    py = d + dx;
    dx = px - c;
    dy = py - d;
    c = px;
    d = py;
    printf("%d %d ", px, py);
  }
  puts("");

  return 0;
}


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

int mod;
int add(int a,int b){return (a+b)%mod;}

int A,B;
int t[1000005][11],size;
int u[100005];
int v[100005],vs;

void Add(int i,int x){
  while(i<100005){
    u[i]=add(u[i],x);
    i+=(i&-i);
  }
}

int Sum(int i){
  int res=0;
  while(i){
    res=add(res,u[i]);
    i-=(i&-i);
  }
  return res;
}

void dfs(int pos,int depth=0){
  if(t[pos][10]>0)v[vs++]=t[pos][10];
  for(int i=0;i<10;i++)
    if(t[pos][i]!=-1)
      dfs(t[pos][i],depth+1);
}

void func(int key){
  int a=key;
  vector<int> vec;
  while(a>0){
    vec.push_back(a%10);
    a/=10;
  }
  reverse(vec.begin(),vec.end());
  int pos=0,depth=0;
  while(depth<(int)vec.size()){    
    if(t[pos][vec[depth]]==-1)t[pos][vec[depth]]=size++;    
    pos=t[pos][vec[depth++]];
  }
  t[pos][10]=key;
}

void init(){
  size=1;
  vs=1;
  memset(u, 0,sizeof(u));
  memset(t,-1,sizeof(t));
}

int main(){
  while(1){
    cin>>A>>B>>mod;
    if(A==0&&B==0&&mod==0)break;
    init();
    for(int i=A;i<=B;i++)func(i);
    dfs(0);
    for(int i=1;i<vs;i++){
      int num=v[i]-A+1;      
      int sum=add(Sum(num),1);
      Add(num,sum);
    }
    cout<< Sum(100002) <<endl;
  }
  return 0;
}

Measured memory_bytes: 44968
def Matrix_Chain_Multiplication(M, p, N):
    
    for l in range(2, N + 1):
        for i in range(1, N - l + 1 + 1):
            j = i + l - 1

            M[i][j] = 500000000

            for k in range(i , j):
                M[i][j] = min(M[i][j], M[i][k] + M[k + 1][j] + p[i - 1] * p[k] * p[j])
    
    return M[1][N]

def Main():
    N = int(input())

    p = [0 for i in range(N+1)]
    M = [[0]*(N+1) for i in range(N+1) ] 

    i = 0
    for n in range(N):
        r, c = map(int, input().split())

        if n == 0:
            p[i] = r
            i += 1
            p[i] = c
            i += 1
        else:
            p[i] = c
            i += 1

    print(Matrix_Chain_Multiplication(M, p, N))

Main()


Measured memory_bytes: 5672
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int books = Integer.parseInt(sc.next());
		int algos = Integer.parseInt(sc.next());
		int level = Integer.parseInt(sc.next());

		int[][] bookArray = new int[books][algos + 1]; // [値段、1番目のスキル...]
		for (int i = 0; i < books; i++) {
			for (int j = 0; j < algos + 1; j++) {
				bookArray[i][j] = Integer.parseInt(sc.next());
			}
		}

		// 全組み合わせを検証
		int[] data = new int[books];
		for (int i = 0; i < books; i++) {
			data[i] = i;
		}
		int total = -1;
		for (int i = 1; i <= books; i++) {

			List<int[]> combination = Combination.combination(data, i);
			for (int[] combi : combination) {
				int[] sumArr = new int[algos + 1]; // 各組合せの合計の配列
				for (int index : combi) {
					for (int j = 0; j < sumArr.length; j++) {
						sumArr[j] += bookArray[index][j];
					}
//					System.out.println(Arrays.toString(sumArr));
					boolean isOKLevel = true;
					for (int j = 1; j < sumArr.length; j++) {
						if (sumArr[j] < level) {
							isOKLevel = false;
						}
					}
					if (isOKLevel && (sumArr[0] < total || total == -1)) {
						total = sumArr[0];
					}
				}
			}
		}
		System.out.println(total);

	}

}

class Combination {

	static List<String[]> combination(String[] data, int k) {
		var result = new ArrayList<String[]>();
		combination(data, 0, new String[k], 0, result);
		return result;
	}

	static void combination(String[] data, int di, String[] comb, int ci, List<String[]> result) {
		if (ci == comb.length) {
			result.add(comb.clone());
			return;
		}
		for (; di <= data.length - (comb.length - ci); di++) {
			comb[ci] = data[di];
			combination(data, di + 1, comb, ci + 1, result);
		}
	}

	static List<int[]> combination(int[] data, int k) {
		var result = new ArrayList<int[]>();
		combination(data, 0, new int[k], 0, result);
		return result;
	}

	static void combination(int[] data, int di, int[] comb, int ci, List<int[]> result) {
		if (ci == comb.length) {
			result.add(comb.clone());
			return;
		}
		for (; di <= data.length - (comb.length - ci); di++) {
			comb[ci] = data[di];
			combination(data, di + 1, comb, ci + 1, result);
		}
	}
}

Measured memory_bytes: 37840
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
int n, a;
set <int> s;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    while(n--){
        read(a);
        if(s.find(a)!=s.end()) s.erase(a);
        else s.insert(a);
    }
    writeln(s.size());
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  int N,K;
  cin>>N>>K;

  int ans=0;
  while(N!=0){
    N/=K;
    ans++;
  }
  if(ans==0)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

using D = tuple<ll, ll, P>;  // gen, area, {w,d}
int main() {
  while (true) {
    ll n, w, d;
    cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) break;
    vector<D> lst;
    lst.emplace_back(-1, w * d, P(w, d));
    rep(i, n) {
      ll p, s;
      cin >> p >> s;
      p--;
      ll nw, nd;
      tie(nw, nd) = get<2>(lst[p]);
      lst.erase(lst.begin() + p);
      s %= 2 * (nw + nd);
      ll nw1, nd1, nw2, nd2;
      if (s < nw) {
        tie(nw1, nd1, nw2, nd2) = make_tuple(s, nd, nw - s, nd);
      } else if (s < nw + nd) {
        tie(nw1, nd1, nw2, nd2) = make_tuple(nw, s - nw, nw, nd - (s - nw));
      } else if (s < 2 * nw + nd) {
        tie(nw1, nd1, nw2, nd2) =
            make_tuple(s - nw - nd, nd, nw - (s - nw - nd), nd);
      } else {
        tie(nw1, nd1, nw2, nd2) =
            make_tuple(nw, (s - 2 * nw - nd), nw, nd - (s - 2 * nw - nd));
      }
      assert(nw1 > 0 && nd1 > 0);
      assert(nw2 > 0 && nd2 > 0);
      lst.emplace_back(i, nw1 * nd1, P(nw1, nd1));
      lst.emplace_back(i, nw2 * nd2, P(nw2, nd2));
      Sort(lst);
    }  // i

    vector<ll> ans;
    rep(i, (ll)lst.size()) ans.push_back(get<1>(lst[i]));
    Sort(ans);
    rep(i, (ll)ans.size()) {
      cout << ans[i];
      cout << ((i == (ll)ans.size() - 1) ? "\n" : " ");
    }

  }  // while
  return 0;
}



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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main() {
  int n,a;
  cin >>n>>a;
  if(n%500<=a) cout << "Yes" << endl;
  else cout << "No" << endl;
}
      

Measured memory_bytes: 3536
#include <iostream>

using namespace std;

long x[10000][10000],h,w,c[11][11];

struct muchie
{
	int i,j;
};

int main ()
{
	cin>>h>>w;
	for (int i=0;i<=9;i++)
		for (int j=0;j<=9;j++)
			cin>>c[i][j];
	for (int k=0;k<=9;k++)
		for(int i=0;i<=9;i++)
			for (int j=0;j<=9;j++)
			{
				if(c[i][k]+c[k][j]<c[i][j])
					c[i][j]=c[i][k]+c[k][j];
			}
	for (int i=0;i<h;i++)
		for (int j=0;j<w;j++)
			cin>>x[i][j];
	long sum=0;
	for (int i=0;i<h;i++)
		for (int j=0;j<w;j++)
			if (x[i][j]!=-1)
			{
				sum = sum + c[x[i][j]][1];
			}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 14720
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(len(A)):
  ans += B[A[i]-1]

  if i != 0:
    if A[i-1] + 1 == A[i]:
      ans += C[A[i-1]-1]

print(ans)

Measured memory_bytes: 3064
N = int(input())
D = [list(map(int,input().split())) for _ in range(N)]

count = 0
flag = 0
for i in range(N):
    if D[i][0] == D[i][1]:
        count += 1
    else:
        count = 0
    
    if count >= 3:
        flag = 1

print("Yes" if flag == 1 else "No")

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

ll divplus(ll a, ll b) {
	return (a+b-1)/b;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> t(n), a(n);
	rep(i,n) cin >> t[i] >> a[i];
	ll ht,ha;  // 得票数の最小値
	ht = t[0], ha = a[0];
	for (int i=1;i<n;i++) {
		ll bai = max(divplus(ht,t[i]), divplus(ha,a[i]));
		ht = bai * t[i], ha = bai * a[i];
	}

	cout << ht + ha << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	ll temp=n,s=0;
	while(temp){
		s+=temp%10;
		temp/=10;
	}
	puts(n%s==0?"Yes":"No");
}

Measured memory_bytes: 128
def main():
    n,d = map(int,input().split())
    d2 = d * d
    res = 0
    for i in range(n):
        x,y = map(int,input().split())
        if d2 >= x*x+y*y:
            res += 1
    return res

    
 
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 69900
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string s[n] = {};
	for ( int i = 0 ; i < n ; i++ ) cin >> s[i];
	for ( int i = 0 ; i < 26 ; i++ ) {
        char a = i + 'a';
        int b = 0 , c = 0;
        for ( int j = 0 ; j < n ; j++ ) {
            b = 0;
            for ( int k = 0 ; k < s[j].length() ; k++ ) {
                if ( s[j][k] == a ) b++;
            }
            if( j == 0 ) c = b;
            c = min( b , c );
        }
        for ( int j = 0 ; j < c ; j++ ) cout << a;
    }
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;

}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int main(){
  int elaps = 0;
  int i, q;
  scanf("%d %d", &n, &q);

  REP(i, 1, n){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    P x = dequeue();
    elaps += min(x.t, q);
    x.t -= q;
    if(x.t > 0) enqueue(x);
    else printf("%s %d\n", x.name, elaps);
  }

  return 0;
}




Measured memory_bytes: 13372
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

template<typename T>
class CumulativeSum {
	vector<T> a;
	public:
	CumulativeSum(vector<T>& x) : a(x.size() + 1,0) {
		rep(i,x.size()){
			a[i + 1] = a[i] + x[i];
		}
	}
	T get(int l, int r){ // [l, r]の区間の合計を求める
		return a[r + 1] - a[l];
	}
	T operator [] (const int i) const {
		return a[i];
	}
};

signed main(){
	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	cin >> a;

	CumulativeSum<int> c(a);
	set<int> al;
	range(len,0,n){
		rep(i,n - len){
			al.emplace(c.get(i,i + len));
		}
	}
	vector<int> v;
	for(auto i : al) v.emplace_back(i);

	int t = 42;
	while(t > 0){
		vector<int> nxt;
		while(t > 0){
			nxt.clear();
			rep(i,v.size()){
				if((v[i] >> t) bitand 1){
					nxt.emplace_back(v[i]);
				}
			}
			//cout << t << ' ' << k << endl;
			//cout << v << endl;
			//show(nxt.size())
			if(nxt.size() < k){
				t--;
				continue;
			}else{
				t--;
				v = nxt;
				break;
			}
		}
	}

	int ans = (1LL << 42) - 1;
	rep(i,v.size()){
		ans = ans bitand v[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 29936
#include<stdio.h>

int main() {

  int m, f, r, s;

  while(1) {
    
    scanf("%d %d %d", &m, &f, &r);
      if(m == -1 && f == -1 && r == -1) goto end;
    s = m + f;
    if(m == -1 || f == -1) {
      printf("F\n");
    } else if(s >= 80) {
      printf("A\n");
    } else if(s >= 65 && s < 80) {
      printf("B\n");
    } else if(s >= 50 && s < 65) {
      printf("C\n");
    } else if(s >= 30 && s < 50) {
      if(r >= 50) {
	printf("C\n");
      } else {
	printf("D\n");
      }
      } else if(s < 30) {
	printf("F\n");
      }
  }  
 end:  
      return 0;
}

Measured memory_bytes: 584
program main
  implicit none
  integer :: n, i, p, a, b, sumx,sumx2
  integer, allocatable ::x(:)

  read *, n
  allocate( x(n) )
  read *, x

  sumx = 0
  sumx2 = 0
  do i = 1, n
    sumx = sumx + x(i)
    sumx2 = sumx2 + x(i)**2
  end do
  if ( mod(sumx,n) == 0 ) then
    p = sumx/n
    a = n*p**2 - 2*p*sumx + sumx2
    print *, a
  else
    p = sumx/n
    a = n*p**2 - 2*p*sumx + sumx2
    p = sumx/n+1
    b = n*p**2 - 2*p*sumx + sumx2
    if ( a>b ) then
      print *, b
    else
      print *, a
    end if
  end if

end program main


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

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


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, D;
    cin >> N >> D;
    vector<int> X(N),Y(N);
    for (int i=0;i<N;i++){
        cin >> X[i] >> Y[i];
    }
    int dd = D*D;
    int cnt = 0;
    for (int i=0;i<N;i++){
        if (X[i]*X[i] + Y[i]*Y[i] <= dd) cnt++;
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 6364