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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

// >= 91
ll A, M;
ll getPhi(ll m) {
	ll res = 1;
	for(int i=2; i*i<=m; i++) {
		if(m%i == 0) {
			m /= i; res *= i-1;
			while(m%i == 0) m /= i, res *= i;
		}
	}
	if(m != 1) res *= m-1;
	return res;
}
ll getMul(ll a, ll b, ll m) {
	ll r = 0, p = a;
	while(b) {
		if(b%2) r = (r + p) % m;
		p = (p + p) % m;
		b >>= 1;
	}
	return r;
}
ll getPow(ll a, ll b, ll m) {
	ll r = 1, p = a;
	while(b) {
		if(b%2) r = getMul(r, p, m);
		p = getMul(p, p, m);
		b >>= 1;
	}
	return r;
}
ll ee(ll a, ll b, ll &s, ll &t) {
	if(b == 0) {
		s = 1; t = 0;
		return a;
	}
	ll ss, tt, g = ee(b, a%b, ss, tt);
	ll q = a / b;
	s = tt;
	t = ss - q * tt;
	return g;
}
ll toPlus(ll a, ll m) {
	a %= m; if(a < 0) a += m;
	return a;
}
ll getCRT(ll a, ll c, ll b, ll d) {
	//printf("%lld %lld %lld %lld\n", a, c, b, d);
	ll s, t;
	ll g = ee(c, d, s, t);
	s = toPlus(s, d), t = toPlus(t, c);
	if(g > 1) {
		return getCRT(a/g, c/g, b/g, d/g) * g + a%g;
	}
	ll av = getMul(getMul(a, d, c*d), t, c*d);
	ll bv = getMul(getMul(b, c, c*d), s, c*d);
	ll k = (av + bv) % (c*d);
	if(k == 0) k = c*d;
	return k;
}
ll getAns(ll a, ll m) {
	ll pm = getPhi(m);
	if(m < 91) {
		for(int i=1; i<=pm*m; i++) if(getPow(a, i, m) == (i % m)) return i;
		return -1;
	}
	ll c, d;
	ll g = ee(pm, m, c, d);
	ll y = getAns(a, g);
	if(y == -1) return -1;
	ll Ay = getPow(a, y, m);
	ll yg = y / g, Ayg = Ay / g;

	//printf("%lld %lld - > %lld [%lld %lld]\n", a, g, y, c, d);
	ll x = getCRT(getPow(a, y, m), m, y, pm);
	//printf("[%lld %lld] (%lld) %lld %lld\n", a, m, x, getPow(a, x, m), x % m);
	return x;
}
int main() {
	int T; cin >> T;
	for(int tc=1; tc<=T; tc++) {
		scanf("%lld%lld", &A, &M);
		//printf("%lld\n", getAns(A, M));
		ll v = getAns(A, M);
		printf("%lld\n", v);
		//if(v > 0) printf("%lld %lld\n", getPow(A, v, M), v % M);
	}
	return 0;
}


Measured memory_bytes: 256
/*
结论题Orz

设$f(x, y)$表示$(x, y)$辗转相除需要的步数，$fib(i)$表示第$i$个斐波那契数

常识：$f(fib[i], fib[i+1]) = i$。

定义一个数对是“好的”，当且仅当对于$(x, y)$，不存在更小的$x', y'$使得$f(x', y') > f(x, y)$

显然我们需要统计的数对一定是好的数对

定义一个数对是“优秀的”，当且仅当对于$(x, y)$，若$f(x, y) = k$, 满足$x, y \leqslant fib[k+2] + fib[k-1]$

结论！：一个好的数对辗转相除一次后一定是优秀的数对！

证明可以用反证法，也就是我先假设一个$f(a, b) = i$是好的，但是得到的数对$(x, y)$满足$y > fib[k+2] + fib[k-1]$

但是这样我们会得到一个$x' = f[i+2], y' = f[i+2]$满足$f(x', y')>f(a, b)$，所以不成立

那么现在要做的就是求“优秀的”数对的个数。

考虑直接用欧几里得算法的定义递推即可

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define Pair pair<LL, LL> 
#define MP(x, y) make_pair(x, y)
#define fi first 
#define se second 
#define LL long long 
#define int long long 
using namespace std;
const int MAXN = 1e6 + 10, B = 90, mod = 1e9 + 7;
inline LL read() {
	char c = getchar(); LL x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
vector<Pair> v[B + 1];
LL f[B + 1];
void Pre() {
	f[0] = f[1] = 1;
	for(int i = 2; i <= B; i++) f[i] = f[i - 1] + f[i - 2];
	v[1].push_back(MP(1, 2)); v[1].push_back(MP(1, 3)); v[1].push_back(MP(1, 4));
	for(int i = 1; i <= B - 3; i++) {
		for(int j = 0; j < v[i].size(); j++) {
			LL x = v[i][j].fi, y = v[i][j].se;
			LL tmp = x; x = y; y = tmp + y;
			while(y <= f[i + 3] + f[i - 1]) v[i + 1].push_back(MP(x, y)), y += x;
		}
	}
}
main() {
	//freopen("1.in", "r", stdin);
	Pre();
	int Q = read();
	while(Q--) {
		LL x = read(), y = read(), K;
		if(x > y) swap(x, y);
		for(K = 1; f[K + 1] <= x && f[K + 2] <= y; K++);
		cout << K << " ";
		if(K == 1) {cout << x * y % mod << endl; continue;}
		LL ans = 0;
		for(int i = 0; i < v[K - 1].size(); i++) {
			int a = v[K - 1][i].fi, b = v[K - 1][i].se;
		//	printf("%d %d\n", a, b);
			if(b <= x) ans += (y - a) / b % mod;
			if(b <= y) ans += (x - a) / b % mod;
			ans %= mod;
		}
		cout << ans % mod<< endl;
	}
	return 0;
}
/*
3
4 4
6 10
12 11
*/


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

