akhauriyash/Code-Regression huggingface dataset:
using Yorukatsu043.Questions;
using Yorukatsu043.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu043.Questions
{
    /// <summary>
    /// ARC093 C
    /// </summary>
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = new[] { 0 }.Concat(inputStream.ReadIntArray()).Concat(new[] { 0 }).ToArray();

            var sum = 0;
            for (int i = 0; i <= n; i++)
            {
                sum += Math.Abs(a[i + 1] - a[i]);
            }

            for (int i = 1; i <= n; i++)
            {
                yield return sum - (Math.Abs(a[i + 1] - a[i]) + Math.Abs(a[i] - a[i - 1])) + Math.Abs(a[i + 1] - a[i - 1]);
            }
        }
    }
}


namespace Yorukatsu043
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu043.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu043.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 29652
// C - Remainder Minimization 2019
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, l, r, ans = 0, count = 2020;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> l >> r;
  repe(i, l, r)
  {
    repe(j, i + 1, r)
    {
      ans = (i * j) % 2019;
      if (ans == 0)
      {
        cout << 0 << endl;
        return 0;
      }
      count = min(count, ans);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <ctime>
#include <fstream>
#include <stdarg.h>
using namespace std;
const bool debug=false;
const bool INJUDGE=false;
#define FASTERCIN cin.tie(0);ios_base::sync_with_stdio(false)
typedef long long ll;
/*Time:2018.4.7
Status:
Type:Atcoder Beginner #93
Author:zm_x*/
int a[3];
int op;
void DO(){
	int maxn=0;
	for(int i=0;i<3;i++)maxn=max(a[i],maxn);
	for(int i=0;i<3;i++){
		op+=(maxn-a[i])/2;
	}
	cout<<op<<endl;
	exit(0);
}
int main(){
	cin>>a[0]>>a[1]>>a[2];
	int i;
	if(a[0]%2==a[1]%2&&a[0]%2==a[2]%2)DO();
	if(a[0]%2!=a[1]%2&&a[0]%2!=a[2]%2){
		op++;
		a[1]++;
		a[2]++;
		DO();
	}
	if(a[1]%2!=a[0]%2&&a[2]%2!=a[1]%2){
		op++;
		a[0]++;
		a[2]++;
		DO();
	}
	if(a[2]%2!=a[0]%2&&a[2]%2!=a[1]%2){
		op++;
		a[1]++;
		a[0]++;
		DO();
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{

  ll n,m,x[100010],dist[100010];
  cin>>n>>m;
  rep(i,m)cin>>x[i];
  if(m==1){
    cout<<0<<endl;
    return 0;
  }
  sort(x,x+m);
  rep(i,m-1){
    dist[i]=abs(x[i]-x[i+1]);
  }
  sort(dist,dist+m-1);

  // rep(i,m-1)cout<<dist[i]<<endl;
  ll ans=0;
  rep(i,m-n){
    ans+=dist[i];
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int mod = 1e9+107;
const int inf = 1e8;
int h[N];
int mx[N];
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>h[i];
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        mx[x] = max(mx[x],h[y]);
        mx[y] = max(mx[y],h[x]);
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(h[i]>mx[i])ans++;
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 4432
#include <stdio.h>
#include <string.h>
typedef struct A{
  int n, right,left,d,parent,depth,height,sibling,degree;
}Node;
Node node[30];
int i,j,N,right,left,n;
int B(int p,int d){
  int a,b;
  if(p==-1)return -1;
  node[p].depth=d;
  a=B(node[p].right,d+1);
  b=B(node[p].left,d+1);
  if(a==-1 && b== -1)node[p].height=0;
  else node[p].height=(a>b?a:b)+1;
  return node[p].height;
}
int main() {
  memset(node,-1,sizeof(node));
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d%d%d",&n,&left,&right);
    node[n].left=left;
    node[n].right=right;
    node[n].degree=(right!=-1)+(left!=-1);
    node[left].sibling=right;
    node[right].sibling=left;
    if(left!=-1)node[left].parent=n;
    if(right!=-1)node[right].parent=n;
  }
  for(i=0;i<N;i++)if(node[i].parent==-1)B(i,0);
  for(i=0;i<N;i++)printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",i,node[i].parent,node[i].sibling,node[i].degree,node[i].depth,node[i].height,node[i].parent==-1?"root":node[i].left==-1&&node[i].right==-1?"leaf":"internal node");
  return 0;
}



Measured memory_bytes: 2112
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a,b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ans,j=0,m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 47548
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))+[0]
monster=sum(b)
for i in range(1,n+2):
  k=min(a[i],b[i]+b[i-1])
  a[i]-=k
  if b[i-1]<k:
    b[i]-=k-b[i-1]
    b[i-1]=0
  else:
    b[i-1]-=k
print(monster-sum(b))

Measured memory_bytes: 18624
import numpy as np
n,k=map(int,input().split())
dlist = []
lists = []
x=np.zeros(n,int)
for i in range(k):
    dlist=input()
    lists.append(input().split())
for list in lists:
  l=len(list)
  for j in range(l):
    index=list[j]
    x[int(index)-1]=1
count = 0
for l in range(n):
  if x[l]==0:
    count+=1
print(count)

Measured memory_bytes: 27440
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> cake(H, vector<char>(W, 0));
    vector<int> check(H, 0);
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        cin >> cake[i][j];
        if (cake[i][j] == '#') ++check[i];
    }
    vector<vector<int>> ans(H, vector<int>(W, 0));
    int count = 1;
    for (int i = 0; i < H; i++) {
        if (check[i] == 0) {
            check[i] = -1;
            continue;
        }
        for (int j = 0; j < W; j++) {
            if (check[i] != 0) ans[i][j] = count;
            else ans[i][j] = count - 1;
            if (cake[i][j] == '#') {
                --check[i];
                ++count;
            }
        }
    }
    for (int i = 1; i < H; i++) if (check[i] == -1) for (int j = 0; j < W; j++) ans[i][j] = ans[i - 1][j];
    for (int i = H - 2; i >= 0; i--) if (check[i] == -1) for (int j = 0; j < W; j++) ans[i][j] = ans[i + 1][j];
    // output
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1536
import numpy as np

N, M, X = map(int, input().split())

ca = []
for _ in range(N):
  ca.append( list(map(int, input().split())))
ca.sort(key=lambda x:-x[0])
ca = np.array(ca)
#
ans = 10000000
skill = [0]*(M+1)


def DFS(n,skill):
  global ans
  if skill[0] >= ans:
    return
  if min(skill[1:]) >= X:
    ans = min(ans, skill[0])
    return
  if n >= N:
    return
  DFS(n+1,skill)
  skill = skill + ca[n]
  DFS(n+1,skill)
  skill = skill - ca[n]
  return
#

DFS(0,skill)
if ans == 10000000:
  print(-1)
else:
  print(ans)
#

Measured memory_bytes: 27164
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int n=60-b+d;
    int m=abs(a-c)*60;
    if(n>0)
        m=m-60;
    int p=m+n;
    cout<<p-e<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void) {
    
    ll k,a,b;
    cin>>k>>a>>b;
    ll ans=1;
    if(b-a-2<=0){
        fin(k+1);
        return 0;
    }
    if(a-1>=k){
        fin(k+1);
        return 0;
    }
    ans+=a-1;
    k-=(a-1);
    ans+=k/2*(b-a);
    ans+=k%2;
    fin(ans);
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((a+b)>(c+d)) cout << "Left" << endl;
  else if((a+b)==(c+d)) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    ll N, K, S;
    cin >> N >> K >> S;
    
    if (K == N){
        rep(i, N){
            cout << S << " ";
        }
    } else {
        
        
        rep(i, K){
            cout << S << " ";
        }
        rep(i, N - K){
            if (S == 1000000000){
                cout << 1 << " ";
            } else {
                cout << ll(1e9) << " ";
            }
        }
    }
    return 0;    
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> A){
  ll mid=accumulate(A.begin(),A.end(),0LL);
  mid;
  ll m=0;
  ll cur=0;
  REP(N){
    A[i]*=2;
    cur+=A[i];
    if(abs(mid-cur)<abs(mid-m)){
      m=cur;
    }
  }
  cout<<abs(mid-m)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
from collections import deque

N,K,*A = map(int, open(0).read().split())
checker = deque(A[:K])
d = deque(A[K:])
for i in range(N-K):
    a = checker.popleft()
    b = d.popleft()
    if b > a:
        print('Yes')
    else:
        print('No')
    checker.append(b)

Measured memory_bytes: 31992
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long
int main() {
	  ll n,k;
	  cin>>n>>k;
	  ll a[n];
	  for(ll i=0;i<n;i++)
	  {
	      cin>>a[i];
	  }
	  for(ll i=0;i<n-k;i++)
      {
          if(a[i]<a[i+k])
            cout<<"Yes"<<endl;
          else
            cout<<"No"<<endl;
      }
}


Measured memory_bytes: 5176
n = gets.to_i
s = readlines.map {|i| i.chomp}

h = Hash.new(0)
s.map do |ss|
  h[ss.chars.sort.to_s]+=1
end

count = 0
h.each_value do |v|
  count += (1..(v-1)).inject(:+) if v>=2
end

puts count

Measured memory_bytes: 43612
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	int arr[n];
	for (int i = 0; i != n; ++i)
		cin >> arr[i];
	sort(arr, arr + n);
	
	long long ans = 0;
	for (int i = 2; i != n; ++i)
	{
		for (int j = 0; j != i - 1; ++j)
		{
			int l = j;
			int r = i;
			
			while (r - l != 1)
			{
				if (arr[l + r >> 1] + arr[j] > arr[i])
					r = l + r >> 1;
				else
					l = l + r >> 1;
			}
			
			ans += i - r;
		}
	}
	
	cout << ans << '\n';
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s, t;
  cin >> s >> t;
  int sl = s.size();
  int tl = t.size();

  for (int i = sl - tl; i >= 0; --i) {
    bool ok = true;
    for (int j = 0; j < tl; ++j) {
      if (i + tl > sl) {
        cout << "UNRESTORABLE" << endl;
        return 0;
      }

      if (!(s[i + j] == '?' || s[i + j] == t[j])) {
        ok = false;
        break;
      }
    }
    if (ok) {
      for (int k = 0; k < i; ++k) cout << (s[k] == '?' ? 'a' : s[k]);
      cout << t;
      for (int k = i + tl; k < sl; ++k) cout << (s[k] == '?' ? 'a' : s[k]);
      cout << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<char> = it.next().unwrap().chars().collect();
    let mut q = std::collections::VecDeque::new();
    for i in 0..n {
        q.push_front(i);
    }
    let mut dp = vec![n + 1; n + 1];
    dp[n] = 0;
    let mut state = std::collections::VecDeque::new();
    state.push_back(n);
    while let Some(v) = state.pop_front() {
        if s[v] == '1' {
            continue;
        }
        while let Some(u) = q.pop_front() {
            if v - u > m {
                q.push_front(u);
                break;
            }
            dp[u] = dp[v] + 1;
            state.push_back(u);
        }
    }
    if dp[0] > n {
        println!("-1");
        return;
    }
    let mut out = String::new();
    let mut now = 0;
    while now < n {
        for i in (now + 1).. {
            if s[i] != '1' && dp[i] < dp[now] {
                out.push_str(&format!("{} ", i - now));
                now = i;
                break;
            }
        }
    }
    out.pop();
    println!("{}", out);
}

fn main() {
    run();
}


Measured memory_bytes: 6524
#include<iostream>
#include<algorithm>
#define MAX 1000;
using namespace std;

int main(){
  int n,m,s;

  while(cin >> n >> m){
    int p[n];
    if(n==0 || m==0) return 0;
    for(int i=0; i<n; i++){
      cin >> p[i];
    }   

    int sum=0,ans=0, min;
    sort(p, p+n, greater<int>());

    for(int i=0; i<n; i+=m){
      sum=0;
      for(int j=i; j<i+m && j<n; j++){
	sum += p[j];
      }
      if(i+m <= n) sum -= p[i+m-1];
      ans += sum;
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define CARDS ((int)4)
#define mp make_pair
#define F first
#define S second
#define endl '\n'

using namespace std;

typedef pair<int, int> pii;

char type[] = { 'S', 'H', 'C', 'D' };

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

	set<pii> card;
	for(int i = 0 ; i < CARDS ; i++)
		for(int j = 1 ; j <= 13 ; j++)
			card.insert(mp(i, j));
	int n, v;
	char c;
	for(cin >> n ; n-- ; ){
		cin >> c >> v;
		for(int i = 0 ; i < CARDS ; i++)
			if(type[ i ] == c){
				card.erase(mp(i, v));
				break;
			}
	}
	for(auto x : card)
		cout << type[ x.F ] << ' ' << x.S << endl;
	return 0;
}


Measured memory_bytes: 3168
#include <stdio.h>

int main(void)
{
	char str[20];
	int i, j = 0;
	
	for (i = 0; i < 20; i++){
		str[i] = 0;
	}
	scanf("%s", str);
	
	while (str[j] != '\0'){
		j++;
	}
	j--;
	while (j >= 0){
		printf("%c", str[j]);
		j--;
	}
	
	printf("\n");
	
	return (0);
}

Measured memory_bytes: 524
#include <iostream>
#include <cstdio>

using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int dp[10+5][331+5][(1<<10)+5];

int calc(int n, int s, int a) {
	if(s > 330 || s < 0) return 0;
	if(dp[n][s][a] >= 0) return dp[n][s][a];
	if(n == 1) {
		if(s < 10 && a>>s&1) return	dp[n][s][a] = 1;
		else return dp[n][s][a] = 0;
	}
	int ret = 0;
	rep(i,10) {
		if(a>>i&1) ret += calc(n-1,s-n*i,a-(1<<i));
	}
	return dp[n][s][a] = ret;
}

int main() {
	rep(i,10+5) {
		rep(j,331+5) {
			rep(k,(1<<10)+5) {
				if(i == 0) dp[i][j][k] = 0;
				else dp[i][j][k] = -1;
			}
		}
	}
	int n, s;
	while(cin >> n){
		cin >> s;
		int ans;
		ans = calc(n,s,(1<<10)-1);
		cout << ans << endl;
	}
	return 0;
}

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


int main() {
	int n,m;
	cin>>n>>m;
	
	int a[n];
	int sum=0;
	
	for(int i =0;i<m;i++)
	{
	    cin>>a[i];
	    sum=sum+a[i];
	}
	
	if(n-sum>=0)
	cout<<n-sum;
	else
	cout<<-1;
}

Measured memory_bytes: 3640
#include<algorithm>
#include<cstdio>
#define mxn 1000010
#define pii pair<int,int> 
#define fr first
#define sc second
#define mp make_pair
using namespace std;
const int mod=1e9+7;
int n,m,sl,fh,tot,cnt,ans,a[mxn],b[mxn],c[mxn],tr[mxn];
pii s[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void add(int &x,int y) {x+=y; if(x>=mod) x-=mod;}
void upd(int i,int x) {for(;i<=tot;i+=(i&-i)) add(tr[i],x);}
int qry(int i) {int res=0; for(;i;i-=(i&-i)) add(res,tr[i]); return res;}
int main()
{
	n=rd();m=rd();
	for(int i=1;i<=n;++i) a[i]=rd();
	for(int i=1;i<=m;++i) b[i]=rd();
	for(int p,i=1;i<=n;++i)
	{
		p=lower_bound(b+1,b+m+1,a[i])-b;
		if(1<p&&p<=m) ++cnt,s[cnt]=mp(a[i]-b[p-1],-(c[cnt]=b[p]-a[i]));
	}
	sort(c+1,c+cnt+1);tot=unique(c+1,c+cnt+1)-c-1;
	sort(s+1,s+cnt+1);cnt=unique(s+1,s+cnt+1)-s-1;
	int res;ans=1;
	for(int i=1;i<=cnt;++i)
	{
		s[i].sc=lower_bound(c+1,c+tot+1,-s[i].sc)-c;
		res=qry(s[i].sc-1)+1;
		add(ans,res);upd(s[i].sc,res);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long tmp=0;
    cin >> n;
    vector<int> a(n+2), t(n+2);
    for (int i=1; i<=n; i++)
        cin >> a[i];
    for (int i=0; i<=n+1; i++) {
        t[i] = abs(a[i-1] - a[i]);
        tmp += t[i];
    }
    for (int i=1; i<=n; i++)
        cout << tmp - t[i] - t[i+1] + abs(a[i-1] - a[i+1]) << endl;
}

Measured memory_bytes: 2048
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
char s[MAXN];
pair<int,int> l[MAXN];
int cnt;
void add_edge(int u,int v){
	l[++cnt]=make_pair(u,v);	
}
int main(){
	SF("%s",s);
	int n=strlen(s);
	if(s[n-1]=='1'||s[0]=='0'){
		PF("-1\n");
		return 0;	
	}
	for(int i=0;i<n-1;i++)
		if(s[i]!=s[n-i-2]){
			PF("-1\n");
			return 0;
		}
	int las=2;
	add_edge(1,2);
	for(int i=1;i<n-1;i++){
		add_edge(las,i+2);
		if(s[i]=='1')
			las=i+2;
	}
	for(int i=1;i<n;i++)
		PF("%d %d\n",l[i].first,l[i].second);
}

Measured memory_bytes: 2176
using namespace std;
#include <bits/stdc++.h>
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b==c+d)std::cout << "Balanced" << std::endl;
    else if(a+b<c+d)std::cout << "Right" << std::endl;
    else std::cout << "Left" << std::endl;
}

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

using namespace std;
#define int long long

const int INF = 200000000007;



const int MAX = 510000;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    COMinit();
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    
    a=(a*inv[(100-c)%MOD])%MOD;
    b=(b*inv[(100-c)%MOD])%MOD;

    int ax=1,bx=1;
    for(int i=0;i<n;i++)ax=(ax*a)%MOD;
    for(int i=0;i<n;i++)bx=(bx*b)%MOD;
    int ans=0,t,bc=1,ac=1,s;
    for(int q=0;q<n;q++){
        t=0;s=1;
         
      t=((((((n+q)*COM(n+q-1,n-1))%MOD)*ax)%MOD)*bc)%MOD;
 
        ans=(ans+t)%MOD;
        bc=(bc*b)%MOD;
    }
    
    for(int q=0;q<n;q++){
        t=0;s=1;
      
            t=((((((n+q)*COM(n+q-1,n-1))%MOD)*bx)%MOD)*ac)%MOD;
        ans=(ans+t)%MOD;
       
      ac=(ac*a)%MOD;
    }
   
    cout<<(((ans*100)%MOD)*inv[100-c])%MOD;
    
    return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
int n;
int A[100010],B[100010];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<=n;++i) read(A[i],B[i]);
  LL res=0;
  for(int i=n;i;--i) {
    LL t=A[i]+res;
    res+=(B[i]-t%B[i])%B[i];
  }
  printf("%lld\n",res);
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string[] S = Console.ReadLine().Split();

            int[] L = new int[S.Length];

            for (int i = 0; i < S.Length; i++)
            {
                L[i] = int.Parse(S[i]);
            }

            int count = 0;

            for(int i = 0; i < S.Length; i++)
            {
                for(int j = 0; j < S.Length; j++)
                {
                    for(int k = 0; k < S.Length; k++)
                    {
                        if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i])
                        {
                            int[] triangle = { L[i], L[j], L[k] };

                            if(triangle.Max() == L[i] && L[i] < L[j] + L[k])
                            {
                                count++;
                            }
                            else if (triangle.Max() == L[j] && L[j] < L[i] + L[k])
                            {
                                count++;
                            }
                            else if (triangle.Max() == L[k] && L[k] < L[i] + L[j])
                            {
                                count++;
                            }
                        }
                    }
                }
            }

            Console.WriteLine(count / 6);
        }
    }
}

