akhauriyash/Code-Regression huggingface dataset:
/*
 * Author: Dumbear
 * Created Time:  2011/8/31 14:29:36
 * File Name: H.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

long long n;

bool solve();

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

bool solve() {
    scanf("%lld", &n);
    if (n == 0)
        return false;
    long long cnt = n - 1;
    for (long long i = 1; ; ++i) {
        if (i * i * 2 >= n)
            break;
        long long m = n / 2 / i;
        if (m * i * 2 == n)
            --m;
        cnt += (m - i) * 2 + 1;
    //printf("-- %I64d\n", cnt);
    }
    //printf("-- %I64d\n", cnt);
    printf("%lld\n", cnt * 8 + 8 * n);
    return true;
}

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

long long n,dp[100005],w,v,k,mxw,ans,pt,lpt;
bool d[100005];
int main(){
	scanf("%lld%lld",&n,&mxw);
	for (int i=100000;i>=1;i--){
		dp[i]=1e9+1;
	}
	d[0]=true; dp[0]=0;
	for (int i=1;i<=n;i++){
		scanf("%lld%lld",&w,&v); 
		for (int j=100000;j>=0;j--){
			if (d[j] == true && j+v <= 100000 && dp[j]+w <= mxw){
				d[j+v]=true;
				dp[j+v]=min(dp[j+v],dp[j]+w);
			}
		}
	}
	for (int i=0;i<=100000;i++){
		if	(d[i])
		ans=i;
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main() {
	int n;

	cin >> n;

	bool is_even = false;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if ((a & 1) == 1) {
			is_even  =  true;
		}
	}

	if (is_even) {
		cout << "first" << endl;
	} else {
		cout << "second" << endl;		
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


int main() {
	int N ;
	string S;
	cin >> N >> S;
	int x = 0;
	int ans = 0;

	for (int i = 0;i < N;i++) {
		if (S.at(i) == 'I')x++;
		if (S.at(i) == 'D')x--;
		ans = max(ans, x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 2005;
const int mod = 1e9+7;
int f[maxn],n,k;
int main(){
	n = rd(),k = rd();
	mem(f,0);
	f[n+1] = 1;
	Dep(i,n,n-k+1){
		Dep(j,n,i+1)f[j]=0;
		Dep(j,i,1) f[j] = (f[j] + f[j+1]) % mod;
	}
	ll ans = f[1];
	Rep(i,1,n-k-1)ans=ans*2%mod;
	writeln(ans);
}
/*

考虑填写数列的前面，后面两边都可以，直接乘上2的若干次幂 

相当于必须得分割成两个递减序列

不妨用贪心，用[a,b]表示两个序列最小的，如果a能小就a小，否则b小。

f[i][j]表示填到第i个数字（还没填），第一个栈的值j的时候的方案数。

如果放第一个数字，设为k，则可以转移到f[i+1][k]

如果放第二个数字，显然只能放之前放的最大的数字，否则不合法（不能分割成2个递减序列）

那么f[i][j]转移到f[i+1][j]——在前面有值的时候才能转移。

可以得到f[k+1][1]。 

*/

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

class union_find {
 public:
  using tp = std::vector<size_t>::size_type;
  // 取り扱う型.

  explicit union_find(const tp n) : parent(n), rank(n, 0), cache() {
    for (tp i = 0; i < n; i++) {
      parent[i] = i;
    }
    cache.reserve(n);
  }

  tp root(tp n) {
    // 番号nの親を求める. ついでに経路圧縮を行う.

    while (parent[n] != n) {
      // 根になるまで親を探索. ついでにキャッシュ変数に追加.
      cache.push_back(n);
      n = parent[n];
    }
    for (const auto i : cache) {
      // キャッシュ変数に追加された子の親を経路圧縮.
      parent[i] = n;
    }
    cache.clear();
    return n;
  }

  bool same(tp x, tp y) {
    // xとyが同じグループに属しているか計算.
    return root(x) == root(y);
  }

  void unite(const tp x, const tp y) {
    // xとyを同じグループにする.
    const auto x_root = root(x);
    const auto y_root = root(y);

    if (x_root == y_root) {
      // 根が同じなら元から同じグループ.
      return;
    }

    if (rank[x_root] < rank[y_root]) {
      // rankの大きい方の根を統合後の根にする.
      parent[x_root] = y_root;
    } else if (rank[y_root] < rank[x_root]) {
      // rankの大きい方の根を統合後の根にする.
      parent[y_root] = x_root;
    } else {
      // rankが同じなら, どっちかを根にして根になったほうのランクを上げる.
      parent[x_root] = y_root;
      rank[x_root]++;
    }
  }

