akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int n, f;
  cin >> n >> f;
  vector<int> m(n);
  vector<vector<string>> item(n);
  map<string, map<string, int>> p;
  set<string> list;
  int i, j, k;
  for (i = 0; i < n; i++) {
    cin >> m[i];
    string input;
    for (j = 0; j < m[i]; j++) {
      cin >> input;
      item[i].push_back(input);
      list.insert(input);
    }
    // cout << "         " << i << ' ' << item[i].size() << endl;
    for (j = 0; j < item[i].size(); j++) {
      for (k = j + 1; k < item[i].size(); k++) {
        // cout << 'a';
        p[item[i][j]][item[i][k]]++;
        p[item[i][k]][item[i][j]]++;
        // cout << p[item[i][j]][item[i][k]] << ' ' << p[item[i][k]][item[i][j]] << endl;
        // if (item[i][j] == item[i][k]) {
        //   cout << "flag0 " << i << ' ' << item[i][j] << ' ' <<  item[i][k] << j << ' ' << k << endl;
        // }
      }
      // cout << endl;
    }
  }

// cout << endl << endl;

  vector<pair<string, string>> result;
  auto ite_i = list.begin();
  // auto ite_std = list.begin();
  // ite_std++;
  // ite_std = ite_std - ite_i;
  for (i = 0; i < list.size(); i++) {
    auto ite_j = list.begin();
    // for (j = 0; j < i; j++) {
    //   ite_j++;
    // }
    for (j = 0; j < list.size(); j++) {
      // cout << *ite_i << ' ' << *ite_j << ' ' << p[*ite_i][*ite_j] << endl;
      if (p[*ite_i][*ite_j] >= f) {
        result.push_back(make_pair(*ite_i, *ite_j));
      }
      ite_j++;
    }
    ite_i++;
  }

  cout << result.size() / 2 << endl;
  for (i = 0; i < result.size(); i++) {
    if (result[i].first < result[i].second) {
      cout << result[i].first << ' ' << result[i].second << endl;
    }
  }

  // cout << result.size() << endl;
  // for (i = 0; i < result.size(); i++) {
  //   cout << result[i].first << ' ' << result[i].second << endl;
  // }

  // auto ite_i = list.begin();
  // for (i = 0; i < list.size(); i++) {
  //   auto ite_j = list.begin();
  //   ite_j += i + 1;
  //   for (j = i + 1; j < list.size(); j++) {
  //     p.insert(make_pair(*ite_i, make_pair(ite_j, 0)));
  //     ite_j++;
  //   }
  //   ite_i++;
  // }




  return 0;
}



Measured memory_bytes: 65948
fn main() {
    let v: Vec<usize> = r();
    let (n, m) = (v[0], v[1]);

    let mut a: Vec<Vec<_>> = vec!();
    for _ in 0..n {
        let v: Vec<u32> = r();
        a.push(v);
    }

    let mut b: Vec<_> = vec!();
    for _ in 0..m {
        let v: Vec<u32> = r();
        b.push(v[0]);
    }

    for i in 0..n {
        let mut res = 0;
        for aa in b.iter().zip(a[i].iter()).map(|(x, y)| x * y) {
            res += aa
        }
        println!("{:?}", res);
    }
}

fn r<T: std::str::FromStr>() -> Vec<T> {
    let mut b = String::new();
    let s = std::io::stdin();
    s.read_line(&mut b).unwrap();
    b.split_whitespace().flat_map(str::parse).collect()
}


Measured memory_bytes: 5052
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> count = new TreeMap<>(Comparator.reverseOrder());
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            count.put(a[i], count.getOrDefault(a[i], 0) + 1);
            max = Math.max(a[i], max);
        }

        for (int i = 0; i < n; i++) {
            if (a[i] == max) {
                System.out.println(getNext(count));
            } else {
                System.out.println(max);
            }
        }
    }

    static int getNext(Map<Integer, Integer> count) {
        int loop = 1;
        for (Entry<Integer, Integer> e : count.entrySet()) {
            if (e.getValue() > 1) {
                return e.getKey();
            }

            if (loop > 1) {
                return e.getKey();
            }
            loop++;
        }
        return 0;
    }
}


Measured memory_bytes: 95752
a=input()
if len(a)%2==0:
    b=len(a)-1
    k=0
    for i in range(int(len(a)/2)):
        if a[i]!=a[b]:
            k+=1
            b-=1
        else:
            b-=1
else:
    b=len(a)-1
    k=0
    for i in range(int(len(a)/2)):
        if a[i]!=a[b]:
            k+=1
            b-=1
        else:
            b-=1
print(k)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long N, A, B;
cin >> N >> A >> B;
  if(N==1&&(A!=B)){
  cout<<0<<endl;
    return 0;
  }
if (A > B) {
	cout << 0 << endl;
	return 0;
}
	long long ax, in;
	ax = A + B * (N - 1);
	in = B + A * (N - 1);
	cout << ax - in + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include<stack>
#include<queue>
#include <cassert>
using namespace std;

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()

#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<" "<<#x<<"="<<x

#define bit(k) (1LL<<(k))

typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N,D,A;
    cin>>N>>D>>A;
    vector<pair<ll, ll>> XH(N);
    rep(i,N){
        cin>>XH[i].first>>XH[i].second;
    }
    sort(all(XH));
    vector<ll> X(N),H(N);
    rep(i,N){
        X[i] = XH[i].first;
        H[i] = XH[i].second;
    }
    //以前の爆発イベントを格納しておく
    //自分に影響のある範囲のみを常に保存していく
    //どこまでいくつの爆発が起きたのかを記録する
    //爆発範囲の右端, 回数
    queue<pair<ll, ll>> q;
    
    //qに詰まっている回数の合計
    ll qsum = 0;
    ll ans = 0;
    rep(i,N){
        while(!q.empty() &&  q.front().first < X[i]){
            qsum -= q.front().second;
            q.pop();
        }
        H[i] -= qsum * A;
        if(H[i] <= 0)continue;
        //回数
        ll cnt = (H[i] + A - 1) / A;
        ans += cnt;
        q.push(make_pair(X[i] + 2 * D, cnt));
        qsum += cnt;
    }
    cout<<ans<<endl;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var abhm = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
        var (a, b, h, m) = (abhm[0], abhm[1], abhm[2], abhm[3]);

        var pi2 = 2 * Math.PI;

        var angleH = (h * 60 + m) * pi2 / (12 * 60);
        var angleM = m * pi2 / 60;
        var theta = Math.Abs(angleH - angleM);
        theta = Math.Min(theta, pi2 - theta);
        var cos = Math.Cos(theta) * a;
        var sin = Math.Sin(theta) * a;
        var t = b - cos;
        var l = Math.Sqrt(Math.Pow(t, 2) + Math.Pow(sin, 2));

        Console.Error.WriteLine(pi2 / Math.PI * 180);
        Console.Error.WriteLine(angleH / Math.PI * 180);
        Console.Error.WriteLine(angleM / Math.PI * 180);
        Console.Error.WriteLine(theta / Math.PI * 180);
        Console.Error.WriteLine(cos);
        Console.Error.WriteLine(sin);
        Console.Error.WriteLine(t);

        Console.WriteLine(l);
    }
}


Measured memory_bytes: 28644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int main() {
  int N, D;
  scanf("%d %d", &N, &D);
  printf("%d", (int)std::ceil((double)N / (2 * D + 1)));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

const int INF = 1000000000;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }

    sort(h.begin(), h.end());
    ll ans = INF;
    for (int i = 0; i < N - K + 1; ++i) {
        ans = min(ans, h[i + K - 1] - h[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> p(a), q(b), r(c);
    vector<pair<ll, int>> sum(a + b + c);
    rep(i, a) {
        cin >> p[i];
        sum[i] = make_pair(p[i], 0);
    }
    rep(i, b) {
        cin >> q[i];
        sum[i + a] = make_pair(q[i], 1);
    }
    rep(i, c) {
        cin >> r[i];
        sum[i + a + b] = make_pair(r[i], 2);
    }

    sort(sum.begin(), sum.end(), [&](pair<ll, int> l, pair<ll, int> m) {return l.first > m.first;});

    int n = x + y;
    ll res = 0;
    int i = 0;
    int num = 0;
    while(num < n) {
        if (sum[i].second == 0) {
            if (x == 0) {
                i++;
                continue;
            }
            --x;
            res += sum[i].first;
        }
        else if (sum[i].second == 1) {
            if (y == 0) {
                i++;
                continue;
            }
            --y;
            res += sum[i].first;
        }
        else {
            if (c == 0) {
                i++;
                continue;
            }
            --c;
            res += sum[i].first;
        }
        num++;
        i++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 7296
ans = []
inp = [int(x) for x in input().split()]

h = inp[2] - inp[0]
w = inp[3] - inp[1]

ans.append(inp[2]-w)
ans.append(inp[3]+h)

ans.append(ans[0]-h)
ans.append(ans[1]-w)

for a in ans:
    print(a , end=" ")



Measured memory_bytes: 3060
S = input()

if int(S[0]) + int(S[1]) + int(S[2]) + int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '+' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) + int(S[1]) + int(S[2]) - int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '+' + S[2] + '-' + S[3] + '=7' )
elif int(S[0]) + int(S[1]) - int(S[2]) + int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '-' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) + int(S[1]) - int(S[2]) - int(S[3]) == 7:
    print( S[0] + '+' + S[1] + '-' + S[2] + '-' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) + int(S[2]) + int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '+' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) + int(S[2]) - int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '+' + S[2] + '-' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) - int(S[2]) + int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '-' + S[2] + '+' + S[3] + '=7' )
elif int(S[0]) - int(S[1]) - int(S[2]) - int(S[3]) == 7:
    print( S[0] + '-' + S[1] + '-' + S[2] + '-' + S[3] + '=7' )

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;int d[51][3210],n,m,s,i,j,k;int main(){while(cin>>n>>m>>s&&n){n*=n;memset(d,0,sizeof(d));d[0][0]=1;for(k=1;k<=m;k++)for(i=n;i;i--)for(j=k;j<=s;j++)d[i][j]=(d[i][j]+d[i-1][j-k])%100000;cout<<d[n][s]<<endl;}return 0;}

