akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL N;
string S;
LL dfs(VEC<bool> add) {
//   DUMP(add);
  if (add.size() == N - 1) {
    LL p = S[0] - '0';
    LL sum = 0;
    REP(i, 0, N - 1) {
      LL next = S[i + 1] - '0';
      DUMP(next);
      if (add[i]) {
        sum += p;
        p = next;
      } else {
        p *= 10;
        p += next;
      }
    }
    sum += p;
    // DUMP(add, sum);
    return sum;
  }
  VEC<bool> a = add;
  VEC<bool> b = add;
  a.push_back(true);
  b.push_back(false);
  return dfs(a) + dfs(b);
}

int main() {
  cin >> S;
  N = S.length();
  cout << dfs({}) << endl;
}

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

using namespace std;

const int N = 1e6 + 5;
const int SIGMA = 26;
int _w;

int son[N][SIGMA] , nidx = 1 , bac[N][SIGMA];
char str[N];
long long ans;
string s[N];

int n , pre[N][SIGMA];

int main( void ) {
  _w = scanf("%d",&n);
  for( int i = 1 ; i <= n ; ++i ) {
    _w = scanf("%s",str);
    s[i] = str;
  }
  sort( s + 1 , s + 1 + n , []( string a , string b ) { return a.length() > b.length(); } );
  for( int _i = 1 , m ; _i <= n ; ++_i ) {
    m = 0;
    for( const char & v : s[_i] )
      str[++m] = v;
    for( int i = 1 ; i <= m ; ++i ) {
      str[i] -= 'a';
      memcpy( pre[i] , pre[i - 1] , sizeof( int ) * SIGMA );
      ++pre[i][str[i]];
    }
    int u = 1;
    for( int i = m ; i > 1 ; --i ) 
      u = son[u][str[i]];
    ans += bac[u][str[1]];
    u = 1;
    for( int i = m ; i ; --i ) {
      for( int j = 0 ; j < 26 ; ++j )
        if( pre[i][j] ) ++bac[u][j];
      if( !son[u][str[i]] ) son[u][str[i]] = ++nidx;
      u = son[u][str[i]];
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 336080
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
ll cnt[100][100];
ll dist[10][10]={
  {0,0,0,0,0,0,0,0,0,0},
  {0,0,1,2,1,2,3,2,3,4},
  {0,1,0,1,2,1,2,3,2,3},
  {0,2,1,0,3,2,1,4,3,2},
  {0,1,2,3,0,1,2,1,2,3},
  {0,2,1,2,1,0,1,2,1,2},
  {0,3,2,1,2,1,0,3,2,1},
  {0,2,3,4,1,2,3,0,1,2},
  {0,3,2,3,2,1,2,1,0,1},
  {0,4,3,2,3,2,1,2,1,0}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  string s;cin>>s;
  for(int i=0;i<n-1;i++)
    cnt[s[i]-'0'][s[i+1]-'0']++;
  vi v={1,2,3,4,5,6,7,8,9};
  ll ans=llINF;
  ll pat;
  do{
    ll cn=0;
    for(int i=1;i<=9;i++)
      for(int j=1;j<=9;j++){
	cn+=dist[i][j]*(cnt[v[i-1]][v[j-1]]);
      }
    if(ans>cn){
      ans=cn;
      ll sum=0;
      ll kake=1;
      for(int i=8;i>=0;i--){
	sum+=v[i]*kake;kake*=10;
      }
      pat=sum;
    }else if(ans==cn){
      ll sum=0;
      ll kake=1;
      for(int i=8;i>=0;i--){
	sum+=v[i]*kake;kake*=10;
      }
      if(pat>sum)
	pat=sum;
    }
  }while(next_permutation(ALL(v)));
  ll an[10][10];
  an[2][2]=pat%10;
  pat/=10;
  an[2][1]=pat%10;
  pat/=10;
  an[2][0]=pat%10;
  pat/=10;
  an[1][2]=pat%10;
  pat/=10;
  an[1][1]=pat%10;
  pat/=10;
  an[1][0]=pat%10;
  pat/=10;
  an[0][2]=pat%10;
  pat/=10;
  an[0][1]=pat%10;
  pat/=10;
  an[0][0]=pat%10;
  pat/=10;

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cout<<an[i][j];
    }
    cout<<endl;
  }
  return 0;
}


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

int main(){
  int a,n,ans=0,x,y;cin>>n;
  map<int,int> mp;
  for(int i=0;i<n;i++) cin>>a,mp[a]++;
  for(auto p:mp){
    x=p.first;y=p.second;
    ans+=y;
    if(x<=y) ans-=x;
  }
  cout<<ans;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define num(a) a-'0'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int x;
	cin>>x;
	if(x>=30){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}	

int main(){
	boost_io;
	cout<<setprecision(10);
	solve();
	return 0;
}


Measured memory_bytes: 3644
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int X, Y; cin >> X >> Y;
    vector<int> v = {0, 300000, 200000, 100000};

    int ans = 0;
    ans += v[X];
    ans += v[Y];
    if(X == 1 and Y == 1) ans += 400000;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll n;
   std::cin >> n;
   ll a[n],sum=0;
   map<ll,ll>mp;
   fr(i,0,n)
   {
       std::cin >> a[i];
       mp[a[i]]++;
       sum+=a[i];
   }
   ll q;
   std::cin >> q;
   while(q--)
   {
       ll b,c;
       std::cin >> b>>c;
       if(mp.find(b)!=mp.end()&&mp[b]>0)
       {
           sum=sum-(b*mp[b])+c*mp[b];
           mp[c]+=mp[b];
           mp[b]=0;
       }
       cout<<sum<<"\n";
   }
   cout<<"\n";
}

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif


const LL MOD = 1e9+7;

const int N = 1e5+50;

int mu[N], prime[N], pcnt;
int minp[N];

int smu[N];

void init() {
    mu[1] = 1;
    for (int i=2; i<N; ++i) {
        if (!minp[i]) {
            minp[i] = i;
            prime[pcnt++] = i;
            mu[i] = -1;
        }
        for (int j=0; j<pcnt; ++j) {
            LL nextp = 1LL * i * prime[j];
            if (nextp >= N)
                break;
            if (!minp[nextp])
                minp[nextp] = prime[j];
            if (i % prime[j] == 0) {
                mu[nextp] = 0;
                break;
            } else {
                mu[nextp] = -mu[i];
            }
        }
    }
    for (int i=1; i<N; ++i)
        smu[i] = smu[i-1] + mu[i];
}

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a%MOD+MOD)%MOD;
    for (; b; b>>=1, a=a*a%p)
        if (b & 1)
            res = res * a % p;

    return res;
}