 private:
  std::vector<tp> parent;
  // 親の番号を格納. 自分が根なら parent[i] == i になる.
  std::vector<tp> rank;
  // 自分の下に何段分の子があるかを格納.
  std::vector<tp> cache;
  // root計算のときに経路圧縮を行うためのキャッシュ変数.
};

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

  for (int64_t i = 0; i < m; i++) {
    int64_t x, y, z;
    std::cin >> x >> y >> z;
    x--;
    y--;
    uf.unite(x, y);
  }

  std::vector<int64_t> ans(n, 0);

  for (int64_t i = 0; i < n; i++) {
    ans[uf.root(i)]++;
  }

  int64_t count = 0;

  for (const auto i : ans) {
    if (i != 0) {
      count++;
    }
  }

  std::cout << count << std::endl;

  return 0;
}


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

#define endl '\n'
#define rep(i,n)       for(int i=0; i<n; i++)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define all(x)         x.begin(), x.end()
const int MOD = 1e9 + 7;

#ifdef SMIT
template<class F, class S> ostream& operator<<(ostream &out, const pair<F, S> &p)
{
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out)
{
	out << '{';
	for (auto i = x.begin(); i != x.end(); i++)
		out << *i << (i == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dmp() {}
template<class T, class... Args> void dmp(T &&x, Args... args)
{
	cerr << x << ";  "; dmp(args...);
}
struct Nl {~Nl() {cerr << '\n';}};
#define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dmp(x), Nl(), cerr << ""
#else
#define debug(...) {}
#endif
// Yes you CAN
const int N = 1e5 + 1;

vector<int> g[N];
bool vis[N];
int n, m, u, v, dp[N];

void dfs(int u)
{
	dp[u] = 0;
	vis[u] = 1;
	for (auto i : g[u])
	{
		if (!vis[i])
			dfs(i);
		dp[u] = max(dp[u], 1 + dp[i]);
	}
}
void solve()
{
// #define TEST
	memset(vis, 0, sizeof vis);
	memset(dp, 0, sizeof dp);
	cin >> n >> m;
	while (m--)
	{
		cin >> u >> v;
		g[u].push_back(v);
	}
	for (int i = 1; i <= n; i++)
	{
		if (!vis[i])
			dfs(i);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, dp[i]);
	cout << ans << endl;
}

int32_t main()
{
// #ifdef SMIT
// 	freopen("/home/smit/Desktop/in.txt", "r", stdin);
// #endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int t = 1;
#ifdef TEST
	cin >> t;
#endif
	while (t--)
		solve();
}

Measured memory_bytes: 12276
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
const int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};

ostream& operator<<(ostream& os, const pair<int, int>& p){
    return os << p.first << ' ' << p.second;
}

pair<int, int> solve(int N, vector<int>& n, vector<int>& d){
    vector<int> x(N), y(N);
    rep(i, (int)n.size()){
        x[i+1] = x[n[i]] + dx[d[i]];
        y[i+1] = y[n[i]] + dy[d[i]];
    }
    auto itrx = minmax_element(all(x)), itry = minmax_element(all(y));
    return mp(*itry.second - *itry.first + 1, *itrx.second - *itrx.first + 1);
}

int main(){
    int N;
    while(cin >> N, N){
        vector<int> n(N-1), d(N-1);
        rep(i, N-1)cin >> n[i] >> d[i];
        cout << solve(N, n, d) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  int m1 = 0;
  int m2 = 0;
  vector <int> A(N);
  for (int i = 0; i < N; i++) {
	  cin >> A[i];
	  if (A[i] >= m1) {
		  m2 = m1;
		  m1 = A[i];
		}
	  else if (A[i] >= m2) {
		  m2 = A[i];
		}
	}
  for (int i = 0; i < N; i++) {
	  if (A[i] == m1) {
		  cout << m2 << endl;
		}
	  else {
		  cout << m1 << endl;
		}
	}
  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

ll n, s, M=1e9+7, a[200005];
int main() {
	ll i;
	cin >> n;
	for(i=1; i<=n; i++) scanf("%lld", &a[i]);
	sort(a+1, a+n+1);
	for(i=1; i<=n; i++) s = (s + (i+1) * a[n+1-i]) % M;
	for(i=1; i<=n-1; i++) s = s * 4 % M;
	cout << s;
	return 0;
}

Measured memory_bytes: 1792
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(all(a));
    cout << a[2] - a[1] + a[1] - a[0] << endl;


    return 0;
}


Measured memory_bytes: 256
//     THE ONLY WAY IS UP
 
#include<bits/stdc++.h>
 
#define ll              long long int
#define ld              long double
#define f1(i, a, b)     for(ll i = a; i < b; i++)
#define f2(a, b)        for(auto a : b)
#define ar(v, i)        v[i]
#define ar_(v, i, j)    v[i][j]
#define in_(x)          ll x; cin >> x;
#define ino_(type, x)   type x; cin >> x;
#define pb              push_back
#define nl              "\n"
#define tcase(t)        ll t; cin >> t; f1(z, 0, t)
# define M_PI           3.14159265358979323846
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    in_(n)
    cout << fixed << setprecision(20);
    cout << 2 * M_PI * n << nl;
}

Measured memory_bytes: 3804
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        a = a.replaceAll("1", "2");
        a = a.replaceAll("9", "3");
        a = a.replaceAll("2", "9");
       a =  a.replaceAll("3", "1");
        System.out.println(a);
    }

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  string s;cin>>s;
  int ans=0;
  int pos=0;
  while ((pos=s.find("ABC",pos))!=string::npos){
    ans++;
    pos+=3;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	// sengen
	long long a,b,n;
	// nyuryoku
	cin >> a >> b >> n;
	// keisan
	if(n < b){
		cout << (long long)floorl((double)a/b*n);
	}else{
		cout <<  (long long)floorl((double)a/b*(b-1));
	}
	// syutsuryoku
}

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

