akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;
const LL inf = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 100100;
vector <int> e[maxn],t[maxn];
struct node {
    LL a,b;
    int id;
    bool operator < (const node & x) const {
        return a-b < (x.a-x.b);
    }
}x[maxn],g[maxn],y[maxn],z[maxn];
int f[maxn],vis[maxn];
int fnd(int u) {
    return u==f[u]?u:(f[u]=fnd(f[u]));
}
node mul(node a,node b) {
    return (node){max(a.a,max(b.a,b.b)+a.b),a.b+b.b};
}

void dp(int u) {
    int sz=t[u].size();
    if (sz == 0) {
        g[u]=x[u];
//        printf("g[%d] = (%lld,%lld) diff %lld\n",u,g[u].a,g[u].b,g[u].a-g[u].b);
        return ;
    }
    for (int i=0;i<sz;i++) dp(t[u][i]);
    for (int i=0;i<sz;i++) y[i]=g[t[u][i]];
    sort(y,y+sz);
    z[sz]=(node){0,0};
    for (int i=sz-1;i>=0;i--) z[i]=mul(z[i+1],y[i]);
    node a,b=(node){0,0};
    g[u] = (node){inf,0};
    for (int i=0;i<sz;i++) {
        a=mul(mul(mul(z[i+1],b),x[u]),y[i]);
        b=mul(y[i],b);
        if (g[u].a > a.a) g[u]=a;
    }
//    printf("g[%d] = (%lld,%lld) diff = %lld\n",u,g[u].a,g[u].b,g[u].a-g[u].b);
}
int main(void) {
//    freopen("f.in","r",stdin);
    int n,m; scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) {
        scanf("%lld%lld",&x[i].a,&x[i].b), x[i].id=i;
        y[i]=x[i];
    }
    for (int i=0;i<m;i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for (int i=1;i<=n;i++) f[i]=i;
    sort(y+1,y+n+1);
    for (int i=1;i<=n;i++) {
        int u = y[i].id;
        for (int j=0;j<e[u].size();j++) {
            int v=e[u][j];
            if (vis[v]) {
                v=fnd(v);
                if (v!=u) {
                    f[v]=u;
                    t[u].push_back(v);
                }
            }
        }
        vis[u]=1;
    }
    int rt = y[n].id;
//    for (int i=1;i<=n;i++) {
//        printf("%d: ",i);
//        for (int j=0;j<t[i].size();j++) printf("%d ",t[i][j]); puts("");
//    }
    dp(rt);
    printf("%lld\n",g[rt].a);
    return 0;
}


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

int main()
{
  int a, b;
  cin >> a >> b;

  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    cout << "Possible" << endl;
  else 
    cout << "Impossible" << endl;

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
q = int(input())
bcl = [list(map(int,input().split())) for nesya in range(q)]
hoge = dict()
for num in a:
  if num in hoge:
    hoge[num] += 1
  else:
    hoge[num] = 1
total = 0
for k,v in hoge.items():
  total += k*v
for bc in bcl:
  b = bc[0]
  c = bc[1]
  if b in hoge:
    total += (c-b)*hoge[b]
  print(total)
  if b in hoge:
    if c in hoge:
      hoge[c] += hoge[b]
    else:
      hoge[c] = hoge[b]
    hoge[b] = 0

Measured memory_bytes: 35916
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    vector<int> v;
    int t;
    for ( int j = 0; j < 3; j++ ) {
      cin >> t;
      v.push_back( t );
    }
    sort( v.begin(), v.end() );
    if ( v[0] * v[0] + v[1] * v[1] == v[2] * v[2] )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}


///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    string S; cin >> S;
    reverse(ALL(S));
    string st[] = {"maerd","remaerd","esare","resare"};
    int N = S.length();
    int idx = 0;
    while(1){
        char a[] = {S[idx],S[idx+1],S[idx+2]};
        int M = -1;
        if ((a[0] == 'm') and (a[1] == 'a') and (a[2] == 'e')){
            M = 0;
        }else if  ((a[0] == 'r') and (a[1] == 'e') and (a[2] == 'm')){
            M = 1;
        }else if  ((a[0] == 'e') and (a[1] == 's') and (a[2] == 'a')){
            M = 2;
        }else if  ((a[0] == 'r') and (a[1] == 'e') and (a[2] == 's')){
            M = 3;
        }

        if (M == -1){
            puts("NO");
            return 0;
        }

        REP(k,st[M].length()){
            if (S[idx] != st[M][k]){
                puts("NO");
                return 0;
            }
            idx++;
        }
        if (idx == N) break;
    }

    puts("YES");
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n;
   string s, t;
   cin >> n >> s >> t;
   FOR(i, 0, n)
      cout << s[i] << t[i];
   cout << endl;
   return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
s = input()
t = input()
s_dic = {}
t_dic = {}
flag = 0
for i in range(len(s)):
    if s[i] in s_dic:
        s_num = s_dic[s[i]]
    else:
        s_num = i
        s_dic[s[i]] = i
    if t[i] in t_dic:
        t_num = t_dic[t[i]]
    else:
        t_num = i
        t_dic[t[i]] = i
    if s_num != t_num:
        flag = 1
        break