Measured memory_bytes: 3740
#include <stdio.h>
int main(void) {
	int n,m,tmp,r;
	while(scanf("%d %d",&n,&m)!=EOF){
		if(n<m) {
			tmp=n;
			n=m;
			m=tmp;
		}
		r=n%m;
		while(r!=0){
			n=m;
			m=r;
			r=n%m;
		}
		printf("%d\n",m);
	}
	return 0;
}


Measured memory_bytes: 2032
import java.util.*;
public class Main {
    public static void main(String[] args){
        int n,m,total = 0;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ArrayList<Integer> t = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int tmp = sc.nextInt();
            total += tmp;
            t.add(tmp);
        }
        m = sc.nextInt();

        for(int i = 0; i < m; i++){
            int p = sc.nextInt();
            int x = sc.nextInt();
            p--;
            System.out.println(total - (t.get(p)-x));
        }
        sc.close();
    }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<string.h>
using namespace std;

char arr[10];

int main(void){
    scanf("%s",arr);
    int len=strlen(arr);
    bool success=true;
    for(int i=0;i<len/2;i++)
        if(arr[i]!=arr[len-1-i]){
            success=false;break;
        }
    if(success)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int n,a[maxn];
int main() {
	cin>>n;
	for(int i=1;i<=n;++i) cin>>a[i];
	int cnt=1;
	vector<int> v;
	for(int i=1;i<=n;++i) {
		if(a[i]==cnt) v.push_back(cnt),cnt++;
	}
	
	if(v.size()==0) cout<<-1;
	else cout<<n-v.size();
	return 0;
} 

Measured memory_bytes: 2168
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_10_A: Fibonacci Number

#include <algorithm>
#include <cstdio>

#define NDEBUG
#include <cassert>

class Fibonnacci {
  static const unsigned int N = 44u;
  unsigned int n_;
  unsigned long* f_;

public:
  Fibonnacci(unsigned int n = N) : n_(std::max(1u, n))
  {
    f_ = new unsigned long[n_+1];
    f_[0] = f_[1] = 1;
    for (auto i = 2u; i <= n; ++i) {
      f_[i] = f_[i-1] + f_[i-2];
    }
  }

  ~Fibonnacci() { delete[] f_; }
  
  unsigned long operator () (unsigned int n) const
  {
    assert(n <= n_);
    return f_[n];
  }
};

int main()
{
  unsigned int n;
  std::scanf("%u", &n);
  Fibonnacci fib;
  std::printf("%lu\n", fib(n));
}

// eof

Measured memory_bytes: 2756
# https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_b

n, m, k = map(int, input().split())

s = set()
for i in range(n + 1):
    for j in range(m + 1):
        t = i * (m - j) + j * (n - i)
        if t <= n * m:
            s.add(t)
if k in s:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 109028
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b;
	string s,p;
	cin>>s>>p;
    s=s+s;
	a=s.size()*2-1;
	b=s.size();
	for(int i=0;i<b;i++){
		for(int n=1;n<a;n++){
	if( p==s.substr(i,n) ){
		cout<<"Yes"<<endl;
		return 0;
		}
}
}
cout<<"No"<<endl;

}



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

