akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/

ll gcd(ll a,ll b){
  if(a<b) swap(a,b);
  if(a%b==0) return b;
  return gcd(b,a%b);
}
int main() {
  ll a,b;
  cin >> a >> b;

  ll ans = a*b/gcd(a,b);
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

class rect {
public:
    int l;
    int u;
    int r;
    int d;

    int area() { return (d - u) * (r - l); }
};

int main() {
    while (true) {
        int n, width, depth;
        cin >> n >> width >> depth;
        if (width == 0)break;

        vector<rect> cake = {{0, 0, width, depth}};
        for (int i = 0; i < n; i++) {
            int p, s;
            cin >> p >> s;
            p--;

            rect now = cake[p];
            rect x, y;

            int nw = now.r - now.l;
            int nd = now.d - now.u;
            s %= 2 * (nw + nd);
            if (s <= nw) {
                int cut = now.l + s;
                x = {now.l, now.u, cut, now.d};
                y = {cut, now.u, now.r, now.d};
            } else if (s <= nw + nd) {
                s -= nw;
                int cut = now.u + s;
                x = {now.l, now.u, now.r, cut};
                y = {now.l, cut, now.r, now.d};
            } else if (s <= 2 * nw + nd) {
                s -= nw + nd;
                int cut = now.l + nw - s;
                x = {now.l, now.u, cut, now.d};
                y = {cut, now.u, now.r, now.d};
            } else {
                s -= 2 * nw + nd;
                int cut = now.u + nd - s;
                x = {now.l, now.u, now.r, cut};
                y = {now.l, cut, now.r, now.d};
            }

            if (x.area() > y.area()) swap(x, y);
            cake.push_back(x);
            cake.push_back(y);
            cake.erase(cake.begin() + p);
        }

        vector<int> v;
        for (auto x:cake) v.push_back(x.area());
        sort(v.begin(), v.end());
        
        for (int i = 0; i < v.size(); i++) {
            if (i > 0)cout << " ";
            cout << v[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3032
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[4];
int main(){
    int a;
    while(scanf("%d",&a),a){
        if(a%1111==0){
            printf("NA\n");
            continue;
        }
        int count=0;
        while(a!=6174){
            for(int i=0;i<4;i++){
                d[i]=a%10;
                a/=10;
            }
            std::sort(d,d+4);
            int b=0;
            for(int i=0;i<4;i++){
                b*=10;
                b+=d[i];
            }
            int c=0;
            for(int i=3;i>=0;i--){
                c*=10;
                c+=d[i];
            }
            a=c-b;
            count++;
        }
        printf("%d\n",count);
    }
}


Measured memory_bytes: 2724
#include <bits/stdc++.h> 
using namespace std;
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int k;
cin>>k;
string s;
cin>>s;

if(s.length()<=k)
cout<<s;
else
{for(int i=0;i<k;i++)
 cout<<s[i];
 cout<<"...";
}
}

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

using namespace std;

string s;

int main(){
    cin>>s;
    int mx = 0, cur = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'S') cur = 0;
        else cur++;

        mx = max(mx, cur);
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
using namespace std;

int A[100005],ans;
int main(){
	int N; scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",A+i);
	}
	for(int i=1;i<N;i++){
		if(A[i]==i && A[i+1]==i+1){
			swap(A[i],A[i+1]);
			ans++;
		}
	}
	for(int i=1;i<=N;i++){
		if(A[i]==i)
			ans++;
	}
	printf("%d",ans);

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int c = 0;
  for(int i=0;i<N-2;i++) {
    if(S[i] == 'A') {
      if(S[i+1] == 'B') {
        if(S[i+2] == 'C') {
          c++;
        }
      }
    }
  }
  cout << c << endl;
}

      

Measured memory_bytes: 256
s = list(input().strip())
t = int(input())
ans = 0
change = False
last = False
# 長さ1の時は回数割る2切り捨てだけ変える必要
if len(s) == 1:
    print(t // 2)
    exit()
before = s[0]
count = 1
first = True
for i in range(1, len(s)):
    if before == s[i]:
        count += 1
    else:
        before = s[i]
        # 最初の文字が何個続くか偶奇判定
        if first:
            first = False
            if count % 2 == 1:
                first_odd = True
            else:
                first_odd = False
        ans += count // 2
        count = 1
# 同じ文字のみの場合
if first:
    print(count*t // 2)
    exit()
# 最後の同じ文字列について
ans += count // 2
# 最後の文字が何個続くか偶奇判定
if count % 2 == 1:
    last_odd = True
else:
    last_odd = False

# 最初と最後が同じ文字かつ、最後が奇数の場合
if s[0] == s[-1] and first_odd and last_odd:
    print(ans + (ans + 1) * (t - 1))
else:
    print(ans * t)


Measured memory_bytes: 3064
package main

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

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	a := next.Int()
	b := next.Int()
	fmt.Println(2*float64(b) - float64(a))
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a []int) int {
	r := 0
	for i := 0; i < len(a); i++ {
		r += a[i]
	}
	return r
}

func pro(a []int) int {
	r := 1
	for i := 0; i < len(a); i++ {
		r *= a[i]
	}
	return r
}

func fill(a []int, n int) []int {
	for i := 0; i < len(a); i++ {
		a[i] = n
	}
	return a
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) String() string {
	return s.next()
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Ints(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = s.Int()
	}
	return r
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}


struct BIT {
  int n;
  vector<ll> tree;
  BIT(int n):n(n),tree(n+1) {} 
  void fill(ll val) {
    REP(i, n+1) tree[i] = (i&-i) * val;
  }
  void add(int idx, ll val) {
    for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val;
  }
  // sum[0, idx]
  ll range(int idx) {
    ll sum=0;
    for (int x=idx+1; x>0; x-=x&-x) sum += tree[x];
    return sum;
  }
  // sum[a, b]
  ll range(int a, int b) {
    return range(b) - range(a - 1);
  }
};


const int SIZE = 100000 + 10;
BIT bit0(2 * SIZE);
BIT bit1(2 * SIZE);

void add(int l, int r, ll x) {
  bit0.add(l, -x*(l-1));
  bit1.add(l, x);
  bit0.add(r+1, x*r);
  bit1.add(r+1,-x);
}
ll get(int i) {
  return bit1.range(i) * i + bit0.range(i);
}

int a[100000 + 10];

int main2() {
  bit0.fill(0);
  bit1.fill(0);

  int N = nextInt();
  int M = nextInt();

  REP(i, N) a[i] = nextInt() - 1;

  ll no = 0;
  for (int i = 0; i + 1 < N; i++) {
    int from = a[i];
    int to = a[i+1];
    if (from > to) {
      to += M;
    }
    no += to - from;

    if (from+2 <= to) {
      add(from + 2, to, 1);
      add(to + 1, to + 1, -(to-from-2+1));
    }
    // for (int i = 0; i < 2 * M; i++) {cout << get(i) << " ";} cout << endl;
  }
  ll ans = 0;
  for (int i = 0; i < M; i++) {
    chmax(ans, get(i) + get(i + M));
  }
  cout << (no - ans) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderB
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int[] dish = new int[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                dish[i] = int.Parse(words[i]);
            }
        }

        int[] point = new int[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                point[i] = int.Parse(words[i]);
            }
        }

        int[] extra = new int[n - 1];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n - 1; i++)
            {
                extra[i] = int.Parse(words[i]);
            }
        }

        int answer = 0;
        int previous = int.MinValue;
        for (int i = 0; i < n; i++)
        {
            int current = dish[i] - 1;
            answer += point[current];
            if (current == previous + 1)
            {
                answer += extra[previous];
            }
            previous = current;
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int main()
{
  int w,h,x,y,r;

  scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);

  if((x+r)>w || (x-r)<0 || (y+r)>h || (y-r)<0) printf("No\n");
  else printf("Yes\n");

  return 0;
}

Measured memory_bytes: 584
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = 0;
    for (int i = 0; i < s.size(); ++i) {
        char fr = i % 2 ? 'p' : 'g';
        char en = s[i];
        if (fr == 'p' && en == 'g') {
            ++n;
        } else if (fr == 'g' && en == 'p') {
            --n;
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 512
#include "stdio.h"

int main(){
  char s[101];
  int n,flag=1;
  scanf("%d",&n);
  scanf("%s",&s); 
  if(n%2==1)printf("No");
  else {
    for(int i=0;i<n/2;i++){
       if(s[i]!=s[i+n/2])flag=-1;
    }
    if(flag==-1)printf("No");
    else printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		int q = scanner.nextInt();
		int[] st = new int[n];
		for (int i = 0; i < n; i++)
			st[i] = scanner.nextInt();
		int[] s = Arrays.copyOf(st, n);
		Arrays.sort(s);
		List<Integer> list = new ArrayList<Integer>();
		while (q-- > 0) {
			char query = scanner.next().charAt(0);
			int x = scanner.nextInt();
			if (query == 'A') {
				list.add(st[x - 1]);
				Collections.sort(list);
			} else if (query == 'R') {
				list.remove(Integer.valueOf(st[x - 1]));
			} else {
				int r = INF;
				int l = 0;
				while (r != l) {
					int mid = (r + l) / 2;
					int pre = 0;
					int BAN = 0;
					for (int i : list) {
						int p = lower(s, i - mid);
						BAN += Math.max(p - pre, 0);
						pre = upper(s, i);
					}
					BAN += n - pre;
					if (BAN <= x)
						r = mid;
					else
						l = mid + 1;
				}
				System.out.println(l != INF ? l : "NA");
			}
		}
	}

	private int lower(int[] s, int i) {
		int p = Arrays.binarySearch(s, i);
		if (p < 0) {
			p = p * -1 - 1;
		} else {
			for (int j = p - 1; j >= 0; j--) {
				if (s[j] != i)
					break;
				p--;
			}
		}
		return p;
	}

	private int upper(int[] s, int i) {
		int pre = Arrays.binarySearch(s, i);
		for (int j = pre + 1; j < n; j++) {
			if (s[j] != i)
				break;
			pre++;
		}

		return pre + 1;
	}

	int INF = 1000000001;
	int n;
}

Measured memory_bytes: 303044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final List<Integer> list = IntStream.range(0, n)
            .mapToObj(i -> scanner.nextInt())
            .sorted()
            .collect(Collectors.toList());

        final int max = list.get(list.size() - 1);

        final List<Integer> duplicatedNumbers = list.stream()
            .collect(Collectors.groupingBy(Integer::intValue))
            .entrySet().stream()
            .filter(e -> e.getValue().size() >= 2)
            .map(Map.Entry::getKey)
            .collect(Collectors.toList());

        final boolean[] array = new boolean[max + 1];
        Arrays.fill(array, true);
        final Set<Integer> candidates = new HashSet<>();
        for (final int value : list) {
            if (!array[value]) {
                continue;
            }

            candidates.add(value);
            for (int i = 2; i * value <= max; i++) {
                array[i * value] = false;
            }
        }

        duplicatedNumbers.forEach(candidates::remove);
        System.out.println(candidates.size());
    }

    private static class FastScanner implements AutoCloseable {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        @Override
        public void close() throws Exception {
            reader.close();
        }
    }
}


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

const int MAX = 510000;
const int MOD = 1000000007;

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

// 二項係数計算
uintmax_t 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;
}

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

  uintmax_t r = 0;

  for (int i = 1; i < s / 3 + 1; i++)
  {
    int t = s - 3 * i;
    if (t < 0)
      continue;
    else if (t == 0)
    {
      r++;
      continue;
    }

    r = (r + COM(t + i - 1, i - 1)) % MOD;
  }

  cout << r << endl;
}


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

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

  if (x >= 400&& x<600) {
    cout << 8 << endl;
  }  
  else if (x >= 600&& x<800) {
    cout << 7 << endl;
  }
  else if (x >= 800&& x<1000) {
    cout << 6 << endl;
  }
  else if (x >= 1000&& x<1200) {
    cout << 5 << endl;
  }
  else if (x >= 1200&& x<1400) {
    cout << 4 << endl;
  }
  else if (x >= 1400&& x<1600) {
    cout << 3 << endl;
  }
  else if (x >= 1600&& x<1800) {
    cout << 2 << endl;
  }
  else if (x >= 1800&& x<2000) {
    cout << 1 << endl;
  }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=1,cntt=1,ans[100000],a[100000],b,c,cmp=0,data,h,w,x,y,xcmp=0,ycmp=0,sum=0;

