akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

constexpr long long mod = 1000000007;
//constexpr long long mod = 11;

long long gcd(long long a, long long b) {
    long long large = max(a, b), small = min(a, b);
    long long mod = large % small;
    if (small % mod == 0) return mod;
    else return gcd(small, mod);
}


pair<long long, long long> ext_gcd_(long long a, long long b, long long c) {
    if (b == 0) return make_pair(c / a, 0);
    long long s = a / b, t = a % b;
    auto r = ext_gcd_(b, t, c);
    return make_pair(r.second, r.first - (s * r.second));
}


pair<long long, long long> ext_gcd(long long a, long long b, long long c) {
    if (a >= b) return ext_gcd_(a, b, c);
    else {
        auto r = ext_gcd_(a, b, c);
        return make_pair(r.second, r.first);
    }
}

long long d_im[110000] = {0};
long long inv_mod(long long n) {
    if (d_im[n] == 0) {
        auto r = ext_gcd(-mod, n, 1);
        d_im[n] = r.first;
    }
    return d_im[n];
}

long long d_fc[110000] = {0};
long long fac_mod(long long n) {
    if(n == 0) return 1;
    if(d_fc[n] == 0) {
        d_fc[n] = (fac_mod(n-1) *n) % mod;
    }
    return d_fc[n];
}

long long d_if[110000] = {0};
long long fac_inv_mod(long long n) {
    if(n == 0) return 1;
    if(d_if[n] == 0) {
        d_if[n] = (fac_inv_mod(n-1) * inv_mod(n)) % mod;
    }
    return d_if[n];
}

long long comb_mod(long long a, long long b) {
    if(b > a) return 0;
    return ((((fac_mod(a) * fac_inv_mod(b)) % mod) * fac_inv_mod(a-b)) % mod);
}