using namespace std;
int main(){
    int a,b,output=0;
    cin>>a>>b;
    for (int i = 0;i < 1275+1; i++){
        if (floor(i * 0.08) == a && floor(i * 0.1) == b){
            output = i;
            break;
        }
    }
    output == 0 ? cout<<-1 : cout<<output; 
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main() {
	int h,m,s;
	int a;
	cin >> a;
	h = a / 3600;
	m = a / 60 - 60 * h;
	s = a % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    vector<int> ball(n, 0);
    vector<int> ans;
    for(int k = n; k >= 1; --k){
        int sum = 0;
        for(int i = k - 1; i < n; i += k){
            sum += ball[i];
        }
        if(sum % 2 != a[k - 1]){
            ++ball[k - 1];
            ans.emplace_back(k);
        }
    }
    int sz = ans.size();
    cout << sz << '\n';
    for(int i = 0; i < sz; ++i){
        cout << ans[i];
        cout << ((i == sz - 1) ? '\n' : ' ');
    }
}

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

#define rep(x, n) for(int i = x; i < (n); ++i)

using namespace std;
using ll = long long;

double calc(ll x, ll y) {
  return sqrt(x * x + y * y);
}

int main(void)
{
  double n, d;
  cin >> n >> d;
  vector<ll> x(n);
  vector<ll> y(n);
  rep(0, n) cin >> x[i] >> y[i];

  int res = 0;
  rep(0, n) {
    if (calc(x[i], y[i]) <= d) ++res;
  }

  cout << res << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll r, d, x;
  cin >> r >> d >> x;

  for (ll i = 0; i < 10; ++i) {
    x = r*x - d;
    cout << x << endl;
  }

  return 0;
}

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

int num;
vector<vector<int>> cl;
vector<vector<int>> bl;
vector<int> flag;
map<int,int>total;

void search(int i) {
    flag[i] = num;
    total[num]++;
    rep(j,(int)cl[i].size()) {
        int target = cl[i][j];
        if(flag[target] == 0) {
            search(target);
        }
    }
}
int main(void) {
    int n, m, k;
    cin >> n >> m >> k;
    flag.resize(n);
    cl.resize(n);
    bl.resize(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        cl[a-1].push_back(b-1);
        cl[b-1].push_back(a-1);
    }
    rep(i,k){
        int a, b;
        cin >> a >> b;
        bl[a-1].push_back(b-1);
        bl[b-1].push_back(a-1);
    }

    rep(i,n) {
        if(flag[i] == 0) {
            num++;
            search(i);
        }
    }
    rep(i,n) {
        int graph = flag[i];
        if(i) cout << " ";
        int blocknum = 0;
        rep(j,(int)bl[i].size()) {
            int target = bl[i][j];
            if(graph == flag[target]) blocknum++;
        }
        cout << total[graph] - 1 - cl[i].size() - blocknum;
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 13824
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n, d;
	cin >> n >> d;
	int k = d*2+1;
	int ans = (n+k-1)/k;
	cout << ans << endl;

}


Measured memory_bytes: 256
import math

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]

length = []
for i in range(N):
    x_1 = xy[i][0]
    y_1 = xy[i][1]
    for j in range(i + 1, N):
        x_2 = xy[j][0]
        y_2 = xy[j][1]
        lon = math.sqrt((x_1 - x_2) ** 2 + (y_1 - y_2) ** 2)
        length.append(lon)

result = (N - 1) * sum(length) / len(length)
print(result)


Measured memory_bytes: 3064
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N = int(input())
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))

    if N == 1:
        print(1)
        exit()

    xy.sort(key=lambda p: (p[0], p[1]))
    # print(xy)

    cand = defaultdict(lambda:0)

    for i in range(N-1):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            key = '{},{}'.format(p, q)
            cand[key] += 1
    counter = Counter(cand)
    pq_count = counter.most_common()[0][1]
    # print(counter.most_common()[0])
    print(N - pq_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40944
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long lli;
const int N = 10;
const int M = 50;
const lli INF = 1LL << 40;

int w, h, f, m, o;
int dat[N][N];
lli dp[N+1][N][1<<N][M+1];

main(){
  while(cin >> w >> h && (w|h)){
    cin >> f >> m >> o;
    assert(3 <= w && w <= 10);
    assert(3 <= h && h <= 10);
    assert(1 <= f && f <= 10000);
    assert(3 <= m && m <= 50);
    assert(o <= m);
    assert(o >= 0);
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> dat[i][j];
      }
    }
    fill(dp[0][0][0], dp[N+1][0][0], -INF);
    for(int i=0;i<w;i++){
      if(o - 1 > 0){
        if(dat[0][i] >= 0){
          dp[0][i][1<<i][min(m, (o-1+dat[0][i]))] = 0;
        }else if(dat[0][i] < 0){
          if(f + dat[0][i] >= 0)
            dp[0][i][1<<i][o-1] = dat[0][i];
        }
      }
    }
    for(int i=0;i<h-1;i++){
      lli nm, cost;
      for(int j=0;j<(1<<w);j++){ // 2
        for(int k=1;k<=m;k++){
          for(int d=0;d<w;d++){
            int l = w-1, r = 0;
            for(int k2=0;k2<w;k2++){
              if((j >> k2) & 1){
                l = min(l, k2);
                r = max(r, k2);
              }
            }
            if(l > 0 && k - abs(l-d) - 1 > 0){
              if(dat[i][l-1] >= 0){
                nm = min(m, (k - abs(l-d) - 1 + dat[i][l-1]));
                cost = 0;
              }else if(dat[i][l-1] < 0){
                nm = k - abs(l-d) - 1;
                cost = dat[i][l-1];
              }
              if(f + dp[i][d][j][k] + cost >= 0)
                dp[i][l-1][j|(1<<(l-1))][nm] = max(dp[i][l-1][j|(1<<(l-1))][nm], dp[i][d][j][k] + cost);
            }
            if(r + 1 < w && k - abs(r-d) - 1 > 0){
              if(dat[i][r+1] >= 0){
                nm = min(m, (k - abs(r-d) - 1+ dat[i][r+1]));
                cost = 0;
              }else if(dat[i][r+1] < 0){
                nm = k - abs(r-d) - 1;
                cost = dat[i][r+1];
              }
              if(f + dp[i][d][j][k] + cost >= 0)
                dp[i][r+1][j|(1<<(r+1))][nm] = max(dp[i][r+1][j|(1<<(r+1))][nm], dp[i][d][j][k] + cost);
            }
            for(int p=l;p<=r;p++){
              if(k - abs(p-d) - 1 > 0){
                if(dat[i+1][p] >= 0){
                  nm = min(m, (k - abs(p-d) - 1 + dat[i+1][p]));
                  cost = 0;
                }else if(dat[i+1][p] < 0){
                  nm = k - abs(p-d) - 1;
                  cost = dat[i+1][p];
                }
                if(f + dp[i][d][j][k] + cost >= 0)
                  dp[i+1][p][1<<p][nm] = max(dp[i+1][p][1<<p][nm], dp[i][d][j][k] + cost);
              }
            }
          }
        }
      }
    }
    lli valM = -INF;
    for(int j=0;j<(1<<w);j++){
      for(int k=1;k<=m;k++){
        for(int d=0;d<w;d++){
          valM = max(valM, dp[h-1][d][j][k]);
          //cout << d << ' ' << j << ' ' << k << ' ' << dp[2][d][j][k] << endl;
        }
      }
    }
    if(f + valM < 0){
      cout << "NA" << endl;
    }else{
      cout << abs(valM) << endl;
    }
  }
}