string s;

vector<int> z;

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


        pair<int,int> p[100000];
       cin >> h >> w >> n;
       rep(i,n){
           cin >> a[i];
           rep(j,a[i]){
               ans[cntt]=cnt;
               cntt++;
           }
           cnt++;
       }
      // sort(a,a+n);
      // reverse(a,a+n);
        //rep(i,n){
          /// rep(j,a[i]){
             //  ans[cntt]=cnt;
               //cntt++;
           //}
           //cnt++;
       //}
       cntt=1;
      // Cout(ans[2]);
       //cout << ans[1]  << ans[2] << ans[3]  << ans[10] << ans[11];
      rrep(i,1,h+1){
          rrep(j,1,w+1){
              if(cmp%2==0){
              cout << ans[cntt]  << " ";
              cntt++;
             // cmp=1;
              }
              else{
                   cout << ans[cntt-1]  << " ";
                   cntt--;
                   //cout << "cntt" << cntt;
                 // cmp=0;
              }
          }
             if(cmp==0){
                   cmp=1;
              }
              else{
                  cmp=0;
                  //cout << ans[cntt-1]  << " ";
              }
               cout << endl;
              cntt=cntt+w;
      }
       
return 0;
}


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

using namespace std;

int dist[111111];
int a[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	for(int i=0;i<=n;i++) dist[i]=int(1e9);
	dist[n]=0;
	for(int i=0;i<m;i++) cin>>a[i];
	queue<int> q; q.push(n);
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(int i=0;i<m;i++)
		{
			if(u-a[i]>=0&&dist[u-a[i]]>=int(1e9))
			{
				dist[u-a[i]]=dist[u]+1; q.push(u-a[i]);
			}
		}
	}
	cout<<dist[0]<<'\n';
}