LL s(LL x) {
    return 1LL * x * (x + 1) / 2 % MOD;
}

int n, k;
LL f(int nn) {
    LL ans = 0;
    for (int l=1, r, v; l<=nn; l=r+1) {
        v = nn / l;
        r = nn / v;
        // printf("f2: %d %lld\n", smu[r] - smu[l-1], bin(v, n, MOD));
        ans = (ans + (smu[r] - smu[l-1]) * bin(v, n, MOD)) % MOD;
    }
    // printf("f: %d %lld\n", n, ans);
    return ans;
}

int main() {
    // int t;
    scanf("%d%d", &n, &k);
    init();
    
    LL ans = 0;
    for (int l=1, r, v; l<=k; l=r+1) {
        v = k / l;
        r = k / v;
        r = min(r, k);
        LL del = 0;
        // printf("%d %d %d\n", l, r, v);
        // for (int j=1; j<=v; ++j) {
        //     del = (del + mu[j] * bin(v/j, n, MOD)) % MOD;
        // }

        ans = (ans + f(v) * (s(r) - s(l-1))) % MOD;
    }
    cout << (ans % MOD + MOD) % MOD;
    return 0;
}

Measured memory_bytes: 4900
n = int(input())
a = [int(_) for _ in input().split()]

res_dict = {}
for i in range(len(a)):
    if not a[i] in res_dict.keys():
        res_dict[a[i]] = 1
    else:
        res_dict[a[i]] += 1

for i in range(len(a)+1):
    if not i+1 in res_dict.keys():
        print(0)
    else:
        print(res_dict[i+1])

Measured memory_bytes: 33352
s = list(input())

a_index = 0
z_index = 0
max_z_index = 0

for i in range(len(s)):
    if s[i] == "A":
        a_index = i
        break

for j in range(len(s)):
    if j <= a_index:
        continue
    else:
        if s[j] == "Z":
            z_index = j
            max_z_index = max(max_z_index, z_index)

print(max_z_index - a_index + 1)