Measured memory_bytes: 46044
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int n,m,k;
int a[200050];
int b[200050];
int f(int i,int j,int k)
{
	if(a[i]>k && a[j]>k)
	return 0;
	
	if(i==(n-1) && j==(m-1))
	return 0;
	
	int inc=0,exc=0;
	if(a[i]<=k && i<n)
	inc+=f(i+1,j,k-a[i])+1;
	if(b[j]<=k && j<m)
	exc+=f(i,j+1,k-b[j])+1;
	
	
	return max(inc,exc);
}

int32_t main()
{
	cin >> n >> m >> k;
	vector<int> v,v2;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		v.push_back(a[i]);
	}
	for(int i=0;i<m;i++)
	{
		cin >> b[i];
		v2.push_back(b[i]);
	}
	for(int i=1;i<n;i++)
	v[i]+=v[i-1];
	
	for(int i=1;i<m;i++)
	v2[i]+=v2[i-1];
	
	int x=k;
	int mx=0;
	for(int i=0;i<n;i++)
	{
		if(v[i]<=k)
		{
			int ans=i+1;
			auto it=upper_bound(v2.begin(),v2.end(),k-v[i]);
			if(it>v2.begin())
			{
				it--;
				ans+=(it-v2.begin()+1);
			}
			mx=max(mx,ans);
		}
		else
		break;
	}
	for(int i=0;i<m;i++)
	{
		if(v2[i]<=k)
		{
			int ans=i+1;
			auto it=upper_bound(v.begin(),v.end(),k-v2[i]);
			if(it>v.begin())
			{
				it--;
				ans+=(it-v.begin()+1);
			}
			mx=max(mx,ans);
		}
		else
		break;
	}
	cout << mx;
}



Measured memory_bytes: 10588
LI = lambda: list(map(int, input().split()))

A, B, C = LI()
K = int(input())


def main():
    a, b, c = A, B, C
    for _ in range(K):
        if a >= b:
            b *= 2
        elif b >= c:
            c *= 2
    if a < b < c:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
#include <stdio.h>

int main(void)
{
    int h, w;
    int i, j;

    while (1){
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0){
            break;
        }else{
            /*1行目*/
            for (j = 1;j <= w; j++){
                printf("#");
            }
            printf("\n");
            /*2 ~ (h -1) 行目*/
            for (i = 2; i <= h - 1; i++){
                printf("#");
                for (j = 2; j <= w - 1; j++){
                    printf(".");
                }
                printf("#\n");
            }
            /*h行目*/
            for (j = 1;j <= w; j++){
                printf("#");
            }
            printf("\n\n");
        }
    }

    return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

ll latter(ll pos, vector<ll>& v){
   return lower_bound(v.begin(),v.end(),pos) - v.begin();
}
ll former(ll pos, vector<ll>& v){
   return upper_bound(v.begin(),v.end(),pos) - v.begin() - 1;
}

const ll INF = 1LL << 60;

int main(){
  ll A,B,Q; cin >> A >> B >> Q;
  vector<ll> s(A),t(B),q(Q);
  
  rep(i,A) cin >> s[i];
  rep(i,B) cin >> t[i];
  rep(i,Q) cin >> q[i];
  
  s.push_back(INF);s.push_back(-INF);sort(s.begin(),s.end()); //範囲外参照をしないように道路の両端に大きな数を入れておく
  t.push_back(INF);t.push_back(-INF);sort(t.begin(),t.end()); //同上
  
  rep(i,Q){
    ll pos = q[i]; //現在位置
    ll res = INF;
    rep(j,2){
      ll first = (j ? s[former(pos,s)]:s[latter(pos,s)]);//先にsを尋ねる(前後２パターン)
      rep(k,2){
        ll second = (k ? t[former(first,t)]:t[latter(first,t)]);//次にその移動先から前後のtを尋ねる
        chmin(res, abs(pos - first)+abs(first - second));
      }
    }
    rep(j,2){
      ll first = (j ? t[former(pos,t)]:t[latter(pos,t)]);
      rep(k,2){
        ll second = (k ? s[former(first,s)]:s[latter(first,s)]);
        chmin(res, abs(pos - first)+abs(first - second));
      }
    }
    cout << res << endl;
  }
  

  
  return 0;
}

Measured memory_bytes: 3680
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	fmt.Scan(&S)
	if len(S) == 1 {
		fmt.Println(S)
		return
	}
	var arr [][]int
	first := make([]int, len(S)-1)
	arr = append(arr, first)
	for i := 0; i < len(S)-1; i++ {
		for _, a := range arr {
			c := make([]int, len(a))
			copy(c, a)
			c[i] = 1
			arr = append(arr, c)
		}
	}
	sum := 0
	for _, v := range arr {
		sum += calc(S, v)
	}
	fmt.Println(sum)
}

func calc(S string, arr []int) int {
	current := toNum(S[0])
	sum := 0
	for i, v := range arr {
		if v == 0 {
			current = current*10 + toNum(S[i+1])
		} else {
			sum += current
			current = toNum(S[i+1])
		}
	}
	sum += current
	return sum
}