Measured memory_bytes: 3492
#include<bits/stdc++.h>
using namespace std;
#define int long long
main()
{
    int n;
    int sm=0;
    map<int,int>cnt;
    cin>>n;
    int a[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        sm+=a[i];
        cnt[a[i]]++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        sm-=cnt[b]*b;
        sm-=cnt[c]*c;
        cnt[c]+=cnt[b];
        sm+=cnt[c]*c;
        cnt[b]=0;
        cout<<sm<<endl;
    }
}



Measured memory_bytes: 10320
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN=100000;
int a[MAXN+5],ans[MAXN+5];
int n,l,cnt,id,flag;
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n-1;i++)
	{
		if(a[i]+a[i+1]>=l)
		{
			flag=1;
			id=i;
			break;
		}
	}
	if(!flag)
	{
		printf("Impossible\n");
		return 0;
	}
	printf("Possible\n");
	for(int i=1;i<=id-1;i++)
		printf("%d\n",i);
	for(int i=n-1;i>=id;i--)
		printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20
#define DIVISOR 1000000007

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define NUM_MAX 1000
#define K_MAX 1000

// pdp[# of partitions][# of balls]
static uint64_t pdp[K_MAX+1][NUM_MAX+1];
void init() {
    pdp[0][0] = 1;
    int i, j;
    for(i = 1; i <= K_MAX; i++) {
        for(j = 0; j <= NUM_MAX; j++) {
            pdp[i][j] = pdp[i-1][j];
            if(j>=i) pdp[i][j] = (pdp[i][j] + pdp[i][j-i])%DIVISOR;
        }
    }
    return;
}