Measured memory_bytes: 4840
class SparseMatrix
	def initialize(m, n)
		@m, @n = m, n
		@rows = (1..m).map{ Hash.new(0) }
	end

	def [](i)
		@rows[i]
	end

	def rank
		save = Marshal.load(Marshal.dump(self))
		rank = 0
		j = 0
		(0..@m-1).each{|i|
			pivot_idx = nil
			j += 1 until j >= @n || pivot_idx = @rows.index{|row| row[j] && row[j] != 0}
			break if j >= @n
			rank += 1

			pivot_row = @rows.delete_at(pivot_idx)
			a = pivot_row[j]
			
			@rows.each{|row|
				b = row[j]
				if b && b != 0
					r = b / a
					pivot_row.each{|k, val|
						row[k] -= r * val
						row.delete(k) if row[k] == 0
					}
				end
			}

			j += 1
		}		
		@rows = save.rows
		rank
	end

	attr_reader :rows
end

require 'mathn'
n, m = gets.split.map &:to_i
mat = SparseMatrix.new(n, m)
m.times{|k|
	i, j = gets.split.map &:to_i
	mat[i-1][k] = -1
	mat[j-1][k] = 1
}
p m - mat.rank

Measured memory_bytes: 8728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5; // check bounds
const int M = 1e9 + 7;
const char nl = '\n';