C = Counter(A)
# 重複削除して降順、この順に処理していく
unique = sorted(set(A), reverse=1) + [0]
# ある値が最初に出現するindexを保持
D = {}
for i in range(N-1, -1, -1):
    D[A[i]] = i

ans = [0] * N
prevcnt = 0
mnidx = INF
for i, a in enumerate(unique[:-1]):
    nxta = unique[i+1]
    # 今回の位置が選ばれる回数 = 次の値との差分 * 今の値の個数
    cnt = (a - nxta) * (C[a] + prevcnt)
    # 今の値の先頭index
    mnidx = min(mnidx, D[a])
    ans[mnidx] += cnt
    # 今回の個数を次回以降用に追加
    prevcnt += C[a]
[print(a) for a in ans]


Measured memory_bytes: 33672
#include<cstdio>
#include<vector>
#include<algorithm>
int field1[1001];
int field2[1001];
using namespace std;
int main(void){
    while(1){
        for(int i = 0;i <= 1001;i++){
            field1[i] = 0;
            field2[i] = 0;
        }
        int n; scanf("%d",&n);
        if(n == 0) break;
        vector<pair<int,int> > v1;
        vector<pair<int,int> > v2;
        pair<int,int> p;
        p.first = 0; p.second = 0;
        v1.push_back(p); v2.push_back(p);
        for(int i = 0;i < n;i++){
            int h,r; scanf("%d%d",&h,&r);
            p.first = h; p.second = r;
            v1.push_back(p);
            p.first = r; p.second = h;
            v2.push_back(p);
        }

        scanf("%d",&n);
        for(int i = 0;i < n;i++){
            int h,r; scanf("%d%d",&h,&r);
            p.first = h; p.second = r;
            v1.push_back(p);
            p.first = r; p.second = h;
            v2.push_back(p);
        }

        sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end());
        for(int i = 1;i < v1.size();i++){
            for(int j = i - 1;j >= 0;j--){
                if(v1[i].second > v1[j].second && v1[i].first > v1[j].first && field1[i] <= field1[j]+1){
                    field1[i] = field1[j]+1;
                }
            }
        }

        for(int i = 1;i < v2.size();i++){
            for(int j = i-1;j >= 0;j--){
                if(v2[i].second > v2[j].second && v2[i].first > v2[j].first && field2[i] <= field2[j]+1){
                    field2[i] = field2[j]+1;
                }
            }
        }
        int ans = -1;
        for(int i = 0;i < v1.size();i++){
            if(field1[i] >= ans) ans = field1[i];
            if(field2[i] >= ans) ans = field2[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Tax Increase
            var line = ReadLine();
            int A = line[0];
            int B = line[1];

            Console.WriteLine(GetPrice(A, B));
        }

        static int GetPrice(int A, int B)
        {
            for (int i = 1; i <= 1500; i++)
            {
                if (i * 8 / 100 == A && i / 10 == B)
                {
                    return i;
                }
            }

            return -1;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define mod 1000000007
int f[1000010];
int main(){
	int n;std::cin>>n;
	f[n]=n;f[n-1]=1ll*n*n%mod;
	int sum=0;
	for(int i=n-2;i>0;--i){
		sum=(sum+f[i+3])%mod;
		f[i]=(f[i+1]+1ll*(n-1)*(n-1)%mod+sum+i+1)%mod;
	}
	printf("%d\n",f[1]);
	return 0;
}


Measured memory_bytes: 4096
N,K=[int(a) for a in input().split(" ")]
TD = [[int(a) for a in input().split(" ")] for i in range(N)]
TD = sorted(TD, key=lambda arr: arr[1])[::-1]

types = set()
stack = []
ans, totald, i = 0, 0, 0
for i in range(K):
    t, d = TD[i]
    if t in types:
        stack.append(d)
    totald += d
    types.add(t)
ans = totald+len(types)**2

while len(stack)>0:
    while i<N and TD[i][0] in types:
        i+=1
    if i>=N: break
    t1, d1 = TD[i]
    lt = len(types)
    d2 = stack.pop()
    totald -= (d2-d1)
    types.add(t1)
    i+=1
    ans = max(ans, totald+len(types)**2)
print(ans)

Measured memory_bytes: 71512
#include<bits/stdc++.h>
using namespace std;
string s[33][6];
int check(int a,int b){
  if(s[a][0]==s[b][0]&&s[a][1]==s[b][1]&&s[a][2]==s[b][2]&&s[a][3]==s[b][3]&&s[a][4]==s[b][4]&&s[a][5]==s[b][5])return 1;
    return 0;
}
void r1(int a){
  string p=s[a][0];
  swap(s[a][0],s[a][2]);swap(s[a][2],s[a][5]);
  swap(s[a][5],s[a][3]);s[a][3]=p;
}
void r2(int a){
  string p=s[a][0];
  swap(s[a][0],s[a][1]);swap(s[a][1],s[a][5]);
  swap(s[a][5],s[a][4]);s[a][4]=p;
}
void r3(int a){
  string p=s[a][1];
  swap(s[a][1],s[a][2]);swap(s[a][2],s[a][4]);
  swap(s[a][4],s[a][3]);s[a][3]=p;
}
int c7(int a,int b){
  int p=0;
  for(int i=0;i<4;i++){
    r1(a);
    for(int j=0;j<4;j++){
      r2(a);
      for(int k=0;k<4;k++){
        r3(a);
        if(check(a,b))p++;
      }
    }
  }
  return p;
}
int main(){
  int n;
  while(cin>>n,n){
    int sum=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<6;j++)
        cin>>s[i][j];
    for(int i=0;i<n;i++){
      int p=0;
      for(int j=i+1;j<n;j++){
        if(c7(i,j))p++;
      }
      if(p)sum++;
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 3136
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n, towns[100005], a, b;
long long ans;

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

    cin >> n >> a >> b;
    for(int i=0; i<n; i++) cin >> towns[i];

    for(int i=0; i<n-1; i++) {
        if((long long)(towns[i+1] - towns[i]) * a > b) ans += b;
        else ans += (long long)(towns[i+1] - towns[i]) * a;
    }

    cout << ans;
}

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

int d[30][30], color[500][500];
int arr[3][30];
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = 0; i < c; i++)
    for (int j = 0; j < c; j++)
      scanf("%d", &d[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      scanf("%d", &color[i][j]);
  int res = INT_MAX;
  for (int cx = 0; cx < c; cx++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        arr[(i + j) % 3][cx] += d[color[i][j] - 1][cx];
      }
    }
  }
  for (int c1 = 0; c1 < c; c1++) {
    for (int c2 = 0; c2 < c; c2++) {
      for (int c3 = 0; c3 < c; c3++) {
        if (c1 == c2 || c2 == c3 || c3 == c1)
          continue;
        for (int i = 0; i < 3; i++) {
          for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
              if (i == j || j == k || k == i)
                continue;
              res = min(res, arr[i][c1] + arr[j][c2] + arr[k][c3]);
            }
          }
        }
      }
    }
  }
  printf("%d\n", res);
}