int main(void) {
    int n, k;
    get_int2(&n, &k);
    init();
    uint64_t ans = (n-k>=0) ? (int)pdp[k][n-k] : 0;
    printf("%d\n", (int)ans);
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  int N;
  N = S.size();
  int cnt = 0;
  int i = 0;
  while(i<=N-1){
    if( S[i+1] == S[i] ){
      cnt++;
      i += 2;
    }
    i++;
  }

  cout << N - cnt << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll dp[111][77777];
void Main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> v;
  for(ll i=1; i*i<=n; i++) {
    v.pb(i);
    if(i*i!=n) v.pb(n/i);
  }
  sort(all(v));
  mem(dp);
  dp[0][0]=1;
  rep(i,m) {
    ll d[v.size()+1];
    mem(d);
    rep(j,v.size()) {
      ll x=v[j];
      if(j) x-=v[j-1];
      d[j+1]=d[j]+dp[i][j];
      d[j+1]%=MAX;
    }
    rep(j,v.size()) {
      ll x=v[j];
      if(j) x-=v[j-1];
      dp[i+1][j]+=d[v.size()-j]*x%MAX;
      dp[i+1][j]%=MAX;
    }
  }
  ll ans=0;
  rep(i,v.size()) {
    ans+=dp[m][i];
    ans%=MAX;
  }
  pr(ans);
}

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


Measured memory_bytes: 68856
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int a, b, c, d;
    
    cin >> a >> b >> c >> d;
    
    if((a*b) >= (c*d)) {
        cout << a*b << "\n";
    } else {
        cout << c*d << "\n";
    }
    
    return 0;
}

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