template< typename T > inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template< typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> void ckmin(T& a, T b) {a = min(a, b);}
template <class T> void ckmax(T& a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



void solve() {
	int n, x;
	cin >> x >> n;
	set<int> s;
	for (int i = 0; i < n; ++i) {
		int cur; cin >> cur;
		s.insert(cur);
	}
	int d = INT_MAX, ans = INT_MAX;
	for (int i = -3000; i <= 3000; ++i) {
		if (s.find(i) == s.end()) {
			int diff = abs(x - i);
			if (diff < d) {
				d = diff;
				ans = i;
			}
		}
	}
	cout << ans << nl;
}

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

	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3664
N = gets.to_i
S = gets.chomp
if S[0] != "B" || S[-1] != "B"
  p 0; exit
end
Mod = 10**9 + 7
opened = 1
ans = 1
last_is_open = true
(1...(2*N)).each{ |i|
  if S[i-1] == S[i]
    last_is_open = !last_is_open
  else
    last_is_open = last_is_open
  end
  if last_is_open
    opened += 1
  else
    ans = ans * opened % Mod
    opened -= 1
  end
}
if opened != 0
  p 0; exit
end

p ans * (1..N).reduce(1){ |a,b| a * b % Mod } % Mod


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

int main() {
    int A,B;
    int ans = 0;
    cin >> A >> B;

    if(A>=B){
        ans += A;
        A = A - 1;
    }
    else{
        ans += B;
        B = B - 1;
    }
    if(A>=B){
        ans += A;
    }
    else
        ans += B;
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 256
n=int(input())
res = 10**10
s=0
l=[list(map(int,input().split())) for _ in range(n)]
for a,b in l:
    s += a
    if a>b:
        res = min(res,b)
if res==10**10:
    print(0)
else:
    print(s-res)


Measured memory_bytes: 47704
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)

int main(){
    int n;
    cin >> n;
    
    cout << 800*n-(n/15)*200 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pb                  push_back
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n;cin>>n;
    if(n>=1800){
        ans=1;
    }
    else if(n>=1600){
        ans=2;
    }
    else if(n>=1400){
        ans=3;
    }
    else if(n>=1200){
        ans=4;
    }
    else if(n>=1000){
        ans=5;
    }
    else if(n>=800){
        ans=6;
    }
    else if(n>=600){
        ans=7;
    }
    else if(n>=400){
        ans=8;
    }
    cout<<ans<<endl;

}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<fixed<<setprecision(3)<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 3804
test = list()
while True:
    m,f,r = map(int,input().split())
    if m == f == r == -1:
        break
    test.append([m,f,r])
    
for i in range(len(test)):
    if test[i][0] == -1 or test[i][1] == -1:
        print("F")
    elif (test[i][0] + test[i][1]) >= 80:
        print("A")
    elif (test[i][0] + test[i][1]) >= 65:
        print("B")
    elif (test[i][0] + test[i][1]) >= 50 or test[i][2] >= 50:
        print("C")
    elif (test[i][0] + test[i][1]) >= 30:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */


int N,A,B,C;
int l[8];
int rec(int a, int b, int c, int cur){
    if(cur == N) {
        if (!a || !b || !c) return 1 << 30;
        return abs(A - a) + abs(B-b) + abs(C-c);
    }
    int res = rec(a, b, c, cur+1);
    chmin(res,rec(a + l[cur], b, c, cur+1) + ((a > 0) ? 10 : 0));
    chmin(res, rec(a, b + l[cur], c, cur+1) + ((b > 0) ? 10 : 0));
    chmin(res, rec(a, b, c + l[cur], cur+1) + ((c > 0) ? 10 : 0));
    return res;

}

int main() {
    cin >> N >> A >> B >>C;
    rep(i, N) cin >> l[i];
    cout << rec(0,0,0,0) << endl;
}


Measured memory_bytes: 256
def resolve():
    import math
    N, M = list(map(int, input().split()))
    modfactor = 10**9+7
    if abs(N-M) >= 2:
        print(0)
        return
    NM = math.factorial(N) * math.factorial(M)
    print(NM%modfactor if N != M else (NM*2)%modfactor)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 55152
#include <cstdio>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int d = a;
    int e = d % b;
    for(int i = 1;; i++){
        if(d % b == c){
            printf("YES\n");
            break;
        }else{
            d = d + a;
            if(d % b == e){
                printf("NO\n");
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s,t;
    cin>>n>>s>>t;
    int a=0;
    for(int i=1;i<=s.size();i++){
        if(s.substr(s.size()-i)==t.substr(0,i)){
            a=i;
        }
    }
    std::cout<<2*n-a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
using cd = complex<double>;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 1e7 + 1;
// const ll m = 1e9 + 7;
// const ll inf= 1e14;
const ll mod =998244353;
const double PI = acos(-1);
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
ll f[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
    int t = 1;
    // cin>>t;
    memset(f,0,sizeof(f));
    for(int i  =1;i<N;i++){
        f[i]++;
        for(int j = 2*i;j<N;j+=i){
            f[j]++;
        }
    }
    while(t--){
        ll n;cin>>n;
        ll ans = 0;
        for(int i  =1;i<=n;i++){
            ans+=i*f[i];
        }
        cout<<ans<<'\n';
    }
} 

Measured memory_bytes: 81760
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

int main(){
    COMinit();
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    vector<ll> modM(N+1);
    modM.at(0) = 0;
    for(int i = 1; i <= N; i++){
        modM.at(i) = modM.at(i-1) + A.at(i-1);
        modM.at(i) %= M;
    }
    sort(modM.begin(), modM.end());
    modM.push_back(M);
    vector<ll> ans(0);
    ll cnt = 1;
    for(int i = 1; i < modM.size(); i++){
        if(modM.at(i) != modM.at(i-1)){
            ans.push_back(cnt);
            cnt = 1;
        }else{
            cnt++;
        }
    }
    ll res = 0;
    for(int i = 0; i < ans.size(); i++){
        ll t = ans.at(i);
        res += t * (t-1) / 2;
    }
    cout << res << endl;
    
}


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

using namespace std;

bool hurui[10000000];

int main()
{
	while(1)
	{
		int m,n;
		cin>>m>>n;
		if(m==0)
			break;
		
		fill(hurui,hurui+10000000,false);
		int cnt=0;
		for(int i=m;i<10000000;i++)
		{
			if(cnt==n)
				break;
			if(hurui[i])
				continue;
			
			cnt++;
			for(int j=i;j<10000000;j+=i)
				hurui[j]=true;
		}

		int ans=0;
		for(int i=m;i<10000000;i++)
		{
			if(!hurui[i])
			{
				ans=i;
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
    int n,m;
    int a,b;
    cin>>n>>m;
    vector<int> c(n,0);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--;
        b--;
        c[a]++;
        c[b]++;
    }
    rep(i,n){
        cout<<c[i]<<endl;
    }
}


Measured memory_bytes: 256
def args():
    N, K = list(map(int, input().split()))
    H = list(map(int, input().split()))

    # print(N, K)
    # print(H)

    return N, K, H


def solve(N, K, H):
    DP = [float("inf")] * N
    DP[0] = 0

    for i in range(N - 1):
        for j in range(1, K + 1):
            # DP[i + 1] = min(DP[i + 1], DP[i] + abs(H[i] - H[i + 1]))
            if i + j < N:
                DP[i + j] = min(DP[i + j], DP[i] + abs(H[i] - H[i + j]))

    # print(DP)
    return DP[-1]


if __name__ == '__main__':
    res = solve(*args())
    print(res)


Measured memory_bytes: 55136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		Integer[] xi = new Integer[5];
		for (int i = 0; i < 5; i++) {
			xi[i] = scan.nextInt();
		}

		for (int i = 0; i < 5; i++) {
			if (xi[i] == 0) {
				System.out.println(i + 1);
			}

		}

		scan.close();

	}

}


Measured memory_bytes: 35780
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		long n=scanner.nextLong();
		long p=scanner.nextLong();
		Map<Long,Long>map=new TreeMap<>(prime_fact(p));
		long ans=1;
		for(long key:map.keySet()) {
			long val=map.get(key);
			if(val>=n) {
				ans*=Math.pow(key,val/n);
			}
		}
		System.out.println(ans);
	}
	
	private static Map<Long, Long> prime_fact(long n) {
		Map<Long, Long> map = new TreeMap<>();
		double d = Math.sqrt(n);
		for (int i = 2; i <= d; i++) {
			int cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt++;
			}
			if (cnt != 0) {
				map.put((long) i, (long) cnt);
			}
		}
		if (n != 1) {
			map.put(n, (long) 1);
		}
		return map;
	}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define int long long int 
#define MOD 1000000007 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
int gcd(int a,int b){if(a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (max(a,b)/gcd(a,b))*min(a,b);}
int powermodm(int x,int n,int M){int result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}



main()
{
    fastIO;
    int t;
    t=1;
    while(t--)
    {
        int n;
        cin >> n;
        int dp[n][3];
        int a,b,c;
        cin >> a >> b >> c;
        dp[0][0]=a;
        dp[0][1]=b;
        dp[0][2]=c;
        for(int i=1;i<n;i++)
        {
            //int a,b,c;
            cin >> a >> b >> c;
            dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=c+max(dp[i-1][1],dp[i-1][0]);
        }
        cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    }
    
    
    
    
    
    
}

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

int main(){
    ll n,d,a;
    cin>>n>>d>>a;

    vector<pair<int,int>> pr;
    for(int i = 0; i < n; i++){
        int x,h;cin>>x>>h;
        pr.push_back({x,h});
    }
    sort(pr.begin(),pr.end());

    queue<pair<ll,ll>> q;
    ll tot = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int x = pr[i].first;
        int h = pr[i].second;
        while(q.size() && q.front().first < x){
            tot-=q.front().second;
            q.pop();
        }
        h-=tot;
        if(h>0){
         int num = (h+a-1)/a;
         ans+=num;
         int damage = num*a;
         tot+=damage;
         q.push({x+2*d,damage});
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
vector<LL> make_divisors(LL n){vector<LL> divisors;for(int i = 1; i <= sqrt(n); i++) {if(n%i == 0){divisors.push_back(i);if(i != n/i){divisors.push_back(n / i);}}}return divisors;}
const LL MOD = 1e9 + 7;
const int INF = 1 << 30;
const LL LLINF = 1LL << 60;
using namespace std;


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

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    int v_max = 0;
    vector<int> rating(8);
    rep(i, N){
        if(a[i] < 400) rating[0] = 1;
        else if(a[i] < 800) rating[1] = 1;
        else if(a[i] < 1200) rating[2] = 1;
        else if(a[i] < 1600) rating[3] = 1;
        else if(a[i] < 2000) rating[4] = 1;
        else if(a[i] < 2400) rating[5] = 1;
        else if(a[i] < 2800) rating[6] = 1;
        else if(a[i] < 3200) rating[7] = 1;
        else if(a[i] >= 3200) v_max++;
    }
    cout << max(accumulate(ALL(rating), 0), 1) << " ";
    cout << accumulate(ALL(rating), v_max) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	double n, p, D1 = 0, D2 = 0, D3 = 0, Dinf = 0;
	cin >> n;
	vector<double>x(n);
	vector<double>y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i < n; i++) {
		if (x[i] < y[i]) {
			D1 += y[i] - x[i];
			D3 += pow(y[i] - x[i], 3);
		}
		else {
			D1 += x[i] - y[i];
			D3 += pow(x[i] - y[i], 3);
		}
		D2 += pow(x[i] - y[i], 2);
	}
	Dinf = fabs(x[0] - y[0]);
	for (int i = 0; i < n; i++) {
		if (Dinf < fabs(x[i] - y[i])) {
			Dinf = fabs(x[i] - y[i]);
		}
	}
	D2 = pow(D2, 0.5);
	D3 = pow(D3, 1.0 / 3.0);
	printf("%.6lf\n", D1);
	printf("%.6lf\n", D2);
	printf("%.6lf\n", D3);
	printf("%.6lf\n", Dinf);
}

Measured memory_bytes: 1284
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	Int year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
	Int month = (s[5] - '0') * 10 + (s[6] - '0');

	if (year <= 2018) {
		cout << "Heisei" << endl;
		return 0;
	}
	if (year == 2019) {
		if (month <= 4) {
			cout << "Heisei" << endl;
			return 0;
		}
		else {
			cout << "TBD" << endl;
			return 0;
		}

	}
	cout << "TBD" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

const int MAX = 55556;


int main(){
    
    int N; cin >> N;
    vector<int> is_prime(MAX, true);
    // エラトステネスのふるい
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < MAX; i++){
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = false;
    }

    vector<int> ans;

    // 素数を列挙
    rep(i, MAX){
        if (is_prime[i]) {
            if (i % 5 == 1){
                ans.push_back(i);
                if (ans.size() == N) break;
            }
        }
    }

    rep(i, ans.size()){
        printf("%d%c", ans[i], i==ans.size()-1?'\n':' ');
    }
}

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

#define pi 3.14159265

int main(){
    int n; cin >> n;
    vector<int> x(n), y(n);
    double p1=0,p2=0,p3=0;
    int p=0;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < n; i++){
        cin >> y[i];
    }
    for(int i = 0; i < n; i++){
        int data = abs(x[i]-y[i]);
        p1 += data;
        p2 += data*data;
        p3 += data*data*data;
        p = max(p,data);
    }
    p2 = sqrt(p2);
    p3 = cbrt(p3);
    cout << fixed << setprecision(8);
    cout << p1 << endl;
    cout << p2 << endl;
    cout << p3 << endl;
    cout << (double)p << endl;

}


Measured memory_bytes: 3480
a = [int(input()) for i in range(5)]

tmp = 0
for i in range(5):
    if a[i] % 10 != 0:
        tmp = i if a[tmp] % 10 > a[i] % 10 else tmp

ans = 0
for i in range(5): 
    if i == tmp:
        continue
    else:
        if a[i] % 10 == 0:
            ans += a[i]
        else:
            ans += (a[i] // 10 + 1) * 10
            
print(ans + a[tmp])


Measured memory_bytes: 3060
def get_prime_list(n)
  sn = (n**(0.5)).to_i
  is_prime = [false, false] + [true]*(n-1)

  (2..sn).each do |i|
    next if !is_prime[i]
    (i*i).step(n, i) do |j|
      is_prime[j] = false
    end
  end
  return (2..n).to_a.select{|i| is_prime[i] }
end
list = get_prime_list(999999)

while gets do
  max = $_.to_i
  puts list.select{ |nu| nu <= max }.count
end

Measured memory_bytes: 35468
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
	fast_io;
	ll a,b;
	cin>>a>>b;
	cout<<max((ll)0,a-2*b)<<"\n";
	return 0;
}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  bool z=false;
  for(int i=1;i<=b;i++){
    if((i*a)%b==c){
      z=true;
      break;
    }
  }
  if(z){
    cout<<"YES";
  }
  else{
    cout<<"NO";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll inf=1e18;
int main(void){
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a+2),t(b+2);
    rep(0,i,a)cin>>s[i+1];
    rep(0,i,b)cin>>t[i+1];
    s[0]=-inf,s[a+1]=inf;
    t[0]=-inf,t[b+1]=inf;
    while(q--){
        ll x;
        cin>>x;
        ll ns=upper_bound(s.begin(),s.end(),x)-s.begin();
        ll nt=upper_bound(t.begin(),t.end(),x)-t.begin();
        ll ans=inf;
        for(ll S:{s[ns-1],s[ns]}){
            for(ll T:{t[nt-1],t[nt]}){
                ans=min({ans,abs(x-S)+abs(S-T),abs(x-T)+abs(T-S)});
            }
        }
        cout<<ans<<endl;
    }
    
}


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

int main(){
  int h, w;
  cin >> h >> w;
  string s[101];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < w+2; i++) {
    printf("#");
  }
  printf("\n");
  for (int i = 0; i < h; i++) {
    cout << "#" << s[i] << "#" << endl;
  }
  for (int i = 0; i < w+2; i++) {
    printf("#");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)

B=sorted(A.copy())
b1=B[-1]
b2=B[-2]

for a in A:
    if a==b1:
        print(b2)
    else:
        print(b1)

Measured memory_bytes: 14920
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> x(n); REP(i, n) cin >> x[i];
  int l; cin >> l;
  vector<vector<int> > dp(30, vector<int>(n));
  REP(i, n) dp[0][i] = prev(upper_bound(ALL(x), x[i] + l)) - x.begin();
  REP(i, 29) REP(j, n) dp[i + 1][j] = dp[i][dp[i][j]];
  int q; cin >> q;
  while (q--) {
    int a, b; cin >> a >> b; --a; --b;
    if (a > b) swap(a, b);
    int lb = 0, ub = n;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2, pos = a;
      REP(i, 30) if (mid >> i & 1) pos = dp[i][pos];
      (pos >= b ? ub : lb) = mid;
    }
    cout << ub << '\n';
  }
  return 0;
}


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

