akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int kth(int arr[], int n, int K) {
	int x;
	for(int i = 0; i < n; i++) {
		x = arr[K-1];
		return x;
	}
}

int main() {
	int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int K;
	cin >> K;
	cout << kth(arr, 32, K);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    ll N;
    cin >> N;
    vector<ll> v(N+1);
    v[0] = 2;
    v[1] = 1;
    rep(i, 2, N+1) v[i] = v[i-1] + v[i-2];
    cout << v[N] << endl;    

    return 0;
}

Measured memory_bytes: 256
def f():
    s = int(input())
    i9 = 10**9
    if s == i9 ** 2:
        print(i9, 0, 0, i9, 0, 0)
    else:
        print(i9 - (s%i9), s//i9 + 1, i9, 1, 0, 0)

if __name__ == '__main__':
    f()


Measured memory_bytes: 9036
S=gets.chomp
us=Array.new(26,0)
hsc,hsi={},{}
('a'..'z').each_with_index{|c,i|
  hsc[c]=i
  hsi[i]=c
}
S.size.times{|i|us[hsc[S[i]]]=1}
ans,f=nil,false
26.times{|i|
  if us[i]==0 then
    ans=S+hsi[i]
    f=true
    break
  end
}
if !f then
  bef=-1
  26.times{|i|
    if hsc[S[25-i]]<bef then
      t=hsc[S[25-i]]
      us=Array.new(26,0)
      S[0,25-i].size.times{|i|us[hsc[S[i]]]=1}
      while true do
        t+=1
        if t>25 then
          break if i>=25
          i+=1
          t=hsc[S[25-i]]
        else
          if us[t]!=1 then
            ans=S[0,25-i]+hsi[t]
            break
          end
        end
      end

      break
    end
    bef=hsc[S[25-i]]
  }
end
ans=-1 if ans==nil

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[100000];
int cnt;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt += a[i];
	}
	cout << cnt - (n*(n + 1) / 2) << endl;
}


Measured memory_bytes: 3884
#include <iostream>
#include <vector>
int main(){
 int n, a, b;
 std::cin >> n;std::cin >> a;std::cin >> b;
 std::string s;
 std::cin >> s;
  
 int pnum = 0, bnum = 1; 
   
 for (size_t i=0; i < n; i++){
   bool pss = false;
   if (s[i] == 'a' && pnum < a+b){
     pss = true;
   }else if (s[i] == 'b' && pnum < a+b && bnum <= b){
     bnum += 1;
     pss = true;
   }
   if (pss){
     pnum += 1;
     std::cout << "Yes" << std::endl;
   }else{
   	 std::cout << "No" << std::endl;
   }
 }
}

Measured memory_bytes: 3220
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int a,b,c;
    cin >>a>>b;
    
    if(b > a){
        cout <<b - a<<endl;
    }else if(a > b){
        cout <<a - b<<endl;
    }else{
        cout <<"0"<<endl;
    }
    
    
}



Measured memory_bytes: 3092
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        if(a.length() == 2){
            System.out.println(a);
        }else{
            for(int i = 2; i >= 0; i--){
                System.out.print(a.charAt(i));
            }
        }
    }
}

Measured memory_bytes: 21844
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0
for a in range(0,A+1):
    for b in range(0,B+1):
        for c in range(0,C+1):
            if 500*a+100*b+50*c==X:
                count+=1
print(count)

Measured memory_bytes: 3060
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int r,c;
	int a[101][101];
	int sum;
	cin >> r >> c;
	for (int i=0;i<r;i++){
		for (int j=0;j<c;j++){
			cin >> a[i][j];
		}
	}
	
	for (int i=0;i<r;i++){
		sum = 0;
		for (int j=0;j<c;j++){
			sum += a[i][j];
			cout << a[i][j] << " ";
		}
		cout << sum << endl;
	}
	
	for (int i=0;i<c;i++){
		sum = 0;
		for (int j=0;j<r;j++){
			sum += a[j][i];
		}
		cout << sum << " ";
	}
	sum = 0;
	for (int i=0;i<c;i++){;
		for (int j=0;j<r;j++){
			sum += a[j][i];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1196
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N, M;
	vector<pair<LL,LL> > ab,cd;
	cin >> N >> M;
	FOR(i, 0, N) {
		LL a, b;
		cin >> a >> b;
		ab.push_back(MP(a, b));
	}
	FOR(i, 0, M) {
		LL a, b;
		cin >> a >> b;
		cd.push_back(MP(a, b));
	}

	FOR(i, 0, N) {
		LL minManh = 1000000007;
		int minCheckpointNumber = 0;
		FOR(j, 0, M) {
			LL nowManh = abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second);
			if (nowManh < minManh) {
				minManh = nowManh;
				minCheckpointNumber = j + 1;
			}
		}
		cout << minCheckpointNumber << endl;
	}


	return 0;
}

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