int main() {

int n;
cin >> n;

vector<vector<int>> timetables (n, vector<int>(0));

for (int i = 0; i < n-1; i++) {
    int c, f, s;
    cin >> c >> s >> f;
    timetables[i].push_back(c);
    timetables[i].push_back(s);
    timetables[i].push_back(f);
}

for (int i = 0; i < n-1; i++) {
    int current_time = timetables[i][0] + timetables[i][1];

    for (int j = i+1; j < n-1; j++) {
        if (current_time < timetables[j][1]) {
            current_time = timetables[j][0] + timetables[j][1];
        }

        else if (current_time % timetables[j][2] == 0) current_time += timetables[j][0];

        else {
            current_time += timetables[j][2] - (current_time % timetables[j][2]) + timetables[j][0];
        }
    }

    cout << current_time << endl;

}

cout << 0 << endl;

}

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

void foo(int &x,int r,int D) {
	x = r * x - D;
	cout << x << endl;
}
int main()
{
	int r, D, x;
	cin >> r >> D >> x;
	for (int i = 0; i < 10; i++) {
		foo(x, r, D);
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter

while 1:
  n = int(stdin.readline().rstrip())
  if n == 0:
    break
  teams = []
  #選抜されたチーム
  Selected_team_id = []
  cnt_selected_teams = 0
  #所属ごとのランキング（所属ごとの選抜チーム数）
  dic_shozoku_and_cntSelected = {}

  for i in range(n):
    * t, = map(int, stdin.readline().split())
    teams.append(t)
    if not dic_shozoku_and_cntSelected.__contains__(t[1]):
      dic_shozoku_and_cntSelected[t[1]] = 0

  sorted_teams1 = sorted(teams, key=itemgetter(3, 0))  # ペナルティ、ID
  sorted_teams = sorted(sorted_teams1, key=itemgetter(2), reverse=True)  # 正解数
  for t in sorted_teams:
    cnt_same_shozoku = dic_shozoku_and_cntSelected[t[1]]
    if cnt_selected_teams < 10:
      if cnt_same_shozoku < 3:
        Selected_team_id.append(t[0])
        dic_shozoku_and_cntSelected[t[1]] += 1
        cnt_selected_teams += 1
    elif cnt_selected_teams < 20:
      if cnt_same_shozoku < 2:
        Selected_team_id.append(t[0])
        dic_shozoku_and_cntSelected[t[1]] += 1
        cnt_selected_teams += 1
    elif cnt_selected_teams < 26:
      if cnt_same_shozoku < 1:
        Selected_team_id.append(t[0])
        dic_shozoku_and_cntSelected[t[1]] += 1
        cnt_selected_teams += 1

  print("\n".join(map(str,Selected_team_id)))



Measured memory_bytes: 5732
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] x = new int[M];
    int[] y = new int[M];
    for (int i = 0; i < M; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    sc.close();

    Map<Integer, Set<Integer>> edge = new HashMap<>();
    for (int i = 0; i < M; i++) {
      Integer key = Integer.valueOf(x[i]);
      if (!edge.containsKey(key)) {
        edge.put(key, new HashSet<>());
      }
      edge.get(key).add(y[i]);
    }

    int[] memo = new int[N + 1];
    Arrays.fill(memo, -1);

    int ans = 0;
    for (int xi = 1; xi < N + 1; xi++)
      ans = Math.max(ans, count(edge, memo, xi));

    System.out.println(ans);
  }

  private static int count(Map<Integer, Set<Integer>> edge, int[] memo, int xi) {
//    if (memo[xi] != -1) return memo[xi];
    int count = 0;
    Set<Integer> dest = edge.get(xi);
    if (dest != null)
      for (int yi : dest)
        count = Math.max(count, (memo[yi] != -1 ? memo[yi] : count(edge, memo, yi)) + 1);
    memo[xi] = count;
    return count;
  }
}

Measured memory_bytes: 95872
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  ll N, M;
  cin >> N >> M;
  priority_queue<ll> A;
  rep(i, N) {
    ll a; cin >> a;
    A.push(a);
  }
  for(int i=M; i>0; --i) {
    ll tmp = A.top(); A.pop();
    tmp = tmp/2;
    A.push(tmp);
  }
  ll ans = 0;
  while(!A.empty()) {
    ans += A.top(); A.pop();
  }
  cout << ans << endl;
}

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

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double deg1 = 30.0 * H + M / 2.0;
    double deg2 = 6.0 * M;
    double deg = abs(deg1 - deg2);
    if (deg > 180) deg = 360 - deg;

    double PI = acos(-1);
    double rad = deg * PI / 180;

    double ans = sqrt(A * A + B * B - 2 * A * B * cos(rad));
    printf("%.15f\n", ans);
}