if flag == 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3624
n = gets.to_i
i = 1
rests = []
while a = gets do
    rest,point = a.split(" ")
    rests.push([rest.to_s,point.to_i,i])
    i = i + 1
end

hash = Hash.new{|h,k| h[k] = []}
rests = rests.sort_by{|r| r[0]}
rests.each do |r|
    hash[r[0].to_s].push([r[1],r[2]])
end

hash.each do |k,v|
    v = v.sort_by{|v| v}.reverse
    v.each do |v|
        puts v[1]
    end
end


Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
    int a[3][3], n, i, j, k, tmp;

    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d", &a[i][j]);
        }
    }

    scanf("%d", &n);

    for(i=0;i<n;i++){
        scanf("%d", &tmp);

        for(j=0;j<3;j++){
            int flag=0;
            for(k=0;k<3;k++){
                if(tmp == a[j][k]){
                    a[j][k] = -1;
                    flag =  1;
                    break;
                }
            }
            if(flag==1) break;
        }
    }

    if(a[0][0]== -1 && a[0][1]== -1 && a[0][2]== -1) printf("Yes\n");
    else if(a[1][0]== -1 && a[1][1]== -1 && a[1][2]== -1) printf("Yes\n");
    else if(a[2][0]== -1 && a[2][1]== -1 && a[2][2]== -1) printf("Yes\n");
    else if(a[0][0]== -1 && a[1][0]== -1 && a[2][0]== -1) printf("Yes\n");
    else if(a[0][1]== -1 && a[1][1]== -1 && a[2][1]== -1) printf("Yes\n");
    else if(a[0][2]== -1 && a[1][2]== -1 && a[2][2]== -1) printf("Yes\n");
    else if(a[0][0]== -1 && a[1][1]== -1 && a[2][2]== -1) printf("Yes\n");
    else if(a[0][2]== -1 && a[1][1]== -1 && a[2][0]== -1) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

const lint INF = 1000000000000000000;
vector<lint> a;
vector<vector<lint>> dp;

lint rec(int l, int r) {
    if (dp[l][r] != INF) return dp[l][r];
    if (l == r) return 0;
    if ((a.size() - (r - l)) & 1) {
        return dp[l][r] = min(rec(l + 1, r) - a[l], rec(l, r - 1) - a[r - 1]);
    } else {
        return dp[l][r] = max(rec(l + 1, r) + a[l], rec(l, r - 1) + a[r - 1]);
    }
}

int main() {
    int N;
    cin >> N;
    a = vector<lint>(N);
    rep(i, N) cin >> a[i];
    dp = vector<vector<lint>>(N + 1, vector<lint>(N + 1, INF));
    cout << rec(0, N) << "\n";
    return 0;
}


Measured memory_bytes: 70912
#include<stdio.h>

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

int main(){
  int MAX_V = 1000000;
  int prime[MAX_V+1];
  int i, v;
  for(i = 2;i <= MAX_V;i++){
    prime[i] = isprime(i);
  }

  while(scanf("%d", &v) != 0){
    for(int i = v;i > 0;i--){
      if(prime[i] == 1&&prime[i-2] == 1){
          printf("%d %d\n",i-2,i);
          break;
        }
      }
    if(v == 0) break;
  }
  return 0;
}

Measured memory_bytes: 5632
n = gets.to_i
a = gets.split.map(&:to_i)
a = a.sort.reverse
f = Array.new(10**6+1, 0)
g = Array.new(10**6+1, 0)
a.each do |aa|
    f[aa] += 1
end
ans = 0
1.upto(10**6) do |i|
    next if g[i] == 1
    next if f[i] == 0
    ans += 1 if f[i] == 1
    1.upto(10**6 / i + 1) do |j|
        g[i*j] = 1
    end
end
puts ans

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n;
  string s;
  cin >> n >> s;
  int b = 0,w = 0;
  for(int i = 0;i < n;i++)w += (s[i] == '.');
  ll res = 1ll << 60;
  res = min(res,w*1ll);
  for(int i = 0;i < n;i++){
    if(s[i] == '#')b++;
    else w--;
    res = min(res,b+w*1ll);
  }
  res = min(res,b*1ll);
  cout << res << endl;






  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	ll ans = 0;
	ll C = c;
	c -= min(c, a);
	if(c > 0)
	{
		ans += a;
		C = c;
		c -= min(c, b);
		if(c > 0)
		{
			ans += b;
			ans ++;
		}
		else
			ans += C;
	}
	else
		ans += C;
	cout << ans+b;
	




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

typedef long long int llint;