Measured memory_bytes: 1280
use std::io::*;
use std::str::FromStr;

fn abc(a: i32, b: i32) -> i32 {
    return (a-1)*(b-1)
    }

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    let a: i32 = read();
    let b: i32 = read();

    let result = abc(a, b);

    println!("{}", result);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#pragma comment(linker, "/STACK:1000000000")
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<cassert>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
////////////////////

int const N = 1e5 + 41;
int const INF = 1e9 + 41;

vector<int> e[N];
int n, d[N], q[N], m;
int a, b;

int getmatch(multiset<int> &t, int x){
	if(sz(t) == 0) return INF;
	multiset<int> :: iterator it = t.upper_bound(x);
	if(it == t.begin()) return INF;
	--it;
	return (*it);
}

void dfs(int x, int p = -1){
	d[x] = 0;
	q[x] = 0;
	vector<int> h;
	fi(0, sz(e[x])){
		int y = e[x][i];
		if(y == p) continue;
		dfs(y, x);
		h.pb(d[y] + 1);
		q[x] += q[y];
	}
	sort(h.begin(), h.end());
	multiset<int> t;
	fdi(sz(h), 0){
		int v0 = h[i];
		int v1 = m - v0;
		int k = getmatch(t, v1);
		if(k + v0 <= m){
			t.erase(t.find(k));
			q[x] += 1;
			continue;
		}
		t.insert(v0);
	}
	q[x] += sz(t);
	if(sz(t) > 0){
		int v0 = (*t.begin());
		if(v0 < m){
			--q[x];
			d[x] = v0;
		}
	}
}

