akhauriyash/Code-Regression huggingface dataset:
a, b, c, x, y = map(int, input().split())
aa = 0
bb = 0
cc = 0

# 小さい方
z = min(x, y)
price = 0
# 単品で買ったほうが安い場合
if a + b <= 2 * c:
  price += z * (a + b)
  aa += z
  bb += z
else:
  price += z * 2 * c
  cc += 2 * z

# 残り
if x > y:
  # aの方が安い場合
  if a <= 2 * c:
    price += (x - y) * a
    aa += x - y
  else:
    price += (x - y) * 2 * c
    cc += 2 * (x - y)
else:
  # bの方が安い場合
  if b <= 2 * c:
    price += (y - x) * b
    bb += y - x
  else:
    price += (y - x) * 2 * c
    cc += 2 * (y - x)

# print(aa, bb, cc)
print(price)


Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
    int i,j;
    int mount[10];
    int tmp;
    for(i = 0;i < 10;i++){
        scanf("%d",&mount[i]);
    }
    for(i = 9;i >= 0;i--){
        for(j = 0;j < i;j++) {
            if(mount[j] < mount[j+1]) {
                tmp=mount[j];
                mount[j]=mount[j+1];
                mount[j+1]=tmp;
            }
        }
    }
    for(i = 0;i < 3;i++){
        printf("%d\n",mount[i]);
    }
    return 0;
}

Measured memory_bytes: 600
L = int(input())

N = L.bit_length()
n = []
for i in range(1, N):
    n += [[i, i + 1, 0], [i, i + 1, 2**(i - 1)]]
v = 2**(N - 1) - 1
while L - 1 - v > 0:
    b = min(N - 1, (L - 1 - v).bit_length())
    n += [[b, N, v + 1]]
    v += 2**(b - 1)
M = len(n)
print(N, M)
for _ in n:
    print(*_)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<int> A(N+1), B(N);
  for (int i = 0; i < N+1; i++)  cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  ll num = 0;
  ll carry = A.at(0);
  for (int i = 0; i < N; i++) {
    if (carry >= B.at(i)) {
      num += B.at(i);
      carry = A.at(i+1);
    }else {
      num += carry;
      int x = B.at(i) - carry;
      if (A.at(i+1) >= x) {
	num += x;
	carry = A.at(i+1) - x;
      }else {
	num += A.at(i+1);
	carry = 0;
      }
    }
  }
  cout << num << endl;

  return 0;
}



