akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;
const ll mod = 1e9 + 7;

ll dp[N][2];
vector<int> adj[N];
int n;

void dfs(int u, int p)
{
	dp[u][0] = dp[u][1] = 1;
	
	for(int v : adj[u])
	{
		if(v == p)
			continue;

		dfs(v, u);

		ll child = (dp[v][0] + dp[v][1]) % mod;
		dp[u][0] = dp[u][0] * child % mod;

		child = dp[v][0];
		dp[u][1] = dp[u][1] * child % mod;
	}

	// cout << u << " " << dp[u][0] << " " << dp[u][1] << endl;
}

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

	cin >> n;

	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;

		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, -1);

	cout << (dp[1][0] + dp[1][1]) % mod << endl;

	return 0;
}

Measured memory_bytes: 14208
use whiteread::parse_line;

fn main() {
    let (a, b): (u32, u32) = parse_line().unwrap();
    let mut cnt = 0;

    for n in a..=b {
        let mut n = n.to_string();
        let mut ans = true;
        while n.len() > 1 {
            if Some(n.remove(0)) != n.pop() {
                ans = false;
                break;
            }
        }
        if ans {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 2136
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int n,p[12],ma,ans;
int main(){
	scanf("%d",&n);
	fo(i,1,n){
		scanf("%d",&p[i]);
		if (p[i]>ma) ma=p[i];
		ans+=p[i];
	}
	ans-=ma/2;
	printf("%d\n",ans);
	return 0;	
}

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

int main() {
	int n;
	cin >> n;
	int temp;
	double result = 0;
	for (int i = 0;i < n;i++) {
		cin >> temp;
		result += 1.0 / temp;
	}
	cout << 1 / result << endl;
	return 0;
}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

int	main() {
	int r, g, b;
	cin >>r >>g >>b;
	b +=g*10;
	if (0==b%4)
		cout <<"YES" <<endl;
	else
		cout <<"NO" <<endl;
	return 0;
}



Measured memory_bytes: 256
n = int(input())
lis = list(map(int, input().split()))
cont = 0
for i in range(n):
  for j in reversed(range(i+1, n)):
    if lis[j-1] > lis[j]:
      lis[j-1], lis[j] = lis[j], lis[j-1]
      cont += 1
      
print(" ".join(map(str, lis)))
print(cont)


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

#define PI 3.14159265358979323846264338327950L
#define ll long long
#define lli long long int
#define lld long double

using namespace std;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> vectors(n);
    for (int i = 0; i < n; i++) {
        cin >> vectors[i];
    }
    sort(vectors.begin(), vectors.end());
    ll sum = 0;
    for (int i = 0; i < k; i++) {
        sum += vectors[i];
    }
    cout << sum << "\n";
}


Measured memory_bytes: 3644
#include<stdio.h>

int main(){
   int n, x;
   int N, i, j, k;

   while(1){
      scanf("%d %d", &n, &x);
      if(n==0 && x==0){
         break;
      }
      N = 0;

      for(i=1; i<n-1; i++){
         for(j=i+1; j<n; j++){
            for(k=j+1; k<n+1; k++){
               if(i+j+k==x)
                  N = N+1;
            }
         }
      }
      printf("%d\n", N);
   }
   return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a>> b >> c;
  int ans;
  if(a-b>=c) ans=0;
  else if(a-b <c){
    ans=c-a+b;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int cnt_digits(ll N) {
    int digits=0;

    while(N > 0) {
        N /= 10;
        digits++;
    }

    return digits;
}

int main() {
    ll N, A, B;
    cin >> N;
    int ans = cnt_digits(N);
    int t_min;

    for(ll i = 1; i * i <= N; i++) {
        if(N%i != 0) continue;
        A = i;
        B = N/i;
        t_min = max(cnt_digits(A), cnt_digits(B));
        if(ans > t_min) ans = t_min;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#逆元(MODあり)
def inverse(x, mod)
  pow(x, mod-2, mod)
end
#べき乗(MODあり)(繰り返し２乗法)
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

l = A[0]
(1...N).each{|i|
  l = l.lcm(A[i])
}
l = l % MOD
ans = 0
A.each{|a|
  ans = (ans + l * inverse(a, MOD) % MOD)
}

puts ans % MOD


Measured memory_bytes: 51804
n = int(input())

li = [0]*(10**4+1)

for i in range(1,100):
  for j in range(1,i+1):
    for k in range(1,j+1):
      value = i**2+j**2+k**2+i*j+j*k+k*i
      if value <= 10**4:
        if len(set([i,j,k])) == 3:
          li[value] += 6
        elif len(set([i,j,k])) == 2:
          li[value] += 3
        else:
          li[value] += 1

for i in range(1,n+1):
  print(li[i])

Measured memory_bytes: 9292
class UnionFind
  attr_reader :rank, :parent, :value
  attr_writer :rank, :parent

  def initialize(x)
    @value = x
    @rank = 0
    @parent = self
  end

  def ==(obj)
    @value == obj.value
  end

  def find
    return self if self.parent == self
    root = self.parent.find
    self.parent = root
    root
  end

  def union(y)
    xr = find; yr = y.find
    return if xr == yr
    if xr.rank >= yr.rank
      yr.parent = xr
      xr.rank += 1
    else
      y.union(self)
    end
  end
end

def minimum_spanning_tree_kruskal(nodes, edges)
  # edges: [[node_from, node_to, weight]]
  edges.sort_by!{ |e| e[2] }
  th = Hash[nodes.map{ |x| [x, UnionFind.new(x)] }]
  i = 0
  mst = []
  while i < edges.size
    e = edges[i]
    i += 1
    f,t,w = *e
    tf = th[f]; tt = th[t]
    next if (tf.find == tt.find)
    tf.union(tt)
    mst << e
  end
  mst
end

N = gets.to_i
ns = (0...N).map{ |i| x,y = gets.split.map(&:to_i); { i: i, x: x, y: y } }
es = {}

[ :x, :y ].each{ |s|
  ns.sort_by!{ |n| n[s] }
  (1...N).each{ |i| 
    f,t = ns[i-1][:i],ns[i][:i]
    es[f] ||= {}
    es[f][t] = [ns[i][:x] - ns[i-1][:x], ns[i][:y] - ns[i-1][:y]].map(&:abs).min
  }
}

p minimum_spanning_tree_kruskal((0...N).to_a, es.map{ |f,e| e.map{ |t,w| [f,t,w] } }.flatten(1)).map{ |e| e[2] }.inject(:+)

Measured memory_bytes: 102012
n=int(input())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans=0
for x in range(n+1):
  if x%2==1:
    
    s=make_divisors(x)
    if len(s)==8:
      ans+=1
    
print(ans)

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 3608
#include <bits/stdc++.h> 
using namespace std;
int main(){
    int N, M;
    cin>>N>>M;

    int L[M], R[M];
    for(int i = 0; i < M; i++) cin>>L[i]>>R[i];

    int l = L[0];
    int r = R[0];
    bool f = 1;
    for(int i = 1; i < M; i++) { 
        if(L[i] > r || R[i] < l) {
            f = 0;
            break; 
        } else { 
            l = max(l, L[i]); 
            r = min(r, R[i]); 
        } 
    }

    if(f){
        if(N >= l){
            int ans = min(N, r) - l + 1;
            cout<<ans<<endl;
        } else cout<<0<<endl;
    } else cout<<0<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
long long dp[200010][2][3][3];

int main() {
    string s; cin >> s;
    string t = s;
    int n = s.size();
    sort(t.begin(), t.end());
    if (t.front() == t.back()) {
        cout << 1 << endl;
        return 0;
    }
    if (n == 2) {
        cout << 2 << endl;
        return 0;
    } else if (n == 3) {
        if (s[0] == s[1] || s[1] == s[2]) {
            cout << 6 << endl;
        } else if (s[0] == s[2]) {
            cout << 7 << endl;
        } else {
            cout << 3 << endl;
        }
        return 0;
    }
    int sum = 0;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        sum = (sum + s[i] - 'a') % 3;
        if (i && s[i-1] == s[i]) flag = false; 
    }
    dp[1][0][0][0] = 1;
    dp[1][0][1][1] = 1;
    dp[1][0][2][2] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            for (int s = 0; s < 3; s++) {
                for (int prev = 0; prev < 3; prev++) {
                    for (int cur = 0; cur < 3; cur++) {
                        if (j == 0) {
                            if (prev == cur) {
                                dp[i+1][j+1][(s+cur)%3][cur] += dp[i][j][s][prev];
                                dp[i+1][j+1][(s+cur)%3][cur] %= mod;
                            } else {
                                dp[i+1][j][(s+cur)%3][cur] += dp[i][j][s][prev];
                                dp[i+1][j][(s+cur)%3][cur] %= mod;
                            }
                        } else {
                            dp[i+1][j][(s+cur)%3][cur] += dp[i][j][s][prev];
                            dp[i+1][j][(s+cur)%3][cur] %= mod;
                        }
                    }
                }
            }
        }
    }
    cout << (flag+dp[n][1][sum][0]+dp[n][1][sum][1]+dp[n][1][sum][2]) % mod << endl;
    return 0;
}

Measured memory_bytes: 28932
#include <iostream>
#include <vector>
#include <bitset>


#define DEBUG(x) do {std::cerr << #x << ": " << x << std::endl; } while (0)

bool is_prime (int n){
	for (int i = 2; i * i <= n; ++i)
		if (n % i == 0) return false;
	return true;
}


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

	while (! is_prime(n)){
		n++;
	}
	std::cout << n << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n,i,min,max,tmp;
	long long int sum = 0;
	int a[10000];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n - 1;i++) {
		if (a[i] < a[i + 1]) {
			tmp = a[i];
			a[i] = a[i + 1];
			a[i + 1] = tmp;
		}
	}
	min = a[n-1];

	for (i = 0; i < n - 1; i++) {
		if (a[i] > a[i + 1]) {
			tmp = a[i];
			a[i] = a[i + 1];
			a[i + 1] = tmp;
		}
	}
	max = a[n-1];
	for (i = 0; i < n; i++) {
		sum += a[i];
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 640
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let (h, w, d) = {
        let list = input
            .split("\n")
            .nth(0)
            .unwrap()
            .split_whitespace()
            .map(|x| x.parse::<i32>().unwrap())
            .collect::<Vec<_>>();
        (list[0], list[1], list[2])
    };
    let a_map = {
        let map = input
            .split("\n")
            .skip(1)
            .take(h as usize)
            .map(|x| {
                x.split_whitespace()
                    .map(|x| x.parse::<i32>().unwrap())
                    .collect::<Vec<_>>()
            })
            .collect::<Vec<_>>();
        let mut r = Vec::new();
        for _ in 0..(w * h) {
            r.push((0, 0));
        }
        for (x, a) in map.into_iter().enumerate() {
            for (y, b) in a.into_iter().enumerate() {
                r[b as usize - 1] = (x as i32, y as i32);
            }
        }
        r
    };

    //累積和
    let mut map_sum: Vec<(i32, (i32, i32))> = vec![];
    for (i, (x, y)) in a_map.into_iter().enumerate() {
        let old = i as i32 - d;
        let v = (
            if old < 0 {
                0
            } else {
                let (old_sum, (old_x, old_y)) = map_sum[old as usize];
                old_sum + (x - old_x).abs() + (y - old_y).abs()
            },
            (x, y),
        );
        map_sum.push(v);
    }
    let map_sum = map_sum.into_iter().map(|(x, _)| x).collect::<Vec<_>>();

    let q_list = input
        .split("\n")
        .skip((2 + h) as usize)
        .map(|x| {
            let list = x.split_whitespace()
                .map(|x| x.parse::<usize>().unwrap())
                .collect::<Vec<_>>();
            (list[0], list[1])
        })
        .collect::<Vec<_>>();
    let mut s = Vec::new();
    for (l, r) in q_list {
        s.push((map_sum[r - 1] - map_sum[l - 1]).to_string());
    }
    s.join("\n").to_string()
}

#[test]
fn test() {
    let tests = vec![
        (
            "3 3 2
1 4 3
2 5 7
8 9 6
1
4 8",
            "5",
        ),
        (
            "4 2 3
3 7
1 4
5 2
6 8
2
2 2
2 2",
            "0
0",
        ),
        (
            "5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13",
            "0
5
0",
        ),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 15724
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u,uc;
map<LL,LL>ww,cc;
LL ar[120005];
LL br[500005];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c,str;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
    while(tt--)
    {
//        UOSMOY;
        cin>>n;
        k=0;
        for(i=0,k=0; i<n; i++)
        {
            cin>>o;
            k+=o;
            v.PSB(o);
            u[o]+=o;
        }
        cin>>m;
        for(i=0; i<m; i++)
        {
            l=k;
            cin>>p>>q;
            if(u[p]!=0)
            {
                o=u[p];
                l=k-o;
                k-=o;
                o/=p;
                o*=q;
                l+=o;
                k+=o;
                u[q]+=o;
                u[p]=0;
            }
            cout<<l<<endl;

        }
    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 9856
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n,k;
	int i;
	int l[60];

	cin >> n >> k;

	for(i = 0; i < n; i++) {
		cin >> l[i];
	}

	sort(l, l+n, std::greater<int>());

	int sum = 0;
	for(i = 0; i < k; i++) {
		sum += l[i];
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[101],ans,minn=2147483647;
int main()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for (int i=a[1];i<=a[n];i++)
	{
		ans=0;
		for (int j=1;j<=n;j++)
		{
			ans+=pow(abs(a[j]-i),2);
		}
		if (minn>ans)
		{
			minn=ans;
		}
	}
	cout<<minn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define N 210
using namespace std;

ll n, m, l, ans, a[N];

inline ll read(){
    ll s = 0, w = 1;
    char ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
    for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}

inline void work(){
    n = read(), m = read();
    REP(i, 1, n) a[++l] = i * 2;
    REP(i, 1, m) a[++l] = (i - 1) * 2 + 1;
    sort(a + 1, a + l + 1);
    REP(i, 1, l)
        REP(j, i + 1, l)
            if ((a[i] + a[j]) % 2 == 0) ans++;
    printf("%lld\n", ans);
}

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

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

int main(void) {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];  
  vector<vector<int64_t>> DP(N+1, vector<int64_t>(N+1, 0));
                         
  for(int length = 1; length <= N; ++length) {
    for(int lp = 0; (lp + length) <= N; ++lp) {
      int rp = lp + length;
      bool first = ((N - length) % 2) == 0;
      if(first) {
        DP[lp][rp] = max(DP[lp+1][rp] + A[lp], DP[lp][rp-1] + A[rp-1]);
      } else {
        DP[lp][rp] = min(DP[lp+1][rp] - A[lp], DP[lp][rp-1] - A[rp-1]);
      }
    }
  }
  cout << DP[0][N] << endl;
  return 0;
}

Measured memory_bytes: 70784
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b,c;
    cin>>a>>b>>c;
  	swap(a,b);
  	swap(a,c);

    // 出力
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N>>K;
  vector<int>p(N);
  
  for(int i=0;i<N;i++){
  cin >>p.at(i);
  }
  sort(p.begin(),p.end());
  
  int sum=0;
  for(int i=0;i<K;i++){
   sum +=p.at(i);
  }
  
  cout<<sum<<endl;
 
return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

struct node
{
    ll key;
    node *parent, *left, *right;
};

node *root = nullptr;
void insert(node *z)
{
    node *y = nullptr;
    node *x = root;
    while (x != nullptr)
    {
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }
    z->parent = y;

    if (y == nullptr)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}
void Preorder(node *x)
{
    printf(" %lld", x->key);
    if (x->left != nullptr)
        Preorder(x->left);
    if (x->right != nullptr)
        Preorder(x->right);
}

void Inorder(node *x)
{
    if (x->left != nullptr)
        Inorder(x->left);
    printf(" %lld", x->key);
    if (x->right != nullptr)
        Inorder(x->right);
}

int main()
{
    int m;
    string str;
    cin >> m;

    for (int i = 0; i < m; i++)
    {
        cin >> str;
        if (str[0] == 'i')
        {
            node *z = (node*)malloc(sizeof(node));
            cin >> z->key;
            z->left = nullptr;
            z->right = nullptr;
            z->parent = nullptr;
            insert(z);
        }
        else
        {
            Inorder(root);
            printf("\n");
            Preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 26548
#                         author:  kagemeka 
#                         created: 2019-11-06 16:52:04(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools 
# import statistics

def main():
    n = int(sys.stdin.readline().rstrip())
    ans = n // 3
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


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

void Shuffle() {	
	int m, h,i;
	string  cards, str1, str2;
	while(1){
		cin >> cards; 
		if (cards == "-") break;
		cin >> m;
		for (i = 0; i < m; i++) {
			cin >> h;

			str1 = cards.substr(0, h);
			str2 = cards.substr(h, cards.size() - h);
			cards = str2 + str1;
		}
		cout << cards << endl;
	}

}

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


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

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

    string s; cin >> s;
    
    map<pair<string, string>, int> mem;

    for(int mask = 0; mask < (1 << n); mask += 1) {
        string red = "";
        string blue = "";

        for(int i = 0; i < n; i += 1) {
            if((1 << i) & mask)
                red += s[i];
            else
                blue += s[i];
        }

        mem[make_pair(red, blue)] += 1;
    }
    
    int64_t ans = 0;

    for(int mask = 0; mask < (1 << n); mask += 1) {
        string red = "";
        string blue = "";

        for(int i = 0; i < n; i += 1) {
            if((1 << i) & mask)
                red += s[i + n];
            else
                blue += s[i + n];
        }

        reverse(red.begin(), red.end());
        reverse(blue.begin(), blue.end());

        ans += mem[make_pair(blue, red)];
    }

    cout << ans << "\n";
}

Measured memory_bytes: 87040
x, y = [int(_) for _ in input().split()]
x = chr(x - 1 + ord('a'))
y = chr(y - 1 + ord('a'))
g = ['aceghjl', 'dfik', 'b']
flg = False
for i in range(3):
  if x in g[i] and y in g[i]:
    flg = True
print('Yes' if flg else 'No')


Measured memory_bytes: 3060
#include <cstdio>
#include <map>
#include <algorithm>

const int maxn=2e5+5;
#define int long long

struct seg{
	int l,r;
}s[maxn];

int n,M,len,cnt[maxn<<1],d[maxn<<1];std::map<int,int> m;

inline int max(int a,int b){
	return a>b?a:b;
}

signed main(){
	scanf("%lld%lld",&n,&M);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i].l,&s[i].r);
	for(int i=1;i<=n;i++){
		d[++len]=s[i].l;
		d[++len]=s[i].r;
	}std::sort(d+1,d+len+1);
	len=std::unique(d+1,d+len+1)-d-1;
	for(int i=1;i<=len;i++){
		m[d[i]]=i;
	}
	for(int i=1;i<=n;i++){
		cnt[m[s[i].l]]++;
		cnt[m[s[i].r]+1]--;
	}
	int tmp=0,maxx=0;
	for(int i=1;i<=len;i++){
		tmp+=cnt[i];
		maxx=max(maxx,tmp);
	}tmp=0;
	if(maxx%2){
		int res=0;
		for(int i=1;i<=len;i++){
			tmp+=cnt[i];
			if(tmp==maxx){
				res=(maxx-1)*M+d[i];
			}
		}printf("%lld\n",res);
		return 0;
	}
	for(int i=1;i<=len;i++){
		tmp+=cnt[i];
		if(tmp==maxx){
			printf("%lld\n",maxx*M-d[i]);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 37212
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n){
        int a, b;
        cin >> a >> b;
        if(a > b) swap(a, b);
        int ans = 0;
        if(a == b){
            ans = 2 * a - 2;
        }else if(a + 1 == b){
            ans = 2 * a - 2;
        }else{
            int tmp = a * b;
            int sqt = sqrt(tmp);
            if(sqt * sqt == tmp) sqt--;
            ans = 2 * sqt - 1;
            if(sqt * (sqt + 1) >= tmp) ans -= 1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
void program(const string &s);
void declaration(const string &s);
void assignment(const string &s);
ll expression(const string &s);
map<char, map<ll, ll>> mp;
map<char, ll> sz;
bool bug = false;
ll mi = INF;
void program(const string &s) {
  bool decl = true;
  for(ll i=0;i<(ll)(s.size());++i) {
    if(s[i] == '=') {
      decl = false;
      break;
    }
  }
  if(decl) declaration(s);
  else assignment(s);
}
void declaration(const string &s) {
  char name = s[0];
  ll num = stoi(s.substr(2, (ll)(s.size())-3));
  sz[name] = num;
}
void assignment(const string &s) {
  ll eqpos = -1;
  for(ll i=0;i<(ll)(s.size());++i) {
    if(s[i] == '=') {
      eqpos = i;
      break;
    }
  }
  char name_left = s[0];
  ll num_left = expression(s.substr(2, eqpos-3));
  ll num_right = expression(s.substr(eqpos+1, (ll)(s.size())-eqpos-1));
  if(num_left == -1 || sz[name_left] <= num_left) {
    bug = true;
  } else {
    mp[name_left][num_left] = num_right + 1;
  }
}
ll expression(const string &s) {
  bool arr = false;
  for(ll i=0;i<(ll)(s.size());++i) {
    if(s[i] == '[') {
      arr = true;
      break;
    }
  }
  if(!arr) {
    return stoll(s);
  } else {
    char name = s[0];
    ll num = expression(s.substr(2, (ll)(s.size())-3));
    if(num == -1 || sz[name] <= num || mp[name][num] == 0) {
      bug = true;
      return -1;
    }
    return mp[name][num]-1;
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  bool init = true;
  ll cnt = 0;
  while(1) {
    string s; cin >> s;
    if(s == "." && init) break;
    cnt++;
    init = false;
    if(s == ".") {
      cout << (mi == INF ? 0 : mi) << endl;
      mp.clear();
      bug = false;
      cnt = 0;
      mi = INF;
      init = true;
      continue;
    }
    if(!bug) program(s);
    if(bug) {
      mi = min(mi, cnt);
    }
  }
}



Measured memory_bytes: 3208
fun main(args:Array<String>) {
  val (m,n) = readLine()!!.split(" ").map(String::toLong)
  when {
    m == 1L && n == 1L -> 1L
    m == 1L && n != 1L -> n - 2  
    m != 1L && n == 1L -> m - 2
    else -> (m-2L)*(n-2L)
  }.let{println(it)}
}



Measured memory_bytes: 37712
s = gets.chomp.split('')

ans = 0
r = 0
prev = ''
s.each do |c|
  if prev == 'R' and c == 'R'
    r += 1
  elsif prev != 'R' and c == 'R'
    r = 1
  else
    r = 0
  end
  prev = c
  ans = [ans, r].max
end

puts ans



Measured memory_bytes: 14360
#include <iostream>

using namespace std;

const int MAX = 105000;

void eratosthenes(bool* p)
{
	for (int i=0; i<=MAX; i++) p[i] = true;
	p[1] = false;
	for (int i=2; i<=MAX; i++) {
		if (!p[i]) continue;
		for (int d=2; i*d<=MAX; d++) p[i*d] = false;
	}
}

int main()
{
	int n;
	
	bool *p = new bool[MAX+1];
	if (p == NULL) return 1;
	eratosthenes(p);
	/*
	int max_prime = 0;
	int max_prime_pos = 0;
	for (int i=2; i<=MAX; i++) {
		if (p[i]) { max_prime = i; max_prime_pos++; }
	}
	cout << max_prime_pos << " : " << max_prime << endl;
	*/
	
	while (true) {
		cin >> n;
		if (n==0) break;
		
		int sum = 0;
		int prime_count = 0;
		for (int i=2; i<=MAX && prime_count < n; i++) {
			if (p[i]) { sum += i; prime_count++; }
		}
		
		cout << sum << endl;
	}
	
	delete[] p;
		
	return 0;
}

Measured memory_bytes: 3136
#include<cstdio>
#include<map>
#include<cmath>
#include<algorithm>
#define MAXN 3006
#define MAXM 100006
#define INF 210000000000
using namespace std;
long long vis[MAXN],prime[MAXN],cnt,n,sum;
long long B,C,ans,last,a;
void waiting()
{
	for(long long i=2;i<MAXN;i++)
	{
		if(!vis[i]) prime[++cnt]=i;
		for(long long j=1;prime[j]*i<MAXN;j++)
		{
			vis[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}
struct node
{
	long long b,c;
}p[MAXM];
bool cmp(node a,node b)
{
	return a.b<b.b;
}
map<long long,long long> ma,gg;
int main()
{
	//freopen("anticube.in","r",stdin);
	//freopen("anticube.out","w",stdout);
	waiting();
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		B=1;
		C=1;
		for(long long j=1;j<=cnt;j++)
		{
			sum=0;
			if(a==1) break;
			while(a%prime[j]==0)
			{
				a/=prime[j];
				sum++;
			}
			sum%=3;
			if(sum)
			{
				if(sum==1)
				{
					B*=prime[j];
					C=C*prime[j];
					C=C*prime[j];
				}
				else
				{
					C*=prime[j];
					B=B*prime[j]*prime[j];
				}
			}
		}
		if(a!=1)
		{
			long long chuizi=sqrt(a);
			if(a==chuizi*chuizi)
			{
				B*=chuizi*chuizi;
				C*=chuizi;
			}
			else
			{
				B*=a;
				C*=a*a;
			}
		}
		p[i].b=B;
		p[i].c=C;
	}
	/*for(long long i=1;i<=n;i++)
		printf("%lld ",p[i].b);
	printf("\n");
	for(long long i=1;i<=n;i++)
		printf("%lld ",p[i].c);*/
	for(long long i=1;i<=n;i++)
		ma[p[i].b]++;
	for(long long i=1;i<=n;i++)
	{
		if(gg[p[i].b]) continue;
		gg[p[i].b]=1;
		if(p[i].c==p[i].b) ans++;
		else
		{
			ans+=max(ma[p[i].b],ma[p[i].c]);
			gg[p[i].c]=1;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 27384
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;




int main(){
  int n;
  cin >> n;
  int l[n];
  int i;
  for(i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l,l+n);

  int j,k;
  long long int ans = 0;
  for(i=0;i<n-2;i++){
    for(j=i+1;j<n-1;j++){
      ans += lower_bound(l+j+1,l+n,l[i]+l[j])-&l[j]-1;
    }
  }

  cout << ans << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }

  sort(a.begin(), a.end(), greater<int>());

  int alice = 0, bob = 0;

  for (int i=0; i<N; i++) {
    if (i % 2 == 0) {
      alice += a.at(i);
    } else {
      bob += a.at(i);
    }
  }

  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
int main()
{
    int n;
    cin >> n;
    vi v(n);
    vi c(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    rep(i, n)
    {
        cin >> c[i];
    }
    lint ans = -100;
    rep(i, 1 << n)
    {
        lint x = 0;
        lint y = 0;
        rep(j, n)
        {
            if ((i >> j) & 1)
            {
                x += v[j];
                y += c[j];
            }
        }
        ans = max(ans, x - y);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 2019
L, R = map(int, input().split())
ans = float('inf')
if R-L <= 2020:
    for l in range(L, R):
        for r in range(l+1, R+1):
            ans = min(ans, (r*l) % MOD)
else:
    for l in range(1, MOD):
        for r in range(l+1, MOD+1):
            ans = min(ans, (r*l) % MOD)
print(ans)


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> sum (N);
  
  for (int i =  0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a-=1;
    b-=1;
    sum.at(a)+=1;
    sum.at(b)+=1;
  }
  
  for (int j = 0; j < N; j++) cout << sum.at(j) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

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

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = 0;
		int b = 0;
		int c = 0;
		int n = scanner.nextInt();

		for(int i = 0; i < n; i++){
			a = scanner.nextInt();
			b = scanner.nextInt();
			c = scanner.nextInt();

			if(c *  c == a * a + b * b || b *  b == a * a + c * c || a *  a == b * b + c * c){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 33300
N = int(input())
lis = list(map(int, input().split()))
list_asc = sorted(lis)
counts = 0
for i in range(0, len(lis)):
  if lis[i] != i + 1:
    counts += 1
  

if counts == 2 or counts == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
// Date: 2020-03-01

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL a[N];
int n;
int main() {
    scanf("%d", &n);
    rep(i, 1, n) scanf("%lld", &a[i]);
    LL l = 2, r = 2;
    int flag = 1;
    per(i, n, 1) {
        LL nl = l/a[i]*a[i];
        if(nl < l) nl += a[i];
        LL nr = r/a[i]*a[i] + a[i]-1;
        if(nl > nr) {
            flag = 0;
            break;
        }
        l = nl, r = nr;
    }
    if(!flag) puts("-1");
    else printf("%lld %lld\n", l, r);

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = [[0, 0] for i in range(n)]
for i in range(n):
  x, l = list(map(int, input().split()))
  a[i] = [x + l, max(x - l, 0)]
a.sort()
ans = 0
p = 0
for i in a:
  if p <= i[1]:
    ans += 1
    p = i[0]
print(ans)

Measured memory_bytes: 24472
#include "bits/stdc++.h"
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1e9+7
#define inf 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec));
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;

signed main() {
	int a,b,c;
	cin>>a>>b>>c;
	set<int>st;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	cout<<st.size()<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,n;cin>>a>>b>>n;
    ll q;
    if(b<=n)q=b-1;
    else q=n;
    cout<<a*q/b<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    string s;
    cin >> s;
    int n = s.size();
    auto dp = make_v(n+1, 13, 0);
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        if(s[i] != '?'){
            for (int j = 0; j < 13; ++j) {
                (dp[i+1][(j*10+s[i]-'0')%13] += dp[i][j]) %= MOD;
            }
        }else {
            for (int j = 0; j < 13; ++j) {
                for (int k = 0; k < 10; ++k) {
                    (dp[i+1][(j*10+k)%13] += dp[i][j]) %= MOD;
                }
            }
        }
    }
    cout << dp.back()[5] << "\n";
    return 0;
}

Measured memory_bytes: 8960
#include <cstdio>
#include <algorithm>
#define Max(x,y) (x)=max((x),(y))
using namespace std;
int n,a[500005],dp[500005];
char s[500005];
int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++){
		a[i]=(s[i]=='0')?i:a[i-1];
	}
	for(int i=1;i<=n;i++){
		dp[i]=dp[i-1];
		if(s[i]=='0')continue;
		if(i>1 && s[i-1]=='0' && s[i-2]=='1')Max(dp[i],max(dp[a[i-2]]+(i-2)-a[i-2],dp[a[i-2]+1]+(i-2)-(a[i-2]+1)));
		else if(a[i]>1 && s[a[i]-1] == '1')Max(dp[i],dp[a[i]-2]+i-a[i]);
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 4608
K, N = map(int, input().split())
A = list(map(int, input().split()))

max_d = K - A[-1] + A[0]
for i in range(N - 1):
    d = A[i + 1] - A[i]
    max_d = max(d, max_d)

ans = K - max_d
print(ans)


Measured memory_bytes: 26444
import java.util.*;
import java.io.*;

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
//......................................@uthor_Alx..............................................
static long mod=(long)1e9+7;

public static void main(String[] args) throws  IOException{
                assign();
                int n=int_v(read());
                int[] a=int_arr();
                long[][] dp=new long[n+1][4];
                dp[0][0]=1000l;
                for(int i=1;i<=n;i++){
                    dp[i][2]=dp[i-1][3]+(long)a[i-1]*dp[i-1][1];//sell all
                    long max=Math.max(dp[i-1][0],Math.max(dp[i-1][2],dp[i][2]));
                    dp[i][0]=max;// doing nothing
                    dp[i][1]= max/a[i-1];//buy all
                    dp[i][3]=max-(long)dp[i][1]*a[i-1];
                }
                /*for(int i=1;i<=n;i++){
                    out.write(dp[i][0]+" "+dp[i][1]+" "+dp[i][2]+" "+dp[i][3]+"\n");
                }*/
                out.write(Math.max(dp[n][0],dp[n][2])+"");
                out.flush();

    }
}


Measured memory_bytes: 36992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class Station {
        public int C;
        public int S;
        public int F;
        public Station(int c, int s, int f) {
            C = c;
            S = s;
            F = f;
        }
    }

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var list = new List<Station> ();

            for (int i = 0; i < N - 1; i++) {
                var c = NextInt();
                var s = NextInt();
                var f = NextInt();
                list.Add(new Station(c, s, f));
            }

            for (int i = 0; i < N; i++) {
                long time = 0;
                for (int s = i; s < N - 1; s++) {
                    var tmp = list[s].S;
                    while (tmp < time) tmp += list[s].F;
                    time = tmp;

                    time += list[s].C;
                }

                Console.WriteLine(time);
            }
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let _: usize = itr.next().unwrap().parse().unwrap();
    let g: Vec<Vec<char>> = (0..h)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();

    let mut ans = vec![vec![0; w]; h];
    let mut num = 1;
    for i in 0..h {
        for j in 0..w {
            if g[i][j] == '#' {
                ans[i][j] = num;
                num += 1;
            }
        }
    }
    for i in 0..h {
        for j in 0..w - 1 {
            if ans[i][j + 1] == 0 {
                ans[i][j + 1] = ans[i][j];
            }
        }
        for j in (1..w).rev() {
            if ans[i][j - 1] == 0 {
                ans[i][j - 1] = ans[i][j];
            }
        }
    }
    for j in 0..w {
        for i in 0..h - 1 {
            if ans[i + 1][j] == 0 {
                ans[i + 1][j] = ans[i][j];
            }
        }
        for i in (1..h).rev() {
            if ans[i - 1][j] == 0 {
                ans[i - 1][j] = ans[i][j];
            }
        }
    }
    let mut out = Vec::new();
    for i in 0..h {
        for j in 0..w {
            write!(out, "{}", ans[i][j]).ok();
            if j != w - 1 {
                write!(out, " ").ok();
            }
        }
        writeln!(out, "").ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 6908
import scala.io.StdIn._

object Main extends App {


  val x = readInt()

  def solve(): Int = {
    var ans = x
    while(!isPrime(ans)) ans += 1
    ans
  }

  def isPrime(num: Int): Boolean = {
    if(num <= 1) false
    else if(num == 2) true
    else (2 until num).forall(num % _ != 0)
  }

  println(solve())

}



Measured memory_bytes: 54812
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    int n, x;
    cin >> n >> x;
    int d = 0;
    int ans = 1;
    for(int i = 0; i < n; ++i){
        int l;
        cin >> l;
        d += l;
        if(d <= x){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256