int calc(int m){
	::m = m;
	dfs(0);
	int res = q[0];
	if(d[0] > 0) res += 1;
	return res;
}

void solve(){
	if(n == 2){
		a = 1;
		b = 1;
		return;
	}
	int l = 0;
	int r = N;
	a = calc(n);
	while(r-l>1){
		int m = (l+r)/2;
		if(calc(m) == a) r = m;
		else l = m;
	}
	b = r;
	/*fi(0, n+1){
		if(calc(i) == a){
			b = i;
			break;
		}
	}*/
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, n-1){
		int x, y;
		scanf("%d %d",&x,&y);
		--x;--y;
		e[x].pb(y);
		e[y].pb(x);
	}

	solve();

	printf("%d %d\n",a,b);
	return 0;
}

Measured memory_bytes: 19840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));
#define op(i) cout<<(i)<<endl;

int main(){
    ll a,n;
  int ans=0;
  cin>>a>>n;
 repf(i,1,n-a){
   ans+=i;
 }
  cout<<ans-a<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

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

	

	vector<ll> a(n);
	
	ll max_a = 0;
	for (int i = 0; i < n;i++) {
		cin >> a[i];
		
		max_a = max(max_a, a[i]);
	}
	ll ans = 0;
	k++;
	for (int i = 0; (1LL << i) <= k;i++) {
		
		ll sum = 0;
		if (((k >> i) & 1) == 1) {
			

			for (int j = i + 1; (1LL << j) <= max(max_a,k);j++) {
				
				int num = (k >> j) & 1;
				
				int cnt = 0;
				for (ll ai : a) {
					if (((ai >> j) & 1) != num) {
						cnt++;
					}
				}
				sum += cnt * (1LL << j);
			}
			int cnt = 0;
			for (ll ai : a) {
				if (((ai >> i) & 1) == 1) {
					cnt++;
				}
			}
			sum += cnt * (1LL << i);

			for (int j = 0; j < i;j++) {
				ll cnt = 0;
				for (ll ai : a) {
					if (((ai >> j) & 1) != 1) {
						cnt++;
					}
				}

				sum += max(cnt, n - cnt) * (1LL << j);
			}
		}
		//cout << sum << endl;
		ans = max(ans, sum);
		
	}

	
	cout << ans << endl;
}



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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    string cs;
    cin >> cs;
    int l = 0, r = n-1, ans = 0;
    while (1) {
        if (l>=r) break;
        while (l<r&&cs[l]!='W') ++l;
        while (l<r&&cs[r]!='R') --r;
        if (l>=r) break;
        ++ans;
        ++l; --r;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int count = 0;
    vector<int> left(N);
    vector<int> right(N);
    rep(i,N){
        cin >> left[i];
        cin >> right[i];
    }
    rep(i,N){
        count += right[i] - left[i] + 1;
    }
    cout << count << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,M;
    string S;
    cin >> N >> M >> S;
    rep(i,S.size()){
        if(i==N){
            if(S[i]!='-'){
                cNo;
                return  0;
            }
        }
        else{
            if(S[i]=='-'){
                cNo;
                return  0;
            }
        }
    }
    cYes;
}

Measured memory_bytes: 256
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい

killed_monsters = 0

for idx in range(N-1):
    killed_monsters += min(A_l[idx], B_l[idx])
    if B_l[idx] - A_l[idx] > 0:
        killed_monsters += min(B_l[idx] - A_l[idx], A_l[idx+1])
        A_l[idx+1] = max(0, A_l[idx+1] - (B_l[idx] - A_l[idx]))

killed_monsters += min(A_l[-2] + A_l[-1], B_l[-1])