Measured memory_bytes: 4128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());
typedef pair<double,int> tmp;

int main(){
	vector<tmp> ans;
	vector<tmp> v;
	rep(i,3){
		vector<tmp> tt(8);
		rep(j,8){
			cin>>tt[j].S>>tt[j].F;
			// cout<<tt[i].F<<endl;
		}
		sort(ALL(tt));
		ans.PB(tt[0]);
		ans.PB(tt[1]);
		// cout<<ans
		v.PB(tt[2]);
	}
	sort(ALL(v));
	ans.PB(v[0]);
	ans.PB(v[1]);
	rep(i,8){
		printf("%d %.2f\n",ans[i].S,ans[i].F);
		// cout<<ans[i].S<<" "<<ans[i].F<<endl;
	}
}

Measured memory_bytes: 1252
#include "atcoder/scc.hpp"
#include <atcoder/all>
#include <vector>
using namespace std;
using namespace atcoder;

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

  int n, m;
  cin >> n >> m;
  dsu uf(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    uf.merge(a, b);
  }

  auto g = uf.groups();
  cout << g.size() - 1 << '\n';
}


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

int main(){
    int n;
    cin>>n;
    double x,s=0;
    string u;
    for(int i=0;i<n;i++){
        cin>>x>>u;
        if(u=="JPY") s+=x;
        else s+=x*380000;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
def extgcd(a,b):
  r=[1,0,a]
  w=[0,1,b]
  while w[2]!=1:
    q=r[2]//w[2]
    r2=w
    w2=[r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r=r2
    w=w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x=extgcd(a,m)[0]
  return (m+x%m)%m

def fact(n):
  fct=[]
  b,e=2,0
  while b*b<= n:
    while n%b==0:
      n=n//b
      e=e + 1
    if e>0:
      fct.append((b, e))
    b,e=b+1,0
  if n>1:
    fct.append((n, 1))
  return fct

n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**6)]
mod=10**9+7
for i in range(n):
  x=fact(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)

Measured memory_bytes: 114800
#include<stdio.h>
int main(void)
{
    int i;
    int dice[7];
    char order[101];
    
    for(i=1;i<=6;i++){
        scanf("%d",&dice[i]);
    }
    scanf("%s",order);
    
    for(i=0;order[i]!='\0';i++){
        dice[0]=dice[1];
        
        switch(order[i]){
            case 'E':
            dice[1]=dice[4];
            dice[4]=dice[6];
            dice[6]=dice[3];
            dice[3]=dice[0];
            break;
            
            case 'N':
            dice[1]=dice[2];
            dice[2]=dice[6];
            dice[6]=dice[5];
            dice[5]=dice[0];
            break;
            
            case 'S':
            dice[1]=dice[5];
            dice[5]=dice[6];
            dice[6]=dice[2];
            dice[2]=dice[0];
            break;
            
            case 'W':
            dice[1]=dice[3];
            dice[3]=dice[6];
            dice[6]=dice[4];
            dice[4]=dice[0];
            break;
        }
    }
    
    printf("%d\n",dice[1]);
    
    return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

map<ll, int> factorize(ll n) {
    map<ll, int> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res[i] = 0;
        while (n % i == 0) {
            n /= i;
            res[i]++;
        }
    }

    if (n != 1) res[n] = 1;
    return res;
}


int main() {
    ll n;
    cin >> n;

    auto f = factorize(n);

    int ans = 0;
    for (auto &e : f) {

        int k = e.second;
        int j = 1;
        while (k >= j) {
            ans++;
            k -= j;
            j++;
        }

    }

    cout << ans << endl;


}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=(int)1e5+5;
vector<int>v;
bool vis[5][5]= {};
int main()
{
#ifdef ONLINE_JUDGE
    FAST;
#endif
    lp(i,1,4) v.pb(i);
    lp(i,1,3)
    {
        int a,b;
        cin>>a>>b;
        vis[a][b]=vis[b][a]=true;
    }
    do
    {
        bool is=true;
        lp(i,0,2)
        if (!vis[v[i]][v[i+1]])
        {
            is=false;
            break;
        }
        if (is)
            f("YES");
    }
    while(next_permutation(all(v)));
    f("NO");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) cin >> nums[i];
  long long sum = 0;
  for (int i = 0; i < n; i++) sum += nums[i];
  cout << *min_element(nums.begin(), nums.end()) << " " << *max_element(nums.begin(), nums.end()) << " " << sum << endl;
  return 0;
}