Measured memory_bytes: 46616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

ll i,j,k;
struct UnionFind{
    vector<long long> par,height,size;
    UnionFind(ll N): par(N),height(N),size(N){
        for(ll i=0;i<N;i++){
            par.at(i)=i;
            height.at(i)=1;
            size.at(i)=1;
        }
    }

    ll root(ll x){
        if(par.at(x)==x)return x;
        return root(par.at(x));
    }

    void unite(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        if(rx!=ry){
            if(height.at(rx)<height.at(ry)) swap(rx,ry);
            size.at(rx)+=size.at(ry);
            height.at(rx)=max(height.at(ry)+1,height.at(rx));
            par.at(ry)=rx;
        }
    }

    bool same(ll x,ll y){
        if(root(x)==root(y))return true;
        else return false;
    }
    
};




int main(){
   ll N,M;
   cin>>N>>M;
   V A(M),B(M);
   rep(i,M)cin>>A[i]>>B[i];
   ll ans=N*(N-1)/2;

   V kot(M);
   kot[M-1]=ans;
   UnionFind bridge(N);

   for(ll cnt=M-1;cnt>=1;cnt--){
      ll a=bridge.size[bridge.root(A[cnt]-1)];
      ll b=bridge.size[bridge.root(B[cnt]-1)];
      bool jud=bridge.root(A[cnt]-1)==bridge.root(B[cnt]-1);
      ans+=a*(a-1)/2+b*(b-1)/2;
      bridge.unite(A[cnt]-1,B[cnt]-1);
      ll c=bridge.size[bridge.root(A[cnt]-1)];
      ans-=c*(c-1)/2;
      if(jud)ans-=c*(c-1)/2;
      kot[cnt-1]=ans;
    }

    rep(i,M)cout<<kot[i]<<endl;

}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define INF (ll)1e18
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
    	string str;
    	cin>>str;
    	ll cnt = 0;
    	rep(i, 3)	{if(str[i] == 'A') cnt++;}

    	if(cnt == 0 || cnt == 3)	cout<<"No";
    	else cout<<"Yes";
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    int i, j;
    int v;
    int array[105];

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> array[i];
    }
    for(j = 0; j < n-1; j++){
        cout << array[j] << " ";
    }
    cout << array[n-1] << endl;

    //?????\?????????
    for(i = 1; i < n; i++){
        v = array[i];
        for(j = i - 1; j >= 0; j--){
            if(v >= array[j]){
                array[j+1] = v;
                break;
            }else{
                array[j+1] = array[j];
                if(j == 0){
                    array[0] = v;
                    break;
                }
            }
        }
        for(j = 0; j < n-1; j++){
            cout << array[j] << " ";
        }    
        cout << array[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int read()
{
	int x = 0, 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();
	}
	return x * f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	int a = read(), b = read();
	int x = a + b, y = a - b, z = a * b;
	int ans = max(x, y);
	ans = max(ans, z);
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
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();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

//repetition//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0)break;
		int p1=0, p2=0;
		REP(i, n){
			int t1, t2;
			cin >> t1 >> t2;
			if(t1 > t2)p1+=t1+t2;
			if(t1 < t2)p2+=t1+t2;
			if(t1 == t2){
				p1 += t1;
				p2 += t2;
			}
		}
		cout << p1 << " " << p2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

using ll = long long;

using namespace std;

const int MAX = 1005;
char sl[MAX][MAX];

const int mod = 1e9 + 7;

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<vector<ll> > dp(h, vector<ll>(w));
    
    for (int i=0; i<h; i++) {
        string s;
        cin >> s;
        for (int j=0; j<w; j++) {
            sl[i][j] = s[j];
        }
    }
    
    dp[0][0] = 1;
    for (int i=1; i<w; i++) {
        if (sl[0][i] == '.') {
            dp[0][i] = dp[0][i-1];
        } else {
            dp[0][i] = 0;
        }
    }
    
    for (int i=1; i<h; i++) {
        if (sl[i][0] == '.') {
            dp[i][0] = dp[i-1][0];
        } else {
            dp[i][0] = 0;
        }
    }
    
    for (int row=1; row<h; row++) {
        for (int col=1; col<w; col++) {
            if (sl[row][col] == '.') {
                dp[row][col] = dp[row-1][col] + dp[row][col-1];
                if (dp[row][col] >= mod) {
                    dp[row][col] -= mod;
                }
//                cout << dp[row][col] << "\n";
            }
        }
    }
    
    cout << dp[h-1][w-1] << "\n";
//    for (int i=0; i<h; i++) {
//        for (auto j : dp[i]) {
//            cout << j << " ";
//        }
//    }
    
    
    return 0;
}




Measured memory_bytes: 9088
N = int(input())
while N != 0:
        total = 0
        minimam = 1000
        maximam = 0
        for _ in range(N):
                s = int(input())
                total += s
                minimam = min(minimam, s)
                maximam = max(maximam, s)
        print(int((total-minimam-maximam)/(N-2)))
        N = int(input())


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

char s[maxn];
int Q;
deque<char>dq;

int main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(register int i=1;i<=len;i++){
		dq.push_back(s[i]);
	}
	cin>>Q;
	int cnt=0;
	while(Q--){
		int T;
		cin>>T;
		if(T==1){
			cnt++;
			// reverse(dq.begin(),dq.end());
		}else{
			int F;
			char C;
			cin>>F>>C;
			if(F==1){
				if(cnt%2) dq.push_back(C);
				else dq.push_front(C);
			}else{
				if(cnt%2==0) dq.push_back(C);
				else dq.push_front(C);
			}
		}
	}
	if(cnt%2) reverse(dq.begin(),dq.end());
	for(auto i=dq.begin();i!=dq.end();i++){
		printf("%c",*i);
	}
	return 0;
}


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

