akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
 
using namespace std;
typedef long long ll;


int main()
{
    string S, T; 
    cin >> S >> T;
    for(char moji='a'; moji<='z'; ++moji){
        vector<ll> index;
        ll pos = 0;
        pos = S.find(moji, pos);
        while(pos != std::string::npos){
            index.push_back(pos);
            pos = S.find(moji, pos + 1);
        }

        for(ll target : index){
            if(T[target] != T[index[0]]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    for(char moji='a'; moji<='z'; ++moji){
        vector<ll> index;
        ll pos = 0;
        pos = T.find(moji, pos);
        while(pos != std::string::npos){
            index.push_back(pos);
            pos = T.find(moji, pos + 1);
        }

        for(ll target : index){
            if(S[target] != S[index[0]]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2500
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
		long mod = (long)(Math.pow(10, 9)+7);
		int n  = sc.nextInt();
 
		long sosu[] = new long[n+1];
 
		for(int i = 2;i <= n;i++){
			int j = i;
			while(j > 1){
				for(int k = 2;k <= j;k++){
					if(j%k == 0){
						//System.out.println("i:"+i+" j:"+j);
						sosu[k]++;
						j /= k;
						break;
					}
				}
			}
		}
		long answer = 1;
		for(int i = 2;i < sosu.length;i++){
			if(sosu[i] > 0)answer = (answer*(sosu[i]+1))%mod;
		}
 
		System.out.println(answer);
	}
}

Measured memory_bytes: 9812
#include <cassert>
#include <vector>

template <class Group> class potentialized_union_find {
public:
  using T = typename Group::value_type;

private:
  using size_t = std::size_t;
  class node_type {
    friend potentialized_union_find;

    T value;
    size_t parent;
    size_t size;

    node_type(const T value, const size_t parent, const size_t size)
        : value(value), parent(parent), size(size) {}
  };

  std::vector<node_type> tree;

  size_t size() const { return tree.size(); }
  void compress(const size_t x) {
    const size_t p = tree[x].parent;
    if (p == x)
      return;
    compress(p);
    tree[x].value = Group::operation(tree[p].value, tree[x].value);
    tree[x].parent = tree[p].parent;
  }

public:
  potentialized_union_find() = default;
  explicit potentialized_union_find(const size_t n)
      : tree(n, node_type(Group::identity, 0, 1)) {
    for (size_t i = 0; i != n; i += 1)
      tree[i].parent = i;
  }

  size_t find(const size_t x) {
    assert(x < size());
    compress(x);
    return tree[x].parent;
  }
  T potential(const size_t x) {
    assert(x < size());
    compress(x);
    return tree[x].value;
  }
  bool same(const size_t x, const size_t y) {
    assert(x < size());
    compress(x);
    return find(x) == find(y);
  }
  T distance(const size_t x, const size_t y) {
    assert(x < size());
    assert(y < size());
    return Group::operation(Group::inverse(potential(x)), potential(y));
  }
  size_t size(const size_t x) {
    assert(x < size());
    return tree[find(x)].size;
  }

  void unite(size_t x, size_t y, T d) {
    if (same(x, y))
      return;
    if (size(x) < size(y)) {
      d = Group::inverse(d);
      std::swap(x, y);
    }
    d = Group::operation(Group::operation(potential(x), d),
                         Group::inverse(potential(y)));
    x = find(x);
    y = find(y);
    tree[x].size += tree[y].size;
    tree[y].parent = x;
    tree[y].value = d;
  }
};

template <class T> class plus_group {
public:
  using value_type = T;
  static constexpr T operation(const T &x, const T &y) noexcept {
    return x + y;
  }
  static constexpr T identity = 0;
  static constexpr T inverse(const T &x) noexcept { return -x; }
};
template <class T> constexpr T plus_group<T>::identity;

#include <iostream>

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

  potentialized_union_find<plus_group<int>> puf(n);

  for (int i = 0; i != m; ++i) {
    int l, r, d;
    std::cin >> l >> r >> d;
    --l;
    --r;
    if (puf.same(l, r)) {
      if (puf.distance(l, r) != d) {
        std::cout << "No" << std::endl;
        return 0;
      }
    } else {
      puf.unite(l, r, d);
    }
  }
  std::cout << "Yes" << std::endl;

  return 0;
}

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 998244353
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vi a(n);
    rep(i,1,n)
        cin>>a[i];
    ll ans=a[1];
    rep(i,2,n)
    {
        ans+=min(a[i-1],a[i]);
    }
    ans+=a.back();
    cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	//cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}


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

using namespace std;

string Solve(const string& str, size_t idx, vector<int> nums) {
  if (idx == 4) {
    int sum = 0;
    for_each(nums.begin(), nums.end(), [&sum](const int& n) { sum += n; });
    if (sum == 7) {
      string res = str.substr(0, 1);
      for (size_t i = 1; i < str.size(); ++i) {
        if (nums[i] >= 0) res += '+';
        res += to_string(nums[i]);
      }
      res += "=7";
      return res;
    }
    return "";
  }
  nums.push_back(str[idx] - '0');
  string res1 = Solve(str, idx + 1, nums);
  if (!res1.empty()) return res1;
  nums.back() = (-1 * (str[idx] - '0'));
  return Solve(str, idx + 1, nums);
}

int main() {
  string S;
  cin >> S;
  
  cout << Solve(S, 0, vector<int>()) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,m,c,b[20],num=0;
	cin>>n>>m>>c;
	for(int i=0;i<m;i++) cin>>b[i];
	for(int i=0;i<n;i++) {
		int sum=0;
		for(int j=0;j<m;j++) {
			int x;
			cin>>x;
			sum+=x*b[j];
		}
		if(sum+c>0) num++;
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
B = list(map(int, input().split()))

A = []
for i in range(n):
    if i == 0:
        A.append(B[i])
    elif i == n-1:
        A.append(B[-1])
    else:
        A.append(min(B[i-1], B[i]))

print(sum(A))


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define STR 10
int main(){
    int a;
    scanf("%d", &a);
    printf("%d",a+a*a+a*a*a);
    return 0;
}

Measured memory_bytes: 1732
#C
N = int(input())
memo = {}
max_word = 1
for i in range(N):
    Si = input()
    try:
        memo[Si] += 1
        max_word = max(max_word, memo[Si])
    except:
        memo[Si] = 1
        
keys = [k for k, v in memo.items() if v == max_word]
keys.sort()
for item in keys:
  print(item)

Measured memory_bytes: 32096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 2e9
#define LINF 1e18
#define PRM 1000000007
#define rep(i, n) for(int i = 0; i < (ll)(n); i++)
#define input(x, n)for(int i = 0; i <(ll)(n); i++)cin >> x[i];
#define until(i,n) for(int i = 1; i <= (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")
#define PI 3.141592653589793
 
int main(){
    
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }
 
    ll ans = 0;
 
    rep(i, n){
        sum -= a[i];
        ans += (sum%PRM)*a[i];
        ans %= PRM;
    }
 
    cout << ans << endl;
 
}

Measured memory_bytes: 4824
#include <stdio.h>

#define MAX_N 1000000

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 }, num_p[ MAX_N + 1 ] = {};

int main( void ) {
	int i, j, n;

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;
	
	for ( i = 1; i <= MAX_N; i++ )
		num_p[ i ] = num_p[ i - 1 ] + isPrime[ i ];

	for ( ; scanf( "%d", &n ) == 1; printf( "%d\n", num_p[ n ] ) ) ;

	return 0;
}

Measured memory_bytes: 8408
#include<bits/stdc++.h>
#define inf 1ll<<62
using namespace std;

int n;
int a[300010];
int max1[300010],ans[300010];

int main()
{
	scanf("%d",&n);
	n=1<<n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j=(j+1)|i)
		{
			ans[j]=max(ans[j],max1[j]+a[i]);
			max1[j]=max(max1[j],a[i]); 
		}
	}
	for(int i=1;i<n;i++)
	{
		ans[i]=max(ans[i],ans[i-1]);
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 6820
from __future__ import division
import sys
#   ad*x + bd*y = cd
# -)ad*x + ae*y = af
#         (bd-ae)*y = cd-af
# and so on...
while True:
    try:
        a, b, c, d, e, f = map(float, raw_input().split())
    except:
        break
    x = (c*e - b*f) / (a*e - b*d) + 0 # -0 towa...
    y = (c*d - a*f) / (b*d - a*e) + 0

    print "{:.3f} {:.3f}".format(round(x,3), round(y,3))

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int k,dp[n+5],f[n+5];
  for(int y=0;y<n;y++){
    cin>>f[y];
    if(y<1)dp[y]=0;
    else if (y==1){
    	dp[y]=abs(f[y]-f[y-1]);
    }
    else {
    	dp[y]=min(dp[y-1]+abs(f[y]-f[y-1]),dp[y-2]+abs(f[y]-f[y-2]));
    }
  }
    cout<<dp[n-1]<<'\n';
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
ss = [int(input()) for i in range(n)]

smax = sum(ss)
not_10 = [s for s in ss if s % 10 != 0]
if smax % 10 != 0:
    print(smax)
elif len(not_10) == 0:
	print(0)
else:
	print(smax - min(not_10))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    string s;
    cin >> s;
    s[3]='8';
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin>>n>>k;
  vector<long long> a(n+1),visit(n+1,-1);
  for(int i=1;i<=n;i++){
      cin>>a[i];
  }
  visit[1]=0;
  long long cnt=0,loop=-1,town=1;
  for(long long i=1;i<=k;i++){
      town=a[town];
     // cout<<town<< "   town"<<endl;
      if(visit[town]==-1){
          visit[town]=i;
      }
      else{
          loop=i-visit[town];
          cnt=i;
          break;
      }
  }
 // cout<<loop<<"  "<<town<<endl;
  if(loop!=-1){
      long long res=(k-cnt)%loop;
      for(long long i=0;i<res;i++){
          town=a[town];
      }
  }
  cout<<town<<endl;
  return 0;
}


Measured memory_bytes: 6348
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    char b;
    cin >> b;
    if(b == 'A') cout << 'T';
    if(b == 'T') cout << 'A';
    if(b == 'G') cout << 'C';
    if(b == 'C') cout << 'G';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 9223372036854775807

vector<pair<long long, int> > adj[100005];
int color[100005];
long long dist[100005];
int N;

void dijkstra(int start_v) {
    priority_queue<pair<long long, int> > Q;
    for (int i = 1; i <= N; i++) {
        dist[i] = INF;
        color[i] = WHITE;
    }

    dist[start_v] = 0;
    Q.push(make_pair(0, start_v));
    color[start_v] = GRAY;

    while (!Q.empty()) {
        pair<long long, int> f = Q.top();
        Q.pop();
        int u = f.second;
        color[u] = BLACK;

        if (dist[u] < f.first * (-1)) continue;

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].second;
            if (color[v] == BLACK) continue;
            if (adj[u][j].first + dist[u] < dist[v]) {
                dist[v] = dist[u] + adj[u][j].first;
                Q.push(make_pair(dist[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }

    return;
}

int main() {
    int Q, K, a, b, x, y;
    long long c;
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b >> c;
        adj[a].push_back(make_pair(c, b));
        adj[b].push_back(make_pair(c, a));
    }
    cin >> Q >> K;
    dijkstra(K);
    for (int i = 0; i < Q; i++) {
        cin >> x >> y;
        cout << dist[x] + dist[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 11504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

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

    // solution comes here
    string A, ans, C;
    cin >> A >> ans >> C;
    cout << A[0] << ans[0] << C[0] << nl;
}

Measured memory_bytes: 256
import math
N = int(input())
mi = float("inf")
def F(x, y):
    return max(len(str(x)), len(str(y)))

for A in range(1, math.floor(math.sqrt(N))+1):
    if N % A == 0:
        B = N // A
        mi = min(F(A, B), mi)
print(mi)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	long long int N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;

	B = min(A, B);
	C = min(B, C);
	D = min(C, D);
	E = min(D, E);

	long long int m = min(A, min(B, min(C, min(D, E))));

	if (m == 1)
	{
		cout << N / m + 4 << endl;
	}
	else
	{
		cout << N / m + 5 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = gets.to_s.to_i
a = gets.to_s.split

n_nega = 1
ans_sum = 0
abs_min = 1_000_000_000

a.each do |t|
  
  t = t.to_i
  
  ab = t.abs
  
  ans_sum += ab
  
  abs_min = ab if abs_min > ab
  
  n_nega *= -1 if t < 0
end

puts n_nega == 1 ? ans_sum : ans_sum - abs_min * 2 

Measured memory_bytes: 7812
#include <iostream>
using namespace std;
int main(){
    int a,b;
    char op;

    while(cin>>a>>op>>b,op!='?'){

        if(op=='+'){
            cout << a + b << endl;
        }else if(op=='-'){
            cout << a - b << endl;
        }else if(op=='*'){
            cout << a * b << endl;
        }else if(op=='/'){
            cout << a / b << endl;
        }

    }
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

ll lcm(ll m, ll n) {
    // If both m and n are large numbers, the result is overflow without parentheses.
    return m * (n / gcd(m, n));
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    ll l = 1;
    bool ok = true;
    REP(i, n) {
        cin >> a[i];
        a[i] /= 2;
        l = lcm(l, a[i]);
        if (l > m) {
            ok = false;
        }
    }
    if (!ok) {
        cout << 0 << EOL;
        return;
    }
    REP(i, n) if ((l / a[i]) % 2 == 0) {
        cout << 0 << EOL;
        return;
    }
    int x = m / l;
    cout << (x + 1) / 2 << EOL;

}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

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

	}
	sort(a,a+10);
	cout<<a[9]<<endl;
	cout<<a[8]<<endl;
	cout<<a[7]<<endl;

return 0;
}

Measured memory_bytes: 1176
#include <iostream>
using namespace std;
char a[1000];
int dp[305][305][305];
int main()
{
    int n = 0, m, ans = 0;
    cin >> a + 1;
    cin >> m;
    for(int i = 1; a[i] != 0; i ++)
        n = i;
    for(int i = 1; i <= n; i ++)
        for(int j = n ; j >= i; j --)
        {
            for(int k = 0; k <= m; k ++)
            {
                if(i == j)
                    dp[i][j][k] = dp[i - 1][j + 1][k] + 1;
                else
                {
                    if(k > 0)
                        dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j + 1][k - 1] + 2);
                    if(a[i] == a[j])
                        dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j + 1][k] + 2);
                    dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j + 1][k]);
                }
                //cout << i << " " << j << " " << k << "  " << dp[i][j][k] << endl;
                ans = max(ans, dp[i][j][k]);
            }
        }
    cout << ans;
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    int ans = 0;

    for(int i=0; i<n; i++){
        cin >> a[i];
        int count = 0;
        while(true){
            if(a[i]%2==0){
                a[i] = a[i]/2; count++;
            }else
                break;
        }
        ans += count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int x;
    double p;
    cin >> x >> p;
    p/=100.0;
    if(1){
        cout << fixed << setprecision(10) << (x+1)/2/p << endl;
    }
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    string s;
    cin >> s;
    if(s[s.length()-1]=='s') cout << s << "es" << endl;
    else cout << s << 's' << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int n=gi();
	    int k=gi();
	    
        System.out.println(n-k+1);
//        if (n%k==0) {
//        	System.out.print(0);
//        }else {
//        	System.out.print(1);
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35604
s = list( input( ) )
n = int( input( ) )
for i in range( n ):
	cmd = input( ).split( " " )
	a = int( cmd[1] )
	b = int( cmd[2] ) + 1
	if "print" == cmd[0]:
		print( "".join( s[ a:b ] ) )
	elif "reverse" == cmd[0]:
		for i, ss in enumerate( reversed( s[ a:b ] ) ):
			s[ a+i ] = ss
	elif "replace" == cmd[0]:
		for i, ss in enumerate( cmd[3] ):
			s[ a+i ] = ss

Measured memory_bytes: 6724
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
void chmax(T &a, T b) {
    if (b > a) a = b;
}

constexpr int M = 26, D = 365;

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

    int r[D];
    int c[M];
    int s[D][M];

    for (int j = 0; j < M; j++) {
        cin >> c[j];
    }
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < M; j++) {
            cin >> s[i][j];
        }
    }

    int l[M];
    for (int j = 0; j < M; j++) {
        l[j] = -1;
    }

    for (int i = 0; i < D; i++) {
        pair<int, int> p = { -1, -1 };
        for (int j = 0; j < M; j++) {
            chmax(p, { 5 * c[j] * (i - l[j]) + s[i][j], j });
        }
        r[i] = p.second;
        l[r[i]] = i;
    }

    {
        ll sc = 0;
        int l[M];
        for (int j = 0; j < M; j++) {
            l[j] = -1;
        }
        for (int i = 0; i < D; i++) {
            sc += s[i][r[i]];
            l[r[i]] = i;

            for (int j = 0; j < M; j++) {
                sc -= c[j] * (i - l[j]);
            }
        }
        cerr << "satisfaction  " << sc << '\n';
    }

    for (int i = 0; i < D; i++) {
        cout << r[i] + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 3660
X = int(input())

b = 3
ans = 1

for i in range(2,X+1):
        t = i ** 2
        if t <= X:
            while(1):
                t = i ** b
                if t <= X:
                    b = b + 1
                else:
                    b = 3
                    t = t // i
                    ans = max(ans, t)
                    break

print(ans)

Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    cur = 1
    ret = 0
    t = []
    for i in range(N):
        v = A[i]
        if v >= cur:
            print(-1)
            return
        t.append(cur)
        ret += cur
        #print(i, cur, ret)
        cur = (cur - v) * 2
    if A[-1] > cur:
        print(-1)
        return
    ret += A[-1]
    #print(ret)

    mx = A[-1]
    for i in range(1, N)[::-1]:
        tmp = min(mx + A[i], 2 ** i)
        if t[i] > tmp:
            ret -= t[i] - tmp
        #ret += tmp
        mx = min(tmp, 2 ** (i - 1))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 0 + 1)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main(){
  int n ;
  cin >> n ;
  int A[n] ;
  rep(i,n) cin >> A[i] ;
  map<int,int> mp ;
  rep(i,n) mp[A[i]+i+1]++ ;
  ll ans = 0 ;
  rep(i,n) ans += mp[i+1 - A[i] ] ;
  cout << ans << endl;
}
  


Measured memory_bytes: 21396
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
long long int gcd(long long int a, long long int b){
  long long int c;
  while( a != 0 ){
    c = a;
    a = b%a;
    b = c;
  }
  return b;
}
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  int ans = a[0];
  for(int i=1; i<n; i++){
    ans = ans * a[i] / gcd(ans, a[i]);
  }
  cout << ans << endl;

  return 0;
}