int main() {
    long long n, k, a[100000];
    cin >> n >> k;
    for (long long i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    long long ret = 0;
    for(int i = 0;i < n;i++ ) {
        ret += a[i] * comb_mod(i,k-1);
        ret -= a[i] * comb_mod(n-i-1,k-1);
        while(ret < 0 || ret > mod)
        ret = (ret + mod) % mod;
    }
    cout << ret << endl;
}

Measured memory_bytes: 4096
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ns := nextInts(n)
	sort.Sort(sort.IntSlice(ns))
	var sum int
	for _, v := range ns {
		sum += v
	}
	fmt.Println(ns[0], ns[n-1], sum)
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}



Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int main()
{
long a,b,c,d,r,f;
cin>>a>>b>>c;
if(a!=b && b!=c && c!=a) cout<<"3"<<endl;
else if((a==b&&b!=c)||(b==c&&c!=a)||(c==a&&a!=b))cout<<"2"<<endl;
else cout<<"1"<<endl;


return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

int _min(int a,int b){return a<b?a:b;}
int _abs(int a){return a<0?-a:a;}

int h[100001],f[100001];

int main()
{
  int n,k;scanf("%d%d",&n,&k);
  for (int i=1;i<=n;++i) scanf("%d",&h[i]);
  f[1]=0;
  for (int i=2;i<=n;++i)
  {
    f[i]=1e9+7;
    for (int j=1;j<=k && i-j>0;++j)
      f[i]=_min(f[i],f[i-j]+_abs(h[i]-h[i-j]) );
  }
	printf("%d\n",f[n]);
}


Measured memory_bytes: 896
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s = {}
    for _ in range(n):
        a = input().rstrip()
        s[a] = 1
    print(len(s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 35440
n = int(input())
price = [int(x) for x in input().split()]

custom_price = []
i = 0
while True:
    # print(custom_price)
    # input()
    while i+1 < n and price[i+1] <= price[i]:
        i += 1
    custom_price.append(price[i])
    i += 1
    if i == n:
        break
    while i+1 < n and price[i+1] >= price[i]:
        i += 1
    custom_price.append(price[i])
    i += 1
    if i == n:
        break
if len(custom_price) % 2 == 1:
    custom_price.pop(-1)

i = 0
cur = 1000
while i < len(custom_price):
    stocks = cur//custom_price[i]
    cur += (stocks * (custom_price[i+1] - custom_price[i]))
    i += 2
print(cur)

Measured memory_bytes: 62004
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
count_ball = [1] * n
check = [False] * n
check[0] = True
for i in range(m):
    count_ball[l[i][0] - 1] -= 1
    count_ball[l[i][1]-1] += 1
    if check[l[i][0]-1]:
        check[l[i][1]-1] = True
    if count_ball[l[i][0]-1] == 0:
        check[l[i][0]-1] = False
print(check.count(True))

Measured memory_bytes: 28964
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

const ll MX = 1e18;

int main(){

  int N;
  cin >> N;
  ll ans = 1;
  bool ng = false;
  ll A;

  for (int i = 0; i < N; i++){
    cin >> A;
    if(A == 0){
      cout << 0 << endl;
      return 0;
    }
    if(ng || __int128(ans)*A > MX){
      ng = true;
    }
    ans *= A;
  }
  if(ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

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

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

    int a;
    cin >> a;
    string s;
    cin >> s;
    if (a >= 3200) cout << s << endl;
    else
        cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x,it) for(auto it = x.begin();it!=x.end();++it)
#define fpresent(x,c) ((c).find(x) != (c).end())  //set,map
#define present(c,x) (find(all(c),x) != (c).end()) //vector
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use mt19937_64 for 64 bit random no.

const int N = 200005;
vector<ll> a(N);

vector<ll> cal(ll k){
    if(k == 1)
        return a;
    vector<ll> temp = cal(k/2), p(a.size());


    for(int i=0;i<a.size();i++){
        p[i] = temp[temp[i]];
    }

    // for(auto it: p)
    //         cout<<it<<" ";
    //     cout<<endl;

    if(k%2){
        for(int i=0;i<a.size();i++){
            temp[i] = p[a[i]];
        }
        p = temp;
    }
    // cout<<k<<endl;
    
    return p;
}

int main()
{
    // freopen("input.in","r",stdin);
    // freopen("output.in","w",stdout);
    fastio;
    cin.tie(NULL);
    ll n,m,i,j,k,ans=0;
    cin>>n>>k;
    a.resize(n);
    for(i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }

    // for(i=1;i<=5;i++){
    vector<ll> res = cal(k);
    cout<<res[0] + 1<<endl;
        // for(auto it: res)
        //     cout<<it<<" ";
        // cout<<endl;
    // }

    return 0;
}


Measured memory_bytes: 7988
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  vector<int> b(n), ans;
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n; i++){
    int Max = -1, id = 0;
    for(int j = 0; j < b.size(); j++){
      if(b[j] == j+1 && Max <= b[j]){
        Max = b[j];
        id = j;
      }
    }
    if(Max == -1){
      cout << -1 << endl;
      return 0;
    }
    b.erase(b.begin() + id);
    ans.emplace_back(Max);
  }
  reverse(ans.begin(),ans.end());
  for(int p : ans){
    cout << p << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastInput in = new FastInput();
        PrintWriter out = new PrintWriter(System.out);
        int d = in.nextInt(), t = in.nextInt(), s = in.nextInt();
        out.println(s * t >= d ? "Yes" : "No");
        out.close();
    }

    static class FastInput {
        BufferedReader br;
        StringTokenizer st;

        public FastInput() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 25060
import sys
input=sys.stdin.readline

n=int(input())
a=list(map(int,input().split()))

ans=0
l=0
for r in range(n-1):
    if a[r]>=a[r+1]:
        l+=1
        ans=max(ans,l)
    else:
        l=0
print(ans)


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

const long long N = 1e3 + 17;
ll cnt, ans, lnt = N, sum, n, l1, b[N][N], a[N], x, y, mx = N, z;
pair<ll,ll>pr[N];
vector<ll>v,v2,v3;
map<ll,ll>mp;
bool used[N], t1, t2;
vector<string>sv;

int main()
{
    cin >> n;
    x = n / 100;
    y = (n / 10) % 10;
    z = n % 10;
    if(x == y and y == z)
    {
        cout << n;
    }
    else
    {
        if(y > x or z > x)
        {
            cout << x + 1 << x + 1 << x + 1;
        }
        if(x >= y and x >= z)
        {
            cout << x  << x << x;
        }
    }
}


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000000000
#define MOD 1000000007

int main(){

    ll a,b,c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);

    cout << a << " " << b << " " << c << endl;


}




















Measured memory_bytes: 256
int main(){

 int a,b,c;

 int buf;

 scanf("%d %d %d",&a,&b,&c); 
 while(a > b || b > c){
  
  if(a > b){
  buf = a;
  a = b;
  b = buf;
  }
  if(b > c){

   buf = b;
   b = c;
   c = buf;
  }
 }

 printf("%d %d %d\n",a,b,c);

 return 0;
}

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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  char c;
  cin >> c;
  cout << (isupper(c) ? 'A' : 'a');

  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
	string msg = "No";
	cin >> s >> t;
 
	for (int i = 0; i < s.size(); i++) {
		s = s[s.size() - 1] + s.substr(0, s.size()-1);
		if (s == t) {
			msg = "Yes";
			break;
		}
	}
 
	cout << msg << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)


// double c(double x)
// {
//   double X = x;
//   X = int(X) % 10;
//   return X;
// }

int main()
{
  ll n;
  cin >> n;
  vector<ll> p(n);
  for(ll i = 0;i < n;i++)
  {
    cin >> p[i];
  }
  int ans = 1;
  int Ans = p[0];
  for(int i = 1;i < n;i++)
  {
    if(p[i] < Ans)
    {
      ans++;
      Ans = p[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
 
int main()
{
  int a[3];
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  int i,tmp = 0;
  while (i < 3)
  {
    int k = i + 1;
    while (k < 3)
    {
      if (a[i] < a[k])
      {
        tmp = a[i];
        a[i] = a[k];
        a[k] = tmp;
      }
      k++;
    }
    i++;
  }
  printf("%d",a[0]-a[2]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//モジュラ逆数
long long modinv(long long n, long long p) {
  long long a = p, u = 1, v = 0;
  while (a) {
    long long t = n / a;
    n -= t * a;
    std::swap(n, a);
    u -= t * v;
    std::swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  ll h, w, a, b, p = 1e9 + 7;
  cin >> h >> w >> a >> b;

  ll ans = 0;

  ll y = h - a - 1, x = b;
  ll c = 1;
  ll cnx = x;
  for (ll i = 0; i < x; i++) {
    c *= x + y - i;
    c %= p;
    c *= modinv(i + 1, p);
    c %= p;
  }
  ll hoge = a, fuga = w - b - 1;
  ll d = 1;
  ll dnx = hoge;
  for (ll i = 0; i < hoge; i++) {
    d *= hoge + fuga - i;
    d %= p;
    d *= modinv(i + 1, p);
    d %= p;
  }
  ans += c * d % p;
  ans %= p;
  //cout << ans << endl;
  while (y > 0 && x < w - 1) { //grid[y][x]経由
    c *= x + y - cnx;
    c %= p;
    c *= modinv(cnx + 1, p);
    c %= p;
    d *= hoge + fuga - dnx;
    d %= p;
    d *= modinv(dnx + 1, p);
    d %= p;
    ans += c * d % p;
    ans %= p;
    y--;
    x++;
    hoge++;
    fuga--;
    cnx++;
    dnx++;
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	   int n,m;
	   cin>>n>>m;
	   int s=0;
	   int a[n];
	   for(int i=0;i<n;i++)
	  { cin>>a[i];s+=a[i];}
	  
	  int cnt=0;
	  for(int i=0;i<n;i++)
	  {
	     if(((float)a[i]/s) >= 0.25/m)
	        cnt++;
	  }
	  if(cnt>=m)
	  cout<<"Yes";
	  else
	  cout<<"No";
	  cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main(){
  std::string S, T;
  std::cin >> S;
  std::cin >> T;
  bool same = true;
  for (int i=0; i<int(S.length()); i++){
    if (S[i]!=T[i]) {
      same=false;
      break;
    }
  }
  printf("%s\n", same?"Yes":"No");
  return 0;
}


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

int gcd(int a, int b) {
  if(a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  long int a, b, c;
  cin >> a >> b;
  long int d = a, e = b;
  if(a < b) {
    c = gcd(b, a);
  } else {
    c = gcd(a, b);
  }
  cout << e * d / c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int,int>pr;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef set<int>si;
const int INF=1070000000ll;
const int mod=1000000007ll;

int n,m;
char seet[100];
void A(){
    rep(i,n)if(seet[i]=='#'){
        seet[i]='A';
        return;
    }
}
void B(){
    rrep(i,n-1)if(seet[i]=='#'){
        if((i!=0||seet[i-1]!='A')&&(i!=n-1||seet[i+1]!='A')){
            seet[i]='B';
            return;
        }
    }
    rep(i,n)if(seet[i]=='#'){
        seet[i]='B';
        return;
    }
}
void C(){
    rep(i,n)if(seet[i]!='#'){
        if(i!=n-1&&seet[i+1]=='#'){
            seet[i+1]='C';return;
        }
        if(i!=0&&seet[i-1]=='#'){
            seet[i-1]='C';return;
        }
    }
    seet[n/2]='C';
}
void D(){
    int ma=0,dist=0;
    rep(i,n)if(seet[i]=='#'){
        int v=1000;
        rep(j,n)if(seet[j]!='#'){
            v=min(abs(i-j),v);
        }
        if(dist<v){
            dist=v;
            ma=i;
        }
    }
    seet[ma]='D';
}
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);

    while(cin>>n>>m,n||m){
        fill_n(seet,n,'#');
        rep(i,m){
            char c;cin>>c;
            switch(c){
                case 'A':A();break;
                case 'B':B();break;
                case 'C':C();break;
                case 'D':D();break;
            }
        }
        rep(i,n)cout<<seet[i];cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int n, k, l[51];

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

    sort(l, l + n, greater<int>());
    int sum = 0;
    for (int 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 main(){
    int A, B, C, i, j;
    cin >> A >> B >> C;
    j = 0;

    for (i = 0; i <= 1000000; i++){
      if(A * i % B == C){
        cout << "YES" << endl;
        j = 1;
        break;
      }
    }
    if (j == 0){
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
                    .map(|e| e.parse().ok().unwrap())
                    .collect()
}

fn main() {
    let n: u32 = read::<u32>();

    let mut lucas: Vec<i64> = Vec::new();
    lucas.push(2);
    lucas.push(1);

    for i in 2..n+1 {
        // ループカウンタのiをas usizeで配列へアクセスできるようにしている
        let u = i as usize;

        let mut nw = lucas[u-2];
        nw = nw + lucas[u-1];
        lucas.push(nw);
    }

    let n = n as usize;
    println!("{}", lucas[n]);

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll D,S,T;
    cin>>D>>T>>S;
    if(ceil(1.0*D/S)<=T){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int AB = Integer.parseInt(sc.next());
	static int BC = Integer.parseInt(sc.next());
	static int CA = Integer.parseInt(sc.next());
	public static void main(String[] args) {
		System.out.println(AB*BC/2);
	}
}


Measured memory_bytes: 23252
#include <cstdio>
#include <algorithm>
using namespace std;

int i, m[10];

int main(void)
{
  for(i = 0; i < 10; i++)
    scanf("%d",&m[i]);

  sort(m,m+10);

  printf("%d\n%d\n%d\n",m[9],m[8],m[7]);
  return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define EREP(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), m = in();

    vvll xyz(n, vll(3));
    rep(i, n) rep(j, 3) cin >> xyz[i][j];

    ll ans = -LINF;
    rep(bit, 8)
    {
        vll score(n);
        rep(i, 3)
        {
            ll sign = 1;
            if (bit & (1 << i))
                sign = -1;
            rep(j, n)
                score[j] += xyz[j][i] * sign;
        }

        sort(ALL(score), greater<ll>());

        ans = max(ans, (ll)accumulate(score.begin(), score.begin() + m, 0ll));
    }
    cout << ans << endl;
}

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


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

int main(){
    int x, ta, tb;
    char a[11234], b[11234];
    scanf("%s", a);
    scanf("%s", b);
    ta = strlen(a);
    tb = strlen(b);
    if (ta > tb)
        printf("GREATER\n");
    else if (tb > ta)
        printf("LESS\n");
    else{
        x = strcmp(a, b);
        if (x > 0)
            printf("GREATER\n");
        else if (x < 0)
            printf("LESS\n");
        else
            printf("EQUAL\n");
    }
    return 0;
}

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

int main(){
    int n,m,b,ans(0);

    cin >> n >> m;
    b = n + m;

    ans = (n*(n-1))/2;
    
    if(m>2){
        ans += (m*(m-1))/2;
    }else if(m==2)    ans++;

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  for(int i=0;i<m;i++) cin>>b[i];
  vector<vector<int>>a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
  cin>>a[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int sum=c;
    for(int j=0;j<m;j++){
  sum+=a[i][j]*b[j];
    }
    if(sum>0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let mut n: u64 = input();
    let mut ans: Vec<u64> = Vec::new();
    while n > 0 {
        if n % 26 == 0 {
            ans.push(26);
            n -= 26;
            n /= 26;
        } else {
            ans.push(n % 26);
            n /= 26;
        }
    }
    ans.reverse();
    // println!("{:?}", ans);
    for a in ans {
        print!("{}", (a as u8 + 96) as char);
    }
    println!();
    // println!("{:?}", ans);
}


Measured memory_bytes: 2136
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		double x[4],y[4];
		rep(j,4)cin>>x[j]>>y[j];
		if(x[0]==x[1]){
			cout<<(x[2]==x[3]?"YES":"NO")<<endl;
		}else{
			if(x[2]==x[3])cout<<"NO\n";
			else{
				cout<<((y[0]-y[1])/(x[0]-x[1])==(y[2]-y[3])/(x[2]-x[3])?"YES":"NO")<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        double dx = x1 - x2;
        double dy = y1 - y2;
        double d = Math.sqrt(dx*dx+dy*dy);
        NumberFormat format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(5);
        format.setMinimumFractionDigits(5);
        format.setGroupingUsed(false);
        System.out.println("" + format.format(d));
    }
}

Measured memory_bytes: 18596
#include<stdio.h>
void main()
{
  int x1,x2,x3,x4,x5;
  scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
  if(x1==0)
    printf("1");
  else if(x2==0)
    printf("2");
  else if(x3==0)
    printf("3");
  else if(x4==0)
    printf("4");
  else if(x5==0)
    printf("5");
}
  


Measured memory_bytes: 1656
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
        String s = sc.next();
        int value = 700;
        sc.close();

        if(s.charAt(0) == 'o') value += 100;
        if(s.charAt(1) == 'o') value += 100;
        if(s.charAt(2) == 'o') value += 100;

		// 出力
		System.out.println(value);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lint;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A + B >= C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)])
graph2 = np.array([[0 if i == j else float("inf")
                   for i in range(N)] for j in range(N)])


for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
dist = floyd_warshall(graph)

graph2[(dist <= L) & (dist != 0)] = 1
dist2 = floyd_warshall(graph2)
dist2[dist2 == float("inf")] = 0

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(int(dist2[s - 1, t - 1]) - 1)



Measured memory_bytes: 19952
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main(void) {
    
    ll n;
    cin>>n;
    vll v=enum_div(n);
    int ans=INF;
    rep(i,v.size()){
        ans=min(ans,(int)max(floor(log10(v[i])),floor(log10(n/v[i])))+1);
    }
    fin(ans);
}

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

Measured memory_bytes: 3564
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int x = s.nextInt(),y=s.nextInt();
        System.out.println(x+(y/2));


    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25356
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	int w;
	cin >> s >> w;
	for(int i = 0;i < SZ(s);i += w){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main(){
  int N,K,C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  int i,count, work, num;
  vector<int> worka(N);
  vector<int> workb(N);
  count=0; work=-C-1;
  for(i=0; i<N; i++){
    if(i-work<=C) continue; 
    if(S[i] == 'o'){
      work = i;
      worka.at(count) = work;
      count++;
    }
  }
  num = count;
  work=N+C+1;
  count--;
  for(i=N; i>0; i--){
    if(work-i<=C) continue; 
    if(S[i] == 'o'){
      work = i;
      workb.at(count) = work;
      count--;
    }
  }
  if(num == K){
	for(i=0; i<K; i++){
      if(worka[i] == workb[i]) cout << worka[i]+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3460
n=int(input())
l=[int(i) for i in input().split()]

def f(l):
    p=[0]*(n+1)
    s=[(-1,0)] #sentinel
    for i,a in enumerate(l):
        while s[-1][1]>a: #delete items if larger than target
            s.pop()
        t=i-s[-1][0] #get distance(left--target)
        p[a]=t #P[x] means distance(left--x) its min equals to x
        s.extend([(i,a)]) #add items
    return p
p=f(l) #distance list (left--target)
q=f(l[::-1]) #distance list (target--right)
print(sum(i*p[i]*q[i] for i in l))


Measured memory_bytes: 42512
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int main(){

	int N,M,A,B,tmp,ans = 0;
	bool FLG = false;

	stack<int> S;

	scanf("%d %d %d %d",&N,&M,&A,&B);
	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		if(FLG == false && tmp >= A){
			S.push(tmp);
			ans++;
		}else{
			FLG = true;
		}
	}

	if(N - ans < M){
		while(!S.empty()){
			if(S.top() <= B){
				ans--;
			}else{
				break;
			}
			S.pop();
		}
	}

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

    return 0;
}

Measured memory_bytes: 2748
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - String Rotation
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            
            if(IsMatchString(s, t))
            {
                Console.WriteLine("Yes");    
            }
            else
            {
                Console.WriteLine("No");    
            }
        }
        
        static bool IsMatchString(string s, string t)
        {
            string rotate = s;

            while (true)
            {
                if(rotate == t)
                {
                    return true;    
                }
                else
                {
                    rotate = RotateString(rotate);    
                }
                
                if(rotate == s)
                {
                    return false;    
                }
            }
        }

        static string RotateString(string s)
        {
            var array = s.ToCharArray();
            char lastChar = s.Last();
            var substring = String.Join("", array.Take(s.Length - 1));
            return lastChar + substring;
        }
    }
}

Measured memory_bytes: 13268
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.d = [-1] * n

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

        if x == y:
            return False
        else:
            if self.d[x] > self.d[y]:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)


    def size(self, x):
        return -self.d[self.find(x)]


n, m, k = map(int,input().split())
fb = [0] * n
uf = UnionFind(n)
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)
    fb[a] += 1
    fb[b] += 1

for j in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c, d) == True:
        fb[c] += 1
        fb[d] += 1

for i in range(n):
    print(uf.size(i) - fb[i] - 1)

Measured memory_bytes: 8704
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
	int N,M;
	cin >>N>>M;
	vector<int> path[N];
	int A,B;
	for(int i=0;i<M;i++){
		cin >>A>>B;
		A--;
		B--;
		path[A].push_back(B);
		path[B].push_back(A);
	}
	//BFSの実装を解説動画で見た。学びがあった。
	queue<int> q;	//次に確認する番号をqueueに蓄える
	vector<int> depth(N,-1);	//そのノードの深さ
	vector<int> previous(N,-1);	//ルートを蓄える
	depth[0]=0;
	q.push(0);	//0から始める
	int target;
	while(q.empty()==false){
		target=q.front();
		q.pop();
		for(int next : path[target]){
			if(depth[next]!=-1) continue;
			depth[next]=depth[target]+1;
			previous[next]=target;
			q.push(next);
		}
	}
	int temp;
	cout <<"Yes"<<endl;
	for(int i=1;i<N;i++){
		temp=previous[i];
		temp++;
		cout <<temp<<endl;
	}
	return 0;
}

Measured memory_bytes: 10636
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 29 21:00:35 2016

@author: dotha
"""

def main():
    N = int(input())
    s = input()
    t = input()
    if s==t:
        return s
    for i in range(N):
        if s[i:] == t[:-i]:
            return(s[:i]+t)
    else:
        return(s+t)
    





if __name__ == "__main__":
    print(len(main()))

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main() {
	cout << fixed << setprecision(6);
	int n;
	cin >> n;
	int x[100], y[100];
	for (int i = 0; i < n; i++)cin >> x[i];
	for (int i = 0; i < n; i++)cin >> y[i];
	double sum1 = 0;
	for (int i = 0; i < n; i++)sum1 += fabs(x[i] - y[i]);
	double sum2 = 0;//?????§??????????????¨???
	for (int i = 0; i < n; i++)sum2 += pow(fabs(x[i] - y[i]), 2);
	double sum3 = 0;//?????§??????????????¨???
	for (int i = 0; i < n; i++)sum3 += pow(fabs(x[i] - y[i]), 3);
	double max = 0;
	for (int i = 0; i < n; i++)if (max < fabs(x[i] - y[i]))max = fabs(x[i] - y[i]);
	cout << sum1 << endl << sqrt(sum2) << endl << pow(sum3, 1.0 / 3) << endl << max << endl;
	return 0;
}

Measured memory_bytes: 1276
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  int total_steps;
  while(~scanf("%d",&total_steps)){
    if(total_steps == 0) break;

    int left_state = 0;
    int right_state = 0;
    int next_target = 1;
    int res = 0;
    for(int step_idx = 0; step_idx < total_steps; step_idx++){
      char command[12];
      scanf("%s",command);

      bool is_updated = false;
      if(strcmp(command,"lu") == 0){
        if(left_state == 0){
          is_updated = true;
          left_state = 1;
        }
      }
      else if(strcmp(command,"ru") == 0){
        if(right_state == 0){
          is_updated = true;
          right_state = 1;
        }
      }
      else if(strcmp(command,"ld") == 0){
        if(left_state == 1){
          is_updated = true;
          left_state = 0;
        }
      }
      else if(strcmp(command,"rd") == 0){
        if(right_state == 1){
          is_updated = true;
          right_state = 0;
        }
      }

      if(is_updated 
         && (right_state == left_state)
         && (right_state == next_target)){
        res++;
        next_target = (next_target == 1 ? 0 : 1);
      }
    }

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

Measured memory_bytes: 1192
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

s = [[0]*2 for i in range(n)]
m = [[0]*2 for i in range(n)]

# 売り
s[0][0] = 0
m[0][0] = 1000
# 買い
s[0][1] = 1000//a[0]
m[0][1] = 1000 - s[0][1] * a[0]

for i in range(1,n):
    s[i][0] = 0
    m[i][0] = max(m[i-1][0], m[i-1][1]+s[i-1][1]*a[i])
    s[i][1] = max(m[i-1][0]//a[i], s[i-1][1])
    if m[i-1][0]//a[i] > s[i-1][1]:
        m[i][1] = m[i-1][0]-s[i][1]*a[i]
    elif m[i-1][0]//a[i] < s[i-1][1]:
        m[i][1] = m[i-1][1]
    else:
        m[i][1] = max(m[i-1][0]-s[i][1]*a[i], m[i-1][1])

print(m[n-1][0])

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

// ModIntR::set_mod()
struct ModIntR {
  int x;
  ModIntR() : x(0) {}
  ModIntR(int64_t y) : x(y >= 0 ? y % mod() : (mod() - (-y) % mod()) % mod()) {}
  static int &mod() {
    static int mod = 0;
    return mod;
  }
  static void set_mod(int md) { mod() = md; }
  ModIntR &operator+=(const ModIntR &p) {
    if ((x += p.x) >= mod()) x -= mod();
    return *this;
  }
  ModIntR &operator-=(const ModIntR &p) {
    if ((x += mod() - p.x) >= mod()) x -= mod();
    return *this;
  }

  ModIntR &operator*=(const ModIntR &p) {
    long long m = mod();
    x = (int)(1LL * x * p.x % m);
    return *this;
  }

  ModIntR &operator/=(const ModIntR &p) {
    *this *= p.inverse();
    return *this;
  }

  ModIntR operator-() const { return ModIntR(-x); }

  ModIntR operator+(const ModIntR &p) const { return ModIntR(*this) += p; }

  ModIntR operator-(const ModIntR &p) const { return ModIntR(*this) -= p; }

  ModIntR operator*(const ModIntR &p) const { return ModIntR(*this) *= p; }

  ModIntR operator/(const ModIntR &p) const { return ModIntR(*this) /= p; }

  bool operator==(const ModIntR &p) const { return x == p.x; }

  bool operator!=(const ModIntR &p) const { return x != p.x; }

  ModIntR inverse() const {
    int a = x, b = mod(), u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModIntR(u);
  }

  ModIntR pow(int64_t n) const {
    ModIntR res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }

  friend ostream &operator<<(ostream &os, const ModIntR &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModIntR &a) {
    int64_t t;
    is >> t;
    a = ModIntR(t);
    return (is);
  }
};

long long n, m;

ModIntR solve();

int main() {
  cin >> n >> m;
  ModIntR::set_mod(m);
  cout << solve() << endl;
  return 0;
}

ModIntR solve() {
  ModIntR res = 0, three = 1;
  for (int i = 0; i <= 3 * n; i += 3) {
    ModIntR now = three;
    for (int j = 0; j <= n - i / 3; ++j) {
      res += now;
      now *= (3 * n - i - 2 * j);
      now *= (3 * n - i - 2 * j - 1);
      now /= 2 * (j + 1);
    }
    for (int j = 0; j < 3; ++j) three *= 3 * n - i - j;
    three /= 3 * (i / 3 + 1);
  }
  return res;
}

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

namespace ABC103
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);Console.WriteLine(a[2] - a[0]);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int zan;
  zan = c-(a-b);
  if (zan < 0) zan = 0;
  cout << zan << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = a[-1]
m = 0
while True:
    if 2**m > max_a:
        break
    m += 1
used = [False] * n


def bisect(val, start, end):
    if start >= end:
        return None
    elif start + 1 == end:
        if a[start] == val:
            if used[start]:
                return None
            used[start] = True
            return start
        else:
            return None
    mid = (start + end) // 2
    if a[mid] == val:
        if used[mid]:
            res = bisect(val, start, mid)
            return res
        else:
            res = bisect(val, mid+1, end)
            if res is not None:
                return res
            used[mid] = True
            return mid
        # if used[mid]:
        #     res = bisect(val, mid+1, end)
        #     if res is not None:
        #         return res
        #     res = bisect(val, start, mid)
        #     return res
        # else:
        #     used[mid] = True
        #     debug("fuga", used)
        #     return mid
    elif a[mid] > val:
        return bisect(val, start, mid)
    else:
        return bisect(val, mid, end)
    # for i in reversed(range(end)):
    #     if (not used[i]) and (a[i]  == val):
    #         used[i] = True
    #         return i
    return None


def _find(b, end, e):
    "slow!!!!"
    # debug(b, end, e)
    val = 2**e - b
    if val <= 0:
        return None
    return bisect(val, 0, end)
    # for i in reversed(range(end)):
    #     if (not used[i]) and (a[i] + b == 2**e):
    #         used[i] = True
    #         return i
    # return None


def find(b, end):
    for e in reversed(range(m+1)):
        res = _find(b, end, e)
        if res is not None:
            return True
    return False


ans = 0
for j in reversed(range(n)):
    if used[j]:
        continue
    b = a[j]
    used[j] = True
    res = find(b, j)
    if res:
        ans += 1


print(ans)


Measured memory_bytes: 131920