print(killed_monsters)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X[300][300],cnt=0;
  for(int i=0; i<300; i++) {
      cin >> X[i][0] >> X[i][1];
      if(X[i][0]==0&&X[i][1]==0) {
          cnt=i;
          break;
      }
  }
  for(int i=0; i<cnt; i++) {
      for(int j=0; j<X[i][0]; j++) {
          for(int k=0; k<X[i][1]; k++) {
              if(j==0||k==0||j==X[i][0]-1||k==X[i][1]-1) {
                  cout << '#';
              }
              else {
                  cout << '.';
              }
          }
          cout << endl;
      }
      cout << endl;
  }
}


Measured memory_bytes: 3028
def change(time):
  if time >= 10:
    return str(time)
  else:
    return "0" + str(time)
def print_times(ans):
  sec = ans % 60
  ans -= sec
  minu = ans % 3600
  ans -= minu
  minu //= 60
  hour = ans//3600
  print(":".join(map(change,(hour,minu,sec))))

while True:
  t,h,s = map(int,input().split())
  if (t,h,s) == (-1,-1,-1):
    break
  ans = 7200 - (3600 * t + 60 * h + s)
  ans2 = ans * 3
  print_times(ans)
  print_times(ans2)

Measured memory_bytes: 7668
#include<iostream>
#include<cmath>

using namespace std;

int main(int argc, char* argv[]){
  size_t X; cin >> X;

  size_t current_max = 0;
  for(size_t i = 1; i <= 32; i++) {
    for(size_t j = 2; j <= 10; j++) {
      size_t current_num = pow(i,j);
      if(current_max < current_num and current_num <= X) {
        current_max = current_num;
      }
      if(current_num > X) {
        break;
      }
    }
  }

  cout << current_max << endl;

  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLineStr();
            var t = ReadLineStr();

            var count = 0;
            for(var i = 0; i < s.Length; i++)
            {
                if(s[i] != t[i]) { count++; }
            }

            Console.WriteLine(count);
        }


        #region 使いまわし
        static string ReadLineStr() { return Console.ReadLine(); }
        static int ReadLineInt() { return Convert.ToInt32(Console.ReadLine()); }
        static (int, int) ReadLineInt2()
        {
            var temp = Console.ReadLine().Split(' ');
            return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));
        }
        static List<int> ReadLineIntList()
        {
            var data = new List<int>();
            foreach (var temp in Console.ReadLine().Split(' '))
            {
                data.Add(Convert.ToInt32(temp));
            }

            return data;
        }

        static long ReadLineLong() { return Convert.ToInt64(Console.ReadLine()); }
        #endregion
    }
}


Measured memory_bytes: 27432
from collections import deque

n, k = map(int, input().split())
Hs = list(map(int, input().split()))

Hs.sort(reverse=True)
Hs = deque(Hs)

for i in range(k):
    if len(Hs) == 0:
        print(0)
        exit()
    Hs.popleft()


print(sum(Hs))

Measured memory_bytes: 26280
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <numeric>
#include <memory>
#include <functional>
#include <stdexcept>
#include <typeinfo>
#include <limits>
#include <complex>
#include <locale>
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define Debug2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<")\n";
#define Debug_arr(v,n) for(int i=0;i<n;++i) cerr<<#v<<"["<<i<<"]"<<" = "<<v[i]<<endl;
#define SET(p,v) fill((__typeof(**p)*)p,(__typeof(**p)*)p+sizeof(p),v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define prl cerr << "called: " << __LINE__ << endl
//#define FILE_JUDGE
//#define TIMES
//#define LINES
//#define home
long long a[4];
long long c[4]={1,2,4,8},t;
pair<float,int> f[4];
int main()
{
	#ifdef FILE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	for (int i=0;i<4;++i)
	{
		cin>>a[i];
	}
	cin>>t;
	t*=4;
	for (int i=1;i<4;++i)
	{
		a[i]=min(a[i],a[i-1]*2);
	}
	for (int i=0;i<4;++i)
	{
		f[i]={(float)a[i]*4/c[i],i};
	}
	sort(f,f+4);
	long long i=0,ans=0;
	while (t>0 && i<4)
	{
		long long x=t/c[f[i].second];
		t-=x*c[f[i].second];
		ans+=x*a[f[i].second];
		i++;
	}
	cout<<ans<<endl;
	#ifdef TIMES
	eprintf("Times = %d ms.\n",clock());
	#endif
	#ifdef LINES
	eprintf("lines : %d line.\n",__LINE__+3);
	#endif
	return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

int main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	static int a[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	static int vec[100010];
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	
	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);


//	scanf("%s",&s);
//	scanf_s("%s",&s,1000010);


	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
//		scanf_s("%d",&a[i]);
	}