using namespace std;

int main(){
    string n;
    cin>>n;
    for(int i=0;i<=3;i++)
    {
        if(abs(n[i]-n[i+1])<=0)
        {
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] heights = new long[n];
    for (int i = 0; i < n; i++) {
      heights[i] = sc.nextLong();
    }
    long ans = 0;
    for (int j = 0; j < n - 1; j++) {
      if (heights[j] <= heights[j + 1]) continue;
      ans += heights[j] - heights[j + 1];
      heights[j + 1] = heights[j];
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 61156
#include <bits/stdc++.h>
using namespace std;
double angle(int h,int m);
int main()
{
	int a,b,h,m;
	cin>>a>>b>>h>>m;
long double ang,dis;
	ang=angle(h,m);
	if(ang>180)
	{
		ang=(360-ang);
	}
	ang=(3.141592653589793238462643383279/180)*ang;

	dis=(a*a)+(b*b)-((2*a*b)*cos(ang));
	dis=sqrt(dis);
	cout<<fixed<<setprecision(20)<<dis;
	
	
}


double angle(int h,int m)
{
	double a,b,c,d;
	a=h*30;
	b=m*6;
	c=30*(b/360);
	if(a>=b)
	{
		d=a+c-b;
	}
	else
	{
		d=b-(a+c);
	}
	return d;
}

Measured memory_bytes: 4156
import java.util.*;
class Main{
    public static void main(String[] av){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	ArrayList<Integer> X = new ArrayList<Integer>();
	for(int i = 0; i < N; i++){
	    X.add(sc.nextInt());
	}
	int M = sc.nextInt();
	for(int j = 0; j < M; j++){
	    int m = sc.nextInt()-1;
	    int num = X.get(m);
	    if(X.contains(num+1) || num+1 == 2020){}
	    else{
		X.set(m,num+1);
	    }
	}
	for(int i = 0; i < N;i++){
	    System.out.println(X.get(i));
	}
    }
}


Measured memory_bytes: 26476
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
	double q;
	while (true) {
		cin >> q;
		if (q == -1) {
			break;
		}
		double x_p;
		double x_n = q / 2;
		double limit = 0.00001 * q;
		while (abs(x_n * x_n * x_n - q) >= limit) {
			x_p = x_n;
			x_n = x_p - (x_p * x_p * x_p - q) / (3 * x_p * x_p);

		}
		cout << fixed << setprecision(6) << x_n << endl;
			
		
	}
	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	while (cin >> a&&a != "0") {
		char b[3][3];
		for (int i = 0; i < 3; i++)
			b[0][i] = a[i];
		for (int i = 1; i < 3; i++) {
			cin >> a;
			for (int j = 0; j < 3; j++) 
				b[i][j] = a[j];
		}
		string e;
		for (int i = 0; i < 3; i++) {
			bool c = true;
			char d = b[i][0];
			for (int j = 1; j < 3; j++) {
				if (b[i][j] != d||d=='+') 
					c = false;
			}
			if (c) {
				e = d;
				goto stop;
			}
		}
		for (int i = 0; i < 3; i++) {
			bool c = true;
			char d = b[0][i];
			for (int j = 1; j < 3; j++) {
				if (b[j][i] != d||d=='+')
					c = false;
			}
			if (c) {
				e = d;
				goto stop;
			}
		}
		if (b[0][0] == b[1][1] && b[1][1] == b[2][2]&&b[1][1]!='+') {
			e = b[0][0];
			goto stop;
		}
		if (b[0][2] == b[1][1] && b[1][1] == b[2][0]&&b[1][1]!='+') {
			e = b[1][1];
			goto stop;
		}
		e = "NA";
	stop:;
		cout << e << endl;
	}
}

Measured memory_bytes: 3060
#include<iostream>
#include<vector>

using namespace std;
typedef long long ll;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (n <= 0) {
		cout << 0 << endl;
		return 0;
	}
	if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	if (a == b) {
		cout << 1 << endl;
		return 0;
	}
	if (a < b) {
		if (n <= 1) {
			cout << 0 << endl;
			return 0;
		}
		cout <<1+   (b-a)*(n - 2) << endl;
		return 0;
	}
}

Measured memory_bytes: 256
n = int(input())
n_list = [str(input()) for i in range(n)]

m = int(input())
m_list = [str(input()) for i in range(m)]

List = list(set(n_list))
print(max(0, max(n_list.count(List[i]) - m_list.count(List[i]) for i in range(len(List)))))



Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>

int isprime (int p)
{
  for (int i = 2; i * i <= p; i ++)
    if (p % i == 0)
      return 0;
  return 1;
}

const int MaxN = 132456;
int primes[MaxN], good[MaxN];

int main (void)
{
  memset (primes, 0, sizeof primes);
  memset (good, 0, sizeof good);
  for (int i = 2; i < MaxN; i++)
  {
    primes[i] =  isprime(i);
    good[i] = good[i-1] + primes[i] * primes[(i+1) / 2];
  }
  int q, l, r;
  scanf ("%d", &q);
  for (int i = 0; i < q; i++)
  {
    scanf ("%d %d", &l, &r);
    printf ("%d\n", good[r] - good[l-1]);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 1000010

template< typename T >
class CumulativeSum
{
public:
    CumulativeSum() {}
    CumulativeSum(int sz) : m_Data(sz, T(0)) {};
    CumulativeSum(int sz, int mod) : m_Data(sz, T(0)) {};

    // k に x を加える O(1)
    void Add(int k, T x) {
        assert(static_cast<int>(m_Data.size()) >= k);
        if(static_cast<int>(m_Data.size()) <= k) { m_Data.push_back(x); }
        else { m_Data[k] = (m_Data[k] + x); }
    }

    // 累積和の構築 O(m_Data.size())
    void Build() {
        for(int i = 1; i < static_cast<int>(m_Data.size()); i++) {
            m_Data[i] = (m_Data[i] + m_Data[i - 1]);
        }
    }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return T(0); }
        return (m_Data[min(k, static_cast<int>(m_Data.size()) - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int l, int h) {
        return (this->Query(h) - this->Query(l-1));
    }
private:
    vector< T > m_Data;
};

ll N, Q;
string S;

void solve(ll K, CumulativeSum<ll>& cs_d, CumulativeSum<ll>& cs_m) {
    // 最後が C であることに注目する
    ll ans = 0;
    ll l = 0, r = 1;
    ll prev_cnt = 0;
    if(S[l] == 'D' && S[r] == 'M') {
        prev_cnt++;
    }
    while(r < N - 1) {
        // r の直後が C なら、 DMC 完成
        if(S[r + 1] == 'C') { ans += prev_cnt; }
        // r を右にずらす
        r++;
        if(S[r] == 'M') {
            // 新たな M が来たら、それより前の D の分だけ
            // D → M のパターンが増える
            prev_cnt += cs_d.Query(l, r-1);
        }
        // 範囲が k - 1 より大きいなら、 l も右にずらす
        if(r - l >= K - 1) {
            if(S[l] == 'D') {
                // D が削られるなら、それより後の M の分だけ
                // D → M のパターンが減る
                prev_cnt -= cs_m.Query(l+1, r);
            }
            l++;
        }
    }
    printf("%lld\n", ans);
}

signed main()
{
    cin >> N >> S >> Q;

    // 累積和の作成
    CumulativeSum<ll> cs_d(N);
    CumulativeSum<ll> cs_m(N);

    REP(i, N) {
        if(S[i] == 'D') { cs_d.Add(i, 1); }
        if(S[i] == 'M') { cs_m.Add(i, 1); }
    }
    cs_d.Build();
    cs_m.Build();

    REP(i, Q) {
        ll k;
        cin >> k;
        solve(k, cs_d, cs_m);
    }
    return 0;
}


Measured memory_bytes: 17028
use strict;

sub main
{
    my $day = $*IN.lines;
    my $days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    for 0..6 {
        if ($days[$_] eq $day) {
            print (7 - $_);
        }
    }
    return 0;
}

&main();


Measured memory_bytes: 52980
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 21145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
struct edge { int to, cost; };

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

	int d = a*x + b*y;
	int e = min(x, y)*c*2;
	if (x > y)e += a*(x - y);
	else e += b*(y - x);
	int f = max(x, y)*c * 2;
	cout << min(d, min(e,f)) << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/apc001/tasks/apc001_b
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    // sort(ALL(a));
    // sort(ALL(b));
    ll cnt = 0;
    REP(i, n) {
        if (a[i] < b[i]) {
            cnt += (b[i] - a[i]) / 2;
        } else {
            cnt -= a[i] - b[i];
        }
    }
    if (cnt >= 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vi vector<ll>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vt vector<tuple<ll, ll, ll>>
using namespace std;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll a, b;
	cin >> a >> b;
	Graph g(a);
	REP(i, b)
	{
		ll n, m;
		cin >> n >> m;
		add_edge(g, n - 1, m - 1, 1);
		add_edge(g, m - 1, n - 1, 1);
	}
	REP(i, a) cout << g[i].size() << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

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

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	int N;
	cin >> N;
	
	ll ans = 0;
	while ((ans+1)*(ans+1) <= N) {
		ans++;
	}
	cout << ans*ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<stdio.h>

	int main(){
		
		int i,n,x[10],v,w,a,b,c;
		a=0;
		b=0;
		c=0;
		
		for(i=0;i<10;i++){
			x[i]=0;
		}
		
		
		for(i=0;i<10;i++){
			scanf("%d",&n);
			x[i]=n;
		}
		
		for(i=0;i<10;i++){
			if(a<x[i]){
				a=x[i];
				v=i;
			}
		}
		
		for(i=0;i<10;i++){
			if(i!=v){
				if(b<x[i]){
					b=x[i];
					w=i;
				}
			}
		}
		
		for(i=0;i<10;i++){
			if(i!=v){
				if(i!=w){
					if(c<x[i]){
						c=x[i];
					}
				}
			}
		}
		
		printf("%d\n%d\n%d\n",a,b,c);
		
	return 0;
}

Measured memory_bytes: 600
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
#define F first
#define S second
#define pb push_back
#define p push
using namespace std;
using ll = long long;
const ll maxn=5e5+5,inf = 1e18+18;
ll n,m,t,d,x,y;
long double dis;

string s;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0 ) ,cout.tie(0);
	cin>>n>>d;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		dis=(x*x+y*y);
		if(sqrt(dis)<=d)m++;
	}
	cout<<m<<endl;
}


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

int main() {
  int N;
  string s[51];
  int t[51];
  int i, j;
  string X;
  int temp = 0;
  int cnt = 0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  cin >> X;
  for (i = 0; i < N; i++)
    if (s[i] == X)
      temp = i;
  for (i = temp+1; i < N; i++)
    cnt += t[i];
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

using namespace std;

int main() {
    int N;
    cin >> N;
    map<pair<int, int>, int64_t> freq;

    for(int i=1; i<=N; ++i) {
        string s = to_string(i);
        int head = s.front() - '0';
        int tail = s.back() - '0';
        if(tail == 0)
            continue;
        freq[{head, tail}]++;
    }

    int64_t sum = 0;
    for(int i=1; i<=N; ++i) {
        string s = to_string(i);
        int head = s.front() - '0';
        int tail = s.back() - '0';
        if(tail == 0)
            continue;
//        cout << itr.first.first << "," << itr.first.second << " " << itr.second << endl;
        sum += freq[{tail, head}];
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    ll ans = 0;

    ll n, k;
    string s;

    cin >> n >> k >> s;

    ll ch = 'a' - 'A';

    s[k-1] += ch;

    cout << s << endl;



}

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

int main() {
  string a,b;
  int count;
  count =0;
  cin >>a >>b;
  for(int i=0;i <3;i++){
    if(a.at(i) ==b.at(i)){
      count++;
    }
  }
  cout <<count <<endl;
}


Measured memory_bytes: 256
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut money = 1000;
    let mut stock = 0;
    let mut s = 'n';
    for i in 1..n {
        if a[i - 1] < a[i] {
            if s != 'u' {
                stock += money / a[i - 1];
                money = money % a[i - 1];
            }
            s = 'u';
        } else if a[i - 1] > a[i] {
            if s != 'd' {
                money += stock * a[i - 1];
                stock = 0;
            }
            s = 'd';
        }
    }
    money += stock * a[n - 1];
    println!("{}", money);
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int h, w; cin >> h >> w;
  vector<string> a(h);
  rep(i, h) cin >> a[i];
  rep(i, h) {
    a[i] = '#' + a[i] + '#';
  }
  rep(i, w+2) cout << "#";
  cout << endl;
  rep(i, h) cout << a[i] << endl;
  rep(i, w+2) cout << "#";
  cout << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int l[Q], r[Q];
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
  }

  int left[N + 1];
  int count = 0;
  left[0] = 0;
  for (int i = 1; i <= N; i++) {
    if (i < N) {
      if (S[i - 1] == 'A' && S[i] == 'C') {
        count += 1;
      }
    }
    left[i] = count;
  }

  int right[N + 1];
  count = 0;
  for (int i = 1; i <= N; i++) {
    if (i - 2 >= 0) {
      if (S[i - 2] == 'A' && S[i - 1] == 'C') {
        count += 1;
      }
    }
    right[i] = count;
  }

  for (int i = 0; i < Q; i++) {
    // cout << "third " << r[i] << ", " << l[i] << endl;
    // cout << "third " << right[r[i]] << ", " << left[l[i] - 1] << endl;
    cout << right[r[i]] - left[l[i] - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 2560
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld long double
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ld dp[3000][3000];
int main()
{
    _fast_
    ll t = 1;
   // cin>>t;
    while(t--){
    memset(dp,0.0,sizeof(dp));
    ll n;
    cin>>n;
    ld arr[n];
    f(n)
    {
        cin>>arr[i];
    }
    dp[0][0] = 1.0;
    for(ll i = 1;i<=n;i++)
    {
        for(ll j = 0;j<=i;j++)
        {
            if(j == 0)
            {
                dp[i][j] = dp[i-1][j]*(1.00-arr[i-1]);
            }
            else
            {dp[i][j] = (dp[i-1][j]*(1.0-arr[i-1]))+(dp[i-1][j-1]*(arr[i-1]));}
            
        }
    }
    ld ans = 0.0;
    for(ll i = (n+1)/2;i<=n;i++){
        ans += dp[n][i];
    }
    cout<<fixed<<setprecision(11)<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 140928
import java.util.Scanner;

public class Main{

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

        int res = 0;

        for(int i=1; i<=n; i++){
            int sum = 0;
            for(char c : String.valueOf(i).toCharArray()){
                sum += Character.getNumericValue(c);
                if(sum > b) break;
            }
            if(a <= sum && b >= sum) res+=i;
            
        }
        System.out.println(res);
        scan.close();
        
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll s,h,m;
    cin >> s;
    h = s/3600;
    s %= 3600;
    m = s/60;
    s %= 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3088
n = gets.to_i
a = [0, *gets.split.map(&:to_i), 0]

sum = (0..n).each.inject(0) do |r, i|
  r + (a[i + 1] - a[i]).abs
end

(1..n).each do |i|
  d1 = [(a[i] - a[i - 1]).abs, (a[i + 1] - a[i]).abs]
  d2 = (a[i + 1] - a[i - 1]).abs

  puts sum - d1.inject(:+) + d2
end


Measured memory_bytes: 12292
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
#endif

  ll n;
  cin>>n;
  ll n1=n-n%3;
  ll n2=n-n%5;
  ll n3=n-n%15;
  ll sum=0;
 sum+=(n1/3)*(3+n1)/2;
 sum+=(n2/5)*(5+n2)/2;
 sum-=(n3/15)*(15+n3)/2;
 ll total=n*(n+1)/2;
 total-=sum;
 cout<<total<<endl;
  return 0;
}

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1;
    } return res;
}

const int maxN = 1e5 + 5;
int x, y, a, b, c;
int p[maxN], q[maxN], r[maxN];

int32_t main() { fastio;
    
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++) {
    	cin >> p[i];
    }
    for (int i = 0; i < b; i++) {
    	cin >> q[i];
    }
    for (int i = 0; i < c; i++) {
    	cin >> r[i];
    }
    sort(p, p + a, greater<int>());
    sort(q, q + b, greater<int>());
    sort(r, r + c, greater<int>());

    int lastA = min(a - 1, x - 1);
    int lastB = min(b - 1, y - 1);
    int firstC = 0;
    int curr = 0;

    if (x > a) {
    	for (auto al : p) {
    		curr += al;
    	}
    	for (int i = 0; i < (x - a); i++) {
    		curr += r[i];
    		firstC++;
    	}
    } else {
    	for (int i = 0; i < x; i++) {
    		curr += p[i];
    	}
    }

    if (y > b) {
    	for (auto al : q) {
    		curr += al;
    	}
    	for (int i = firstC; i < (y - b); i++) {
    		curr += r[i];
    		firstC++;
    	}
    } else {
    	for (int i = 0; i < y; i++) {
    		curr += q[i];
    	}
    }

    for (int i = firstC; i < c; i++) {
    	if (lastA < 0 and lastB < 0) {
    		break;
    	} else if (lastA < 0 and lastB >= 0) {
    		if (r[i] < q[lastB]) {
    			break;
    		} else {
    			curr -= q[lastB];
    			curr += r[i];
    			lastB--;
    		}
    	} else if (lastA >= 0 and lastB < 0) {
    		if (r[i] < p[lastA]) {
    			break;
    		} else {
    			curr -= p[lastA];
    			curr += r[i];
    			lastA--;
    		}
    	} else if (p[lastA] > q[lastB]) {
    		if (r[i] < q[lastB]) {
    			break;
    		} else {
    			curr -= q[lastB];
    			curr += r[i];
    			lastB--;
    		}
    	} else {
    		if (r[i] < p[lastA]) {
    			break;
    		} else {
    			curr -= p[lastA];
    			curr += r[i];
    			lastA--;
    		}
    	}
    }

    cout << curr << endl;

    return 0;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
MAXV = 160 * 80

grid1 =build_grid(H, W, 0, int)
grid2 =build_grid(H, W, 0, int)
grid = list2d(H+1, W+1, 0)
for i in range(H):
    for j in range(W):
        grid[i+1][j+1] = abs(grid1[i][j]-grid2[i][j])

dp = list2d(H+1, W+1, 0)

dp[1][1] = (1<<MAXV-grid[1][1]) | (1<<MAXV+grid[1][1])
for i in range(1, H+1):
    for j in range(1, W+1):
        v = grid[i][j]
        dp[i][j] |= dp[i-1][j] << v
        dp[i][j] |= dp[i-1][j] >> v
        dp[i][j] |= dp[i][j-1] << v
        dp[i][j] |= dp[i][j-1] >> v
ans = INF
S = dp[H][W] >> MAXV
for k in range(MAXV+1):
    if S & (1<<k):
        ans = min(ans, k)
print(ans)


Measured memory_bytes: 20336
# -*- coding: utf-8 -*-


from itertools import groupby


def runLengthEncode(S: str):
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, str(len(list(v)))))
    return res


def main():
    s = input()
    length = len(s)
    s_count = 0

    # See:
    # https://qiita.com/Kept1994/items/e9179d1dd7c6455d6883
    runLength = runLengthEncode(s)

    for first, second in zip(runLength, runLength[1:]):
        if first[0] == 'S' and second[0] == 'T':
            first_count = int(first[1]) + s_count
            second_count = int(second[1])

            if first_count > second_count:
                s_count = first_count - second_count
            else:
                s_count = 0

            length -= 2 * min(first_count, second_count)

    print(length)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23416
import math


a, b, h, m = map(int, input().split())

kaku = abs((h+m/60)*5+-m)*6
angle = min(kaku, 360-kaku)
cos = math.cos(math.radians(angle))

ans2 = a**2 + b**2 - 2*a*b*cos

print(math.sqrt(ans2))


Measured memory_bytes: 9500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] list = Console.ReadLine().Split(' ');   
            int a = int.Parse(list[0]);
            int b = int.Parse(list[1]);
            if (-1000<=a && b <= 1000)
            {
                if (a > b)
                {
                    Console.WriteLine("a > b");
                }
                else if (a == b)
                {
                    Console.WriteLine("a == b");
                }
                else if (a < b)
                {
                    Console.WriteLine("a < b");
                }
            }
        }
    }
}