Measured memory_bytes: 3136
import java.util.*;

public class Main {
    
    static int mille(int y, int m) {
        if(y%3 == 0) return 20;
        else {
            if(m%2 == 0) return 19;
            else return 20;
        }
    }
    
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            while(n-- != 0) {
                int y = sc.nextInt();
                int m = sc.nextInt();
                int d = sc.nextInt();
                int dif = mille(y, m) - d + 1;
                for(int i=m+1; i<=10; i++) {
                    dif += mille(y, i);
                }
                for(int i=y+1; i<1000; i++) {
                    for(int j=1; j<=10; j++) {
                        dif += mille(i, j);
                    }
                }
                System.out.println(dif);
            }
        }
    }
}



Measured memory_bytes: 27616
const { reverse } = require("dns");

const main = stdin => {
    const input = stdin.trim().split('\n')
    //ここにかく
    //A円で一回聞ける
    const A = parseInt(input[0].split(" ")[0]);
    //所持金
    const B = parseInt(input[0].split(" ")[1]);
    //最大値Cと比較
    const K = parseInt(input[0].split(" ")[2]);
    
    let Aresults = [];
    for (let i=1; i<=A; i++){
        if(A%i == 0){
            Aresults.push(i);
        }
    }
    let ABresults = [];
    for(let i=0; i<Aresults.length; i++){
        if(B%Aresults[i] == 0){
            ABresults.push(Aresults[i])
        }
        
    }
    const ABresults2 = ABresults.reverse();
    console.log(ABresults2[K-1]);
    }
    // 標準入力
    main(require("fs").readFileSync("/dev/stdin", "utf8"))

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;
    ll sn = s.size(), tn = t.size();

    ll res = 1e9;
    for(ll i=0; i+tn<=sn; i++) {
        ll k = 0;
        for(ll j=0; j<tn; j++)
            k += s[i+j] != t[j];
        res = min(res, k);
    }
    cout << res << endl;
}

Measured memory_bytes: 3656
import math
from decimal import *


def _run(n, k, a_list):
    integral_windows = [Decimal(0)] * (len(a_list) + 1)
    for i in range(len(a_list)):
        integral_windows[i + 1] = integral_windows[i] + Decimal(math.log10(a_list[i]))
    sliding_size = n - k
    for i in range(sliding_size):
        sum_value_a = integral_windows[k + i] - integral_windows[i]
        sum_value_b = integral_windows[k + i + 1] - integral_windows[i + 1]
        if sum_value_a < sum_value_b and (math.fabs(sum_value_b - sum_value_a) > 5e-25):
            print("Yes")
        else:
            print("No")


def _main():
    N, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    _run(N, K, A_list)


if __name__ == "__main__":
    _main()


Measured memory_bytes: 42244
#include<stdio.h>

int main(){
  int N,M;
  int s,c;
  int ans[4];
  int i,j,k;
  bool en = true;
  for(i=0;i<4;i++){
    ans[i] = -1;
  }
  scanf("%d%d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d%d",&s,&c);
    if(ans[s] == -1){
      ans[s] = c;
    }
    else if(ans[s] != c){
      en = false;
    }
  }
  if(ans[1] == 0 && N != 1){
    en = false;
  }
  else if(ans[1] == -1 && N != 1){
    ans[1] = 1;
  }
  if(!en){
    printf("-1");
    return 0;
  }
  else{
    ans[0] = 0;
    j=1;
    for(i=N;i>0;i--){
      if(ans[i] == -1){
        ans[i] = 0;
      }
      if(en){
        ans[0] += j*ans[i];
        j*=10;
      } 
    }
  }
  printf("%d\n",ans[0]);
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		List<int> RL = new List<int>();
		List<int> LR = new List<int>();
		LR.Add(-1);

		for (int i = 0; i < s.Length - 1; i++)
		{
			if (s[i] == 'R' && s[i + 1] == 'L')
			{
				RL.Add(i);
			}
			if (s[i] == 'L' && s[i + 1] == 'R')
			{
				LR.Add(i);
			}
		}
		LR.Add(s.Length - 1);

		int[] ans = new int[s.Length];
		for (int i = 0; i < s.Length; i++)
		{
			ans[i] = 0;
		}

		while (RL.Count > 0)
		{
			int R1 = (RL[0] - LR[0] + 1) / 2;
			int L1 = (LR[1] - RL[0]) / 2;
			ans[RL[0]] += L1 + R1;

			int R2 = (RL[0] - LR[0]) / 2;
			int L2 = (LR[1] - RL[0] + 1) / 2;
			ans[RL[0] + 1] += L2 + R2;

			RL.RemoveAt(0);
			LR.RemoveAt(0);
		}


		for (int i = 0; i < ans.Length; i++)
		{
			Console.Write($"{ans[i]} ");

		}
	}
}


