akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int m = s.length(),n=t.length();

    int dp[m+1][n+1];

    memset(dp[0],0,sizeof(dp[0]));
    for(int i=0;i<=m;i++)dp[i][0] = 0;

    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(s[i-1] == t[j-1] )
            {
                dp[i][j] = 1+ dp[i-1][j-1];
            }else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    string a="";
    int i=m,j=n;

    while(i>0 && j>0)
    {
        if(dp[i][j] > dp[i-1][j] && dp[i][j] > dp[i][j-1])
        {
            a = s[i-1] + a;
            i--,j--;
        }else{
           if(dp[i][j-1] > dp[i-1][j]){
                j--;
           }else{
                i--;
           }
        }
    }

    cout<<a;

}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const int W(1), B(0);
vector<vector<pair<int,int>>>M; // d,c
int n;
int prim() {
	vector<int>d(n, INF), color(n, W);
	d[0] = 0;
	priority_queue<pair<int,int>>pq; // d[v], v
	pq.push(make_pair(0, 0));
	while (!pq.empty()) {
		pair<int, int>f(pq.top()); pq.pop();
		color[f.second] = B;
		if (d[f.second] < f.first*(-1)) continue;
		rep(i, 0, M[f.second].size()) {
			pair<int, int>u(M[f.second][i]);
			if (color[u.first] != B&&u.second<d[u.first]) {
				d[u.first] = u.second;
				pq.push(make_pair(d[u.first] * (-1), u.first));
			}
		}
	}
	return accumulate(all(d), 0) / 100 - d.size()+1;
}
signed main() {
	while (cin >> n, n) {
		M = vector<vector<pair<int,int>>>(n, vector<pair<int,int>>());
		int m; cin >> m;
		rep(i, 0, m) {
			int a, b, d; char c; cin >> a >> c >> b >> c >> d;
			M[a].push_back(make_pair(b, d));
			M[b].push_back(make_pair(a, d));
		}
		cout << prim() << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <utility>
#include <set>

using namespace std;

int main()
{
    int n, ans=0, x, y;
    set<pair<int, int>> r, b;
    cin>>n;
    for (int i=0; i<n; i++) { cin>>x>>y; r.insert({x, y}); }
    for (int i=0; i<n; i++) { cin>>x>>y; b.insert({x, y}); }
    for (auto u : b)
    {
        x=-200; y=-200;
        for (auto v : r)
        {
            if (v.first<u.first && v.second<u.second)
            {
                if (v.second>y)
                {
                    x=v.first;
                    y=v.second;
                }
            }
        }
        if (x!=-200 && y!=-200) { r.erase({x, y}); ans++; }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
h = []
for i in 1..n do
  h << gets.to_i
end

h = h.sort
ans = 10**9
for i in 0..(n - k) do
  diff = h[i + k - 1] - h[i]
  ans = diff if diff < ans
end

puts ans

Measured memory_bytes: 4528
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N;

void _main() {
  cin >> N;
  int sqrt_n = sqrt(N);
  while (sqrt_n * sqrt_n > N) sqrt_n--;
  cout << (sqrt_n * sqrt_n) << "\n";
}

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

using namespace std;

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

        if ((str[0] == str[1] && str[1] == str[2]) || (str[1] == str[2] && str[2] == str[3])) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }

        return 0;
}

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

int m_p(int p, int n){
  int m = 1;
  while(m <= n){
    m *= p;
  }
  return(m / p);
}

int main()
{
  int n;
  cin >> n;
  int l = 1;
  for(int i = 2; i * i <= n; i++){
    l = max(l, m_p(i, n));
  }
  cout << l << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define inl inline
#define br break
#define con continue
#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))
#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))
#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))
#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))
#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))
#define re register
#define stt struct
#define nms namespace
#define gc getchar
#define sl(sl_a) strlen(sl_a)
#define gt(gt_a) goto gt_a
#define rt return
#define infa (0x3f3f3f3f)
#define infb (0x7fffffff)
#define infd (0x7f)
#define in(in_a) freopen("D:/""/in"in_a".in","r",stdin)
#define out(out_a) freopen("D:/""/out"out_a".out","w",stdout)
#define filein(filein_a) freopen(filein_a".in","r",stdin)
#define fileout(fileout_a) freopen(fileout_a".out","w",stdout)
#define file(file_a) filein(file_a);fileout(file_a)
typedef long long ll;
typedef int itn,nti,tin,tni,nit;
using namespace std;
const nit maxa=104;
const nit maxb=1000004;
const nit maxc=4;
const tni maxd=10004;
#include<cstring>

tni s,f=0;
char x[maxa];

tni main()
{
	scanf("%s",x+1);
	s=sl(x+1);
	//
	fora(i,1,s)
	{
		if(x[i]=='C')
		{
			f=1;
		}
		else if(x[i]=='F')
		{
			if(f)
			{
				gt(Yes);
				br;
			}
		}
	}
	//
	printf("No\n");
	rt 0;
	//
	Yes:
	pritnf("Yes\n");
	rt 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define foru(i, a, n) for (int i = (a); i <= (n); ++i)
#define sqr(x) (x) * (x)
using namespace std;
const string NAME = "FROG3";
const int N = 202020;
#define ll long long
#define ld long double
#define a first
#define b second
const int inf = 1e9 + 7;
typedef pair<ll, ll> line;
ll val(line u, ll x)
{
    return u.a * x + u.b;
}
ld giaoX(line u, line v)
{
    return (ld)(v.b - u.b) / (u.a - v.a);
}
struct convex //convexhux he so goc giam dan
{
    vector<line> dq;
    void insert(line u)
    {
        while (dq.size() >= 2 && giaoX(dq[dq.size() - 1], u) <= giaoX(dq[dq.size() - 2], u))
            dq.pop_back();
        dq.push_back(u);
    }
    ll querymin(ll x)
    {
        ll l = 0, r = dq.size() - 1, m1, m2, res = 1e18;
        while (r - l > 3)
        {
            m1 = l + (r - l) / 3;
            m2 = r - (r - l) / 3;
            if (val(dq[m1], x) <= val(dq[m2 + 1], x))
                r = m2;
            else
                l = m1;
        }
        for (int i = l; i <= r; i++)
            res = min(res, val(dq[i], x));
        return res;
    }
};

ll n, m, k, c, h[N], dp[N];

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    //dp[i] = min(dp[j] + (hj - hi)^2 + c)
    //dp[j] + (hj - hi)^2 + c = dp[j] + hj^2 - 2hihj + hi^2 + c
    //-2hj*hi + hj^2 + dpj +(hi^2 + c)
    //-2hj*hi + hj^2 + dpj co dang duong thang y = a*x + b voi a = -2hj,  b = hj^2 + dp[j]
    //Toi uu bang convex hull
    convex T;
    dp[1] = 0;
    T.insert({-2 * h[1], h[1] * h[1] + dp[1]});
    for (int i = 2; i <= n; i++)
    {
        dp[i] = T.querymin(h[i]) + h[i] * h[i] + c;
        T.insert({-2 * h[i], h[i] * h[i] + dp[i]});
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 9072
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,q,l,r;
char d[200005],t[200005];
string s;

int main() {
	cout << fixed << setprecision(18);
	cin>>n>>q>>s;
	for(int i=0;i<q;i++){
		cin>>t[i]>>d[i];
	}
	//左端
	long long int ng=-1,ok=n,mid=(ng+ok)/2;
	while(ok-ng>1){
		long long int now=mid;
		for(int i=0;i<q;i++){
			if(s[now]==t[i]){
				if(d[i]=='R'){now++;}
				else{now--;}
			}
			if(now<0){ng=mid;}
		}
		if(ng!=mid){ok=mid;}
		mid=(ng+ok)/2;
	}
	l=ok;

	ng=-1,ok=n,mid=(ng+ok)/2;
	while(ok-ng>1){
		long long int now=mid;
		for(int i=0;i<q;i++){
			if(s[now]==t[i]){
				if(d[i]=='R'){now++;}
				else{now--;}
			}
			if(now>=n){ok=mid;}
		}
		if(ok!=mid){ng=mid;}
		mid=(ok+ng)/2;
	}
	r=ng;
	cout<<max(r-l+1,0LL);
} 

Measured memory_bytes: 900
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: u64 = read();

    let div500 = x / 500;
    let under500 = x % 500;
    let div5 = under500 / 5;
    println!("{}", div500 * 1000 + div5 * 5);
}


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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int n;
	cin >> n;
	rep(i,9)rep(j,9) {
		if((i+1)*(j+1) == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;

  return 0;
}


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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static long Calc(long x, long y) {
        if (x == y) return 0;

        if (x < y) {
            if (x >= 0) return y - x;

            if (y <= 0) {
                return y - x;
            }
            else if (x > -y) {
                return y - (-x) + 1;
            }
            else {
                return -y - x + 1;
            }
        }
        else { // x > y
            if (y >= 0) {
                if (y == 0) return Math.Abs(x) + 1;

                return x - y + 2;
            }

            // y < 0
            if (x >= 0) {
                if (x > -y) {
                    return x - (-y) + 1;
                }
                return -y - x + 1;
            }
            else { // x < 0
                if (-x <= -y) {
                    return -y - (-x) + 2;
                }
                return -x - (-y) + 1;
            }
        }
    }

    static long F(long a, long b) {
        if (a > b) return int.MaxValue;
        return b - a;
    }

    static long Calc2(long x, long y) {
        if (x == y) return 0;

        long a = F(x, y);
        long b = F(-x, y) + 1;
        long c = F(x, -y) + 1;
        long d = F(-x, -y) + 2;

        return new[] { a, b, c, d }.Min();
    }

    static void Main() {
        var xy = ReadInts();
        long x = xy[0];
        long y = xy[1];

        var ans = Calc2(x, y);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    int A[n],B[n], C[n-1];
    for (int i=0;i<n;i++) cin >> A[i];
    for (int i=0;i<n;i++) cin >> B[i];
    for (int i=0;i<n-1;i++) cin >> C[i];

    int ans=0;
    for (int i=0;i<n;i++) ans += B[i];
    for (int i=0;i<n-1;i++){
        if (A[i]+1==A[i+1]) ans += C[A[i]-1];
    }
  cout << ans << endl;

}

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

int main()
{
	//Homework
	int num1,num2,num3,num4,num5,num6,num7,num8,num9;

	cin>>num1>>num2>>num3>>num4>>num5;
	num6=num2/num4;
	num7=num2%num4;
	if(num7>0){
		num6=num6+1;
	}
	num8=num3/num5;
	num9=num3%num5;
	if(num9>0){
		num8=num8+1;
	}
	if(num6<num8){
		num6=0;
		num6=num8;
	}
	num9=num1-num6;
	cout<<num9;
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 1164
n = gets.to_i
as = gets.chomp.split.map(&:to_i).sort
bs = gets.chomp.split.map(&:to_i).sort
cs = gets.chomp.split.map(&:to_i).sort

ans = 0

bs.each do |b|
  a_i = as.bsearch_index { |a| a >= b }
  c_i = cs.bsearch_index { |c| c > b }
  if a_i.nil?
    a_i = as.size
  end
  if c_i.nil?
    c_i = 0
  else
    c_i = cs.size - c_i
  end
  ans += a_i * c_i
end
puts ans


Measured memory_bytes: 26804
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<int MOD> struct modint {
    long long val;
    constexpr modint(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr modint operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr modint operator + (const modint& r) const noexcept { return modint(*this) += r; }
    constexpr modint operator - (const modint& r) const noexcept { return modint(*this) -= r; }
    constexpr modint operator * (const modint& r) const noexcept { return modint(*this) *= r; }
    constexpr modint operator / (const modint& r) const noexcept { return modint(*this) /= r; }
    constexpr modint& operator += (const modint& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr modint& operator -= (const modint& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr modint& operator *= (const modint& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr modint& operator /= (const modint& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const modint& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const modint& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const modint<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr modint<MOD> modpow(const modint<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = modint<MOD>;

int main() {
    int n; cin >> n;
    mint ans = 1;
    mint t1 = 1, t2 = 1;

    rep(_, n) {
        ans *= 10;
        t1 *= 9;
        t2 *= 8;
    }
    t1 *= 2;
    cout << ans - t1 + t2 << endl;
}


Measured memory_bytes: 3628
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])
    [T, A] = string_to_int(inputs[1])
    H = string_to_int(inputs[2])

    min_diff = -1
    min_diff_i = -1
    for i, h in enumerate(H):
        t = T - h * 0.006
        diff = abs(A-t)
        if min_diff == -1 or diff < min_diff:
            min_diff = diff
            min_diff_i = i
    return min_diff_i + 1


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(3))
    print(ret)


Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

string s;

int main(){
	cin >> s;
	REP(i, s.size()){
		if (s[i] != ',')cout << s[i];
		else cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V< pair<string, int> > v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
    v[i].second *= -1;
  }
  V<> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) { return v[i] < v[j]; });
  for (int i : idx) {
    cout << i + 1 << '\n';
  }
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

struct Sieve {
	int n;
	vector<int> f, primes;
	Sieve(int n=1):n(n), f(n+1) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; ++i) {
			if (f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for (ll j = i*i; j <= n; j += i) {
				if (!f[j]) f[j] = i;
			}
		}
	}
	bool isPrime(int x) { return f[x] == x;}
	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<P> factor(int x) {
		vector<int> fl = factorList(x);
		if (fl.size() == 0) return {};
		vector<P> res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			} else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

// now += mint(2).pow(s) - 1; こんな感じで、2のs乗を求められrう
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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*(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;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main()
{
	Sieve sieve(1e6);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	
	map<int,int> mp;
	rep(i,n) {
		auto f = sieve.factor(a[i]);
		for (auto p : f){
			mp[p.first] = max(mp[p.first], p.second);
		}
	}

	mint lcm = 1;
	for(auto p : mp){
		rep(i,p.second){ 
			lcm *= p.first;
		}
	}

	mint ans;
	rep(i,n) {
		mint b = lcm/a[i];
		ans += b;
	}
	cout << ans.x << endl;
}


Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll pw(ll x, ll n)
{
    ll ret = 1;
    rep(i,n) ret *= x;
    return ret;
}

bool query(ll n)
{
    cout << "? " << n << endl;
    cout << flush;

    char c;
    cin >>c;
    return c=='Y';

}

ll f1()
{
    for(int i=9; i>0; --i)
    {
        if(!query(pw(10,i)-1)) return pw(10,i);
    }
    return 1;
}

ll f2()
{
    int p = 1;
    while(query(pw(10,p))) ++p;

    ll l = pw(10,p-1), r = pw(10,p)-1;
    while(r-l>1)
    {
        ll m = (l+r)/2;
        if(query(m*10)) r=m;
        else l=m;

    }
    return r;
}

int main()
{
    ll ans;
    if(query(pw(10,10))) ans = f1();
    else ans = f2();

    cout << "! " << ans << endl;
    cout << flush;
    return 0;
}


Measured memory_bytes: 596
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int N, W;
vector<ll> w(110);
vector<ll> v(110);
vector<vector<ll>> dp(110, vector<ll>(100010));

int main(void){
	cin >> N >> W;
	for(int i = 0; i < N; i++) cin >> w[i] >> v[i];

	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= W; j++){
			dp[i][j] = dp[i-1][j];
			if(j-w[i-1] >= 0){
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
			}
		}
	}
	cout << dp[N][W] << endl;
}


Measured memory_bytes: 87296
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    int N;
    cin >>N;
    int M;
    if(N%2==0){
        M =N*(N-2)/2;
        cout <<M<<endl;
        rep2(i,1,N){
            rep2(j,i+1,N+1){
                if(i+j==N+1) continue;
                cout << i<<" "<<j<<endl;
            }   
        }
    }
    else{
        M =(N-1)*(N-1)/2;
        cout <<M<<endl;
        rep2(i,1,N){
            rep2(j,i+1,N+1){
                if(i+j==N) continue;
                cout << i<<" "<<j<<endl;
            }   
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a,b,c,d,t1,t2;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a>b)
    t1=b;
  else
    t1=a;
  if(c>d)
    t2=d;
  else
    t2=c;
  printf("%d\n",t1+t2);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

map<int, string> data;
void FizzBuzz(){
	for(int i = 1; i <= 10000; i++){
		bool flag = false;
		string S;
		if(i % 3 == 0){
			S += "Fizz";
			flag = true;
		}
		if(i % 5 == 0){
			S += "Buzz";
			flag = true;
		}
		if(flag){
			data[i] = S;
		}else{
			data[i] = IntToStr(i);
		}
	}
}

int main(void){
	FizzBuzz();
	int m, n;
	while(cin >> m >> n, n||m){
		vector<int> player;
		for(int i = 1; i <= m; i++){
			player.pb(i);
		}
		int count = 0;
		for(int i = 1; i <= n; i++){
			string s;
			cin >> s;
			int safe = player.size();
			if(player.size() == 1)continue;
			if(data[i] != s){
				remove(player, count%safe);
				count %= safe;
			}else{
				count++;
			}
		}

		rep(i, player.size()){
			cout << player[i];
			if(i != player.size()-1)cout << " ";
		}
		cout << endl;
	}


	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

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

int dfs(vector<int> &P, vector<int> &C, int i, int sum, int g, int count){
  if(sum>=g) return count;
  if(i==0) {
    return 1000;
  }
  else{
    int k = 100*i;
    int j = g-sum;
    int t;
    if(j%k == 0) t = j/k;
    else t = j/k+1;
    //cout << t << endl; 
    if(t<=P[i-1]) {
      return min(dfs(P, C, i-1, sum, g, count), count+t);
    }
    else {
      int q = 100*i*P[i-1] + C[i-1] + sum;
      //cout << q << endl;
      if(q>=g) return min(dfs(P, C, i-1, sum, g, count), count+P[i-1]);
      else return min(dfs(P, C, i-1, sum, g, count), dfs(P, C, i-1, q, g, count+P[i-1]));
      
    }
  }
}

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
  int n, i, j, g;
  cin >> n >> g;
  vector<int> P(n);
  vector<int> C(n);
  for(i=0; i<n; i++) cin >> P[i] >> C[i];
  int count = dfs(P, C, n, 0, g, 0);
  cout << count << endl;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	x := scanInt()
	fmt.Fprintln(wr, x/11*2+(x%11+10)/11+(x%11-6+10)/11)
}


Measured memory_bytes: 1776
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=sc.I;
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<n;i++) {
			var e=sc.Ia;
			var a=Gp5(s[0],s[1],s[2],s[3],e[0],e[1]);
			sb.Append(a.Item1).Append(" ").Append(a.Item2+"\n");
		}
		Console.Write(sb);
	}
	static Tuple<double,double> Gp5(double p1x,double p1y,double p2x,double p2y,double p0x,double p0y){
		double rx=p0x,ry=p0y;
		if(p1x==p2x){rx=p1x;}
		else if(p1y==p2y){ry=p1y;}
		else{
			double m1=(p2y-p1y)/(p2x-p1x),b1=p1y-(m1*p1x),m2=-1.0/m1,b2=p0y-(m2*p0x);
			rx=(b2-b1)/(m1-m2);
			ry=(b2*m1-b1*m2)/(m1-m2);
		}
		return Tuple.Create(rx,ry);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

s=ord(input().rstrip("\n"))


for i in range(65,97):
    if s==i:
        print("A")
        sys.exit()
print("a")

Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i,n) for (int i = 1; i <= (int)(n); i++)

int main()
{
  ll n;
  cin >> n;
  
  ll a[n],b[n+1];
  b[0] = 0;
  ll mod = 1000000007;
  rep(i,n)
  {
    cin >> a[i];
    b[i+1] = a[i] + b[i];
  }
  
  ll ans = 0;
  rep(i,n)
  {
    ll sum = (b[n] - b[i+1]) % mod;
    ans += a[i] * sum;
    ans %= mod;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 6696
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
L = input().rstrip()

lenL = len(L)
mod = 10**9+7

dp0 = [0]*(lenL+1) # dp0[i] : 上からi桁目まで L と一致する (A,B) の場合の数
dp1 = [0]*(lenL+1) # dp1[i] : 上からi桁目までで L と一致しない (A,B) の場合の数

dp0[0] = 1

for i,l in enumerate(L, 1):
    # 現在の桁が 0 の時
    if l=="0":
        dp0[i] = dp0[i-1]   # (0,0) のみ
        dp1[i] = dp1[i-1]*3 # (0,0), (0,1), (1,0) の3通り
    # 現在の桁が 1 の時
    else:
        dp0[i] = dp0[i-1]*2 # (0,1), (1,0)
        dp1[i] = dp0[i-1] + dp1[i-1]*3 
        # (i-1)桁まで一致している場合, (0,0) のみ
        # (i-1)桁まで一致していない場合, (0,0), (0,1), (1,0) の3通り
    dp0[i] %= mod
    dp1[i] %= mod

print((dp0[-1] + dp1[-1]) % mod)


Measured memory_bytes: 11124
#include <iostream>

int main()
{
    int H = 0;
    int W = 0;
    
    while( 1 )
    {
        // input
        std::cin >> H;
        std::cin >> W;
        
        if( 0 == H && 0 == W )
        {
            break;
        }
        
        if( H < 3 || H > 300 || W < 3 || W > 300 )
        {
           std::cout << "Error : out of range!" << std::endl;
           return -1;
        }
        
        for( int i = 0; i < H; ++i )
        {
            if( 0 == i || H - 1 == i )
            {
                for( int j = 0; j < W; ++j )
                {
                    std::cout << "#";
                }
                std::cout << std::endl;
            }
            else
            {
                for( int j = 0; j < W; ++j )
                {
                    if( 0 == j || W - 1 == j )
                    {
                        std::cout << "#";
                    }
                    else
                    {
                        std::cout << ".";
                    }
                }
                std::cout << std::endl;
            }
        }
        std::cout << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
int dat[ohara];
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------

struct UnionFind{
	std::vector<int> data;
	
	UnionFind(int n){
		data.assign(n,-1);
	}
	
	void unite(int x, int y){
		x=find(x); y=find(y);
		if(x==y) return;
		if(data[x]>data[y]) swap(x,y);
		data[x]+=data[y];
		data[y]=x;
	}
	
	int find(int k){
		if(data[k]<0) return k;
		return data[k]=find(data[k]);
	}
 
	int size(int k) {
		return -data[find(k)];
	}
 
	bool same(int x, int y){
		return find(x)==find(y);
	}
};
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>m>>k;
    UnionFind uf(ohara);
    rep(i,ohara)dat[i]=-1;
    rep(i,k){
        cin>>a>>b>>c;
        if(a==1){
            if(dat[uf.find(b)]==-1||dat[uf.find(c)]==-1){
                tmp=dat[uf.find(b)];
                tmpp=dat[uf.find(c)];
                dat[uf.find(b)]=-1;
                dat[uf.find(c)]=-1;
                uf.unite(b,c);
                if(tmp!=-1)dat[uf.find(b)]=tmp;
                else dat[uf.find(b)]=tmpp;
            }
            else{
                if(dat[uf.find(b)]!=dat[uf.find(c)]){
                    Cout(i+1);
                    return 0;
                }
                else{
                    tmp=dat[uf.find(b)];
                    dat[uf.find(b)]=-1;
                    uf.unite(b,c);
                    dat[uf.find(b)]=tmp;
                }
            }
        }
        else{
            //if(i==3)Cout(dat[uf.find(b)]);
            if(dat[uf.find(b)]==-1){
                dat[uf.find(b)]=c;
            }
            else{
                //if(i==3)Cout(dat[uf.find(b)]);
                if(dat[uf.find(b)]!=c){
                    Cout(i+1);
                    return 0;
                }
            }
        }
    }
    Cout(0);
    return 0;
}


Measured memory_bytes: 10884
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = c-a-b;
		
		if(d>0&&4*a*b<d*d) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		
	}
 
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
#define LL long long
int n;
LL x,cnt2[N],cnt5[N],ans;
string s;
map<int,map<int,int> > sum;
int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = -65;i <= 65;++i)
		for(int j = -65;j <= 65;++j)
			sum[i][j] = 0;
	for(int i = 1;i <= n;++i) {
		int res = -100;
		cin >> s;
		x = 0;
		for(int j = 0;j < s.length();++j) {
			++res;
			if(s[j] != '.') x = x * 10 + s[j] - '0';
			else res = 0;
		}
		while(x % 2 == 0) ++cnt2[i],x >>= 1;
		while(x % 5 == 0) ++cnt5[i],x /= 5;
		if(res >= 0) cnt2[i] -= res,cnt5[i] -= res;
		++sum[-cnt2[i]][-cnt5[i]];
	}
	for(int i = -64;i <= 64;++i)
		for(int j = -64;j <= 64;++j)
			sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
			/*
	while(1) {
		int x,y;
		cin >> x >> y;
		cout << sum[x][y] <<endl;
	}
	*/
	for(int i = 1;i <= n;++i) {
		ans += sum[cnt2[i]][cnt5[i]];
		if(cnt2[i] >= 0 && cnt5[i] >= 0) --ans;
	}
	printf("%lld\n",ans/2);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef pair<ll, vll> plv;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i, a, b) for(ll i=ll(a);i<=ll(b);++i)
#define REPR(i, a, b) for(ll i=ll(a);i>=ll(b);--i)
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()

template<typename T>
T absolute(T a, T b) { return a >= 0 ? a : -a; }

template<typename T>
T sqr(T a) { return a * a; }

ll read() {
    ll res, f = 1;
    register char ch;
    while ((ch = getchar()) > '9' || ch < '0')(ch == '-') && (f = -1);
    for (res = ch - '0'; (ch = getchar()) >= '0' && ch <= '9'; res = res * 10 + ch - '0');
    return res * f;
}

int main() {
    fastio
    ll n;
    cin>>n;stack<ll>s;
    while(n){
        s.push(n%10);
        n/=10;
    }
    while(!s.empty()){
        ll x=s.top();
        s.pop();
        if(x==1)cout<<9;
        else if(x==9)cout<<1;
        else cout<<x;
    }
    cout<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    ll ans = k;
    while (--n) 
        ans *= k - 1;
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct BIT{
    int N;
    vector<int> bit;

    BIT(int n = 0){
        N = n;
        bit.resize(n + 1);
    }

    void init(int n){
        N = n;
        bit.resize(n + 1);
    }

    int sum(int i){
        int s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x){
        while(i <= N){
            bit[i] += x;
            i += i & -i; 
        }
    }
};
BIT bit[26];
int N, Q;
string S;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> S;
    for(int i = 0; i < 26; i++){
        bit[i].init(N);
    }
    for(int i = 0; i < N; i++){
        auto& b = bit[S[i] - 'a'];
        b.add(i + 1, 1);
    }

    cin >> Q;
    for(int i = 0; i < Q; i++){
        int t;
        cin >> t;
        if(t == 1){
            int idx;
            char c;
            cin >> idx >> c;
            bit[S[idx - 1] - 'a'].add(idx, -1);
            bit[c - 'a'].add(idx, 1);
            S[idx - 1] = c;
        }else{
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            for(int j = 0; j < 26; j++){
                int rsum = bit[j].sum(r);
                int lsum = bit[j].sum(l - 1);
                if(lsum != rsum) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 51740
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;

int main(){
	int n;
	ll dp[21][100];
	int nums[100];
	while(cin >> n){
		for(int i = 0; i < n; i++){
			cin >> nums[i];
		}
		fill(&dp[0][0], &dp[20][99]+1, 0);
		dp[nums[0]][0] = 1;
		for(int i = 1; i < n-1; i++){
			for(int j = 0; j <= 20; j++){
				int n1 = j + nums[i];
				int n2 = j - nums[i];
				if(n1 <= 20){
					dp[n1][i] += dp[j][i-1];
				}
				if(n2 >= 0){
					dp[n2][i] += dp[j][i-1];
				}
			}
		}
		cout << dp[nums[n-1]][n-2] << endl;;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
numbers = list(map(int,input().split()))
p = numbers[0]
a, b = 0, 0
if p > 0:
    q = -1
    b = p + 1
elif p < 0:
    q = 1
    b = -p + 1
else:
    p, q = 1, -1
    a, b = 1, 1
    
for i in range(1, n):
    if p > 0:
        p += numbers[i]
        if p >= 0:
            a += (p + 1)
            p -= (p + 1)
    else:
        p += numbers[i]
        if p <= 0:
            a -= (p - 1)
            p -= (p - 1)

for j in range(1, n):
    if q > 0:
        q += numbers[j]
        if q >= 0:
            b += (q + 1)
            q -= (q + 1)
    else:
        q += numbers[j]
        if q <= 0:
            b -= (q - 1)
            q -= (q - 1)


print(min(a, b))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<string> a(n);
  for(auto & v : a) cin >> v;
  for(int i = 0; i < n; i++){
  	int tot = 0;
    for(int j = 0; j < m; j++) tot += a[i][j] == '#';
    if(tot){
    	for(int j = 0; j < m; j++){
        	int ntot = 0;
          	for(int k = 0; k < n; k++) ntot += a[k][j] == '#';
          	if(ntot) cout << a[i][j];
        }
      	cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        System.out.print(s1.toUpperCase().charAt(0));
        System.out.print(s2.toUpperCase().charAt(0));
        System.out.print(s3.toUpperCase().charAt(0));
    }
}


Measured memory_bytes: 35408
import java.util.*;
import java.util.stream.*;

class Main {
	Scanner sc;
	int N, M;
	int[][] B;
	Edge[] E;
	List<Edge>[] to;
	boolean[] seen;
	boolean[] cut;
	
	static class Edge {
		int pos, idx;
		Edge to;
	}
	
	@SuppressWarnings("unchecked")
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		B = new int[N+1][2];
		for (int i = 0; i < N; i++) {
			B[i][0] = sc.nextInt();
			B[i][1] = sc.nextInt();
		}
		B[N][0] = Integer.MAX_VALUE;
		B[N][1] = 0;
		Arrays.sort(B, Comparator.comparingInt(b -> b[0]));
		int v = 0;
		for (int i = 0; i <= N; i++) {
			int t = B[i][1];
			B[i][1] = v ^ B[i][1];
			v = t;
		}
		E = new Edge[M*2];
		for (int i = 0; i < M; i++) {
			E[i*2] = new Edge();
			E[i*2].pos = sc.nextInt();
			E[i*2+1] = new Edge();
			E[i*2+1].pos = sc.nextInt()+1;
			E[i*2].to = E[i*2+1];
			E[i*2+1].to = E[i*2];
			E[i*2].idx = i;
			E[i*2+1].idx = i;
		}
		Arrays.sort(E, Comparator.comparingInt(r -> r.pos));
		
		int j = 0;
		for (int i = 0; i <= N; i++) {
			while (j < E.length && E[j].pos <= B[i][0]) E[j++].pos = i;
		}
		
		to = new List[N+1];
		for (int i = 0; i <= N; i++) to[i] = new ArrayList<>();
		for (int i = 0; i < M*2; i++)
			if (E[i].pos != E[i].to.pos)
				to[E[i].pos].add(E[i]);
		
		seen = new boolean[N+1];
		cut = new boolean[M];
		int i = 0;
		for (; i <= N; i++)
			if (!seen[i]) if (!dfs(null, i)) break;
		if (i > N) {
			List<Integer> l = IntStream.range(0, M).filter(k -> cut[k]).mapToObj(k -> k+1).collect(Collectors.toList());
			System.out.println(l.size());
			System.out.println(l.stream().map(o -> String.valueOf(o)).collect(Collectors.joining(" ")));
		} else {
			System.out.println(-1);
		}
	}
	
	boolean dfs(Edge es, int s) {
		seen[s] = true;
		for (Edge e : to[s]) {
			if (seen[e.to.pos]) continue;
			dfs(e, e.to.pos);
		}
		if (B[s][1] == 1) {
			if (es == null) return false;
			cut[es.idx] = true;
			B[s][1] = 0;
			B[es.pos][1] ^= 1;
		}
		return true;
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 188488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 入力
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();

		// 計算
		int fx = sum(X);

		// 出力
		if (X % fx == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		return;
	}

	public static int sum(int X) {
		int fx = 0;
		while(X > 0) {
			fx += X % 10;
			X /= 10;
		}
		return fx;
	}
}


Measured memory_bytes: 22740
#include <stdio.h>

int prime(int x){
  if(x == 1) return 0;
  else{
    int i = 2;
    while(i * i <= x){
      if(x % i == 0) return 0;
      i++;
    }
  }
  return 1;
}

int
main(int argc, char *argv[])
{
  int n, a[10000], ans = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
    ans += prime(a[i]);
  }

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

  return 0;
}



Measured memory_bytes: 2040