// EOF

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

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; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

int N;

// *********************************************************
int main(){

    cin >> N;
    
    ll A=1;
    vll vl;
    ll Ai;


    for(int i=0; i<N; ++i) {
        cin >> Ai;
        if (Ai==0){
            cout << 0 << endl;
            return 0;
        }
        vl.emplace_back(Ai);
    }


    for(int i=0; i<N; ++i) {
        if(1000000000000000000/A >= vl.at(i)){
            A *= vl.at(i);
        }else{
            cout << "-1" << endl;
            return 0;
        }
    }


    cout << A << endl;




    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  cin >> n;
  unordered_map<int, int> a;
  ll sum = 0;

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

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;

    sum = sum + (c - b) * a[b];
    cout << sum << endl;

    a[c] += a[b];
    a[b] = 0;
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
  for(;;) {
    int n;
    cin >> n;
    if(n==0) break;
    int n22 = n*2+2;
    bool prime[n*2+2];
    for(int i = 0; i < n22; i++) {
      prime[i] = true;
    }
    prime[0] = false;
    prime[1] = false;
    for(int p = 2; p < n22; p++) {
      if(prime[p]) {
        for(int k = p+p; k < n22; k+=p) {
          prime[k] = false;
        }
      }
    }
    int cnt = 0;
    for(int i = n+1; i <= 2*n; i++) {
      if(prime[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

    lint a,b,c;
    cin >> a >> b>>c;

    lint ans, tmp;

    lint l, r;

    l = 4 * a * b;
    r = c - a - b;
    r = r * r;

    if(c<=a+b){
        cout << "No" << "\n";
        return 0;
    }

    if (l < r)
    {
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> vary;
	int p,n,i;
	cin >> p;
	while (p--)
	{
		cin >> n;
		if (n == 0)
		{	long long int x;

			cin >> x;
			vary.push_back(x);
		}
		if (n == 1)
		{
			if (vary.size() <= 0)break;
			cin >> i;
			cout << vary[i] << endl;
		}
		if (n == 2)
		{
			if (vary.size() <= 0)break;
			vary.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x1,y1,x2,y2,area1,area2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	area1=x1*y1;
	area2=x2*y2;
	if(area1<area2){
		printf("%d",area2);
	}else
	printf("%d",area1);
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

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

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a = b; return true;} return false; }


ll N, M;
vl H;
vector<vi> G;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N >> M;
    H.resize(N);
    G.resize(N);
    REP(i, N) cin >> H[i];
    REP(i, M)
    {
        int A, B; cin >> A >> B;
        A--; B--;
        G[A].pb(B);
        G[B].pb(A);
    }

    int ans = 0;
    REP(i, N)
    {
        bool good = true;
        for(int n : G[i]) if(H[n] >= H[i]) good = false;
        if(good) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9260
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N, M, D) = rd.readListLong()

    var cnt = 0L
    if (D == 0L) {
        cnt = N
    } else {
        for (x in 1..N) {
            if (x - D >= 1) cnt++
            if (x + D <= N) cnt++
        }
    }
    cnt *= (M-1)

    val ans = cnt / (N*N).toDouble()
    println("%.10f".format(ans))
}


//val rd = debug.Reader("etc", "soundhound2018-summer-qual", "c", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 38076
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    sort( A.begin(), A.end() );
    long long a = A[N-1]/2;
    long long b = (A[N-1]+1)/2;
    long long c = LLONG_MAX;

    int ai;
    for ( int i = 0; i < N-1; i++ ) {
        long long d = min( abs( A[i]-a ), abs( A[i]-b ) );
        if ( c > d ) {
            c = d;
            ai = i;
        }
    }

    cout << A[N-1] << " " << A[ai] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

LL cnt=0;

LL func(string s, LL n){
    if(!s.empty() && stoull(s) > n)return cnt;
    if(!s.empty() && stoull(s)>=357 && stoull(s)<=n){
        int exist_3 = s.find("3");
        int exist_5 = s.find("5");
        int exist_7 = s.find("7");
        // cout<<s<<endl;
        if (exist_3 == string::npos || exist_5 == string::npos || exist_7 == string::npos){}
        else{cnt++;}
    }
    
    func(s+'3',n);
    func(s+'5',n);
    func(s+'7',n);
    return cnt;
}

int main()
{
    LL n; cin>>n;
    cout<<func("",n)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	vector<int> nums;
	int now = 1;
	int cnt = 0;
	for (unsigned int i = 0; i < s.size(); ++i) {
		if (s[i] == (char)(now + '0')) cnt++;
		else {
			nums.push_back(cnt);
			now = 1- now;
			cnt = 1;
		}
	}
	if (cnt != 0) nums.push_back(cnt);
	if (nums.size() % 2 == 0) nums.push_back(0);
	int left = 0;
	int right = 0;
	int add = 2 * k + 1;
	int ans = 0;
	int tmp = 0;
	for (int i = 0; i < nums.size(); i += 2) {
		int now_left = i;
		int now_right = min(i + add, (int)nums.size());
		while (left < now_left) {
			tmp -= nums[left];
			left++;
		}
		while (right < now_right) {
			tmp += nums[right];
			right++;
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return;
}

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

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

int main (){
	string s;
	cin>>s;
	int n=s.length();int c=0;
	for (int i=0;i<n;i++)if(s[i]=='x')c++;
	if(c<=7)cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
struct node {
	int v, next1;
} e[1000009];
int n,m;
int cnt=0;
int dis[1000009];
int head[1000009];
void add(int x,int y) {
	e[++cnt].v=y;
	e[cnt].next1=head[x];
	head[x]=cnt;
}
bool bfs(int a) {
	queue<int>q;
	q.push(a);
	dis[a]=0;
	while(q.size()) {
		int x=q.front();
		q.pop();
		for(int i=head[x]; i; i=e[i].next1) {
			int y=e[i].v;
			if(dis[y]==-1) {
				dis[y]=x;
				q.push(y);
			}

		}

	}
	for(int i=2; i<=n; i++) {
		if(dis[i]==-1)
			return false;


	}
	return true;
}
int main() {
	cin>>n>>m;
	memset(dis,-1,sizeof(dis));
	memset(head,0,sizeof(head));
	for(int i=1; i<=m; i++) {
		int x,y;
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}

	if(!bfs(1)) {
		cout<<"No"<<endl;
		return 0;
	} else {
		cout<<"Yes"<<endl;
		for(int i=2; i<=n; i++)
			cout<<dis[i]<<endl;
	}
}



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

ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 10001;

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;

int N;
VI p;

void input(){
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp; std::cin >> tmp;
    p.PB(tmp);
  }
}


void solve(){
  int result;
  SORT(p);
  p[N-1] = p[N-1]/2;
  result = std::accumulate(p.begin(), p.end(), 0);
  std::cout << result << '\n';
}


int main(int argc, char const *argv[]) {
  input();
  solve();

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.io.IOException;

class Main{
	public static void main(String args[]){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int  n
			,m;
		
		String[] input = new String[100];
		
		try{
			//n,mの入力
			input = br.readLine().split("[\\s]+");
			n = Integer.parseInt(input[0]);
			m = Integer.parseInt(input[1]);
			
			int[][] A = new int[n][m]; 
			int[] b = new int[m];
			
			//Aの入力
			for(int i=0;i<n;i++){
				input = br.readLine().split("[\\s]+");
				for(int j=0;j<m;j++){
					A[i][j] = Integer.parseInt(input[j]);
				}
			}
			
			//bの入力
			for(int j=0;j<m;j++){
				b[j] = Integer.parseInt(br.readLine());
			}
			//計算・出力
			int c = 0;
			for(int i=0;i<n;i++){
				for(int j=0;j<m;j++){
					c += A[i][j] * b[j];
				}
				System.out.println(c);
				c = 0;
			}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
		
	}
}



Measured memory_bytes: 30848
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b = list(map(int, input().rstrip('\n').split()))
    if a <= 9 and b <= 9:
        print(a * b)
    else:
        print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38496
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+9
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n):
        a = [I() for _ in range(n)]
        t = [(0,0,0)]
        for c in a:
            nt = collections.defaultdict(lambda: inf)
            c1 = c % 1000
            c5 = c % 500
            mc5 = 500 - c5
            for g,k,p in t:
                nt[(g,k)] = p
            if c1 == 0:
                for g,k,p in t:
                    if k >= 500 and nt[(g+1,k-500)] > p + c:
                        nt[(g+1,k-500)] = p + c
            elif c1 == 500:
                for g,k,p in t:
                    if nt[(g+1, k)] > p + c:
                        nt[(g+1, k)] = p + c
            elif c1 < 500:
                for g,k,p in t:
                    if nt[(g+1, k+mc5)] > p + c:
                        nt[(g+1, k+mc5)] = p + c
            else:
                for g,k,p in t:
                    if k + mc5 >= 500 and nt[(g+1,k+mc5-500)] > p + c:
                        nt[(g+1,k+mc5-500)] = p + c
                    if nt[(g, k+mc5)] > p + c:
                        nt[(g, k+mc5)] = p + c
            t = []
            cg = -1
            mk = -1
            mp = inf
            # print('nt',nt)
            for g,k in sorted(nt.keys(), reverse=True):
                p = nt[(g,k)]
                if p == inf:
                    continue
                if cg != g:
                    mp = inf
                    cg = g
                if mk < k or mp > p:
                    t.append((g,k,p))
                    if mk < k:
                        mk = k
                    if mp > p:
                        mp = p
            # print(len(t))
        r = 0
        rp = inf
        for g,k,p in t:
            if r < g or (r==g and rp > p):
                r = g
                rp = p
        return '{} {}'.format(r, rp)

    while 1:
        n = I()
        if n == 0:
            break
        rr.append(f(n))

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 17060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const ll INF = 1e18;
ll N;

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

  cin >> N;
  ll mn = INF;
  for (ll i=1; i*i<=N; i++) {
    if (N%i ==0) {
      mn = min(i+(N/i), mn);
    }
  }

  cout << mn - 2 << "\n";
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class APluralForm {
public:
    void solve(std::istream &in, std::ostream &out) {
        string s;
        in >> s;
        if (s.back() == 's') {
            out << s << "es" << endl;
        } else {
            out << s << 's' << endl;
        }
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    APluralForm solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<ll> s(n);
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    int end = n-1;
    ll ans = 0;
    for(int c = 1; c < end; c++)
    {
        int l = 0;
        int r = end;
        ll sum = 0;
        if(end % c == 0)
        {
            while(l < r)
            {
                sum += s[l] + s[r];
                l += c;
                r -= c;
                ans = max(ans, sum);
            }
        }
        else
        {
            while(l < end && r > 0 && c < r)
            {
                sum += s[l] + s[r];
                l += c;
                r -= c;
                ans = max(ans, sum);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
 char S[4],T[4];
 scanf("%s",S);
 scanf("%s",T);

 int i,n=0,p;
 for(i=0;i<3;i++)
{if(S[i]==T[i]){n=n+1;}
 else n=n;
}
 printf("%d",n);


return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin>>n;
	int d[n][2];
	for(int i=0;i<n;i++)
	{
		cin>>d[i][0]>>d[i][1];
	}
	for(int i=0;i<=n-3;i++)
	{
		if(d[i][0]==d[i][1] && d[i+1][0]==d[i+1][1] && d[i+2][0]==d[i+2][1]){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>

using namespace std;

int digits(int n) {
    if (n < 10) return n;
    return n % 10 + digits(n / 10);
}

int main() {
    int n, mins = (int) 1e8;
    cin >> n;
    for (int a = 1; a < n; ++a) {
        int b = n - a;
        mins = min(mins, digits(a) + digits(b));
    }

    cout << mins << endl;

    return 0;
}

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

N=input()

#約数列挙
def make_divisors(n):
    divisors=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n/i:
                divisors.append(n/i)
    return divisors

def func(a,b):
    return a**5-b**5

L=make_divisors(N)
for yakusu in L:
    for a in range(1,10**3):
        b=a-yakusu
        ret=func(a,b)
        if ret==N:
            print a,b
            quit()


Measured memory_bytes: 87332
L, R = map(int, input().split())
m = 2*(10**9)+1

R = int(min([R, L+2019*2]))

for i in range(L, R):
    for j in range(i+1, R+1):
        a = (i*j) % 2019
        if(m >= a):
            m = a
print(m)

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

int main() {
    int n;
    stack<char> t;
    string s, ans="";
    cin >> s;
    n = s.length();
    for(int i=0;i<n;i++){
        if(s[i] == 'B'){
            if(!t.empty())t.pop();
        }else{
            t.push(s[i]);
        }
    }
    while(!t.empty()){
        char c=t.top();
        t.pop();
        ans = c + ans;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256