Measured memory_bytes: 1024
fn main() {
    let mut sc = Scanner::new();
    let mut get_sum = |sc: &mut Scanner| {
        let s: Vec<char> = sc.read::<String>().chars().collect();
        let n = s.len();
        let mut s_sum_a = vec![0; n + 1];
        let mut s_sum_b = vec![0; n + 1];
        for i in 0..n {
            s_sum_a[i + 1] = s_sum_a[i];
            s_sum_b[i + 1] = s_sum_b[i];
            if s[i] == 'A' {
                s_sum_a[i + 1] += 1;
            } else {
                s_sum_b[i + 1] += 1;
            }
        }
        (s_sum_a, s_sum_b)
    };
    let (s_sum_a, s_sum_b) = get_sum(&mut sc);
    let (t_sum_a, t_sum_b) = get_sum(&mut sc);

    let q: usize = sc.read();
    for _ in 0..q {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        let c = sc.read::<usize>() - 1;
        let d = sc.read::<usize>() - 1;

        let s_a = (s_sum_a[b + 1] - s_sum_a[a]) % 3;
        let s_b = (s_sum_b[b + 1] - s_sum_b[a]) % 3;
        let t_a = (t_sum_a[d + 1] - t_sum_a[c]) % 3;
        let t_b = (t_sum_b[d + 1] - t_sum_b[c]) % 3;
        println!(
            "{}",
            if (s_a + 3 - s_b) % 3 == (t_a + 3 - t_b) % 3 {
                "YES"
            } else {
                "NO"
            }
        );
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 6652
#include <cstdio>
#include <algorithm>
using namespace std;
long long a,b,c;
int main()
{
    scanf("%lld%lld%lld",&a,&b,&c);
    printf("%lld\n",(a&b&c&1)?min(a*b,min(a*c,b*c)):0LL);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

const int mod = 1000 * 1000 * 1000 + 7;

int main() { IO;
  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  for (auto &x : v) cin >> x;

  vector<vector<int>> dp(n + 1);
  for (auto &v : dp) {
    v.resize(k + 1);
  }

  v.insert(v.begin(), 0);
  dp[0][0] = 1;

  for (int i = 1; i <= n; ++i) {
    vector<int> sum(k + 1);
    sum[0] = dp[i - 1][0];

    for (int j = 1; j <= k; ++j) {
      sum[j] = (sum[j - 1] + dp[i - 1][j]) % mod;
    }

    for (int j = 0; j <= k; ++j) {
      dp[i][j] = sum[j];
      if (j > v[i]) {
        dp[i][j] = (dp[i][j] - sum[j - v[i] - 1] + mod) % mod;
      }
    }
  }

  cout << dp[n][k] << endl;

  return 0;
}


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

int main() {
    string s;
  	int ans;
  	cin >> s;
  	if(s[0] == '1') ans++;
  	if(s[1] == '1') ans++;
  	if(s[2] == '1') ans++;

    cout << ans  << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
    static Scanner sc;
    static String s;
    static long[] lbs;
    public static void main(String[] args) {
        sc = new Scanner(System.in);
        s = sc.nextLine();
        lbs = new long[s.length() + 1];
        Arrays.fill(lbs, 0);
        long cnt = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == '>') {
                cnt++;
            } else {
                cnt = 0;
            }
            lbs[i] = cnt;
        }
        long ans = 0;
        long crt = 0;
        for (int i = 0; i < s.length() + 1; i++) {
            if (i > 0 && s.charAt(i - 1) == '<') {
                crt++;
            } else {
                crt = 0;
            }
            crt = Math.max(crt, lbs[i]);
            ans += crt;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 39488
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

   const static long long MOD = 1e9 + 7;

    vector<long long> pow2;
    vector<long long> F;
    vector<long long> IF;

    long long norm(long long a) {
        a %= MOD;
        if (a < 0) {
            a += MOD;
        }
        return a;
    }

    long long inverse(long long a) {
        long long b = MOD;
        long long u = 0, v = 1;
        a = norm(a);
        while (a != 0) {
            long long d = b / a;
            b -= d * a;
            u -= d * v;
            swap(a, b);
            swap(u, v);
        }
        return norm(u);
    }

    long long powM(long long x, long long e) {
        long long res = 1;
        while (e > 0) {
            if (e & 1) {
                res = res * x % MOD;
            }
            x = x * x % MOD;
            e >>= 1;
        }
        return res;
    }

    void init(int n) {
        F.clear();
        F.resize(n + 1, 1);
        IF = F;
        pow2.clear();
        pow2.resize(n + 1, 1);
        for (int i = 1; i <= n; ++i) {
            pow2[i] = pow2[i - 1] * 2 % MOD;
        }

        for (int i = 1; i <= n; ++i) {
            F[i] = F[i - 1] * i % MOD;
        }
        IF[n] = inverse(F[n]);
        for (int i = n - 1; i > 0; --i) {
            IF[i] = IF[i + 1] * (i + 1) % MOD;
        }
    }

    long long nCr(int n, int r) {
        if (r < 0 || r > n) {
            return 0;
        }
        long long res = F[n] * IF[r] % MOD * IF[n - r] % MOD;
        return res;
    }


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int K;
    cin >> K;

    string S;
    cin >> S;

    int n = S.length();
    init(n + K + 10);

    const long long A = 26;

    auto calc = [&](int N, int M) {
        long long res = nCr(N - 1, M - 1);
        res *= powM(A - 1, N - M);
        res %= MOD;
        return res;
    };

    long long res = 0;
    long long P = 1;
    for (int i = K; i >= 0; --i) {
        (res += calc(n + i, n) * P % MOD) %= MOD;
        // cout << i + n << " " <<  " " << calc(n + i, n) << endl;
        (P *= A) %= MOD;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 51188
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] s = new char[H][W];
		for (int i = 0; i < H; ++i) {
			s[i] = sc.next().toCharArray();
		}
		int[] dx = { 1, -1, 0, 0 };
		int[] dy = { 0, 0, 1, -1 };
		boolean ans = true;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (s[i][j] == '.')
					continue;
				boolean tmp = false;
				for (int k = 0; k < 4; ++k) {
					if (dx[k] + i < 0 || dx[k] + i >= H || dy[k] + j < 0 || dy[k] + j >= W)
						continue;
					tmp |= s[dx[k] + i][dy[k] + j] == '#';
				}
				ans = ans && tmp;
			}
		}
		System.out.println(ans ? "Yes" : "No");
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 21844
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = map(int,read().split())

ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if a[i]!=a[j] and a[j]!=a[k] and a[k]!=a[i] and a[i]+a[j]+a[k] > 2*max(a[i],a[j],a[k]):
                ans += 1
                #print(a[i],a[j],a[k])

print(ans)
            


Measured memory_bytes: 9184
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int K,N;
  cin>>K>>N;
  
  vector<int> A(N);
  rep(i,N){
    cin>>A[i];
  }
  
  sort(A.begin(),A.end());
  int max=0;
  
  for(int i=0;i<N-1;++i){
    int dist=A[i+1]-A[i];
    if(dist>max)
      max=dist;
  }
  
  if(K-A[N-1]+A[0]>max)
    max=K-A[N-1]+A[0];
  
  cout<<K-max<<endl;
  
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int N = n[0];
        int M = n[1];
        int[,] map = new int[N, N];
        for(int i = 0; i < M; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]) - 1;
            int b = int.Parse(s[1]) - 1;
            map[a, b]++;
            map[b, a]++;
        }
        for(int i = 0; i < N; i++)
        {
            int sum = 0;
            for(int j = 0; j < N; j++)
            {
                sum += map[i, j];
            }
            Console.WriteLine(sum);
        }
    }
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define llrep(i,a,b) for(ll i=a;i<b;i++)
#define llrepd(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
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 _main() {
    ll N; cin >> N;
    vector<ll> A(N, 0); rep(i, 0, N) cin >> A[i];
    ll q; cin >> q;
    map<ll, bool> exist;
    rep(i, 0, 1 << N) {
        ll sum = 0;
        rep(j, 0, N) {
            if ((1<<j)&i) sum += A[j];
        }
        exist[sum] = true;
    }
    rep(x, 0, q) {
        ll m; cin >> m;
        if(exist[m]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3196
s = input()
ans = 0

for i in range(1, len(s)):
  if s[i-1] == s[i]:
    if s[i] == '0':
      s = s[:i] + '1' + s[i+1:]
      ans += 1
    else:
      s = s[:i] + '0' + s[i+1:]
      ans += 1

print(ans)    

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

a = []

for i in range(1,n+1):
    
    if i % 3 == 0 or i % 10 == 3:
        a.append(i)
    elif int(int(i / 10) % 10) == 3:
        a.append(i)
    elif int(int(i / 100) % 10) == 3:
        a.append(i)
    elif int(int(i / 1000) % 10) == 3:
        a.append(i)

a = sorted(set(a))
print(" ",end="")
print(*a)


Measured memory_bytes: 6368
/*
    Author: Arham_doshi
    @quote "Code like there's no tommorow!"
     ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
    */
    #include <bits/stdc++.h>
     
    #define int         long long
    #define double      long double
    #define pb          push_back
    #define pf          push_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define hell        998244353
    #define PI          3.141592653589
    #define bs(v,n)     binary_search(all((v)),(n))
    #define lb(v,n)     lower_bound(all((v)),(n))
    #define ub(v,n)     upper_bound(all((v)),(n))
    #define fo(i,l,u)   for(i=l;i<u;i++)
    #define rfo(i,l,u)  for(i=l;i>=u;i--)
    #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
    #define _init(b)     memset(b,-1,sizeof(b))
    #define _init0(b)     memset(b,0,sizeof(b))
    #define MOD         1000000007
     
     
     
    using namespace std;
     
    int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
    bool mod(double a,double b) {return a/b - floor(a/b);}
    int ceil(int n,int k){if(k%n==0){return k/n;}else return (k/n)+1;}
    int occurs(vi v,int n){
    auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}
     
    int logb(int base, int x) {
        return (log(x) / log(base));
    }
  
  int mat[21][21],dp[21][1<<22],n;
  
     int match(int m,int mask){
        // cout<<m<<' '<<mask<<endl;
         if(dp[m][mask]!=-1){
             return dp[m][mask];
         }
         else if(m==(n-1)){
             int i,j;
            // cout<<m<<' '<<mask<<endl;
             dp[m][mask]=0;
             fo(i,0,n){
                 if((mat[m][i]==1)&&((mask&(1<<i))==0)){
                     dp[m][mask]++;
                 }
             }
             return dp[m][mask];
         }
         else{
             int i,j;
             dp[m][mask]=0;
          //   cout<<111;
              fo(i,0,n){
                //  cout<<i<<' '<<mat[m][i]<<" "<<((mask&(1<<i)))<<endl;
                 if((mat[m][i]==1)&&((mask&(1<<i))==0)){
                     dp[m][mask]=(dp[m][mask]+match(m+1,mask|(1<<i)))%MOD;
                 }
             }
             return dp[m][mask];
         }
     }
     
     
     
     
    signed main()
    {
        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        int i,j,x,t,k;
       
       cin>>n;
       fo(i,0,n){
           fo(j,0,n){
               cin>>x;
               mat[i][j]=x;
              // cout<<mat[i][j]<<" ";
           }
           //cout<<endl;
       }
       _init(dp);
       cout<<match(0,0);
       
       
        return 0;
    }

Measured memory_bytes: 688512
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int b[n - 1];
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  int max = 0;
  for (int i = 0; i < n - 2; i++) {
    max += min(b[i], b[i + 1]);
  }
  max += b[0];
  max += b[n - 2];
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	k, _ := strconv.Atoi(stringLineScan())
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i], _ = strconv.Atoi(stringLineScan())
	}
	ans := make([]int, 1)
	for i := 1; i < n; i++ {
		t := make([]int, min(i, k))
		for j := 0; j < min(i, k); j++ {
			t[j] = abs(h[i-j-1]-h[i]) + ans[i-j-1]
		}
		ans = append(ans, minimum(t))
	}
	fmt.Println(ans[n-1])
}
func min(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}
func minimum(x []int) int {
	y := x[0]
	for _, i := range x {
		if i < y {
			y = i
		}
	}
	return y
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}