func toNum(r byte) int {
	res, _ := strconv.Atoi(string(r))
	return res
}


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

int main()
{
    int n, a, b, p[100], tempA = -1, tempA1 = -1, tempB = -1, ans;

    cin >> n >> a >> b;
    for(int i = 0;i < n;i++){
        cin >> p[i];
    }

    sort(p,p + n);

    for(int i = 0;i < n;i++) {
        if(a >= p[i]){
            tempA = i;
        }
        if(a + 1 <= p[i] && b >= p[i]) {
            tempA1 = i;
        }
        if(b + 1 < p[i]) {
            tempB = i;
        } 
    }
    tempA++; tempA1++; tempB++;
    if( tempA == 0 ||tempA1 == 0||tempB == 0||tempA == tempA1 || tempA == tempB || tempA1 == tempB){
        cout << 0 <<"\n";

        return 0;
    }

    if(tempA < (tempA1 -  tempA)){
        if((tempB-  tempA1) < tempA){
            ans = (tempB-  tempA1);
        }
        else{
            ans = tempA;
        }
    }
    else{
        if((tempB-  tempA1) < (tempA1 -  tempA)){
            ans = (tempB-  tempA1);
        }
        else{
            ans = (tempA1 -  tempA);
        }
    }

    cout << ans <<"\n";

    return 0;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    int m, r, f;
    for (;;) {
        cin >> m >> r >> f;
        if (m == -1 && r == -1 && f == -1) {
            break;
        }
        if (m == -1 || r == -1) {
            cout << "F\n";
        } else if (m + r >= 80) {
            cout << "A\n";
        } else if (m + r >= 65) {
            cout << "B\n";
        } else if (m + r >= 50 || f >= 50) {
            cout << "C\n";
        } else if (m + r >= 30) {
            cout << "D\n";
        } else {
            cout << "F\n";
        }
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3208
#include <iostream>

using namespace std;

int main(void)
{
    int x, y;
    
    cin >> x >> y;
    
    while ((x != 0) || (y != 0))
    {
        if (x > y)
        {
            int tmp;
            tmp = x;
            x = y;
            y = tmp;
        }
        cout << x << " " << y << endl;
        cin >> x >> y;
    }
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n - 1); i >= 0; --i)
#define mod 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
//#define INF 931931114518101
using namespace std;
typedef pair<ll, ll> P;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
#define yo 100001
//------------------変数-----------------------//
ll n, z, w, c[2002];
ll dp[2][2001];
//-------------------関数----------------------//

ll sa(P a) { return abs(a.first - a.second); }

ll DP(ll num, ll pl, ll oth) {
  if (num == n - 1) {
    return sa(P(c[n - 1], oth));
  }
  if (dp[pl][num] >= 0) {
    return dp[pl][num];
  }
  if (pl == 0) {
    ll now = 0;
    FOR(i, num, n - 1) { now = max(now, DP(i + 1, 1, c[num])); }
    return dp[pl][num] = now;
  }
  if (pl == 1) { // y
    ll now = INF;
    FOR(i, num, n - 1) { now = min(DP(i + 1, 0, c[num]), now); }
    dp[pl][num] = now;
    return dp[pl][num] = now;
  }
}

int main() {
  fill_all(dp, (ll)-1);
  cin >> n >> z >> w;
  REP(i, n) { cin >> c[i]; }
  ll cnt = 0;
  REP(i, n) { cnt = max(DP(i, 1, w), cnt); }
  cout << cnt << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
const ll BetsuMOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
string ans[] = { "No","Yes" };
int main() { // 問題文はしっかり読め!!!
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}
	bool cheak = true;
	for (int i = n - 1; i >= 1; i--) {
		if (a[i] - a[i - 1] <= -1) a[i - 1]--;
	}
	rep(i, n - 1) {
		if (a[i] > a[i + 1]) cheak = false;
	}
	cout << ans[cheak] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <iterator>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T> std::vector<std::string> split(const std::string& s, const T& separator, bool ignore_empty = 0, bool split_empty = 0) {
  struct {
    auto len(const std::string&             s) { return s.length(); }
    auto len(const std::string::value_type* p) { return p ? std::char_traits<std::string::value_type>::length(p) : 0; }
    auto len(const std::string::value_type  c) { return c == std::string::value_type() ? 0 : 1; /*return 1;*/ }
  } util;
  
  if (s.empty()) { /// empty string ///
    if (!split_empty || util.len(separator)) return {""};
    return {};
  }
  
  auto v = std::vector<std::string>();
  auto n = static_cast<std::string::size_type>(util.len(separator));
  if (n == 0) {    /// empty separator ///
    if (!split_empty) return {s};
    for (auto&& c : s) v.emplace_back(1, c);
    return v;
  }
  
  auto p = std::string::size_type(0);
  while (1) {      /// split with separator ///
    auto pos = s.find(separator, p);
    if (pos == std::string::npos) {
      if (ignore_empty && p - n + 1 == s.size()) break;
      v.emplace_back(s.begin() + p, s.end());
      break;
    }
    if (!ignore_empty || p != pos)
      v.emplace_back(s.begin() + p, s.begin() + pos);
    p = pos + n;
  }
  return v;
}

int main(){
  ios::sync_with_stdio(false);
	cin.tie(0);
  
  string s;
  cin >> s;
  int y,m,d;
  auto x = split(s, '/');
  y = stoi(x[0]);
  m = stoi(x[1]);
  d = stoi(x[2]);
  if (y < 2019) {
    cout << "Heisei" << endl;
    return 0;
  } else if (y == 2019 && m < 4) {
    cout << "Heisei" << endl;
    return 0;
  } else if (y==2019 && m == 4 && d <= 30) {
    cout << "Heisei" << endl;
    return 0;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int fibonacci(int);
int F[45];
int main()
{
  int n;

  scanf("%d",&n);

  fibonacci(n);
  printf("%d\n",F[n]);
  return 0;
}

int fibonacci(int n)
{
if(n == 0 || n == 1)
  {
    return F[n]=1;
  }

 if(F[n]!=0) return F[n];

 return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

Measured memory_bytes: 596
import java.util.Scanner;


public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int height = sc.nextInt();
		int width = sc.nextInt();

		long area = (long)height * width;
		long length = (long)height*2 +(long)width*2;
		System.out.println(area +" "+length);

		sc.close();
	}

}

Measured memory_bytes: 17348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<pr> vp;
typedef vector<vp> vpp;
typedef vector<vector<ll> > graph;
#define pb push_back
#define mp make_pair
#define endl '\n'
void set_val(vector<ll>& v, ll val){for(ll i=0;i<v.size();i++) v[i]=val;}

ll mod = pow(10,9) + 7;
ll modulo = 998244353;
double pi = 3.141592653589793238;
ll i_mov[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
ll j_mov[8] = {1, 1, 1, 0, -1, -1, -1, 0};


ll power(ll a, ll n)
{
    if(n==0)
    return 1;
    ll temp = power(a,n/2);
    if(n%2==0)
    return (temp*temp)%mod;
    return (((temp*temp)%mod)*a)%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout<<setprecision(10);
    ll n, m;
    cin>>n>>m;
    cout<< (n*(n-1))/2 + (m*(m-1))/2;
    
    
    
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=500010;
int n,m,b[N],p[N];
char s[10];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x;cin>>x>>s;
		if(s[0]=='A')b[x]=1;
		else if(!b[x])p[x]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)ans+=b[i];
	printf("%d ",ans);ans=0;
	for(int i=1;i<=n;i++)ans+=p[i]*b[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
int n,u,v;
bool win=false;
vector <int> to[maxn];
int dfs(int now,int fa){
	int siz=to[now].size(),cnt=0;
	for(int i=0;i<siz;i++){
		int t=to[now][i];
		if(t==fa) continue;
		cnt+=dfs(t,now);
	}
	if(fa==0&&cnt==0) win=true;
	if(cnt==1) return 0;
	if(cnt==0) return 1;
	win=true;
	return 0;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		to[u].push_back(v);
		to[v].push_back(u);
	}
	dfs(1,0);
	if(win){printf("First\n");}
	else{printf("Second\n");}
	return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T;
	cin >> T;
	int arr[T];
	for(int i = 0; i<T;i++)
	{
		cin >>arr[i];
	}
	int pt1 = 1;
	int mini = arr[0];
	int maxi = arr[0];
	ll money = 1000;
	while(pt1 < T)
	{
		while(pt1 < T && arr[pt1] >= arr[pt1-1])
		{
			mini = min(arr[pt1],mini);
			maxi = max(arr[pt1], maxi);
			pt1++;
		}
		ll temp = money/mini;
		money -= temp*mini;
		money += temp*maxi;
		mini = arr[pt1];
		maxi = arr[pt1];
		pt1++;
	}
	ll temp = money/temp;
	money -= temp*mini;
	money += temp*maxi;
	cout <<money;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N;
    cin >> N;
    cout << N * (N - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

vector<ll> inv,fac;

void inverse(ll n){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

void inverse_u(ll n){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%MOD;
    }
}

void factorial(ll n){
    //要素数:n+1 (0~n)
    fac[0]=1;
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%MOD;
    }
}

ll nCr(ll n,ll r){
    return fac[n]*inv[r]%MOD*inv[n-r]%MOD;
}

ll proinverse(ll x,ll m){
    ll res=1,M=m-2;
    while(M>0){
        if(M&1) res=res*x%m;
        x=x*x%m;
        M>>=1;
    }
    return res;
}

void init_nCr(ll n){
    inv.assign(n+1,0);
    fac.assign(n+1,0);
    inverse(n); inverse_u(n);
    factorial(n);
}

int main(){
    ll n,m,ans=1; cin>>n>>m;
    init_nCr(m);
    ll cnt=fac[m]*inv[m-n];
    rep(i,n){
        ans=(ans*(m-i))%MOD;
        cnt=(MOD+cnt+(i%2*2-1)*nCr(n,i+1)*((fac[m-i-1]*inv[m-n])%MOD)%MOD)%MOD;
    }
    cnt=(cnt+MOD)%MOD;
    cout<<(ans*cnt+MOD)%MOD<<endl;
}


Measured memory_bytes: 11084
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] + [1e10]*(N-1)

for i in range(0, N):
    for j in range(1, K+1):
        if i + j < N:
            dp[i+j] = min(dp[i+j], abs(h[i] - h[i+j]) + dp[i])

print(dp[-1])

Measured memory_bytes: 86524
#include<cstdio>
#include<algorithm>

#define	inrange(x,y)	(0<=(x) && (x)<=5000 && 0<=(y) && (y)<=5000)

using namespace std;

bool pole[5001][5001];

int main(){
	for(int n;scanf("%d",&n),n;){
		for(int i=0;i<=5000;i++)for(int j=0;j<=5000;j++)	pole[i][j]=false;
		static int x[3000],y[3000];
		for(int i=0;i<n;i++){
			scanf("%d%d",x+i,y+i);
			pole[y[i]][x[i]]=true;
		}

		int area=0;
		for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
			int ax=x[i],ay=y[i];
			int bx=x[j],by=y[j];
			int cx,cy,dx,dy,ex,ey,fx,fy;
			cx=ax-(by-ay);	cy=ay+(bx-ax);
			dx=bx-(by-ay);	dy=by+(bx-ax);
			ex=ax+(by-ay);	ey=ay-(bx-ax);
			fx=bx+(by-ay);	fy=by-(bx-ax);
			if((inrange(cx,cy) && inrange(dx,dy) && pole[cy][cx] && pole[dy][dx])
			|| (inrange(ex,ey) && inrange(fx,fy) && pole[ey][ex] && pole[fy][fx]))
				area=max(area,(bx-ax)*(bx-ax)+(by-ay)*(by-ay));
		}

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

	return 0;
}

Measured memory_bytes: 24000
import java.util.*;
public class Main{public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  Map<String,Integer>map=new HashMap<>();
  int n=sc.nextInt();
  for(int i=0;i<n;i++)map.put(sc.next(),1);
  System.out.println((map.size()==3)?"Three":"Four");
}}


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

assert len(A) == N + 1
assert len(B) == N

count = 0
for i in range(N-1, -1, -1):
  cost2 = min(A[i + 1], B[i])
  A[i+1] -= cost2
  cost1 = min(A[i], B[i] - cost2)
  A[i] -= cost1
  count += cost1 + cost2
print(count)

Measured memory_bytes: 90552
#include<stdio.h>
#include<string.h>
 
int main(){
 
    char s[100];
    char p[100];
    char a[200];
 
    scanf("%s",s);
    scanf("%s",p);
 
    strcpy(a,s);
    strcat(a,s);
 
    if(strstr(a,p))
        printf("Yes\n");
    else
        printf("No\n");
     
return 0;
 
}

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;



int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<int> sorted = a;
  sort(all(sorted));

  set<int> even,odd;
  for(int i = 0; i < n; i++){
    if(i%2 == 0) even.insert(sorted[i]);
    else odd.insert(sorted[i]);
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 != 0){
      if(even.count(a[i]) > 0) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int h,w,n;
  cin>>h>>w;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  int now=0;
  int cnt=0;
  vector<vi> ans(h,vi(w));
  rep(i,h)rep(j,w){
    if(i%2){//rev
      ans[i][w-1-j]=now+1;
    }else{
      ans[i][j]=now+1;
    }
    cnt++;
    if(cnt==a[now]){
      now++;
      cnt=0;
    }
  }
  rep(i,h){
    rep(j,w){
      if(j)cout<<" ";
      cout<<ans[i][j];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stack>
#include <cstring>
using namespace std;

#define MAX_LENGTH  3000

string s1;					//string 1
string s2;					//string 2
stack <char> soln;	//soln stack
int dp[MAX_LENGTH][MAX_LENGTH];

//Memoisation solution
//step 1 : Base Case
//step 2 : if soln not computed already then compute recursively
//step 3 : return the soln
int solve(int p1,int p2){
	if(p1<0||p2<0)
		return 0;
	if(dp[p1][p2]==-1){
		if(s1[p1]==s2[p2])
			return dp[p1][p2] = 1+ solve(p1-1,p2-1);
		else
			return dp[p1][p2] = max( solve(p1-1,p2) , solve(p1,p2-1) );
	}
	return dp[p1][p2];
}

void build(int p1,int p2){
	if(p1<0||p2<0)
		return;
	if(s1[p1]==s2[p2]){
		soln.push(s1[p1]);
		build(p1-1,p2-1);
		return;
	}
	if(p1>0 && p2>0){
		if(dp[p1-1][p2] > dp[p1][p2-1] )
			build(p1-1,p2);
		else
			build(p1,p2-1);
	}
	else if(p1>0)
		build(p1-1,p2);
	else if(p2>0)
		build(p1,p2-1);
	return;
}

int main(){
	
	memset(dp,-1,sizeof(dp));
	//memset(first_ptr,value,size_in_bytes)
	//sets the bytes equal to the given value
	//initial state of our dp table

	cin>>s1>>s2;
	int L = s1.length();
	int M = s2.length();

	solve(L-1,M-1);
	build(L-1,M-1);
	
	while(!soln.empty()){
		cout<<soln.top();
		soln.pop();
	}

}


Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[52];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>m;
        num[i]=m;
    }
    sort(num,num+n);
    for(i=n-1;i>=0&&k>0;i--,k--)
    {
        sum+=num[i];
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 256