/*	//scanf("%c",&dummy);
	scanf_s("%c",&dummy);
	for(i=0;i<n;i++){
//		scanf("%c",&s[i]);
		scanf_s("%c",&s[i]);
	}*/


/*	for(i=0;i<3;i++){
//		scanf("%s",&s);
		scanf_s("%s",&s[i],100010);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	for(i=0;i<10000;i++){
		vec[i]=0;
	}

	for(i=0;i<n;i++){
		vec[a[i]]++;
	}

	ans=0;
	for(i=1;i<=99998;i++){
		ans=max(ans,vec[i-1]+vec[i]+vec[i+1]);
	}

	printf("%d",ans);

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=(int)a,i<(int)b;++i)

int main(){

  while(1){
    int n;
    cin >> n;
    if(n==0) break;
    string s;
    int ans=0;
    int l=0,r=0,pre=0;
    //    rep(i,0,n){
    for(int i = 0; i<n;i++){
      cin >> s;
      if(s[0] == 'l'){
	l+=1;
	l%=2;
      }
      if(s[0] == 'r'){
	r+=1;
	r%=2;
      }
      if(pre == 0 && l==1 && r==1){
	ans++;
	pre=1;
      }
      if(pre == 1 && l == 0 && r == 0){
	ans++;
	pre=0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

// グローバル変数
ll n;
vector<ll> c;
//vector<pair<ll, ll>> a; // No.16

// 関数プロトタイプ
void input();
void solve();

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> n;
    c.resize(n);
    for (int i = 0; i < n;i++) {
        cin >> c[i];
    }
}

void solve() {
    sort(c.begin(), c.end());
    double ans = (c[0] + c[1]) / 2.0;
    for (int i = 2; i < n; i++) {
        ans = (ans + c[i]) / 2.0;
    }
    cout << ans << endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  if (!(b % a)) {
    cout << b;
    return 0;
  }
  
  long long result = a;
  
  
  
  while (1){
    if (!(result % b)) break;
    result += a;
  }
    
    
  cout << result;
  return 0;
}


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

using namespace std;


typedef long long ll;
int main() {
  ll k;
  cin >> k;
  ll s = k/50;
  vector<ll> ans;
  for (int i = 0; i < 50; ++i) {
    ans.push_back(s+i);
  }
  for (int i = 0; i < k%50; ++i) {
    ans[i] += 50;
    for (int j = 0; j < 50; ++j) {
      if (i==j) continue;
      ans[j]--;
    }
  }
  cout << 50 << endl;
  for (auto a : ans) {
    cout << a << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define PII pair<int,int>
#define s second
#define f first
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x)%MOD;
        }
        p = p >> 1;
        x = (x*x)%MOD;
    }
    return res;
}

int main() {
    IO;
    int n, m;
    cin >> n >> m;
    char arr[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> arr[i][j];
        }
    }
    ll dp[n][m];
    dp[n-1][m-1] = 1;
    for(int i = n-1; i >= 0; i--){
        for(int j = m-1; j >= 0; j--){
            if(i == n-1 && j == m-1)continue;
            dp[i][j] = 0;
            if(arr[i][j] == '#')continue;
            if(i < n-1){
                dp[i][j] += dp[i+1][j];
            }
            if(j < m-1){
                dp[i][j] += dp[i][j+1];
            }
            dp[i][j] %= MOD;
        }
    }
    cout << dp[0][0];

    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


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

  int N; std::cin >> N;
  std::vector<std::vector<int>> A(N, std::vector<int>(N-1));
  for(int i=0; i<N; i++) for(int j=0; j<N-1; j++) { std::cin >> A[i][j]; A[i][j]--; }


  // (1) worst solution : O(N*N*N)
  /*
  std::vector<int> index(N);
  int day;
  for(day=1; ; day++) {
    bool update = false;
    for(int i=0; i<N; i++) {
      if ( index[i] == N-1 ) continue;
      int Y = A[i][index[i]];
      if ( (i < Y && A[Y][index[Y]] == i) || (i > Y && A[Y][index[Y]-1] == i) ) {
        index[i]++;
        update = true;
      }
    }
    bool check = false;
    for(int i=0; i<N; i++) if ( index[i] != N-1 ) check = true;
    if ( !check ) break;

    if ( !update ) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  std::cout << day << std::endl;
  */


  // (2) : faster than (1)
  std::vector<int> index(N);
  std::vector<std::pair<int,int>> q;
  auto check = [&](int I) {
    if ( index[I] == N-1 ) return;
    int Y = A[I][index[I]];
    if ( A[Y][index[Y]] == I ) { 
      if( I < Y ) std::swap(I,Y);
      q.push_back( std::pair<int,int>(I,Y) );
    }
    return;
  };
  rep(i,N) check(i);

  int day;
  for(day=1; ; day++) {
    std::sort( all(q) );
    q.erase( std::unique( all(q) ), q.end() );
    std::vector<std::pair<int,int>> PrevQ; std::swap(PrevQ, q);
    for(auto&& n : PrevQ) {
      index[n.first]++;
      index[n.second]++;
    }
    for(auto&& n : PrevQ) {
      check(n.first);
      check(n.second);
    }
    if(sz(q) == 0) break;
  }
  rep(i,N) if ( index[i] != N-1 ) { std::cout << -1 << std::endl; return 0; }
  std::cout << day << std::endl;

  return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main{

	    public static void main(String[] args){
	        Scanner scan = new Scanner(System.in);
	        int n = scan.nextInt();
	        int m = scan.nextInt();
	        int l = scan.nextInt();
	        long[][] array_A = new long[n][m];
	        long[][] array_B = new long[m][l];
	        long[][] array_C = new long[n][l];

	        for(int i=0; i<n; i++){
	            for(int j=0; j<m; j++){
	                array_A[i][j] = scan.nextInt();
	            }
	        }

	        for(int i=0; i<m; i++){
	            for(int j=0; j<l; j++){
	                array_B[i][j] = scan.nextInt();
	            }
	        }

	        for(int i = 0; i<n; i++){
	            for(int j=0; j<l; j++){
	                for(int k = 0; k<m; k++){
	                    array_C[i][j] += array_A[i][k]*array_B[k][j];
	                }
	            }
	        }

	        for(int i = 0; i<n; i++){
	            System.out.print(array_C[i][0]);
	            for(int j=1;j<l;j++){
	                System.out.print(" "+array_C[i][j]);
	        }
	        System.out.println();
	        }

	    }
	}