int main() {
    int n, l, r;
    while (cin >> n >> l >> r, n | l | r) {
        int ans = 0;
        int a[n];
        for (int i = 0; i < n; i++) cin >> a[i];
        for (int x = l; x <= r; x++) {
            int f = 1;
            for (int i = 0; i < n; i++) {
                if (x % a[i] == 0) {
                    f = 0;
                    if (i % 2 == 0) ans++;
                    break;
                }
            }
            if (f && n % 2 == 0) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {
	
	int A;
	int B;
	cin >> A;
	cin >> B;

	int p = A + B;
	int m = A - B;
	int t = A * B;

	int ans = max(t, max(p, m));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
template <class T> int size(const T &x) { return x.size(); }
const int INF = 2147483647;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

int main() {
    int n, l;
    cin >> n >> l;
    vi rop(n);
    rep(i,0,n) {
        cin >> rop[i];
    }
    int at = 0;
    while (at+1 < n && rop[at] + rop[at+1] < l) {
        at++;
    }
    if (at+1 >= n) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for (int i = 0; i < at; i++) {
        cout << i+1 << endl;
    }
    for (int i = n-2; i > at; i--) {
        cout << i+1 << endl;
    }
    cout << at+1 << endl;
    return 0;
}



Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		int k2 = k * 2;
		int k4 = k * 4;
		int[][] sum = new int[k4 + 1][k4 + 1];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			int x = Integer.parseInt(sa[0]) % k2;
			int y = Integer.parseInt(sa[1]) % k2;
			if (sa[2].equals("W")) {
				y = (y + k) % k2;
			}
			sum[x + 1][y + 1]++;
		}
		br.close();

		for (int i = 1; i <= k2; i++) {
			for (int j = 1; j <= k2; j++) {
				sum[i][j + k2] = sum[i][j];
				sum[i + k2][j] = sum[i][j];
				sum[i + k2][j + k2] = sum[i][j];
			}
		}

		for (int i = 1; i <= k4; i++) {
			for (int j = 1; j <= k4; j++) {
				sum[i][j] += sum[i][j - 1];
			}
		}
		for (int i = 1; i <= k4; i++) {
			for (int j = 1; j <= k4; j++) {
				sum[i][j] += sum[i - 1][j];
			}
		}

		int ans = 0;
		for (int i = 0; i < k2; i++) {
			for (int j = 0; j < k2; j++) {
				int val1 = sum[i + k][j + k]
						- sum[i + k][j]
						- sum[i][j + k]
						+ sum[i][j];
				int val2 = sum[i + k2][j + k2]
						- sum[i + k2][j + k]
						- sum[i + k][j + k2]
						+ sum[i + k][j + k];
				ans = Math.max(ans, val1 + val2);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 134676
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define RANGE_1(e) (boost::irange(0,(e)))
#define RANGE_2(s,e) (boost::irange((s),(e)))
#define RANGE_3(s,e,step) (boost::irange((s), (e), (step)))
#define RANGE_SELECTER(_1,_2,_3,SELECT,...) SELECT
#define range(...) RANGE_SELECTER(__VA_ARGS__, RANGE_3, RANGE_2, RANGE_1) (__VA_ARGS__)
#define guard(x) if(x);
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define CALL(x) (x).cbegin(),(x).cend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define BIT(n) (1LL<<(n))

using namespace std;
using lint = long long;

// template<class T>class irange{private:struct I{T x;T operator*(){return x;}bool operator!=(I&lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:irange(T i,T n):i({i}),n({n}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>class srange{private:struct I{T x,s;T operator*(){return x;}bool operator!=(I&lhs){if(s<(T)0)return x>lhs.x;return x<lhs.x;}void operator++(){x=x+s;}};I i,n;public:srange(T i,T n,T s):i({i,s}),n({n,s}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>irange<T>range(T n){return irange(0,n);}template<class T>irange<T>range(T i,T n){return irange(i,n);}template<class T>srange<T>range(T i,T n,T s){return srange(i,n,s);}
template<class T>bool amax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool amin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

struct initialize{initialize(){cin.tie(nullptr);ios::sync_with_stdio(false);};}__ini__;

int main(){
    /* Code Area */
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (auto&& e : p) {
        cin >> e;
    }

    for (auto&& i : range(n + 1)) {
        if (find(ALL(p), x - i) == p.end()) {
            cout << x - i << endl;
            return 0;
        } else if (find(ALL(p), x + i) == p.end()) {
            cout << x + i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k; cin>>n>>k; int arr[n];
	for(int i = 0; i <n; i++){
			cin>>arr[i];
	}
	int dp[n+1]; dp[0] = 0;
	for(int i = 1; i < n; i++) dp[i] = INT_MAX;
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= k; j++){
			if(i-j >= 0) dp[i] = min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
		}
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
n,m=gets.split.map(&:to_i)
ope=[]
gets.split.map(&:to_i).each{|a|
  ope << [1,a]
}
m.times{
  ope << gets.split.map(&:to_i)
}
ope.sort_by!(&:last)
ans=0
while n>0
  b,c=ope.pop
  min=[b,n].min
  ans+=min*c
  n-=min
end
puts ans

Measured memory_bytes: 33648
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
print(A*B//gcd(A, B))

Measured memory_bytes: 5148
#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef complex<ld> Point;
typedef pair<double, int> P;

const ld eps = 1e-9, pi = acos(-1.0);

namespace std {
	bool operator <(const Point &lhs, const Point &rhs) {
		if (lhs.real() < rhs.real() - eps) return true;
		if (lhs.real() > rhs.real() + eps) return false;
		return lhs.imag() < rhs.imag();
	}
}

Point input_point() {
	ld x, y;
	cin >> x >> y;
	return Point(x, y);
}

bool eq(ld a, ld b) {
	return (abs(a - b) < eps);
}

ld dot(Point a, Point b) {
	return real(conj(a)*b);
}

ld cross(Point a, Point b) {
	return imag(conj(a)*b);
}

class Line {
public:
	Point a, b;
	int own;//a?????????1 b?????????0
	int pos;//?????¶??????1 ??°?????????0
	Line():a(Point(0,0)),b(Point(0,0)),own(-1),pos(-1){}
	Line(Point a, Point b,int own,int pos) :a(a), b(b),own(own),pos(pos) {}
};

int ccw(Point a, Point b, Point c) {
	b -= a; c -= a;
	if (cross(b, c) > eps) return 1;//a,b,c??????????¨???????
	if (cross(b, c) < -eps) return - 1;//a,b,c???????¨???????
	if (dot(b, c) < 0) return 2;//c,a,b????????§??´??????
	if (norm(b) < norm(c)) return -2;//a,b,c????????§??´??????
	return 0;//a,c,b??§??´??????
}

bool isis_ss(Line s, Line t) {//????????¨?????????????????????
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
		ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

bool isis_sp(Line s, Point p) {//?????????????????????
	return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}

Point is_ll(Line s, Line t) {//??´?????¨??´????????????
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv*cross(tv, t.a - s.a) / cross(tv, sv);
}

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

	int num; cin >> num;
	while (num--) {
		ld xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb;
		Point a(xa, ya), b(xb, yb);
		int n; cin >> n;
		vector<Line> rosen;//????????¨??¨
		for (int i = 0; i < n; i++) {
			ld xs, ys, xt, yt; int o, l;
			cin >> xs >> ys >> xt >> yt >> o >> l;
			Point s(xs, ys), t(xt, yt);
			Line li(s, t, o, l);
			rosen.push_back(li);
		}
		Line route(a, b, 1, -1);//?§??????????
		vector<P> lines;//P(?????¢???index) ???????????????????????????
		for (int i = 0; i < n; i++) {
			if (cross(route.b - route.a, rosen[i].b - rosen[i].a) == 0) continue;
			if (isis_ss(route, rosen[i])) {
				Point kouten = is_ll(route, rosen[i]);
				double dis = norm(route.a - kouten);
				lines.push_back(P(dis, i));
			}
		}
		sort(lines.begin(), lines.end());
		int res = 0, pos;
		if (lines.size() == 0) {
			cout << 0 << endl;
			continue;
		}
		int idx = lines[0].second;
		if (rosen[idx].own == 1) {
			pos = rosen[idx].pos;
		}
		else {
			pos = 1 - rosen[idx].pos;
		}
		for (int i = 0; i < (int)lines.size(); i++) {
			int idx = lines[i].second;
			//cout << idx<<" "<<pos << " " << rosen[idx].own << " " << rosen[idx].pos << endl;
			if (rosen[idx].own == 1) {
				if (rosen[idx].pos == pos) continue;
				else {
					pos = 1 - pos;
					res++;
				}
			}
			else {
				if (rosen[idx].pos != pos) continue;
				else {
					pos = 1 - pos;
					res++;
				}
			}
			//cout << i<<" "<<pos << endl;
		}
		cout << res << endl;
	}
}

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

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> h(N+1);
    rep(i, N) cin >> h[i];
    // 一個前で水をやってるか
    int c = 0;
    // 1以上育てなければいけない花が存在するかどうか
    int t = 1;
    int ans = 0;
    while (t) {
        t = 0;
        rep(i, N+1) {
            if (c) {
                // 続いてるときに0がくればans += 1
                if (h[i] <= 0) {
                    c = 0;
                    ans += 1;
                } else {
                    h[i] -= 1;
                }
            } else {
                // 水をやり始める
                if (h[i] > 0) {
                    c = 1;
                    h[i] -= 1;
                    t = 1;
                }
            }
        }
    }
    cout << ans << 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++)

int n;
int a[100];

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

  long long money = 1000;
  for (int i = 0; i < n-1; i++) {
    if (a[i] < a[i+1]) {
      long long num = money / a[i];
      money += (a[i+1]-a[i]) * num;
    }
  }

  cout << money << endl;

  return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;

int main()
{
	ll n, m;
	cin >> n >> m;
	ll ret = 1;
	for (ll i = 1; i*i <= m; i++) {
		if (m%i == 0) {
			ll p = m / i;
			if (p >= n)
				ret = max(ret, i);
			if (i >= n)
				ret = max(ret, p);
		}

	}
	cout << ret;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char a[101],b[101];
int aa=0;
scanf("%s",a);
scanf("%s",b);
if(strlen(a)>strlen(b)){printf("GREATER");}
else if(strlen(a)<strlen(b)){printf("LESS");}
else if(strcmp(a,b)==0){printf("EQUAL");}
else if(a[0]>b[0]) {printf("GREATER");}
else{printf("LESS");}
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return -1;}
    else if(*(int*)a<*(int*)b){return 1;}
    else {return 0;}
}
int min(int a,int b){

    if(a>=b){return b;}
    return a;
}

int main(void){
    //0000<=a<=9999
int a;
scanf("%d",&a);
int mn,yr;
mn=(a%10)+(((a/10)%10)*10);
yr=(a/10/10%10)+(a/10/10/10%10*10);
if(1<=mn&&mn<=12&&1<=yr&&yr<=12){printf("AMBIGUOUS");}
else if(1<=mn&&mn<=12){printf("YYMM");}
else if(1<=yr&&yr<=12){printf("MMYY");}
else {printf("NA");}

}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  int n, m;
  cin >> n >> m;
  priority_queue<int> que;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    que.push(a);
  }
  while (m && que.size()) {
    int cur = que.top();
    que.pop();
    cur >>= 1;
    m--;
    if (cur == 0) continue;
    else que.push(cur);
  }
  long long ans = 0;
  while (que.size()) {
    ans += que.top(), que.pop();
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MAX_N = 1e5;

int N;
int a[MAX_N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	int multiple_2 = 0, multiple_4 = 0;
	rep(i, 0, N) {
		cin >> a[i];
		if(a[i] % 4 == 0) {
			multiple_4++;
		} else if(a[i] % 2 == 0) {
			multiple_2++;
		}
	}

	if(multiple_4 >= N / 2) {
		cout << "Yes" << endl;
	} else if(N - 2 * multiple_4 <= multiple_2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	string S;
	cin >> S;
	rep(i, S.size() - 1) {
		if (i < S.size()-2 && S.at(i) == S.at(i + 2)) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
		if (S.at(i) == S.at(i + 1)) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
	}

	cout << "-1 -1" << endl;
}


Measured memory_bytes: 3704
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        input! {
            n: usize,
            a: [usize;n],
            mut b: [usize;n],
        }

        b.reverse();
        let mut conflict = None;
        for i in 0..n {
            if a[i] == b[i] {
                conflict = Some((i, a[i]));
                break;
            }
        }
        if let Some((p2, val)) = conflict {
            let level = |i| if a[i] == val { 1 } else { 0 } + if b[i] == val { 1 } else { 0 };
            let p1 = (0..p2).filter(|&i| level(i) == 0).count();
            let p3 = p2 + (p2..n).filter(|&i| level(i) == 2).count();
            let p4 = p3 + (p3..n).filter(|&i| level(i) == 1).count();

            if (p1 - 0) + (n - p4) < p3 - p2 {
                println!("No");
                return;
            }
            let p = min( p2 + (p1 - 0), p3 );
            &b[0..p].reverse();
            &b[p..n].reverse();
        }

        println!("Yes");
        for i in 0..n {
            print!("{} ", b[i]);
        }
        println!("");
    }
}

//#[proconio::fastout]
fn main() {
    let mut s: Solver = Default::default();
    s.solve();
}


Measured memory_bytes: 7876
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
const int N = 2e5 + 123;
int main(){
    speed;
    int n, k;
    cin >> n >> k;
    vi v(n + 1);
    vi dp(n + 1, INT_MAX);
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
    }
    dp[1] = 0;
    for(int i = 2; i <= n; ++i){
        for(int j = 1; j <= k; ++j){
            if(i - j > 0)
                dp[i] = min(dp[i - j] + abs(v[i] - v[i - j]), dp[i]);
        }
    }
    cout << dp[n];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC target ("avx")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b) {
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if(a<b){a=b;return true;}
	return false;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=998244353;
constexpr int inf=3e18;


signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;cin>>s;
	rep(i,3){
		if(s[i]=='7'){
			cout<<"Yes\n";return 0;
		}
	}
	cout<<"No\n";
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;

int main(){
	int a,b;
  cin>>a>>b;
  cout<<6-a-b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <vector>
#include <iostream>

using namespace std;

int
main ()
{
  int n;
  while (true)
    {
      map < char, char >dic;
      vector < char >data;
      cin >> n;
      if (n == 0)
	exit (0);
      while (n-- > 0)
	{
	  char a, b;
	  cin >> a >> b;
	  dic[a] = b;
	}
      cin >> n;
      while (n-- > 0)
	{
	  char a;

	  cin >> a;
	  auto buf = dic.find (a);
	  if (buf == dic.end ())
	    cout << a;
	  else
	    cout << buf->second;
	}
      cout << endl;
    }
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
string s;
int main(void){
  cin >> s;
  if(s.substr(0,4) == "YAKI")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
int n,i,x,c;
map<string,int>S;
main()
{
  cin>>n;
  for(i=0;i<n;i++)
  {
    string s,t;cin>>c>>s;
    if(c==0)
    {
      cin>>x;S[s]=x;
    }
    else if(c==1)
    {
      cout<<S[s]<<endl;
      if(S[s]==0)S.erase(s);
    }
    else if(c==2)S.erase(s);
    else
    {
      cin>>t;
      map<string,int>::iterator a=S.lower_bound(s),b=S.upper_bound(t);
      for(map<string,int>::iterator it=a;it!=b;it++)cout<<it->first<<" "<<it->second<<endl;
    }
  }
}


Measured memory_bytes: 27732
n, q = map(int, input().split())
s = input()
tmp = [0]
cnt = 0
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    cnt += 1
  tmp.append(cnt)

for i in range(q):
  l, r = map(int, input().split())
  print(tmp[r-1]-tmp[l-1])


Measured memory_bytes: 6100
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>
typedef long long ll;
using namespace std;

ll n,m,ret;
vector<vector<ll> > v;
vector<ll> p;
bool ch[10];

void check(){
  ll i,j,k,cnt=0;
  for(i=0;i<m;i++){
    ll sw=0;
    for(j=0;j<v[i].size();j++){
      if(ch[v[i][j]-1])sw++;
    }
    if(sw%2==p[i])cnt++;
  }
  if(cnt==m)ret++;
  return;
}

void dfs(ll cnt){
  if(cnt==n){
    check();
    return;
  }else{
    ch[cnt]=0;
    dfs(cnt+1);
    ch[cnt]=1;
    dfs(cnt+1);
  }
  return;
}

int main(){
  ll i,j,k;
  cin >> n >> m;
  v.resize(m);
  p.resize(m);
  for(i=0;i<m;i++){
    cin >> k;
    v[i].resize(k);
    for(j=0;j<k;j++){
      cin >> v[i][j];
    }
  }
  for(i=0;i<m;i++){
    cin >> p[i];
  }
  dfs(0);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using long_t = int64_t;

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int N;
		cin >> N;

		long_t sum = 0;
		for( int i = 1; i <= N; ++i ) {
			if( i%3 == 0 || i%5 == 0 ) { continue; }
			sum += i;
		}

		cout << sum << endl;
	}
};

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


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int abs(int x, int y) {
  if (x < y) {
    return y-x;
  }
  else{
    return x-y;
  }
}
int main(){
  int N;
  cin >>N;
  vector<int> V(N),C(N);
  for(int i =0;i<N; i++){
    cin >> V.at(i);
  }
  for(int i =0;i<N; i++){
    cin >> C.at(i);
  }
  vector<int> sa(N);
  int max =0;
  for(int i =0;i<N;i++){
    sa.at(i) =V.at(i)-C.at(i);
  }
  for(int i =0;i<N;i++){
    if(sa.at(i) >= 0){
      max += sa.at(i);
    }
  }
  cout << max <<endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
 int main()
 {
    
    l n; 
     cin>>n;
   l x,y,z;
    x=y=z=0;
    while(n--)
    {
        l a,b,c;
         cin>>a>>b>>c;
         l p= a+max(y,z);
         l q= b+max(x,z);
         l r= c+max(x,y);
         x=p,y=q,z=r;
    }
    cout<<max({x,y,z});
    
       return 0;
     
 }
  

Measured memory_bytes: 3604
import itertools, math

N = int(input())
city = []
for i in range(N):
  x, y = map(int, input().split())
  city.append((i, (x, y)))

ans = 0
pat = list(itertools.permutations(city))
for c in pat:
  l = 0
  for j in range(N-1):
    l += math.sqrt(pow(c[j][1][0] - c[j+1][1][0], 2) + pow(c[j][1][1] - c[j+1][1][1], 2))
  ans += l
print(ans/len(pat))

Measured memory_bytes: 7972
from collections import deque
import sys
input = sys.stdin.buffer.readline

N = int(input())
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

def calcDist(fr):
    minDist = [10**18] * N
    que = deque([(fr, 0)])

    while que:
        now, dist = que.pop()

        if minDist[now] < dist:
            continue
        minDist[now] = dist

        for to in edges[now]:
            if minDist[to] > dist + 1:
                minDist[to] = dist + 1
                que.append((to, dist + 1))

    return minDist

D0 = calcDist(0)
R = max(calcDist(D0.index(max(D0)))) + 1

print('Second' if R % 3 == 2 else 'First')


Measured memory_bytes: 58604
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cstring>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

string s;
int N, K;
int memo[1000][5][2];

int comb(int n, int r){
  if(r < 0 || n < r) return 0;
  if(r == 1) return n;
  if(r == 2) return n*(n-1)/2;
  return n*(n-1)*(n-2)/6;
}

int solve(int i, int k, int less){
  if(memo[i][k][less] != -1) return memo[i][k][less];
  if(k == 0) return memo[i][k][less] = 1;
  if(i == N) return memo[i][k][less] = 0;

  if(less) return memo[i][k][less] = comb(N-i, k)*pow(9, k);
  if(s[i] == '0') return memo[i][k][less] = solve(i+1, k, false);
  return memo[i][k][less] = solve(i+1, k, true)+solve(i+1, k-1, false)+solve(i+1, k-1, true)*(s[i]-'1');
}


signed main() {
  cin >> s >> K;
  N = s.size();

  memset(memo, -1, sizeof(memo));
  cout << solve(0, K, false) << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
using namespace std;
//using namespace __gnu_pbds;
#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
double PI=3.1415926535897932384626;
//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll arr[5];
	for(ll i=0;i<5;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+5);
	ll out=LLONG_MAX;
	do
	{
		ll tim=0;
		ll ans;
		for(int i=0;i<5;i++)
		{
		    //cout<<arr[i]<<" ";
			ll tmp=(arr[i]+tim);
			//cout<<tim<<endl;
			ans=tmp;
			if(tmp%10==0)
			    tim=(tmp/10)*10;
			else
			    tim=((tmp/10)*10+10);
		}
	//	cout<<endl;
		out=min(out,ans);
	}while(next_permutation(arr,arr+5));
	cout<<out;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int A, B, C, D;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &D);

    for (int a = A, c = C;;)
    {
        c -= B;
        if (c <= 0)
        {
            printf("Yes");
            break;
        }
        a -= D;
        if (a <= 0)
        {
            printf("No");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1680
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ls = [False] * 8
    cnt = 0
    for i in A:

        if i < 3200:
            ls[i // 400] = True
        else:
            cnt += 1

    if ls.count(True) == 0:
        if cnt == 0:
            minval = 0
        else:
            minval = 1
    else:
        minval = ls.count(True)

    if ls.count(False) <= cnt:
        maxval = 8+cnt-ls.count(False)
    else:
        maxval = 8 - (ls.count(False) - cnt)

    print(minval, maxval)


resolve()

Measured memory_bytes: 38384
H,W  = map(int, input().split())

A = []

for i in range(H):
  S = input()
  if S != "."*W:
    A.append(S)

Wcount = [0]*W

for i in range(len(A)):
  for j in range(W):
    if A[i][j] == "#":
      Wcount[j] = 1

      
for i in range(len(A)):
  S = ""
  for j in range(W):
    
    if Wcount[j] == 1:
      S = S + str(A[i][j])
    
  print(S)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long a[n], b[n];
  REP(i, n) cin>>a[i]>>b[i];
  vector<long long> ta(n), tb(n);
  REP(i, n){
    ta[i] = a[i]; tb[i] = b[i];
  }
  sort(ALL(ta));
  sort(ALL(tb));
  long long l, r;
  long long ans;
  if(n % 2 == 0){
    l = ta[n/2 - 1] + ta[n/2];
    r = tb[n/2 - 1] + tb[n/2];
    ans = r - l + 1;
  }else{
    l = ta[(n+1) / 2 - 1];
    r = tb[(n+1) / 2 - 1];
    ans = r - l + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9608
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    string s;
    cin >>s;
    if(s.at(s.size()-1)=='s'){
        cout<<s+"es"<<endl;
    }
    else{
        cout<<s+"s"<<endl;
    }
}
    



Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long ans = 1;
        for (int i = 1; i <= n; i++) {
            ans = ans * i % 1000000007;
        }
        
        System.out.println(ans);
    }
}


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

if 100<=n<=111:
  print(111)
if 111<n<=222:
  print(222)
if 222<n<=333:
  print(333)
if 333<n<=444:
  print(444)
if 444<n<=555:
  print(555)
if 555<n<=666:
  print(666)
if 666<n<=777:
  print(777)
if 777<n<=888:
  print(888)
if 888<n<=999:
  print(999)

Measured memory_bytes: 3064
# coding: utf-8

# 入力
h, w = map(int, input().split())

# カウント関数
def check(li, x, y):
    round_list = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
    count = 0
    num = 0
    for i, j in round_list:
        if 0 <= x + i < h and 0 <= y + j < w:
            if li[x+i][y+j] == "#":
                count += 1
    return count

# メイン処理
m = []
for i in range(h):
    m.append(list(input()))

for i in range(h):
    for j in range(w):
        if m[i][j] != "#":
            m[i][j] = check(m, i, j)

# 出力
for i in m:
    print("".join(map(str, i)))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	double a, b, c = 0, d = 1000, e = 0;
	cin >> a;
	int test[100] = { 0 };
	for (int h = 0; h < a; h++) {
		cin >> b;
		c += b;
		test[h] = b;
	}
	for (int j = 0; j < a; j++) {
		if (d > abs(test[j] - c / a)) {
			e = j;
			d = abs(test[j] - c / a);
		}
	}
	cout << e << endl;
	cin >> e;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;

#define M 1000005
int n;
int a[M];

inline bool check(int x) {
	int sum=0;
	for(int i=1;i<=n;i+=2) {
		if(sum>=x) sum=max(sum+a[i]-a[i-1],a[i]);
		else sum+=a[i]-a[i-1];
	}
	return sum>=x;
}

int main () {
	//freopen("a.in","r",stdin);
	scanf("%d",&n);
	for1(1,n,i) scanf("%d",a+i);
	int sum[2]={0};
	for1(1,n,i) sum[i&1]+=a[i];
	if(!(n&1)) printf("%d %d\n",max(sum[0],sum[1]),min(sum[0],sum[1]));
	else {
		int l=0,r=sum[1],mid,ans;
		while (l<=r) {
			mid=l+r>>1;
			if(check(mid)) ans=mid,l=mid+1;
			else r=mid-1;
		}
		printf("%d %d\n",sum[0]+ans,sum[1]-ans);
	}
}

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

typedef pair<int, int> pr_i;

int main() {  
  int n, m; scanf("%d %d", &n, &m);
  
  pr_i ab[m];
  for (int i = 0; i < m; i++) {
    int a, b; scanf("%d %d", &a, &b);
    ab[i].first = a;
    ab[i].second = b;
  }
  
  sort(ab, ab + m, [](pr_i l, pr_i r){return l.second < r.second;});
  
  int ans = 0;
  int line = 0;
  
  for (pr_i pr : ab) {
    if (pr.first <= line) continue;
    line = pr.second - 1;
    ans++;
  }
    
  printf("%d\n", ans);
}

Measured memory_bytes: 1024
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=300,MOD=1e9+7,MAXL=25;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
ll d[MAX][MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m,r,x,y,c;
	cin>>n>>m>>r;
	for(int i=0;i<r;i++)
		cin>>a[i];
	for(int i=0;i<=210;i++){
		for(int j=0;j<=210;j++)
			d[i][j]=INF;
		d[i][i]=0;
	}
	for(int i=0;i<m;i++){
		cin>>x>>y>>c;
		d[x][y]=min(d[x][y],c);
		d[y][x]=min(d[y][x],c);
	}
	sort(a,a+r);
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		}
	}
	ll ans=INF*10000,z=0;
	for(int i=0;i<=pow(r,r);i++){
		z=0;
		for(int j=1;j<r;j++)
			z+=d[a[j]][a[j-1]];
		ans=min(z,ans);
		/*for(int j=0;j<r;j++)
			cout<<a[j]<<" ";
		cout<<"\n";*/
		next_permutation(a,a+r);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100002

int n;
char s[MAXN], t[MAXN];
int sa[MAXN], sb[MAXN], ta[MAXN], tb[MAXN];

int input() {
	if (scanf("%s %s", s, t) < 0) return 0;
	return 1;
}

void init() {
}

void calc(char *s, int *sa, int *sb) {
	sa[0] = sb[0] = 0;
	for (int i=0; s[i]; i++) {
		sa[i+1] = sa[i] + (s[i]=='A');
		sb[i+1] = sb[i] + (s[i]=='B');
	}
}

int result(int *sa, int *sb, int i, int j) {
	int ka = sa[j]-sa[i-1];
	int kb = sb[j]-sb[i-1];
	int k = abs(ka-kb) % 3;
	//printf("%d %d %d==\n", ka, kb, k);
	if (k && ka<kb) k = 3-k;
	return k;
}

void prints(char *s, int a, int b) {
	for (int i=a-1; i<b; i++) printf("%c", s[i]);
	printf("\n");
}

long solve() {
	calc(s, sa, sb);
	calc(t, ta, tb);

	int q;
	scanf("%d", &q);
	for (int i=0; i<q; i++) {
		int a, b, c, d;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		//prints(s, a, b); prints(t, c, d);
		int fs = result(sa, sb, a, b);
		int ft = result(ta, tb, c, d);
		printf("%s\n", (fs==ft? "YES":"NO"));
	}
	return 1;
}

void output(long ans) {
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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


int main() {
    int n,a,b,c;
    string s;
    vector<string>V1;
    vector<char>V2;
    cin >> n >> a >> b >> c;
    for (int i=0;i<n;i++) {
        cin >> s;
        V1.push_back(s);
        }
    V1.push_back(s);
    for (int i=0;i<n;i++) {
        if (V1[i]=="AB") {
            if (a<b) {
                V2.push_back('A');
                a++; b--;
            }
            else if(a>b) {
                V2.push_back('B');
                b++; a--;
            }
            else if (V1[i+1]=="AC") {
                V2.push_back('A');
                a++; b--;
            }
            else {
                V2.push_back('B');
                b++; a--;
            }
        }
        else if (V1[i]=="AC") {
            if (a<c) {
                V2.push_back('A');
                a++; c--;
            }
            else if(a>c) {
                V2.push_back('C');
                c++; a--;
            }
            else if (V1[i+1]=="AB") {
                V2.push_back('A');
                a++; c--;
            }
            else {
                V2.push_back('C');
                c++; a--;
            }
        }
        else if (V1[i]=="BC") {
            if (b<c) {
                V2.push_back('B');
                b++; c--;
            }
            else if(b>c) {
                V2.push_back('C');
                c++; b--;
            }
            else if (V1[i+1]=="AB") {
                V2.push_back('B');
                b++; c--;
            }
            else {
                V2.push_back('C');
                c++; b--;
            }
        }
        if (a<0 || b<0 || c<0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (auto e : V2) cout << e << endl;

}



Measured memory_bytes: 7464