Measured memory_bytes: 17116
N = int(input())
B = list(map(int, input().split()))
 
# A_1 <= B_1
# A_2 <= min(B_1, B_2)
# A_3 <= min(B_2, B_3)
# A_(N-1) <= min(B_(N-2), B_(N-1))
# A_N <= B_(N-1)
# ans = B_1 + min(B_1, B_2) + ... + min(B__(N-2), B_(N-1)) + B_(N-1)
 
ans = B[0] + B[N-2]
for i in range(1, N-1):
  ans += min(B[i-1], B[i])

print(ans)

Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct UnionFind {
  int parent[1010 * 1010];
  UnionFind() { memset(parent, -1, sizeof(parent)); }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) { return false; }
    if (parent[y] < parent[x]) { swap(x, y); }
    parent[x] += parent[y];
    parent[y] = x;
    return true;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
};

int n;
int w, h;
char field[1010][1010];
int gx, gy;
int xs[1010];
int ys[1010];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
UnionFind ufind;

void Merge(int x, int y) {
  if (field[y][x] == '#') { return; }
  REP(dir, 4) {
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (nx < 0 || nx >= w || ny < 0 || ny >= h || field[ny][nx] == '#') { continue; }
    ufind.unionSet(y * w + x, ny * w + nx);
  }
}

int main() {
  while (scanf("%d %d", &w, &h) > 0) {
    ufind = UnionFind();
    REP(y, h) {
      scanf("%s", field[y]);
      REP(x, w) {
        if (field[y][x] == 't') { gx = x; gy = y; }
      }
    }
    scanf("%d", &n);
    REP(i, n) { scanf("%d %d", &xs[i], &ys[i]); }
    int ans = -1;
    REP(y, h) REP(x, w) {
      Merge(x, y);
    }
    if (ufind.findSet(0, gy * w + gx)) {
      ans = 0;
    } else {
      REP(i, n) {
        field[ys[i]][xs[i]] = '.';
        Merge(xs[i], ys[i]);
        if (ufind.findSet(0, gy * w + gx)) {
          ans = i + 1;
          break;
        }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int flag[200000] = {};
	int sum = 0;
	int N, K;
	int R, S, P;
	string T;
	cin >> N >> K;
	cin >> R >> S >> P;
	cin >> T;
	int i, j;

	for (i = 0; i < N; ++i) {
		if (i < K) {//場合分け考えない
			//cout << "test" << endl;
			if (T[i] == 'r') {
				sum += P;
			}
			else if (T[i] == 's') {
				sum += R;
				//cout << "test" << endl;
			}
			else if (T[i] == 'p') {
				sum += S;
			}
		}

		else if (i >= K) {//場合分け考える
			if ((T[i] == 'r')&&(T[i-K]!= 'r')) {
				sum += P;
			}
			else if ((T[i] == 's') && (T[i - K] != 's')) {
				sum += R;
			}
			else if ((T[i] == 'p') && (T[i - K] != 'p')) {
				sum += S;
			}
			else if ((T[i] == 'r') && (T[i - K] == 'r')&&(flag[i-K]==1)) {
				sum += P;
				
			}
			else if ((T[i] == 's') && (T[i - K] == 's') && (flag[i - K] == 1)) {
				sum += R;
			
			}
			else if ((T[i] == 'p') && (T[i - K] == 'p') && (flag[i - K] == 1)) {
				sum += S;
			
			}


			else {
				sum += 0;
				flag[i] = 1;
			}
		}
	}

	cout << sum << endl;


}



Measured memory_bytes: 1280