lli i,j,k,l,m,n,t,a,b,c,d,x,y,p,q,sum=0,total=0;

#define read(in) freopen("Input.txt","r",stdin)
#define write(out) freopen("Ouput.txt","w",stdout)

int main()
{
    cin>>t;
    double ans=0.0;
    ans=2*3.14159*t;
  	cout<<ans<<"\n";
}


Measured memory_bytes: 3784
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

using namespace std;

int main() {
    long long int N, b = 0, a[100000 * 2] = {}, ans = 0, sum[100000 * 2 + 1] = {}, dif = 0, mini = 1000000000 * 2 + 1;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    for (int i = 0; i < N - 1; i++) {
        b = (sum[N] - sum[i + 1]) - sum[i + 1];
        dif = abs(b);
        mini = min(dif, mini);
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6;
int n,t[6],tt[4],cnt[4],s[maxn],fr[maxn],nxt[maxn];
char c[maxn];
void del(int now){
	int u=fr[now],v=nxt[now];
	nxt[u]=v;fr[v]=u;
	cnt[t[s[now]]]--;
}
void work1(){
	int f=6;
	for(int i=0;i!=(n+1);i=nxt[i]){
		if(f==t[s[i]]){del(i);}
		else{f=t[s[i]];}
	}
}
void work2(){
	for(int i=0;i!=(n+1);i=nxt[i]){
		if(cnt[2]==cnt[3]){return;}
		if((t[s[i]]==3)&&(s[fr[i]]!=s[nxt[i]])){del(i);}
	}
}
void work3(){
	for(int i=0;i!=(n+1);i=nxt[i]){
		if(cnt[2]==cnt[3]){return;}
		if((t[s[i]]==3)&&(t[s[fr[i]]]==1)){if(s[fr[fr[i]]]!=s[nxt[i]]){del(i);del(fr[i]);}}
	}
}
void work4(){
	for(int i=0;i!=(n+1);i=nxt[i]){
		if((cnt[1]==cnt[2])||(cnt[1]==cnt[3])) return;
		if(t[s[i]]==2&&t[s[fr[i]]]==3){if(s[fr[fr[i]]]!=s[nxt[i]]){del(i);del(fr[i]);}}
		if(t[s[i]]==3&&t[s[fr[i]]]==2){if(s[fr[fr[i]]]!=s[nxt[i]]){del(i);del(fr[i]);}}
	}
}
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	nxt[0]=1;fr[n+1]=n;s[0]=4;s[n+1]=5;
	for(int i=1;i<=n;i++){
		if(c[i]=='A'){cnt[1]++;s[i]=1;}
		if(c[i]=='B'){cnt[2]++;s[i]=2;}
		if(c[i]=='C'){cnt[3]++;s[i]=3;}
		fr[i]=i-1;nxt[i]=i+1;
	}
	t[1]=1;t[2]=2;t[3]=3;t[4]=4;t[5]=5;
	work1();
	if(cnt[1]>cnt[2]){swap(cnt[1],cnt[2]);swap(t[1],t[2]);}
	if(cnt[2]>cnt[3]){swap(cnt[2],cnt[3]);swap(t[2],t[3]);}
	if(cnt[1]>cnt[2]){swap(cnt[1],cnt[2]);swap(t[1],t[2]);}
	tt[1]=t[1];tt[2]=t[2];tt[3]=t[3];
	t[tt[1]]=1;t[tt[2]]=2;t[tt[3]]=3;
	work2();
	work3();
	work4();
	if(cnt[2]==cnt[3]){
		for(int i=nxt[0];i!=n+1;i=nxt[i]){
			if(s[i]==1){putchar('A');}
			if(s[i]==2){putchar('B');}
			if(s[i]==3){putchar('C');}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 18688
n = int(input())
A = list(map(int,input().split()))
ok = 0

for i in range(n):
    if A[i] % 2 == 1:
        ok += 1
    else:
        if A[i] % 3 == 0 or A[i] % 5 == 0:
            ok += 1
            
print(["DENIED","APPROVED"][ok == n])

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int a, b;
  int sum, dif, mul;
  int max;
  scanf("%d %d",&a,&b);
  sum = a + b;
  dif = a - b;
  mul = a * b;
  max = sum;
  if(max < dif){
    max = dif;
  }
  if(max < mul){
    max = mul;
  }
  printf("%d",max);
  return 0;
}

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

int main(){
    //inputs
    int n;
    cin >> n;
    int R[n];
    for(int i=0;i<n;i++){
        cin >> R[i];
    }
    
    //calculation
    int minv = R[0];
    int maxv = -1000000001;
    for(int j=1;j<n;j++){
        maxv = max(maxv, R[j]-minv);
        minv = min(minv, R[j]);
    }
    
    //output
    cout << maxv << endl;
}

Measured memory_bytes: 1940
fun main(args: Array<String>) = abc156d()

fun abc156d() {
    val (n, a, b) = readLine()!!.split(' ').map { it.toInt() }

    var answer = modPow(2, n.toLong())
    answer -= 1
    answer = (answer + MOD) % MOD
    answer -= comb(n, a)
    answer = (answer + MOD) % MOD
    answer -= comb(n, b)
    answer = (answer + MOD) % MOD

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

private fun modPow(n: Long, p: Long, m: Long = MOD): Long {
    var x = n
    var y = p
    var result = 1L
    x %= m
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x) % m
        y = y shr 1
        x = (x * x) % m
    }
    return result
}

private fun comb(n: Int, k: Int, m: Long = MOD): Long {
    if (n < k) return 0
    val min = Math.min(k, n - k)
    var numerator = 1L
    var denominator = 1L
    for (i in 1L..min) {
        numerator *= n - i + 1
        numerator %= m
        denominator *= i
        denominator %= m
    }
    return numerator * modPow(denominator, m - 2, m) % m
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll k, s, d=0, c=0, t=0, z;
  cin >> k >> s;
  forll(i, 0, k + 1){
	forll(j, 0, k + 1){
	  z = s - i - j;
	  if (z < 0 || z > k)
		continue;
	  if (i == j && z == i)
		t++;
	  else if (i != j && j != z && i != z)
		c++;
	  else
		d++;
	}
  }
  cout << c + d + t << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define INF 1e10
using namespace std;
const int maxn = 1e6+10;
int n,m,a[maxn],b[maxn];

int32_t main(){
    IOS;
    cin>>n>>m;
    string k;
    cin>>k;

    fu(i,0,k.length()-1)
    {
        if(i==(m-1))cout<<(char)tolower(k[i]);
        else cout<<k[i];
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
 
int main() {
    ll n, A[200000], i;
    cin>>n;
    for(i=0; i<n; i++)
    cin>>A[i];
    ll s=A[0];
    for(i=1; i<n; i++)
    s=s^A[i];
    for(i=0; i<n; i++)
    {
        ll k= s^A[i];
        cout<<k<<" ";
    }
    return 0;
}

Measured memory_bytes: 5060
#include <stdio.h>

int main(void)
{
	int A,B;
	int s[4],temp;
	scanf("%d %d",&A,&B);
	s[0]=A+B;
	s[1]=A-B;
	s[2]=A*B;
	if(s[0]>s[1]){
		s[1]=s[0];
	}
	if(s[1]>s[2]){
		s[2]=s[1];
	}
	printf("%d\n",s[2]);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){

int i,j,H,W;

for(i=1; ;i++){

scanf("%d %d",&H,&W);

if(H==0&&W==0)break;

for ( i = 0; i < H; i++ ){
    for ( j = 0; j < W; j++ ){
        printf("#");
    }
    printf("\n");
}

printf("\n");

}

return 0;


}

Measured memory_bytes: 572