Measured memory_bytes: 53348
x, y, a, b, c = map(int, input().split())
p_array = list(map(int, input().split()))
q_array = list(map(int, input().split()))
r_array = list(map(int, input().split()))
apple = []
p_array.sort()
q_array.sort()
for _ in range(x):
    apple.append((p_array.pop(), 1))
for _ in range(y):
    apple.append((q_array.pop(), 2))
for r in r_array:
    apple.append((r, 0))
apple.sort()
print(sum(map(lambda z: z[0], apple[-(x + y):])))

Measured memory_bytes: 37552
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a,b,c,x,y = inpm()

ans = float('inf')
for ab in range(max(x+1,y+1)):
    ans = min(ans,c*ab*2 + a*max(0,x - ab) + b*max(0,y-ab))

print(ans)

Measured memory_bytes: 31212
/**********

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*********/

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

long long gcd(long long a,long long b){
    return b?gcd(b,a%b):a;
}

long long primechk[10000];

void preprocess(long long N){
    long long i,j;
    for(i=2;i<=N;i++){
        primechk[i]=1;
    }
    for(i=2;i<=N;i++){
        if(primechk[i]==1){
            for(j=2;i*j<=N;j++){primechk[i*j]=0;}
        }
    }
}

long long Binexpo(long long a,long long b){
    if(b==0)
        return 1;
    long long res=Binexpo(a,b/2);
    if(b%2){return res*res*a;}
    else{return res*res;}
}
long long Pwr(long long a,long long b,long long m){
    a%=m;
    long long res=1;
    while(b>0){
        if(b%2){res=res*a%m;}
        a=a*a%m;
        b>>=1;
    }
    return res;
}
int main()
{   long long a,b,c,d,e,f,g,h,i,j,k,x,y,z,sum,cnt=0,cnt2=0;
    string s;
    cin>>a>>b;
    char arr[a+1][b];
    char arr2[2*a+1][b];
    for(i=1;i<=a;i++){
        for(j=1;j<=b;j++){
            cin>>arr[i][j];
        }        
    }
    for(i=1;i<=2*a;i++){
        for(j=1;j<=b;j++){
            cout<<arr[(i+1)/2][j];
        }
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int , input().split()))
b = [a[i] - (i+1) for i in range(n)]

b.sort()
#print(b)
#ans = 10 ** 10
bi = b[n//2]
s = 0
for i in range(n):
    s += abs(a[i] - (i + 1 + bi))
#print(((n-1)//2+j)%n, s)
#ans = min(ans, s)
print(s)

"""
for j in range(3):
    bi = b[(n//2+j)%n]
    s = 0
    for i in range(n):
        s += abs(a[i] - (bi + i + 1))
    #print(((n-1)//2+j)%n, s)
    ans = min(ans, s)
print(ans)
"""

Measured memory_bytes: 25200