akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoder
{
    public static void Main()
    {
        //入力を保持する
        var N = int.Parse(Console.ReadLine());
        var As = Console.ReadLine().Split().Select(e => ulong.Parse(e)).ToArray() ;
        //Array.Sort(As);
        foreach (var a in As)
        { 
            if (a == 0)
            {
                Console.WriteLine(0);
                return;
            }
        }
        ulong ans = 1;
        for (   int i = 0; i < N; i++)
        {
            ulong work = ans * As[i];
            if ((work > 1000000000000000000)|| (work < ans))
            {
                Console.WriteLine(-1);
                return;
            }
            ans = ans * As[i];
        }        
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 41624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N, T, A;
    cin >> N >> T >> A;
    map<double, int> diff2IndexMap;
    for (int i = 0; i < N; ++i)
    {
        double Hi;
        cin >> Hi;
        double temp = static_cast<double>(T)-0.006 * Hi;
        diff2IndexMap[abs(temp - A)] = i + 1;
    }
    cout << diff2IndexMap.begin()->second << endl;
}

Measured memory_bytes: 256
import numpy as np
def resolve():
    s = [int(num) for num in input()]

    ten = 1
    num = 0
    mod_table = np.zeros(shape=2019, dtype=int)

    for i in range(len(s)):
        num += s[len(s) - i - 1] * ten
        num %= 2019
        mod_table[num] += 1
        ten = (ten * 10) % 2019

    ans = sum((mod_table * (mod_table - 1)) // 2)
    ans += mod_table[0]
    print(ans)
    
resolve()

Measured memory_bytes: 28644
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, z, w; cin >> n >> z >> w;
	int a1, a2, a;
	if (n == 1) {
		cin >> a; 
		cout << abs(w - a) << endl;
		return 0;
	}
	for (int i = 0; i < n - 2; ++i) cin >> a;
	cin >> a1 >> a2;
	cout << max(abs(w - a2), abs(a1 - a2)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>

int64_t getMinNum(const std::vector<int64_t> &v, const int64_t k) {
  const auto min_it = std::min_element(v.begin(), v.end());
  const auto min_pos = static_cast<int>(min_it - v.begin());
  int64_t total = 0;
  total = min_pos / (k - 1);
  const int64_t mod = min_pos % (k - 1);
  const int64_t current_pos = min_pos - mod;
  const int64_t last_pos = static_cast<int>(v.size()) - 1;
  total += (last_pos - current_pos) / (k - 1);
  if ((last_pos - current_pos) % (k - 1) != 0) {
    ++total;
  }
  return total;
}

int main() {
  int64_t n,k;
  std::cin >>n >> k;
  std::vector<int64_t> v(n);
  for (int64_t i = 0; i < n; ++i) {
    std::cin >> v[i];
  }
  std::cout << getMinNum(v, k) << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,n=0;
    
    scanf("%d",&n);
    for(i=1; i<=n; i++){
        if(i%3==0){
            printf(" %d",i);
        }
        else if(i%10==3 || i/10%10==3 || i/10/10%10==3 || i/100==3 || i/1000==3){
            printf(" %d",i);
        }
//        else if(i==n && i%3==0){
//            printf("%d",i);
//        }else if(i%10==3 && i==n){
//            printf("%d",i);
//        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  V<pair<i64, i64>> points(n);
  V<i64> xs(n), ys(n);
  REP(i, n) {
    cin >> xs[i] >> ys[i];
    points[i] = {xs[i], ys[i]};
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  V<V<i64>> cum(n + 1, V<i64>(n + 1));
  for (auto [x, y] : points) {
    int xi = lower_bound(xs.begin(), xs.end(), x) - xs.begin();
    int yi = lower_bound(ys.begin(), ys.end(), y) - ys.begin();
    cum[xi + 1][yi + 1] += 1;
  }

  REP(i, n) cum[0][i + 1] += cum[0][i];
  REP(i, n) cum[i + 1][0] += cum[i][0];
  REP(i, n) {
    REP(j, n) {
      cum[i + 1][j + 1] += cum[i][j + 1] + cum[i + 1][j] - cum[i][j];
    }
  }

  REP(i, n + 1) {
    REP(j, n + 1) { cerr << (cum[i][j]) << ' '; }
    cerr << endl;
  }

  u64 ans = 1LL << 63;
  REP(i, n) REP(i1, i) REP(j, n) REP(j1, j) {
    i64 s = cum[i + 1][j + 1] - cum[i + 1][j1] - cum[i1][j + 1] + cum[i1][j1];
    u64 area = (xs[i] - xs[i1]) * (ys[j] - ys[j1]);
    DEBUG(s, area);
    if (s >= k) {
      ans = min(ans, area);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

using namespace std;

using Graph = vector<vector<int>>;

int main(int argc, char* argv[]){
	int N;
	unsigned long long K;

	cin >> N >> K;

	Graph G(N+1);

	int loopp = 0;
	int loopc = 0;
	for(int i=1; i<=N; i++){
		int a;
		cin >> a;
		G[i].push_back(a);
	}

	if(G[1][0]==1){
		printf("%d\n", 1);
		return 0;
	}
	if(K==1){
		printf("%d\n", G[1][0]);
		return 0;
	}

	unordered_map<int, int> mp;
	int from=1, to=1;
	mp.insert({from, 0});
	int pos = 0;
	while(true){
		to = G[from][0];
		pos++;
		if(mp.count(to)){
			loopp = to;
			break;
		}
		else{
			mp.insert({to, 0});
		}
		from = to;
	}

	from=1, to=1;
	int init = 0;
	while(true){
		to = G[from][0];
		init++;
		if(to == loopp){
			if(init==1){ init = 0;}
			break;
		}
		from = to;
	}
	if(pos==init){
		loopc = init;
		init = 0;
	}
	else{
		loopc = pos - init;
	}

	if(K<=init){
		from=1, to=1;
		for(int i=0; i<K; i++){
			to = G[from][0];
			from = to;
		}
		printf("%d\n", to);
		return 0;
	}

	unsigned long long r = (K-init)%loopc;
	from=loopp, to=loopp;
	for(int i=0; i<r; i++){
		to = G[from][0];
		from = to;
	}
	printf("%d\n", to);
	return 0;
}

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

namespace AtCoder.Abc
{
    class QuestionG2
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int num_N = int.Parse(Console.ReadLine());

            var num_Sum = Sum(num_N) - Sum(num_N / 3) * 3 - Sum(num_N / 5) * 5 + Sum(num_N / 15) * 15;

            Console.WriteLine(num_Sum);

            Console.Out.Flush();
        }

        public static long Sum(long N)
        {
            long NN = N * (N + 1) / 2;
            return NN;
        }
    }
}


Measured memory_bytes: 27412
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	var N, K int
	if scanner.Scan() {
		str := scanner.Text()
		//cols := strings.Split(str, " ")
		N, _ = strconv.Atoi(str)
	}
	if scanner.Scan() {
		str := scanner.Text()
		K, _ = strconv.Atoi(str)
	}
	x := make([]int, N)
	if scanner.Scan() {
		str := scanner.Text()
		cols := strings.Split(str, " ")
		for i := 0; i < N; i++ {
			p, _ := strconv.Atoi(cols[i])
			x[i] = p
		}

	}
	var sum int
	for i := 0; i < N; i++ {
		sum += min(x[i], K-x[i])
	}

	fmt.Fprintln(wtr, sum*2)
	_ = wtr.Flush()
}

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

func min(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 640
n=int(input())
t,a= map(int, input().split())
h= list(map(int, input().split()))
ans=[abs(a-t+h[0]*0.006),0]
for i in range(1,n):
    if abs(a-t+h[i]*0.006)<ans[0]:
        ans[1]=i
        ans[0]=abs(a-t+h[i]*0.006)
print(ans[1]+1)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int m;
	scanf ("%d", &m );
	while (m-- ){
		int cash; scanf ("%d", &cash );
		int year; scanf ("%d", &year );
		int kind; scanf ("%d", &kind );
		int res = 0;
		rep (i, kind ){
			int ss; double rate; int fee; scanf ("%d %lf %d", &ss, &rate, &fee );
			int sum1 = cash, sum2 = 0;
			rep (j, year ){
				double tmp = (double)sum1*rate;
				if (ss == 0 ){	// 単利
					sum2 += (int)tmp;
					sum1 -= fee;
				}else{			// 複利
					sum1 += (int)tmp;
					sum1 -= fee;
				} // end if
			} // end rep
			if (res < sum1 + sum2 ){
				res = sum1 + sum2;
			} // end if
		} // end rep
		printf ("%d\n", res );		
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b; cin >> a >> b;
    cout << "a ";
    cout << (a == b ? "==" : (a > b ? ">" : "<")) << " b" << endl;
    
}





Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include<algorithm>
#include <set>
#include <stack>
#include <cmath>
#include <stdlib.h>
#include <functional>
using namespace std;
int main()
{
    int n,arr[100]={0};
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    long long small,t=1000;
    small=arr[0];
    for(int i=0;i<n;i++)
    {
        long long q=0;
        if(arr[i]>small)
        {
            q=t/small;
            t-=q*small;
            t+=q*arr[i];
            small=arr[i];
        }
        else if(arr[i]<small)
        {
            small=arr[i];
        }
    }
    printf("%lld",t);
    return 0;
}

Measured memory_bytes: 3768
[X,Y,A,B,C] = list(map(int,input().split()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)

S = P[0:X]+Q[0:Y]+R
S.sort(reverse=True)

print(sum(S[0:(X+Y)]))

Measured memory_bytes: 111784
n = int(input())
sps = []
for i in range(n):
	s, p = [j for j in input().split()]
	sps.append(([s, p], i + 1))
    
sps = sorted(sps, key = lambda x: int(x[0][1]), reverse=True)
sps = sorted(sps, key = lambda x: x[0][0])
for sp in sps:
	print (sp[1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

void Add(ll &a, ll b){
    a=(a+b)%mod;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%mod;
    return;
}

int main(){
    ll D,T,S; cin>>D>>T>>S;
    if(D<=S*T) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+1;
const int INF=1e9+7;
ll a[maxn];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    ll ans=1e18;
    ll sum=0;
    ll secsum=0;
    for(int i=1; i<=n; ++i){
        cin>>a[i];
        secsum+=a[i];
    }

    for(int i=1; i<n; ++i){
        secsum-=a[i];
        sum+=a[i];
        ans=min(ans,abs(sum-secsum));
    }
    cout<<ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
    string s, t;
    cin >> s >> t;
    cout << (t + s) << endl;

    return 0;
}

Measured memory_bytes: 256
import copy

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

a=copy.copy(A)
A.sort()
dic={}
for i in range(0,N):
    dic[a[i]]=0
    dic[a[i]]=i

ans=0
for i in range(0,N):
    if i%2==1:
        if dic[A[i]]%2==0:
            ans+=1

print(ans)

Measured memory_bytes: 62808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int n, m, sum = 0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }

  int b = (sum+4*m-1)/(4*m);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  if(a[m-1] < b) cout << "No" << endl;
  else cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

int main(){
  ll a,b;
  cin >> a >> b;
  ll ans;
  if(a%2==0 && b%2==0){
    if((b-a)/2%2)ans=1^b;
    else ans=b;
  }else if(a%2==0 && b%2==1){
    if((b+1-a)/2%2)ans=1;
    else ans=0;
  }else if(a%2==1 && b%2==0){
    if((b-a)/2%2)ans=a^1^b;
    else ans=a^0^b;
  }else if(a%2==1 && b%2==1){
    if((b-a)/2%2)ans=1^a;
    else ans=0^a;
  }

  if(a==b)ans=a;
  if(b==a+1)ans=a^b;
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  int sum;
  
  if(a+b>=24){
    sum=a+b-24;
  }
  else{
    sum=a+b;
  }
  
  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 128
w,h,n = map(int, input().split())
l,r,d,u = (0,w,0,h)
for i in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    l = max(l,x)
  elif a == 2:
    r = min(r,x)
  elif a == 3:
    d = max(d,y)
  else:
    u = min(u,y)
print((r-l)*(u-d) if r>l and u>d else 0)

Measured memory_bytes: 9088
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int k;

	void run(){
		int n=17;
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=(i+1)*(i+1);
		}
		int max=300;
		int[] dp=new int[max];
		dp[0]=1;
		for(int j=0; j<n; j++){
			for(int i=a[j]; i<max; i++){
				dp[i]+=dp[i-a[j]];
			}
		}
		for(;;){
			k=sc.nextInt();
			if(k==0){
				break;
			}
			println(""+dp[k]);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 11000
import java.util.*;

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

    int n = sc.nextInt();
    int[] a = new int[n];
    int[] c = new int[n-1];
    int ans = 0;

    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    for(int i = 0; i < n; i++){
      ans += sc.nextInt();
    }

    for(int i = 0; i < n - 1; i++){
      c[i] = sc.nextInt();
    }

    for(int i = 0; i < n - 1; i++){
      if(a[i] + 1 == a[i + 1]){
        ans += c[a[i] - 1];
      }
    }

    System.out.println(ans);
  }
}


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

#define thegamebegins   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fileio          freopen('input.txt', 'r', stdin); freopen('output.txt', 'w', stdout);
#define int             long long
#define float           long double
#define test            int T; cin>>T; for(int i=1; i<=T; ++i)
#define in(a,n)         for(int i=0; i<(n); ++i)  cin>>a[i]
#define r0              return 0
#define E               '\n'
#define S               ' '
#define elif            else if 
#define M               1000000007
#define fi(i,x,y)       for(int i=(x); i<(y); ++i)
#define fb(i,x,y)       for(int i=(x); i>=(y); --i)
#define fa(i,s)         for(auto i:(s))
#define fp(i,s)         for(auto i=(s).begin(); i!=(s).end(); ++i)
#define pf(i,s)         for(auto i=(s).rbegin(); i!=(s).rend(); ++i)
#define all(s)          (s).begin(), (s).end()
#define rev(s)          (s).rbegin(), (s).rend()
#define sz(s)           (int)(s).size()
#define vi              vector <int>
#define vpii            vector <pair <int,int> >
#define mii             map <int,int>
#define pii             pair <int,int>
#define seti            set <int>
#define setd            set <int,greater <int> >
#define sortd(a,n)      sort(a, a+n, greater<int>())
#define pb              push_back
#define fr              first
#define sc              second
#define lb              lower_bound
#define ub              upper_bound
#define er              equal_range
 
const int INF = 0x3f3f3f3f;

signed main()
{
    thegamebegins

    int x;	cin>>x;
    int i=0, sum=100;
    while(sum<x)
    {
    	++i;
    	sum+=(sum/100);
    }
    cout<<i;
    r0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int a,b; cin>>a>>b;
	int ans=0;
	if(a>=b){
		ans+=a;
		--a;
	}
	else {
		ans+=b;
		--b;
	}
	if(a>=b){
		ans+=a;
		--a;
	}
	else {
		ans+=b;
		--b;
	}
	cout<<ans<<endl;
	
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    string w, t;
    cin >> w;

    int count = 0;

    while (cin >> t)
    {

        if (t == "END_OF_TEXT")
        {
            break;
        }
        rep(i, t.size())
        {
            t.at(i) = tolower(t.at(i));
        }
        if (t == w)
        {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3184
s = input()
f = True
odd = ['R','U','D']
even = ['L','U','D']
for i in range(len(s)):
  if i%2==0:
    if s[i] not in odd:
      f = False
      break
  else:
    if s[i] not in even:
      f = False
      break
if f: print('Yes')
else: print('No')

Measured memory_bytes: 3064
# N = input()   # 単純な入力
# input = list(input()) # ひとかたまりの文字列をリスト化
# N = int(input())  # 整数一つ
# input = input().split()   # スペース区切りを文字としてリスト化
X,Y,Z = map(int,input().split())  # ２個や３個の整数をそれぞれ取得
# input = list(map(int,input().split())) #整数リストの取得
print(int(X*Y/2))

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

//temmplate------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define ZERO(a) memset(a, 0, sizeof(a))
typedef long long lint;
//------template

int main(){
    int N;
    int K;
    cin >> N >> K;
    vector<lint> H;
    REP(i,N){
        lint h;
        cin >> h;
        H.push_back(h);
    }
    sort(all(H));
    lint count = 0;
    if (N <= K){
        count = 0;
    } else {
        REP(i,K){
            H.pop_back();
        }
        count = accumulate(H.begin(), H.end(), 0LL);
    }
    cout << count << "\n";
}

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


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


int main(){
    #ifdef LOCAL_MACHINE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    
    int n,w;
    scanf("%d %d",&n,&w);

    long long dp[(int)1e5+5];
    memset(dp,0x0F,sizeof(dp));

    dp[0]=0;
    for(int i=0;i<n;i++){
        int wt,vl;
        scanf("%d %d",&wt,&vl);

        for(int j=(int)1e5;j>=vl;j--)dp[j]=min(dp[j],dp[j-vl]+wt);
    }   
    
    int ans=0;
    for(int i=0;i<=(int)1e5;i++){
        if(dp[i] && dp[i]<=w){
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
# C
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
l = [list(map(int, input().split())) for i in range(q)]
# print(l)
l.sort(key=lambda x: x[3], reverse=True)
# 順列A全捜索
# 1~mまでの値を持った長さnの順列を i に出力する。
# >>combinations_with_replacement()
# print(combinations_with_replacement(range(1, m + 1), n))

ans = 0
for i in combinations_with_replacement(range(1, m + 1), n):
    # print(i)
    t = 0
    #列を出力
    for a, b, c, d in l:
        # print(a, b, c, d)
        #条件が合うなら +d
        if i[b - 1] - i[a - 1] == c:
            t += d
    # ansが大きい値を出力
    ans = max(t, ans)
print(ans)


Measured memory_bytes: 9024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int hi = 0;
		int[] x = new int[n], y = new int[n], h = new int[n];
		for ( int i = 0; i < n; i++ ) {
			x[i] = in.nextInt();
			y[i] = in.nextInt();
			h[i] = in.nextInt();

			if ( h[i] != 0 ) hi = i;
		}
		in.close();

		for ( int cy = 0; cy <= 100; cy++ ) {
			for ( int cx = 0; cx <= 100; cx++ ) {
				boolean match = true;
				int Height = h[hi] + Math.abs(x[hi] - cx) + Math.abs(y[hi] - cy);

				for ( int i = 0; i < n; i++ ) {
					int tempH = h[i] + Math.abs(x[i] - cx) + Math.abs(y[i] - cy);
					if ( (h[i] != 0 && Height != tempH) || (h[i] == 0 && Height > tempH) ) {
						match = false;
						break;
					}
				}
				if ( match ) {
					System.out.println(cx + " " + cy + " " + Height);
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ld x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    cout << sqrtl((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    n--;
    cout<<n*(n+1)/2<<endl;
    
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int cnt = -1; // 戻ってくる回数
  int last = -1;
  int next = 1;
  rep(i, n) {
    last = next;
    next = a.at(next - 1);
    if (next == 1) {
      cnt = i + 1;
      break;
    }
  }

  // 途中で 1 に戻ってこないようなループがある
  if (cnt == -1) {
//    cout << "last: " << last << endl;
    int cnt2 = 0;
    int toLast = -1;
    int toLast2 = -1;
    int next2 = 1;
    rep(ii, n) {
      cnt2++;
      next2 = a.at(next2 - 1);
      if (next2 == last) {
        if (toLast == -1) {
          toLast = cnt2;
        } else if (toLast2 == -1) {
          toLast2 = cnt2;
          break;
        }
      }
    }
//    cout << "toLast: " << toLast << endl;
//    cout << "toLast2: " << toLast2 << endl;
    if (k < toLast) {
      int res = 1;
      rep(i, k) {
        res = a.at(res - 1);
      }
      cout << res << endl;
      return 0;
    }
    int res = 1;
    ll ddd = (k - toLast) % (toLast2 - toLast);
    rep(i, toLast + ddd) {
      res = a.at(res - 1);
    }
    cout << res << endl;
    return 0;
  }

  int res = 1;
  ll ddd = k % cnt;
  rep(i, ddd) {
    res = a.at(res - 1);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4016
#include<iostream>
using namespace std;
long gcd(long a,long b){return b==0?a:gcd(b,a%b);}
long lcm(long a,long b){return a/gcd(a,b)*b;}
int main(){
long a1,m1,a2,m2,a3,m3,x,y,z,n1,n2,n3;
while(cin>>a1){
cin>>m1>>a2>>m2>>a3>>m3;
if(a1==0)break;
for(n1=1,x=1;;){
x=(a1*x)%m1;
if(x==1)break;
n1++;
}
for(n2=1,y=1;;){
y=(a2*y)%m2;
if(y==1)break;
n2++;
}
for(n3=1,z=1;;){
z=(a3*z)%m3;
if(z==1)break;
n3++;
}
cout<<lcm(lcm(n1,n2),n3)<<endl;
}
return 0;
}

Measured memory_bytes: 1160
/*
  AOJ 
  title:Gossip
  @kankichi57301
 */
#include <stdio.h>
#include <string.h>
#define max(x,y) (((x)>(y))?(x):(y))

int main()
{
  int a,b,m,n, i,ret;

  scanf("%d %d",&n,&m);
  scanf("%d",&a);
  ret=a-1;

  if(m==1)
    ret=max(ret,n-a);
  else
  {
    for(i=2;i<n;i++)
    {
      scanf("%d",&b);
      ret = max(ret,(b-a)/2);
      a=b;
    }
    scanf("%d",&b);
    ret=max(ret,n-b);
  }
  printf("%d\n",ret);
  return(0);
}



Measured memory_bytes: 2112
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int a,b;int c=2019;
	cin>>a>>b;
	if(b/2019!=a/2019){
		cout<<0<<endl;
		return 0;
	}
	a%=2019;b%=2019;
	for(int i=a;i<b;i++)for(int j=i+1;j<=b;j++){
		int d=(i*j)%2019;
		if(c>d)c=d;
	}
	cout<<c<<endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a, b;
  cin >> a >> b;

  if(a > b){
    ll tmp = a;
    a = b;
    b = tmp;
  }
    
  bool sysflag = false;
  ll n = abs(a-b);
  ll ans;
  REP(i, n-1){
    ll k = a+i+1;
    if(abs(a-k) == abs(b-k)){
      ans = k;
      sysflag = true;
    }
  }

  if(sysflag)
    cout << ans << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  
  
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,k,a[N];
int main()
{
    string s,t;cin>>s>>t;int ans=0;for(int i=0;i<s.size();i++) ans+=s[i]!=t[i];cout<<ans;
}



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

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741
const ll MAXN=100005;
ll n,k;
ll dp[MAXN];

const ll mod=1000000007; //change

ll add(ll a,ll b) {
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a,ll b) {
	return ((a%mod)-(b%mod)+mod)%mod;
}
ll mul(ll a,ll b) {
	return ((a%mod)*(b%mod))%mod;
}

ll expo(ll base, ll exponent, ll mod) {
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}

void calc(){
	dp[k]=1;
	repr(i,k,1){
		dp[i]=expo(k/i,n,hell);
		ll temp=0;
		for (ll j=2*i;j<=k;j+=i){
			temp=add(temp,dp[j]);
		}
		dp[i]=sub(dp[i],temp);
	}
}

void solve() {
    cin>>n>>k;
    calc();
    ll ans=0;
    rep(i,1,k+1){
    	ans=add(ans,mul(i,dp[i]));
    }
    cout<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 4432
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Dec  6 23:49:33 2018
//
package main

import "fmt"

func divisors(n int) int {
	ans := 0
	for i := 1; i <= n; i++ {
		if n%i == 0 {
			ans++
		}
	}
	return ans
}

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

	count := 0
	for i := 3; i <= N; i += 2 {
		if divisors(i) == 8 {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;


ll N, L;

vector<ll> a;

int main() {
	ll x;

	cin >> N >> L;
	rep(i, N) {
		cin >> x;
		a.push_back(x);
	}

	bool flag = false;
	ll index = 0;
	rep(i, N - 1) {
		if (a[i] + a[i + 1] >= L) {
			flag = true;
			index = i;
			break;
		}

	}

	if (flag == false) {
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;

	rep(i, index) {

		cout << i+1 << endl;
	}

	for (int i = N - 2; i >= index; i--) {

		cout << i + 1 << endl;
	}



	return 0;
}

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

using namespace std;

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

    for(long long a = -120; a < 120; a++) {
        for(long long b = -120; b < 120; b++) {
            long long res = a * a * a * a * a - b * b * b * b * b;
            if(res == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3628
#include<stdio.h>

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

    int a = n / 100;
    int b = n % 100;

    if(a >= 1 && a <= 12) {
        if(b >= 1 && b <= 12) {
            puts("AMBIGUOUS");
        } else {
            puts("MMYY");
        }
    } else {
        if(b >= 1 && b <= 12) {
            puts("YYMM");
        } else {
            puts("NA");
        }
    }
}

Measured memory_bytes: 128
#include<iostream>

int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    int D,T,S;std::cin >> D >> T >> S;
    std::string ans="Yes";

    if (S*T < D) {
        ans="No";
    }

    std::cout << ans;
    return 0 ;
}



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

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 <iostream>
#include <algorithm>

using namespace std;

void solve() {
    int h,w, n;
    cin >> h >> w;
    cin >> n;
    int grid[h*w];
    int last = 0;
    for (int i=0; i<n; ++i) {
        int ai;
        cin >>ai;
        for (int j = 0; j < ai; ++j) {
            grid[last + j] = i+1;
        }
        last += ai;
    }
    for (int i=0; i<h; ++i) {
        if (i%2 == 0) {
            for (int j=0; j<w; ++j) {
                cout << grid[w*i + j] << " ";
            }
            cout << '\n';
        } else {
            for (int j=w-1; j >=0; --j) {
                cout << grid[w*i +j] << " " ;
            }
            cout << '\n';
        }
    }

}

int main() {

	solve();
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    string s; cin>>s;
    regex bc_to_d("BC");
    regex borc_to_e("B|C");
    s = regex_replace(s,bc_to_d,"d");
    s = regex_replace(s,borc_to_e,"e");
    ll ans = 0, x = 0;
    rep(i,(int)s.size()){
        if(s.at(i) == 'A') x++;
        if(s.at(i) == 'd') ans += x;
        if(s.at(i) == 'e') x = 0;
    }
    cout << ans << endl;
}


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

#define ll long long

using namespace std;

int n, a[104], s[104];
int main() {
    cin >> n;
    for (int i = 0; i < n - 1; ++i)
        cin >> a[i];
    s[0] = s[1] = a[0];
    for (int i = 1; i < n - 1; ++i) {
        s[i + 1] = a[i];
        if (s[i] > a[i])
            s[i] = a[i];
    }

    int sum = 0;
    for (int i = 0; i < n; ++i)
        sum += s[i];
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n,m; cin >> n >> m;
  Graph G(n);
  vector<int> r(n);
  for(int i = 0; i < n+m-1; ++i){
    int u,v; cin >> u >> v;
    --u;--v;
    G[u].push_back(v);
    ++r[v];
  }
  
  queue<pint> q;
  for(int i = 0; i < n; ++i){
    if(r[i]==0)q.push({i,0});
  }
  vector<pint> dp(n, {-1,0});
  while(!q.empty()){
    pint p = q.front();q.pop();
    int u = p.first ;
    int c = p.second;
    if(dp[u].second > c)continue;
    for(int v : G[u]){
      --r[v];
      if(dp[v].second < c+1){
        dp[v]= {u,c+1};
      }
      if(r[v]==0){
        q.push({v, dp[v].second});
      }
    }
  }
  for(int i = 0; i < n; ++i){
    cout << dp[i].first + 1 << endl;
  }
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll x,y;
cin >> x>>y;
if(x==y||abs(x-y)==1)cout << "Brown" << endl;
else cout << "Alice" << endl;

return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
l=gsmi.sort

n.times do |i|
  (i+1).upto(n-2) do |j|
    sum = l[i]+l[j]
    idx = l.bsearch_index{|x|x>=sum}
    idx = n if idx.nil?
    #puts ar.to_s
    cnt+=idx-j-1
  end
end

puts cnt

Measured memory_bytes: 1916
import java.util.*;


public class Main {
	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(System.in);
			while(true){
				int n = sc.nextInt(), m = sc.nextInt();

				if(n==0 && m==0){
					sc.close();
					break;
				}
				
				int[] c = new int[m];
				for (int i=0;i<m;i++){
					c[i] = sc.nextInt();
				}
				
				int[] dp = new int[256];
				Arrays.fill(dp, Integer.MAX_VALUE);
				dp[128] = 0;
				
				for (int i=0;i<n;i++){
					int xx = sc.nextInt();
					int[] dp2 = new int[256];
					Arrays.fill(dp2,Integer.MAX_VALUE);
					for (int j=0;j<256;j++){
						if (dp[j] == Integer.MAX_VALUE){
							continue;
						}
						for (int k=0;k<m;k++){
							int next = j + c[k];
							if (next > 255) {
								next = 255;
							}
							if (next < 0){
								next = 0;
							}
							int x = dp[j] + (next - xx) * (next - xx);
							dp2[next] = Math.min(dp2[next], x);
						}
					}
					dp = dp2;
				}
				
				int min = Integer.MAX_VALUE;
				for (int v : dp) {
					min = Math.min(min,v);
				}
				System.out.println(min);
			}
			sc.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 63244
#include<iostream>
#include<string>
typedef long long ll;
using namespace std;
int main() {
	string S;
	cin >> S;
	ll N = S.size();
	ll x = S[0] - '0' + (N - 1) * 9;
	if (N == 1)cout << S << endl;
	else {
		for (ll i = 1; i < N; i++) {
			if (S[i] != '9')
				x = (N - 1) * 9 + (S[0] - '1');
		}
      cout << x << endl;
	}

}

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

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x)                       (ll) x.size()
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define endl                        '\n'

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 2010;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ld PI = 4 * atan((ld) 1);
ll dp[MAXA][MAXA], A[MAXA], B[MAXA];

int main() {
    fast_io;
    set_random;
    ll n, m;
    cin >> n >> m;
    for (ll i = 1; i <= n; i++) cin >> A[i];
    for (ll i = 1; i <= m; i++) cin >> B[i];
    for (ll i = 0; i < MAXA; i++) {
        dp[i][0] = dp[0][i] = 1;
    }
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            if (A[i] == B[j]) {
                dp[i][j] += dp[i][j - 1] + dp[i - 1][j];
            } else {
                dp[i][j] += dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
            }
            dp[i][j] = (dp[i][j] + MOD) % MOD;
        }
    }
    cout << (dp[n][m] + MOD) % MOD << endl;
    return 0;
}



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

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

  int cnt = 0;
  for(int x = a; x<= b; x++){
    if(c % x == 0)cnt++;
  }

  cout<<cnt<<endl;

  return 0;
}



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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int n,k;
	cin >> n >> k;
	int ans = 0;
	if(n % k != 0)ans = 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		s = s.replaceAll("eraser","");
		s = s.replaceAll("erase","");
		s = s.replaceAll("dreamer","");
		s = s.replaceAll("dream","");
		System.out.println(s.equals("")?"YES":"NO");
	}
}


Measured memory_bytes: 28832