Measured memory_bytes: 8852
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	aStr := strconv.Itoa(a)
	bStr := strconv.Itoa(b)

	var ansStr string
	if a > b {
		for i := 0; i < a; i++ {
			ansStr += bStr
		}
	} else {
		for i := 0; i < b; i++ {
			ansStr += aStr
		}
	}
	ans, _ := strconv.Atoi(ansStr)
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main() {
	int x,y,z;
	int a[110][110] = {0};
	int b[110][110] = {0};
	long int c[110][110] = {0};
	int i, j,l;
	cin >> x; cin >> y; cin >> z;
	for (i = 0; i < x; i++) {
		for (j = 0; j < y; j++) {
			cin >> a[i][j];
		}
	}
	for (i = 0; i < y; i++) {
		for (j = 0; j < z; j++) {
			cin >> b[i][j];
		}
	}
	for (i = 0; i < x; i++) {
		for (j = 0; j < y; j++) {
			for (l = 0; l < z; l++) {
				c[i][l] = c[i][l] + a[i][j] * b[j][l];
			}
		}
	}
	for (i = 0; i < x; i++) {
		for (j = 0; j < z - 1; j++) {
			cout << c[i][j]<<" ";
		}
		cout << c[i][j] << "\n";
	}






}


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

int main(){
  int x, cnt1=0, cnt2=0;
  cin >> x;

  while(x>=500){
    x-=500;
    cnt1++;
  }
  while(x>=5){
    x-=5;
    cnt2++;
  }

  cout << cnt1*1000+cnt2*5 << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    static int n = 0;
    static long k = 0;
    static int[] a = null;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextLong();
        a = new int[n+1];
        for(int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }
        int[] visited = new int[n+1];
        for(int i=1; i<=n; i++) {
            visited[i] = -1;
        }
        
        int count = 0;
        int offset = 0;
        int loopTerm = 0;
        int current = 1;
        visited[current] = 0;
        while(true) {
            int next = a[current];
            count++;
            if(visited[next] >= 0) {
                offset = visited[next];
                loopTerm = count - offset;
                break;
            }
            visited[next] = count;
            current = next;
        }
        if(k>offset) {
            k -= offset;
            k %= loopTerm;
            k += offset;
        }
        current = 1;
        for(int i=0; i<k; i++) {
            current = a[current];
        }
        System.out.println(current);
    }
}