int main(){
	llint n, num;
	double temp;
	cin >> n;
	temp = sqrt(n);
	num = (llint)sqrt(n);
	if(temp == (double)num){
		cout << n << endl;
	}
	else{
		cout << (llint)powl(num,2) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

	const int MX = 1<< 17;
	ll dat[2 * MX - 1];
struct SegTree{
	int n;
	void init(int n_){
		n = 1;
		while(n < n_) n *= 2;

		rep(i, 2 * n -1) dat[i] = 0LL;
	}
	void update(int k, ll a){
		k += n-1;
		dat[k] = a;
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	ll query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return 0LL;
		if(a <= l && r <= b) return dat[k];
		ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
	ll query(int a, int b){
		return query(a, b, 0, 0, n);
	}
};

int main(){
	int n = in.nextInt();
	SegTree st;
	st.init(n);

	rep(i, n){
		int x = in.nextInt();
		ll c = st.query(0, x);
		st.update(x-1, x + c);
	}
	cout<<(ll)n * (n + 1) / 2LL - st.query(0, n)<<endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  int D,N;
  cin>>D>>N;
  if(N==100)N=101;
  int A=1;
  for(int i=0;i<D;i++)A*=100;
  cout<<N*A<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int N;
	scanf("%d", &N);

	if (N % 2 == 0) {
		printf("%d\n",N);
	}else {
		printf("%d\n", N * 2);
	}

	return 0;
}
  

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

int main(){
  string s, t;
  cin >> s >> t;
  if(s.at(0)==t.at(2)&&s.at(1)==t.at(1)&&s.at(2)==t.at(0)) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

const long long MOD = 1e9+7;

long long power_mod(long long num, long long power){
    long long prod = 1;
    num %= MOD;
    while(power > 0){
        if((power&1) == 1){
            prod = prod * num % MOD;
        }
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

void add(long long& a, long long b){
    a = (a + b) % MOD;
}
void mul(long long& a, long long b){
    a = (a * b) % MOD;
}

int N;
const int MAX = 200010;
vector<int> child[MAX];
int dnum[MAX];
typedef deque<vector<long long>> DP;
DP dp[MAX];

void merge(DP& dp1, DP& dp2, bool isLast){
    if(dp1.size() < dp2.size()) swap(dp1, dp2);
    for(int d=0; d<dp2.size(); d++){
        vector<long long> tmp(3);
        for(int j=0; j<3; j++){
            tmp[j] = dp1[d][j];
            dp1[d][j] = 0;
        }
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                int j2 = min(j+k, 2);
                if(isLast && j2==2) j2 = 0;
                add(dp1[d][j2], tmp[j] * dp2[d][k] % MOD);
            }
        }
    }
}

void dfs(int i, int depth){
    dnum[depth] += 1;
    for(auto c : child[i]) dfs(c, depth+1);
    sort(child[i].begin(), child[i].end(), [](int a, int b){return dp[a].size() < dp[b].size();});
    for(auto j=0; j<(int)child[i].size(); j++){
        merge(dp[i], dp[child[i][j]], j == child[i].size()-1);
    }
    dp[i].push_front({1, 1, 0});
}

int main(){
    int i, j, k;
    cin >> N;
    for(i=1; i<=N; i++){
        int p;
        cin >> p;
        child[p].push_back(i);
    }
    dfs(0, 0);
    long long ans = 0;
    for(i=0; i < dp[0].size(); i++){
        long long a = dp[0][i][1] * power_mod(2, N+1-dnum[i]) % MOD;
        add(ans, a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 243956
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
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;}

#define INF 1120000000
#define MOD 1000000007

const int X = 3005;
long dp[2][X+5][2];

int main(){
  int n,m;
  cin>>n>>m;

  auto prev = dp[0];
  auto nxt = dp[1];

  fill(prev[0], prev[X+1], 0L);
  repl(i,1,n+1) prev[i][0] = 1;
  prev[0][1] = 1;

  rep(i,m){
    // [j] blue j, red N-j, [k] visited j==0
    fill(nxt[0], nxt[X+1], 0);
    rep(j,n+1)rep(k,2) if(prev[j][k]>0){
      if(j>0){
        nxt[j][k|(j==1)] += prev[j][k]; // b r
        nxt[j-1][k|(j==1)] += prev[j][k]; // b b
      }
      if(j<n){
        nxt[j][k] += prev[j][k]; // r b
        nxt[j+1][k] += prev[j][k]; // r b
      }
    }
    rep(j, n)rep(k,2) nxt[j][k] %= MOD;
    swap(nxt, prev);
  }

  long ans = 0;
  rep(i,n+1) ans += prev[i][1];

  cout << ans%MOD << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	StringBuilder str = new StringBuilder(scan.next());
	String[] key = new String[]{"dream", "dreamer", "erase", "eraser"};
	
	boolean flag = true;
	while(flag) {
	    flag = false;

	    for(int i=0; i<key.length; i++) {
		int index = str.length() - key[i].length();
		if( index > -1) {
		    if(str.substring(index).equals(key[i])) {
			str.delete(index, str.length());
			flag = true;
			break;
		    }
		}
	    }
	}
	System.out.println(str.length() == 0 ? "YES" : "NO");
	scan.close();
    }
}


Measured memory_bytes: 28452
package main

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

func main() {
	nextReader = newScanner()

	a := nextInts(3)
	sort.Sort(sort.IntSlice(a))

	fmt.Printf("%d %d %d\n", a[0], a[1], a[2])
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}



Measured memory_bytes: 1144
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; ++i) { cin >> s[i]; }

	bool can = true;
	int dx[4] = { 0, 1, 0, -1 };
	int dy[4] = { 1, 0, -1, 0 };
	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			if (s[y][x] == '.') { continue; }

			bool tmp = false;
			for (int i = 0; i < 4; ++i) {
				int nx = x + dx[i];
				int ny = y + dy[i];

				if ((nx < 0) || (nx >= W) || (ny < 0) || (ny >= H)) {
					continue;
				}

				if (s[ny][nx] == '#') { tmp = true; }
			}

			if (!tmp) { can = false; }
		}
	}

	if (can) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}


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

int main(){
  int64_t n,b,r;
  cin >> n >> b >> r;
  int64_t ans=0;
  ans=n/(b+r);
  ans*=b;
  ans+=min(n%(b+r),b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
n = int(input())
a = list(map(int, input().split()))
s = [0]*n
ss = 0
mod = 10**9+7
for i in range(n):
  ss += a[i]
  s[i] = ss
a.reverse()
ans = 0
for i in range(n-1):
  ans += (a[i]*s[n-2-i])%mod
print (ans%mod)

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

int main() {
    int n;
    int ans;
    cin >> n;
    for(int i=1; i<=100; i++)
    {
        if(1000*i >= n)
        {
            ans = 1000*i - n;
            break;
        }
    }

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



Measured memory_bytes: 3592
#include <stdio.h>
#define N 100000

int main(void) {

    int i, j;
    int num[N];

    for (i = 0; i < N; i++) {
        num[i] = 0;
    }

    scanf("%d", &num[0]);
    i = 1;
    while (num[i - 1] != 0) {
        scanf("%d", &num[i]);
        i++;
    }
    j = i;

    for (i = 0; i < j - 1; i++) {
        printf("Case %d: %d\n", i + 1, num[i]);
    }

    return 0;

}

Measured memory_bytes: 992
n = int(input())
a = list(map(int, input().split()))
q = int(input())
r = []
for _ in range(q):
  r.append(list(map(int, input().split())))

s = {}

for v in a:
  if v in s:
    s[v] += v
  else:
    s[v] = v

p = sum(s.values())

for t in r:
  if t[0] in s:
    n = s[t[0]] // t[0] * t[1]
    p = p - s[t[0]] + n
    if t[1] in s:
      s[t[1]] += n
    else:
      s[t[1]] = n
    del s[t[0]]
  print(p)

Measured memory_bytes: 38372
l,r=[int(i) for i in input().split()]
mod = 2019
ans=10**9

if(r-l<2019):
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%mod)
    print(ans)
else:
    print(0)


Measured memory_bytes: 2940
from math import sqrt

def solve(N):
    dp = [2 for _ in range(N+1)]
    dp[1] = 1

    for i in range(2,int(sqrt(N)) + 1):
        for j in range(2, N//i + 1):
            if j <= int(sqrt(N)):
                dp[i * j] += 1
            else:
                dp[i * j] += 2

    ans = 0
    for i in range(1,N+1):
        ans += (i * dp[i])

    return ans

def main():
    N = int(input())

    print(solve(N))

if __name__ == "__main__":
    main()


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

using namespace std;

string s, t;

bool match(int pos){
	bool f = true;
	for(int i = 0; i < t.size(); ++i){
		if(s[pos+i] == '?') continue;
		else if(s[pos+i] != t[i]){
			f = false;
			break;
		}
	}
	return f;
}

int main(){
	cin >> s >> t;
	bool matchable = false;
	for(int i = s.size()-t.size(); i >= 0; --i){
		if(match(i)){
			for(int j = 0; j < t.size(); ++j) s[i+j] = t[j];
			matchable = true;
			break;
		}
	}
	if(!matchable){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for(int i = 0; i < s.size(); ++i) if(s[i] == '?') s[i] = 'a';
	cout << s << endl;
}

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

#define pb push_back
#define all(a) (a).begin(),(a).end()

#define MAX_V 6000
#define INF (1<<29)

using namespace std;

struct edge{
  int to,cost;
  edge(int to,int cost):to(to),cost(cost){}
};

struct State{
  int d,c,id;
  State(int d,int c,int id):d(d),c(c),id(id){}
  bool operator < (const State &p)const{
    return d>p.d;
  }
};

vector<edge>G[MAX_V];
set<int>st;
int mincost[MAX_V][2001];

int dijkstra(int s,int g,int cap){

  priority_queue<State>que;
  que.push(State(0,cap*10,s));
  fill(mincost[0],mincost[MAX_V],INF);

  while(!que.empty()){
    State now=que.top();
    que.pop();

    if(now.id==g)return now.d;
    if(st.count(now.id))now.c=cap*10;
    if(mincost[now.id][now.c]<=now.d)continue;
    mincost[now.id][now.c]=now.d;

    for(int i=0;i<G[now.id].size();i++){
      int c=G[now.id][i].cost;
      int next=G[now.id][i].to;
      if(now.c<c)continue;
      int idx=(st.count(next)?cap*10:now.c-c);
      for(int j=0;j<=now.c-c;j++)
        mincost[next][j]=min(mincost[next][j],mincost[next][idx]);
      que.push(State(now.d+c,now.c-c,next));
    }
  }
  return -1;
}

vector<string>from,to;
vector<int>cost;
map<string,int>id;
set<string>v;

int main(void){

  int n,m,c;
  while(cin >> n >> m >> c,n|m|c){

    string s,dst,f,t;
    v.clear(),from.clear(),to.clear();
    cost.clear(),id.clear();
    int in;

    cin >> s >> dst;
    v.insert(s),v.insert(dst);

    for(int i=0;i<n;i++){
      cin >> f >> t >> in;
      from.pb(f),to.pb(t),cost.pb(in);
      v.insert(f),v.insert(t);
    }

    for(int i=0;i<MAX_V;i++)G[i].clear();

    set<string>::iterator it=v.begin();
    for(int j=0;it!=v.end();it++,j++)id[*it]=j;

    for(int i=0;i<n;i++){
      G[id[from[i]]].pb(edge(id[to[i]],cost[i]));
      G[id[to[i]]].pb(edge(id[from[i]],cost[i]));
    }

    string a;
    st.clear();
    for(int i=0;i<m;i++){
      cin >> a;
      if(id.count(a))st.insert(id[a]);
    }

    cout << dijkstra(id[s],id[dst],c) << endl;
  }

  return 0;
}

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

using namespace std;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

int solve(int A, int B, int K)
{
    auto d = gcd(A, B);

    vector<int> ds;

    for (int i = d; i >= 1; --i)
        if (d % i == 0)
            ds.push_back(i);

    return ds[K - 1];
}

int main()
{
    ios::sync_with_stdio(false);

    int A, B, K;
    cin >> A >> B >> K;

    auto ans = solve(A, B, K);

    cout << ans << '\n';

    return 0;
}


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()
	if x >= 30 {
		fmt.Fprintln(wr, "Yes")
	} else {
		fmt.Fprintln(wr, "No")
	}
}


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

# 最上公倍数を考える
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers)

num_list=[]
for _ in range(n):
    num_list.append(int(input()))
print(lcm(*num_list))

Measured memory_bytes: 5076
A,B,C=map(int,input().split())
l=[A,B,C]
K=int(input())
id=0
flag=1
i=0
while i<K:
    if id==0:
        if l[id]>=l[id+1]:
            l[id+1]=2*l[id+1]
            i=i+1
        else:
            id=id+1
    elif id==1:
        if l[id]>=l[id+1]:
            l[id+1]=2*l[id+1]
            i=i+1
        else:
            break
    #print(l,i)
for i in range(2):
    if l[i]>=l[i+1]:
        flag=0
        break
if flag==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 61744
# r,g,bにそれぞれ代入
r, g, b = map(int, input().split())
# 3桁の整数を作る
num = (r * 100) + (g * 10 ) + b
#4の倍数か判定
if num % 4 == 0: #numを4で割った余りが0
	print('YES')
else:
	print('NO')  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int h, w;
vector<vector<bool>> c;
vector<vector<bool>> v;
const int dx[8] = { 0, 1, 1,  1,  0, -1, -1, -1 };
const int dy[8] = { 1, 1, 0, -1, -1, -1,  0,  1 };

bool dfs(const int x, const int y) {
    // cout << x << " " << y << " " << c[x][y] << " " << v[x][y] << endl;
    if(not c[x][y]) return false; // sea
    if(v[x][y]) return false; // already visited
    v[x][y] = true;

    for (auto i = 0; i < 8; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if(nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
        dfs(x + dx[i], y + dy[i]);
    }

    return true;
}

int main(){
    while(true) {
        cin >> w >> h;
        if(w == 0 and h == 0) break;

        c.assign(h, vector<bool>(w, false));
        for (auto i = 0; i < h; i++) {
            for (auto j = 0; j < w; j++) {
                int val; cin >> val;
                c[i][j] = static_cast<bool>(val); // true : land, false : sea
            }
        }

        int ans = 0;
        v.assign(h, vector<bool>(w, false));
        for (auto i = 0; i < h; i++) {
            for (auto j = 0; j < w; j++) {
                if(dfs(i, j)) ans++;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int n,a[maxn],b[maxn];
inline bool check(int k){
	rep(i,1,2*n-1)b[i]=(a[i]>=k);
	int l=n,r=n;
	while(l>1&&b[l-1]!=b[l])l--;
	while(r<2*n-1&&b[r+1]!=b[r])r++;
	if(l==1&&r==2*n-1){
		return (n&1)?b[n]:(b[n]^1);
	}
	return n-l<r-n?b[l]:b[r];
}
int main(){
	//judge();
	read(n);rep(i,1,2*n-1)read(a[i]);
	int l=1,r=2*n-1,ans;
	while(l<=r){
		int md=(l+r)>>1;
		if(check(md)){
			ans=md;l=md+1;
		}else
			r=md-1;
	}printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
struct num{
	int x,y;
	int sum;
	int No;	
}a[100001];
bool cmp(num x,num y){
	return x.sum<y.sum;
}
int main(){
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
		a[i].sum=a[i].x+a[i].y;
		a[i].No=i;
	}
	sort(a+1,a+n+1,cmp);
	cout<<a[1].sum;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define N 101
#define NIL -1
#define INF 10000

int A[N][N];
int n;

int func(int );

int main() {

  int i,j,ans;

  scanf("%d", &n);
  for(i = 1;i <= n;i ++){
      for(j = 1;j <= n;j ++){
      scanf("%d", &A[i][j]);
        }
    }

  ans = func(1);

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

  return 0;
}

int func(int r){

  int i,k,p,ans=0;
  int B[N],C[N];;
  char color[N];

  for(i = 1;i <= n;i ++){
      B[i] = INF;
      C[i] = NIL;
      color[i] = 'W';
    }

  B[r] = 0;

  while(1) {
    p = INF;
    for (i = 1;i <= n;i ++){
    if (color[i] != 'B' && B[i] < p){
        p = B[i];
        k = i;
      }
      }

    if (p == INF) break;
    color[k] = 'B';
    for (i = 1;i <= n;i ++){
    if (A[k][i] != NIL){
        if(color[i] != 'B' && A[k][i] < B[i]){
        C[i] = k;
        B[i] = A[k][i];
          }
      }
      }
  }

  for(i = 1;i <= n;i ++){
      ans += B[i];
    }
  return ans;
}



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

int main(void) {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	int maxX = 0;
	int maxY = 0;
	double ans = -1.0;
	for (int i = 0; i*100*a <= f; i++) {
		for (int j = 0; j*100*b + i*100*a <= f; j++) {
			for (int k = 0; j*100*b + i*100*a + k*c <= f; k++) {
				for (int l = 0; j*100*b + i*100*a + k*c + l*d <= f; l++) {
					int x = 100*i*a + 100*j*b;
					int y = k*c + l*d;
					if (x*e < 100*y) break;
					if (ans < (double)y/(y+x)) {
						ans = (double)y/(y+x);
						maxX = x;
						maxY = y;
					}
				}
			}
		}
		
	}
	cout << maxX + maxY << " " << maxY << endl;
	return 0;
}

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

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var p = ReadLongs();
            var needSwap = new bool[N];
            for (int i = 0; i < N; i++)
            {
                needSwap[i] = i + 1 == p[i];
            }

            var swapCount = 0L;
            for (int i = 0; i < N; i++)
            {
                if (needSwap[i])
                {
                    swapCount++;
                    if (i < N - 1 && needSwap[i + 1])
                    {
                        needSwap[i + 1] = false;
                    }
                }
            }
            return swapCount;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 37040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (auto i=(a); i<(b); ++i)
#define iter(it,c) for (auto it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 2147483647;

char arr[2010][2010];
int D[2010][2010],
    R[2010][2010],
    L[2010][2010],
    U[2010][2010];

int main() {
    int n, m;
    scanf("%d %d\n", &n, &m);
    rep(i,0,n) {
        rep(j,0,m) {
            scanf("%c", &arr[i][j]);
        }
        scanf("\n");
    }

    rep(i,0,n) {
        rep(j,0,m) {
            if (arr[i][j] == '#') {
                L[i][j] = 0;
            } else {
                L[i][j] = 1;
                if (j-1 >= 0) {
                    L[i][j] += L[i][j-1];
                }
            }
        }
    }
    rep(i,0,n) {
        for (int j = m-1; j >= 0; j--) {
            if (arr[i][j] == '#') {
                R[i][j] = 0;
            } else {
                R[i][j] = 1;
                if (j+1 < m) {
                    R[i][j] += R[i][j+1];
                }
            }
        }
    }
    rep(i,0,n) {
        rep(j,0,m) {
            if (arr[i][j] == '#') {
                U[i][j] = 0;
            } else {
                U[i][j] = 1;
                if (i-1 >= 0) {
                    U[i][j] += U[i-1][j];
                }
            }
        }
    }
    for (int i = n-1; i >= 0; i--) {
        rep(j,0,m) {
            if (arr[i][j] == '#') {
                D[i][j] = 0;
            } else {
                D[i][j] = 1;
                if (i+1 < n) {
                    D[i][j] += D[i+1][j];
                }
            }
        }
    }

    // rep(i,0,n) {
    //     rep(j,0,m) {
    //         printf("%d", R[i][j]);
    //     }
    //     printf("\n");
    // }

    int cnt = 0;
    rep(i,0,n) {
        rep(j,0,m) {
            if (arr[i][j] != '#') {
                cnt = max(cnt, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3);
            }
        }
    }
    printf("%d\n", cnt);

    return 0;
}



Measured memory_bytes: 67328
Public Class Program
  Shared Sub Main()
    Dim ab As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim a As Long = ab(0)
    Dim b As Long = ab(1)
    Dim k As Double = (a * a - b * b) / (2 * (a - b))
    Dim output As String = If(k = Math.Ceiling(K), k.ToString(), "IMPOSSIBLE")
    Console.WriteLine(output)
  End Sub
End Class

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>

using namespace std;

int main(){
    int s;
    cin >> s;

    int a,b,c,d;

    d=s%10;
    c=(s/10)%10;
    b=(s/100)%10;
    a=(s/1000)%10;

    vector<int> ope={1,-1};

    for(auto i:ope){
        for(auto j:ope){
            for(auto k:ope){
                if(a+i*b+j*c+k*d==7){
                    cout << a;
                    if(i==1){
                        cout << "+";
                    }else{
                        cout << "-";
                    }
                    cout << b;
                    if(j==1){
                        cout << "+";
                    }else{
                        cout << "-";
                    }
                    cout << c;
                    if(k==1){
                        cout << "+";
                    }else{
                        cout << "-";
                    }
                    cout << d << "=7" << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
  double temp = 0;
  double sum = 0;
  int n;
  int arr[1000];
  while(1)
    {
      scanf("%d", &n);
      if(n == 0)
	{
	  break;
	}
      for(int i = 0; i < n; i++)
	{
	  scanf("%d", &arr[i]);
	  sum+=arr[i];
	}
      sum = sum/n;
      for(int i = 0; i < n; i++)
	{
	  temp += ((arr[i]-sum)*(arr[i]-sum));
	}
      temp = temp/n;
      temp = sqrt(temp);
      printf("%f\n", temp);
      temp = 0;
      sum = 0;
    }
}


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

int main() {
  int n;
  cin>>n;
  int ans=0;
  vector<int>vec(n+1);
  for(int i=0;i<n;i++) {
    char a;
    cin>>a;
    if(a=='I') {
      ans++;
      vec.at(i)=ans;
    }
    else if(a=='D') {
      ans--;
      vec.at(i)=ans;
    }
  }
  vec.at(n)=0;
  sort(vec.begin(),vec.end());
  cout<<vec.at(vec.size()-1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
void vp(long a[3], long b[3], long c[3]){
	for(long i=0;i<3;i++) c[i] = a[i]+b[i];
}
void vm(long a[3], long b[3], long c[3]){
	for(long i=0;i<3;i++) c[i] = a[i]-b[i];
}
void mv(long a[3][3], long b[3], long c[3]){
	for(long i=0;i<3;i++){
		c[i] = 0;
		for(long j=0;j<3;j++) c[i] += a[j][i]*b[j];
	}
}
long minv(long a[3][3], long b[3][3]){
	long c = a[0][0]*a[1][1]*a[2][2];
	c     += a[1][0]*a[2][1]*a[0][2];
	c     += a[2][0]*a[0][1]*a[1][2];
	c     -= a[0][0]*a[2][1]*a[1][2];
	c     -= a[2][0]*a[1][1]*a[0][2];
	c     -= a[1][0]*a[0][1]*a[2][2];
	b[0][0] = (a[1][1]*a[2][2]-a[1][2]*a[2][1]);
	b[0][1] = (a[0][2]*a[2][1]-a[0][1]*a[2][2]);
	b[0][2] = (a[0][1]*a[1][2]-a[0][2]*a[1][1]);
	b[1][0] = (a[1][2]*a[2][0]-a[1][0]*a[2][2]);
	b[1][1] = (a[0][0]*a[2][2]-a[0][2]*a[2][0]);
	b[1][2] = (a[0][2]*a[1][0]-a[0][0]*a[1][2]);
	b[2][0] = (a[1][0]*a[2][1]-a[1][1]*a[2][0]);
	b[2][1] = (a[0][1]*a[2][0]-a[0][0]*a[2][1]);
	b[2][2] = (a[0][0]*a[1][1]-a[0][1]*a[1][0]);
	return c;
}

int main(){
	long v1[3],v2[3],v3[3],v4[3],v5[3];
	cin >> v1[0] >> v1[1] >> v1[2];
	cin >> v2[0] >> v2[1] >> v2[2];
	cin >> v3[0] >> v3[1] >> v3[2];
	cin >> v4[0] >> v4[1] >> v4[2];
	cin >> v5[0] >> v5[1] >> v5[2];
	long c1[3],c2[3],c3[3],c4[3];
	vm(v2,v1,c1);
	vm(v3,v1,c2);
	vm(v4,v1,c3);
	vm(v5,v1,c4);
	long m[3][3],b[3][3];
	for(long i=0;i<3;i++) m[0][i] = c2[i];
	for(long i=0;i<3;i++) m[1][i] = c3[i];
	for(long i=0;i<3;i++) m[2][i] = c4[i];
	long a = minv(m,b);
	long c = 1;
	if(a<0) c = -1;
	long s[3];
	mv(b,c1,s);
	if(((s[0]+s[1]+s[2])*c >= a*c) and s[0]*c>=0 and s[1]*c>=0 and s[2]*c>=0 ) cout << "MISS" << endl;
	else cout << "HIT" << endl;
}

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

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

    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        reverse(S[i].begin(), S[i].end());
    }
    sort(S.begin(), S.end(), [](auto& s1, auto& s2) {
        return s1.size() > s2.size();
    });
    unordered_map<ll, vector<int>> cnt;
    vector<int> one(26);
    ll ans = 0;
    for (auto& s : S) {
        int n = s.size();
        if (n == 1) {
            ans += one[s[0] - 'a'];
            continue;
        }
        vector<ll> hashes(n - 1);
        hashes[0] = s[0];
        for (int i = 1; i < n - 1; i++) hashes[i] = hashes[i-1] * 100007 + s[i];
        if (cnt.count(hashes[n-2])) ans += cnt[hashes[n-2]][s[n-1] - 'a'];
        vector<int> found(26);
        found[s[n-1] - 'a'] = 1;
        for (int i = n - 2; i > 0; i--) {
            found[s[i] - 'a'] = 1;
            if (cnt.count(hashes[i-1]) == 0) cnt[hashes[i-1]] = vector<int>(26);
            for (int c = 0; c < 26; c++) cnt[hashes[i-1]][c] += found[c];
        }
        found[s[0] - 'a'] = 1;
        for (int c = 0; c < 26; c++) one[c] += found[c];
    }
    cout << ans << endl;
}


Measured memory_bytes: 171824
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
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; }

vector<ll> cum(vector<ll> a, ll N){
    vector<ll> S;
    ll sum = 0;
    priority_queue<ll> que;
    rep(i, N) sum += a[i], que.push(-a[i]);
    S.pb(sum);

    for (ll i = N; i < 2 * N; ++i){
        ll mn = -que.top();
        if(a[i] > mn){
            que.pop();
            que.push(-a[i]);
            sum -= mn;
            sum += a[i];
        }
        S.pb(sum);
    }

    return S;
}

vector<ll> cum2(vector<ll> a, ll N)
{
    vector<ll> S;
    ll sum = 0;
    priority_queue<ll> que;
    rep(i, N) sum += a[i], que.push(a[i]);

    S.pb(sum);
    for (ll i = N; i < 2 * N; ++i)
    {
        ll mx = que.top();
        if (a[i] < mx)
        {
            que.pop();
            que.push(a[i]);
            sum -= mx;
            sum += a[i];
        }
        S.pb(sum);
    }

    return S;
}

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

    ll N;
    cin >> N;
    vec a(3 * N);
    rep(i, 3 * N) cin >> a[i];

    vec s = cum(a, N);
    reverse(ALL(a));
    vec sr = cum2(a, N);

    ll ans = -1e18;
    rep(i, N + 1) chmax(ans, s[i] - sr[N - i]);
    print(ans);

    return 0;
}

Measured memory_bytes: 8380
import string
lc = string.ascii_lowercase
n = int(input())

lst = [0]
for i in range(1, 100000):
    tmp = pow(26, i)
    lst.append(tmp)
    if tmp > n:
        break
cum = [lst[0]]
for i in range(1, len(lst)):
    cum.append(cum[-1] + lst[i])
idx = 0
while True:
    if n-1 < cum[idx]:
        break
    idx += 1
num = n - cum[idx-1] - 1
ans = ''
for i in range(idx)[::-1]:
    tmp = pow(26, i)
    k = num // tmp
    num = num - tmp *k
    ans += lc[k]
print(ans)

Measured memory_bytes: 71852
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    char word[12];
    char bword[12];
    
    char list[105][12];
    
    int blen;
    
    int i, j, k;
    
    scanf("%d\n", &n);
    
    for(i = 0; i < n; i++) {
        if(i == n - 1) {
            scanf("%s", word);
            
            for(j = 0; j < 12; j++) {
                list[i][j] = word[j];
            }
            
        } else if(i == 0){
            scanf("%s\n", bword);
            
            for(j = 0; j < 12; j++) {
                list[i][j] = bword[j];
            }
            
        } else {
            scanf("%s\n", word);
            for(j = 0; j < 12; j++) {
                list[i][j] = word[j];
            }
        }
        
        for(k = 0; k < i; k++) {
            if(strcmp(list[i], list[k]) == 0) {
                printf("No\n");
                return 0;
            }
        }
        
        
        if(i >= 1) {
            blen = strlen(bword);
            if(word[0] != bword[blen - 1]) {
                printf("No\n");
                return 0;
            } else {
                for(j = 0; j < 12; j++) {
                    bword[j] = word[j];
                }
            }
        }
        
    }
    
    
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 2; i < 1e7; i++ {
		j := i
		for n%j == 0 {
			ans++
			n /= j
			j *= i
		}
		for n%i == 0 {
			n /= i
		}
	}
	if n >= 1e7 {
		ans++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1780
import sys
from pprint import pprint

A, V = map(int, sys.stdin.readline().strip().split())
B, W = map(int, sys.stdin.readline().strip().split())
T = int(sys.stdin.readline().strip())

d = abs(A - B)
if d == 0:
    print("YES")
elif V < W:
    print("NO")
else:
    if d <= T * (V - W):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9960