int main()
{
  map<char ,int> count;
  char str[4];
  cin >> str;
  string res = "Yes";
  for(int i = 0; i < 4; i++) {
    count[str[i]]++;
  }
  for(auto itr = count.begin(); itr != count.end(); itr++) {
    if(itr->second != 2)
    {
      res = "No";
      break;
    }
  }
  cout << res << endl;
  return 0;
}

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

int main() {
	long n;

	cin >> n;

	long l = 0, r = 0;

	for (long i = 0; i < n; i++) {
		long ll,rr;
		cin >> ll >> rr;
		if (ll >= l && rr >= r) {
			l = ll;
			r = rr;
		} else {
			long ml = 1;
			long mr = 1;
			long m = 1;
			if (ll >= l && rr <= r) {
				m = (r - 1) / rr + 1;
			} else if (rr >= r && ll <= l) {
				m = (l - 1) / ll + 1;
			} else if (rr < r && ll < l) {
				long mr = (r - 1) / rr + 1;
				long ml = (l - 1) / ll + 1;
				m = max(mr,ml);
			}
			l = ll * m;
			r = rr * m;

		}
	}

	cout << l + r << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
	int i,j,k,a,b,sum=0;
	cin>>a>>b;
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=a;j++)
		{
			k=b-i-j;
			if(k<=a&&k>=0) sum++;
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
N = int(input())

res = 0
BxA = 0
xxA = 0
Bxx = 0

for _ in range(N):
    s = list(input())
    for i in range(len(s) - 1):
        if s[i] + s[i + 1] == "AB":
            res += 1
    if s[0] == "B" and s[-1] == "A":
        BxA += 1
    elif s[0] == "B":
        Bxx += 1
    elif s[-1] == "A":
        xxA += 1

res_2 = 0
if xxA == 0 and Bxx == 0 and BxA != 0:
    res_2 = BxA - 1
else:
    res_2 = min(BxA + xxA, Bxx + BxA)

print(res + res_2)

Measured memory_bytes: 50408
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    string N, K;
    scan(N, K);
    auto D = aryread();
    uint ng;
    foreach (d; D)
        ng = ng | (1 << d);
    // writefln("%010b", ng);
    // foreach (i; 0 .. 10)
    // {
    //     writeln(!(ng & (1 << i)));
    // }
    auto dp = new long[][](2, N.length + 1);
    dp[0][] = 10 ^^ 9;
    dp[1][] = 10 ^^ 9;
    dp[0][0] = 0;
    foreach (i; 1 .. 10)
        if (!(ng & (1 << i)))
        {
            dp[1][0] = i;
            break;
        }
    foreach (i; 0 .. N.length)
    {
        if (!(ng & (1 << (N[i] - '0'))))
        {
            dp[0][i + 1] = dp[0][i + 1].min(dp[0][i] * 10 + (N[i] - '0'));
        }
        foreach (j; 0 .. 10)
            if (!(ng & (1 << j)))
            {
                dp[1][i + 1] = dp[1][i + 1].min(dp[1][i] * 10 + j);
                if (N[i] - '0' < j)
                    dp[1][i + 1] = dp[1][i + 1].min(dp[0][i] * 10 + j);
            }
    }
    // writeln(dp[0]);
    // writeln(dp[1]);
    writeln(min(dp[0][$ - 1], dp[1][$ - 1]));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int a, b;
    cin >> a >> b;
    for(int i=1; i<=100000; i++)
    {
        double tmp = i * 1.0;
        double i1 = tmp * 0.08;
        int ii1 = (int)i1;
        // cout << ii1 << endl;
        double i2 = tmp * 0.1;
        int ii2 = (int)i2;
        // cout << ii2 << endl;
        if(ii1 == a && ii2 == b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int join_count=0;
  int outside_rate;
  int inside_rate;
  cin >> join_count >> outside_rate;


  if(10 <=  join_count){
	inside_rate = outside_rate;
  }
  else{
	//outside_rate = inside_rate - 100 * (10 - join_count);
	inside_rate = outside_rate + 100 * (10 - join_count);
  }
  cout << inside_rate << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> num(3);
  cin >> num.at(0) >> num.at(1) >> num.at(2);
  sort(num.begin(), num.end());
  cout << num.at(0) << " " << num.at(1) << " " << num.at(2) << endl;
}



Measured memory_bytes: 3144
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    ll N, M;
    scanf("%lld %lld", &N, &M);
    if(M >= N){
        printf("unsafe\n");
    }else{
        printf("safe\n");
    }
    // double ans = ((double)N * 2.) * acos(-1);

    // cout << ans << endl;
    // printf("%lf\n", ans);

    return 0;

}

Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;



namespace free
{
    class Program
    {
        static void Main(string[] args)
        {

            Stopwatch sw = new Stopwatch();

            while (true)
            {
                string[] line = Console.ReadLine().Split(' ');
                int R = int.Parse(line[0]);
                if (R == 0) break;
                int C = int.Parse(line[1]);

                int[][] cell = new int[R][];
                int[][] cell_R = new int[R][];
                int[][] cell_temp = new int[R][];
                var T = new int[][][] { cell, cell_R };
                for (int i = 0; i < R; i++)
                {
                    cell[i] = new int[C];
                    cell_R[i] = new int[C];
                    cell_temp[i] = new int[C];
                }
                for (int i = 0; i < R; i++)
                {
                    string[] l = Console.ReadLine().Trim().Split(' ');

                    var values = Array.ConvertAll(l, int.Parse);

                    for (int j = 0; j < C; j++)
                    {
                        cell[i][j] = values[j];
                        cell_R[i][j] = values[j] ^ 1;
                    }
                }

                int num = 1;
                for (int i = 0; i < R; i++)
                {
                    num *= 2;
                }

                int ans = 0;
                for (int k = 0; k < num; k++)
                {
                    int[] array = new int[R];
                    for (int t = 0; t < k; t++)
                    {
                        for (int i = 0; i < R; i++)
                        {
                            array[i] = (1 & (t >> i)) == 1 ? 1 : 0;
                        }
                    }
                    for (int i = 0; i < R; i++)
                    {
                        for (int j = 0; j < C; j++)
                        {
                            cell_temp[i][j] = T[array[i]][i][j];
                        }
                    }
                    int sum_cnt_max = 0;
                    for (int i = 0; i < C; i++)
                    {
                        int cnt0 = cell_temp.Select(x => x[i]).Count(y => y == 0);
                        sum_cnt_max += new int[] { cnt0, R - cnt0 }.Max();
                    }

                    ans = new int[] { sum_cnt_max, ans }.Max();
                }

                Console.WriteLine(ans);
            }

        }
    }
}



Measured memory_bytes: 29924
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int N;
	int X;
	cin >> N;
	vector<int>A(N+1); 
	
	for(int i = 1;i<=N;i++){
		cin >> X; 
		A[X] = i; 
	}
	
	for(int i = 1;i<=N;i++){
		cout << A[i] <<  std::endl; 
	}	
	return 0;
}


Measured memory_bytes: 1152