Measured memory_bytes: 60496
n = int(input())
ans = []
if n == 0:
    print(0)
    exit()
for i in range(10**5):
    if n == 0:
        break
    if n%pow(2,i+1) != 0:
        ans.append('1')
        n -= pow(-2,i)
    else:
        ans.append('0')
    

ans = ans[::-1]
ans_s = ''.join(ans)
print(ans_s)

Measured memory_bytes: 61760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,c=0;cin>>N;
  for(int i=1; i<=N; i++){
    int d=0;
    if(i%2==1){
    for(int j=i; j>0; j--){
      if(i%j==0)d++;
    }}
    if(d==8)c++;
  }  
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <limits>
#include <chrono>

using namespace std;

class vec2d
{
public:
	vec2d() : x(0.0), y(0.0) {};
	vec2d(double _x, double _y) : x(_x), y(_y) {};
	double x, y;
	vec2d operator-(const vec2d &);
	double vec(const vec2d &);
};

vec2d vec2d::operator-(const vec2d &b)
{
	vec2d r;
	r.x = x - b.x;
	r.y = y - b.y;
	return r;
}

double vec2d::vec(const vec2d &b)
{
	return x * b.y - y * b.x;
}

int main()
{
	double x1, y1, x2, y2, x3, y3, xp, yp;
	while(1)
	{
		if (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp)
		{
			vec2d a(x1, y1), b(x2, y2), c(x3, y3), p(xp, yp);

			vec2d ab, bc, ca, ap, bp, cp;
			ab = a - b;
			bp = b - p;
			bc = b - c;
			cp = c - p;
			ca = c - a;
			ap = a - p;

			double c1, c2, c3;
			c1 = ab.vec(bp);
			c2 = bc.vec(cp);
			c3 = ca.vec(ap);

			if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0))
				cout << "YES" << '\n';
			else
				cout << "NO" << '\n';
		}
		else
			break;
	}

	return 0;
}

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

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