Measured memory_bytes: 13184
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int main() {
	int N;
	cin >> N;
	int sum = 0;
	vector<int>V;
	for (int i = 0; i < N; ++i) {
		int s;
		cin >> s;
		sum += s;
		V.push_back(s);
	}
	sort(V.begin(), V.end());
	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else {
		for (int i = 0; i < N; ++i) {
			if ((sum - V[i]) % 10 != 0) {
				cout << sum - V[i] << endl;
				return 0;
			}
		}
		cout << 0 << endl;
	}
	return 0;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int ret=0, a;
	for (int i=0; i<n; i++)
		cin>>a, ret+=(a-1);
	cout << ret << endl;
	return 0;
}


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

int main() {
  int N, sum;
  cin >> N;
  sum = 0;

  for (int i=0; i < N; i++){
    int L, R;
    cin >> L >> R;
    sum += R-L+1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

#define ALPHABET_NUM ('z'-'a'+1)
using namespace std;

int main(int argc, char* argv[]) {
  vector<int> num(ALPHABET_NUM, 0);

  char c;
  while (cin >> c) {
    if (!('A' <= c && c <= 'Z') &&
	!('a' <= c && c <= 'z')) continue;
    if ('A' <= c && c <= 'Z') c += 'a' - 'A';
    num[c-'a']++;
  }
  
  for (int i = 0; i < num.size(); i++) {
    cout << (char)('a'+i) << " : " << num[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1172
left = {"q":True, "w":True, "e":True, "r":True, "t":True, "a":True, "s":True, "d":True, "f":True, "g":True, "z":True, "x":True, "c":True, "v":True, "b":True}
while True:
  s = raw_input()
  if s == "#" : break
  counter = 0
  is_left = True
  for i in xrange(len(s)):
    judge = s[i] in left
    if i != 0 and not is_left == judge:
      counter += 1
    is_left = judge
  print counter

Measured memory_bytes: 6288
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int main(int argc, char **argv) {
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    S[K - 1] += 32;
    cout << S << endl;
}

Measured memory_bytes: 256
import numpy as np
import heapq

if __name__ == "__main__":
    N, M = map(int, input().split())
    nodes = [[] for i in range(N)]
    costs = [N+1 for i in range(N)]
    costs[0] = 0
    parents = [None for i in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        nodes[a-1].append(b-1)
        nodes[b-1].append(a-1)
    # (cost, node, parent)
    open_list = [(costs[0]+1, c, 0) for c in nodes[0]]
    heapq.heapify(open_list)

    while True:
        # print("="*10)
        # print('costs')
        # print(costs)
        # print('parents')
        # print(parents)
        # print('open_list')
        # print(open_list)
        # print("len", len(open_list))
        if len(open_list) == 0:
            break
        cost, node, parent = heapq.heappop(open_list)
        if parents[node] is not None:
            # 既に親が決まっているなら追加しない
            continue
        else:
            #print("Select:", node)
            costs[node] = cost
            parents[node] = parent
            for child in nodes[node]:
                # print(child)
                if child == 0 or parents[child] is not None:
                    continue
                else:
                    t = (costs[node]+1, child, node)
                    heapq.heappush(open_list, t)
        
    # print(costs)
    # print(parents)
    for i in range(N):
        if i == 0:
            print('Yes') # 'No' になるようなケースはある？
        else:
            print(parents[i]+1)



        




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

int main(){
  string S; cin >> S;
  int N; N = S.size();
  string ans;
  
  for(int i = 0; i < N; i++){
    if(S.at(i) == '0') ans += '0';
    else if(S.at(i) =='1') ans += '1';
    else if(S.at(i) == 'B' && ans != ""){
      ans.pop_back();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char m[200];
int main()
{
	scanf(" %s",m);
	int len=strlen(m),flag=1;
	for(int i=0;i<len;i++)
		if((i%2==0&&m[i]=='L')||(i%2!=0&&m[i]=='R')) {flag--;break;}
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
def main():
    A, B, C, D = map(int, input().split())
    hoge = A + B
    fuga = C + D

    if hoge > fuga:
        print("Left")
    elif hoge == fuga:
        print("Balanced")
    else:
        print("Right")


if __name__ == "__main__":
    main()

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

#define PI 3.1415 

double circumference(double r) 
{ 
	double cir = 2*PI*r; 
	return cir; 
} 

int main() 
{ 
double r;
  cin>>r;
  cout<<circumference(r); 
	return 0; 
} 


Measured memory_bytes: 3788
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
using namespace std;

int main() {
	int n, q, ans = 0; cin >> n;
	int s[n];
	for (int i = 0; i < n; i++)cin >> s[i];
	cin >> q;
	int t[q];
	for (int i = 0; i < q; i++)cin >> t[i];
	for (int i = 0; i < q; i++) {
		int left = 0, right = n;
		while (left < right) {
			int mid = (left + right) / 2;
			if (s[mid] == t[i]) {
				ans++;
				break;
			}
			else if (t[i] < s[mid])right = mid;
			else left = mid + 1;
		}
	}
	cout << ans << endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;
const int mod = 1e9+7;

int a[N], c[N];

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }
  long long ans = 0;
  for (int i = n-2; i >= 0; --i) {
    ans = (ans + 1LL*a[i]*a[i+1]) % mod;
    a[i] = (a[i] + a[i+1]) % mod;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4648
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int x,n;
  cin >> x >> n;
  if(n == 0){
    cout << x << endl;
  }
  else{
  vector<int> p(n);
  for(int i = 0; i< n; i++){
    cin >> p.at(i);
  }
  vector<int> q(102,0);
  for(int i= 0 ; i<102; i++){
    q.at(i) = i; 
  }
  for(int j= 0; j<n; j++){
    q.at(p.at(j)) = -100000000000; 
  }
  int d = 1000;
  int ans = 1000;
  for(int i = 101 ; i> -1 ; i--){
    if(d >= abs(q.at(i)-x)){
      d = abs(q.at(i)-x);
      ans = q.at(i);
    }
  }
  cout << ans << endl;

}
}

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

#define MOD 1000000007

int main() {
    ll n, k;
    cin >>n >>k;
    ll S=1;
    for (ll i=0; i<n; i++) {
        S *=k;
        S %=MOD;
    }
    cout <<S <<endl;
    return 0;
}



Measured memory_bytes: 3108
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int power = Integer.parseInt(scan.next());
        int cnt = Integer.parseInt(scan.next());

        //int second = Integer.parseInt(scan.next());
        //long in = Long.parseLong(scan.next());
        //String s = scan.next();
        //String second = scan.next();
        int sum = 0;
        for (int i = 0; i <cnt; i++) {
            sum += Integer.parseInt(scan.next());
        }
        result(sum>=power);
    }

    public static void result(boolean flg) {
        if(flg) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

int n, ans = 1;
typedef long long ll;
ll m, a, r, c, h;
ll D[5];
int A[]={0,0,0,0,0,0,1,1,1,2};
int B[]={1,1,1,2,2,3,2,2,3,3};
int C[]={2,3,4,3,4,4,3,4,4,4};
int main() {
    
    ios::sync_with_stdio(false);
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        string t;
        cin >> t;
        if (t[0] == 'M')
            m++;
        if (t[0] == 'A')
            a++;
        if (t[0] == 'R')
            r++;
        if (t[0] == 'C')
            c++;
        if (t[0] == 'H')
            h++;
    }
    D[0] = m;
    D[1] = a;
    D[2] = r;
    D[3] = c;
    D[4] = h;
    
    ll ans = 0;
    for (int i = 0; i < 10; i++)
        ans += D[A[i]]*D[B[i]]*D[C[i]];
    
    cout << ans << endl;
    
    
    
    
    return 0;
}



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

typedef pair<int, int> pii;

const int N = 1e5 + 10;
bool mark[N];
bool ans = true;
vector<pii> adj[N];
int d[N];

void dfs(int root) {
    mark[root] = true;
    for (int i = 0; i < adj[root].size(); i++) {
        int u = adj[root][i].first, w = adj[root][i].second;
        if (!mark[u]) {
            d[u] = d[root] + w;
            dfs(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m, u, v, w;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> u >> v >> w;
        adj[--u].push_back({--v, w});
        adj[v].push_back({u, -w});
    }
    for (int i = 0; i < n; i++)
        if (!mark[i])
            dfs(i);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < adj[i].size(); j++)
            if (d[adj[i][j].first] != d[i] + adj[i][j].second)
                ans = false;
    }
    cout << (ans? "Yes": "No") << "\n";
    return 0;
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

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

  int ans = a*b;
  prt(ans);
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(a*b)/2<<endl;
}

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

ab = [list(map(int,input().split())) for i in range(n)]
ma = max(a for a,b in ab)


dp = [10**10]*(h+ma+1)
dp[0] = 0

for i in range(1,h+ma+1):
    dp[i] = min(dp[i-a]+b for a,b in ab)

print(min(dp[h:]))


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

using namespace std;

typedef long long ll;



int main(){
    ll n, ans;
	cin >> n;
	ans = n+1;
	for(ll i = 1; i*i <= n; i++) {
		if(n%i) continue;
		ans = min(ans, i + (n/i));
	}
	cout << ans-2;

    
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
      	int i;	
      
		for (i = 1; i < 10; i++) {
        	if (N % i == 0 && N / i < 10) {
            System.out.print("Yes");
            return;
            }
        }
	System.out.print("No");
	return;

	}
}

Measured memory_bytes: 22996
package main
 
import (
    "fmt"
)
 
func main() {
  	var a,b,c,ans int
   	fmt.Scan(&a)
   	fmt.Scan(&b)
   	fmt.Scan(&c)
		ans = b+c-a
		
		if ans < 0{
			ans = 0
		}
  	fmt.Println(ans)
}

Measured memory_bytes: 512
import numpy as np
N,C = map(int,input().split())

f=[[0]*100000 for _ in range(C)]

for n in range(N):
    s, t, c = map(int, input().split())
    f[c-1][s-1:t] = [1] * (t-s + 1)

arr = np.array(f)
print(np.max((np.sum(arr, axis=0))))


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

long long P = 1000000007;

class C {
public:
  int n;
  vector<long long> fac, inv, facInv;

  long long power(long long e, long long x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }

  C(int n_) {
    n = n_;
    fac.resize(n + 1);
    inv.resize(n + 1);
    facInv.resize(n + 1);
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }

  long long comb(int N, int K) {
    if (N < K || K < 0 || N < 0)
      return 0;
    if (N == 0 || K == 0 || K == N)
      return 1;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }

  long long hcomb(int N, int K) {
    if (N == 0 && K == 0)
      return 1;
    return comb(N + K - 1, K);
  }

  long long mul(long long a, long long b) { return (a * b) % P; }

  long long add(long long a, long long b) { return (a + b) % P; }

  // find c
  // where a^c = b (mod P)
  long long dlp(long long a, long long b) {
    long long m = ceil(sqrt(P));
    map<long long, long long> mp;
    for (int i = 0; i < m; i++)
      mp[power(a, i)] = i;
    long long ainvm = power(power(a, m), P - 2);
    cout << m << endl;
    for (int i = 0; i < m; i++) {
      if (mp.find(b) != mp.end()) {
        return i * m + mp[b];
      }
      b = mul(b, ainvm);
    }
    return -1;
  }
};

C c(201010);

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;

  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < m; j++) {
      ll rx = (i + 1) * (j + 1) * j;
      rx %= P;
      ll lx = i * (m - j) * (m - j - 1);
      lx %= P;
      ll dy = i * (i + 1) * m;
      dy %= P;
      ll sum = (rx + lx + dy) % P;
      sum *= c.inv[2];
      sum %= P;
      ans += sum;
      ans %= P;
    }
  ans *= c.comb(n * m - 2, k - 2);
  ans %= P;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>

int main () {
    std::string s;
    std::cin >> s;

    bool f1 = true;
    bool f2 = true;
    bool f3 = true;

    for (int i = 0; i < s.size() / 2; i++) {
        if(s[i] != s[s.size() - 1 - i]) {
            f1 = false;
        }
    }

    for (int i = 0; i < (s.size() - 1) / 4; i++) {
        if(s[i] != s[(s.size() - 1) / 2 - i - 1]) {
            f2 = false;
        }
    }

    for (int i = (s.size() + 3) / 2 ; i < (s.size() + 3) / 4; i++)
    {
        if (s[i] != s[s.size() - i - 1])
        {
            f2 = false;
        }
    }

    std::string ans;
    if (f1 && f2 && f3)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }

    std::cout << ans << std::endl;
}

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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ret1 = 0, ret2 = 0;
    vector<ll> b1(n), b2(n);
    int turn = 0;
    rep(i, n) {
        if (i == 0 or i == n-1) {
            b1[i] = (i%2 ? 1 : -1);
            b2[i] = (i%2 ? -1 : 1);
        }
        else {
            b1[i] = (i%2 ? 1 : -1) * 2;
            b2[i] = (i%2 ? -1 : 1) * 2;
        }
    }
    sort(b1.begin(), b1.end());
    sort(b2.begin(), b2.end());
    rep(i, n) {
        ret1 += b1[i] * a[i];
        ret2 += b2[i] * a[i];
    }
    cout << max(ret1, ret2) << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
bool prime(int n){
  if(n == 2)return true;
  if(n <=1 or n % 2 == 0)return false;
  for(int i = 3; i * i <= n; i+=2){
    if(n % i == 0)return false;
  }
  return true;
}
int main(){
  int n;
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    if(prime(x))cnt ++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//65 90
int main()

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

    int n;
    string s;

    cin >> n >> s;

    for (int i = 0; i < s.size(); i++) {

        if (int(s[i])+n > 90) cout << char(65+(s[i]+n)%90-1);
        else cout << char(s[i]+n);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

#define LOOP(N) for(int i=N; i--;)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(start); i<(end); ++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;


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

    int N; cin >> N;
    
    int a, b, c;
    int _a, _b, _c;
    int ha, hb, hc;
    ha = hb = hc = 0;
    LOOP(N) {
        cin >> a >> b >> c;
        _a = max(hb, hc) + a;
        _b = max(hc, ha) + b;
        _c = max(ha, hb) + c;
        ha = _a;
        hb = _b;
        hc = _c;
    }
    cout << max(ha, max(hb, hc));
}


Measured memory_bytes: 256
N,K=list(map(int,input().split()))
S=list(input())
if S[K-1]=='A':
    S[K-1]="a"
if S[K-1]=='B':
    S[K-1]='b'
if S[K-1]=='C':
    S[K-1]='c'
print(''.join(S))

Measured memory_bytes: 3060
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.r(5).sort((a,b)=>a-b);
  var ans = Math.ceil(n / a[0]) + 4;
  return ans;
}

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

using namespace std;

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


Measured memory_bytes: 3612
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        char[] s = S.toCharArray();
        for (int i = 0; i < S.length(); i++) {
            if (s[i] == '1') {
                K--;
                if (K == 0) {
                    System.out.println(s[i]);
                    return;
                }
            }
            if (s[i] != '1') {
                System.out.println(s[i]);
                return;
            }
        }
    }
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int n;
    cin >> n;
    vector<ll> vi(n);
    REP(i, n)
    cin >> vi[i];

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    set<int> si;
    REP(i, n)
    {
        int idx=-1;
        ll maxa=0;
        REP(j, n)
        {
            if(si.find(j)==si.end()&&vi[j]>maxa){
                idx=j;
                maxa=vi[j];
            }
        }
        si.insert(idx);
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+abs(idx-j)*vi[idx]);
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+((n-1)-idx-(i-j))*vi[idx]);
        }
    }
    ll ans=0;
    REP(i,n+1)
        ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 35084
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

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

typedef long long ll;

const int kMaxN = 100000;

int N;
string S[kMaxN];
ll ans = 0;

int c[5];
string march = "MARCH";

int main() {
  cin >> N;
  REP(i, N) { cin >> S[i]; }

  fill(c, c+5, 0);
  REP(i, N) { REP(j, 5) { if (S[i][0] == march[j]) { ++c[j]; } } }

  REP(i, 5) {
    FOR(j, i+1, 5) {
      FOR(k, j+1, 5) {
        ans += (ll)c[i]*c[j]*c[k];
      }
    }
  }

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


Measured memory_bytes: 6144
N = int(input())
A = list(map(int, input().split()))

ans = 1
res = 10 ** 9 + 7
B = 0
R = 0
G = 0
for a in A:
    cnt = 0
    if a == B:
        cnt += 1
    else:
        pass
    if a == R:
        cnt += 1
    else:
        pass
    if a == G:
        cnt += 1
        G += 1
    elif a == R:
        R += 1
    else:
        B += 1
    ans = ans * cnt % res
print(ans)


Measured memory_bytes: 14056
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode(int x) : val(x), left(NULL), right(NULL) {}
	
};


int main() {
	//freopen("data_in.txt","r",stdin);
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> va(A, 0), vb(B, 0), vx(M, 0), vy(M, 0), vc(M, 0);
	int ma = INT_MAX, mb = INT_MAX;
	for (int i = 0; i < A; ++i) {
		cin >> va[i];
		ma = min(va[i], ma);
	}
	for (int i = 0; i < B; ++i) {
		cin >> vb[i];
		mb = min(vb[i], mb);
	}
	for (int i = 0; i < M; ++i) {
		cin >> vx[i] >> vy[i] >> vc[i];
	}
	int res = INT_MAX;
	for (int i = 0; i < M; ++i) {
		res = min(res, va[vx[i] - 1] + vb[vy[i] - 1] - vc[i]);
	}
	cout << min(res, ma + mb) << endl;
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    char s[5];
    int i,f1=0,f2=0,f,b,n;
    scanf("%s",s);
    n=atoi(s);
    f=n/100;
    b=n%100;
    if(f<13&&f>0){
        f1=1;
    }
    if(b<13&&b>0){
        f2=1;
    }
    if(f1==1&&f2==1){
        printf("AMBIGUOUS");
    }else if(f1==0&&f2==1){
        printf("YYMM");
    }else if(f1==1&&f2==0){
        printf("MMYY");
    }else{
        printf("NA");
    }

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846;

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

    double theta1 = (H * 60 + M) * 0.5;
    double theta2 = M * 6;
    double kyoukaku = max(theta1, theta2) - min(theta1, theta2);
    if (kyoukaku > 180)
    {
        kyoukaku = 360 - kyoukaku;
    }
    double ans = sqrt(A * A + B * B - 2 * A * B * cos(kyoukaku * PI / 180));

    cout << fixed << setprecision(20);
    cout << ans << endl;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    ll N;
  cin>>N;
  ll ans=0;
  vector<ll>A(N);
  rep(i,N){
cin>>A[i];
  }
  sort(A.begin(),A.end());
  ans=abs(A[N-1]-A[0]);
  cout<<ans<<endl;
}






Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define LL long int

const LL MOD = pow(10,9) + 7;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a > b) swap(a,b);
    if(a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let a = read_vec::<i64>();

    let mut sum_a = vec![0; n];
    sum_a[0] = a[0];
    for i in 1..n {
        sum_a[i] = a[i] + sum_a[i - 1];
    }

    let best = |x| if x > 0 { x } else { 0 };
    let mut sum_a_best = vec![0; n];
    sum_a_best[0] = best(a[0]);
    for i in 1..n {
        sum_a_best[i] = best(a[i]) + sum_a_best[i - 1];
    }

    let mut ans = max(sum_a[k - 1], 0) + sum_a_best[n - 1] - sum_a_best[k - 1];
    for i in 0..n - k {
        let temp = sum_a_best[i]
            + max(sum_a[k + i] - sum_a[i], 0)
            + (sum_a_best[n - 1] - sum_a_best[k + i]);
        ans = max(ans, temp);
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444