int main()
{
    cin >> n;
    for(ll i = 0; i < 5; i ++)
    {
        cin >> a[i];
        if(n < a[i])
        {
            v.pb(1);
        }
        if(n >= a[i])
        {
            if(n % a[i] == 0)
            {
                v.pb(n / a[i]);
            }
            else
            {
                v.pb((n / a[i]) + 1);
            }
        }
    }
    sort(v.begin(), v.end());
    cout << v[v.size() - 1] + 4;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

class Block{
public:
  Block *above;
  Block *below;
  Block() {
    above = 0;
    below = 0;
  }

  Block *getRoot() {
    if(below == 0) return this;
    return below->getRoot();
  }
  Block *rgetRoot() {
    if(above == 0) return this;
    return above->rgetRoot();
  }
  int getRank(int rank = 1) {
    if(below == 0) return rank;
    return below->getRank(rank + 1);
  }

  int rgetRank(int rank = 1) {
    if(above == 0) return rank;
    return above->rgetRank(rank + 1);
  }

  void onFloor() {
    if(above != 0) {
      above->onFloor();
    }
    if(below != 0) {
      below->above = 0;
      below = 0;
    }
  }

  void put(Block *block) {
    Block *tmp = block->rgetRoot();
    below = tmp;
    tmp->above = this;
  }
};

main() {
  while(1) {
    int m;
    int I, J;
    Block block[100];
    cin >> m;
    if(m == 0) break;
    while(1) {
      cin >> I >> J;
      if(I == 0 && J == 0) break;
      I--;
      J--;
      if(J == -1) {
	if(block[I].below != 0) block[I].onFloor();
      } else if(block[I].getRoot() == block[J].getRoot()) {
	if(block[I].getRank() < block[J].getRank()) {
	  block[I].onFloor();
	  block[I].put(&block[J]);
	}
      } else {
	block[I].onFloor();
	block[I].put(&block[J]);
      }
    }
    set<Block *> s;
    vector<int> rank;
    for(int i = 0; i < m; i++) {
      Block *tmp = block[i].getRoot();
      if(s.find(tmp) == s.end()) {
	s.insert(tmp);
	rank.push_back(tmp->rgetRank());
      }
    }
    sort(rank.begin(), rank.end());

    for(int i = 0; i < rank.size(); i++) {
      cout << rank[i] << endl;
    }
    cout << "end" << endl;
  }
}

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

int func(int n)
{
    if(n % 2 == 0){
        return n / 2;
    }else{
        return (3 * n + 1);
    }
}

int main()
{
    int s;
    int a[1000000];
    cin >> s;
    a[0] = s;
  
    if(s == 1 || s == 2){
      cout << 4 << endl;
      return 0;
    }else{
    for(int i = 0; i < 1000000; i++){
        a[i+1] = func(a[i]);
        if(func(a[i] == 4)){
            cout << i + 4 << endl;
            return 0;
        }
    }
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
      result=(3*N+K)/2;
                    Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}

Measured memory_bytes: 13140
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    extra=0
    if C>(A+B):
        extra=1
    print(B+min((A+B),C)+extra)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){

    int a, b;
    cin>>a>>b;

    for(int i = 1;i<=3;i++){
        if( (a * b * i) % 2 == 1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

using namespace std;
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;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;

int atcoder(){
    //入力
    ll n;
    cin >> n;
    ll t[n];
    ll sum=0;
    REP(i,0,n){
        cin >> t[i];
        sum += t[i];
    }
    ll m;
    cin >> m;
    ll p[m],x[m];
    REP(i,0,m) cin >> p[i] >> x[i];
    
    REP(i,0,m) cout << sum-t[p[i]-1]+x[i] << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;
const long long int MOD=1e9+7;

int main(){
  int n;
  char tmp;
  vector<int> v[209];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> tmp;
      if(tmp=='1'){
        v[i].push_back(j);
      }
    }
  }
  int ans = -1;
  int check[209];
  for(int i=0;i<n;i++){
    queue<int> Q;
    int mx=0;
    bool chk = true;
    for(int j=0;j<n;j++){
      check[j] = -1;
    }
    check[i] = 1;
    while(!Q.empty())Q.pop();
    Q.push(i);
    while(!Q.empty()){
      int fr = Q.front();Q.pop();
      for(int j=0;j<v[fr].size();j++){
        if(check[v[fr][j]]==-1){
          Q.push(v[fr][j]);
          check[v[fr][j]] = check[fr]+1;
          mx = max(check[fr]+1, mx);
        }
        else if(check[v[fr][j]]!=check[fr]-1 && check[v[fr][j]]!=check[fr]+1){
          chk=false;
          break;
        }
      }
      if(!chk)break;
    }
    if(chk)ans = max(mx, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    string S,T;
    cin >> S >> T;
    int i=S.size();
    int count=0;
    for(int j=0;j<i;j++){
        if(S.at(j)==T.at(j)){
            count++;
        }
    }
    if(count==i){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 2e5 + 100;
int n, a[N], k;

int main() {
	
	cin >> k >> n;
	
	int ans = 0x3f3f3f3f;
	
	for(int i = 0; i < n; i++) cin >> a[i];
	
	for(int i = 0; i < n; i++) {
		int pre = (i-1+n) % n;
		int nex = (i+1) % n;
		
		int x = (a[pre] - a[i] + k) % k;
		ans = min(ans, x);
		x = (a[i] - a[nex] + k) % k;
		ans = min(ans, x);
	}
	
	cout << ans << endl;
	return 0;	
} 

Measured memory_bytes: 3968
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    ll ans = 0ll;

    for(int i=0;i<N;i++){
        ans += A[i]/2;
        A[i] %= 2;

        if(i+1 < N){
            int d = min(A[i], A[i+1]);
            A[i] -= d;
            A[i+1] -= d;
            ans += d;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
from itertools import permutations
n=int(input())
xy=[list(map(int,input().split()))for _ in range(n)]
ans=0
calc=lambda x1,y1,x2,y2:(abs(x1-x2)**2+abs(y1-y2)**2)**(0.5)
for i in permutations(xy):
  for j in range(1,n):
    ans+=calc(i[j-1][0],i[j-1][1],i[j][0],i[j][1])
for i in range(2,n+1):ans/=i
print(ans)


Measured memory_bytes: 3064
N,X,Y = [int(i.strip()) for i in input().split(' ')]
X = X-1
Y = Y - 1
diff = (Y-X-1)//2
result = [0]*N
for i in range(N):
    for j in range(i+1,N):
        dist = min(j-i,abs(X-i)+abs(Y-j)+1)
        result[dist-1] += 1

L = len(result) - 1
for i,j in enumerate(result):
    if not i == L:
        print(j)

Measured memory_bytes: 3444