akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
    int n;
    cin >> n;
    vector<ll> arr(n);
    for(ll &x : arr)
        cin >> x;
    ll pref = 0;
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        sum = (sum + (pref % mod * arr[i] % mod) % mod) % mod;
        pref = (pref % mod + arr[i] % mod) % mod;
    }
    cout << sum;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
int A;
int main()
{
    int n=0,k;
    scanf("%d",&A);
    while(true)
    {
        if(n*(n+1)/2>=A)
            break;
        n++;
    }
    k = n*(n+1)/2-A;
    for(int i=0;i<n-k;i++)
        printf(")");
    printf("(");
    for(int i=0;i<k;i++)
        printf(")");
    for(int i=0;i<n-1;i++)
        printf("(");
    printf("\n");
    return 0;
}

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

int main(){
    int n, m, l, k, a, h;
    while(cin >> n >> m >> l >> k >> a >> h, n){
        vector<bool> aid(n, 0);
        while(l-- > 0){
            int x;  cin >> x;
            aid[x] = true;
        }
        vector<pair<int,int>> v[n];
        while(k-- > 0){
            int x, y, t;
            cin >> x >> y >> t;
            v[x].push_back({y,t});
            v[y].push_back({x,t});
        }
        vector<vector<int>> dp(n, vector<int>(m+1, 1<<30));
        priority_queue<pair<int, pair<int,int>>> pq;
        pq.push({0, {a, m}});
        dp[a][m] = 0;
        int ans = 1<<30;
        while(!pq.empty()){
            auto p = pq.top();  pq.pop();
            int cost = -p.first, pos = p.second.first, fre = p.second.second;
            if(dp[pos][fre] != cost)    continue;
            dp[pos][fre] = cost;
            if(pos == h){
                ans = cost;
                break;
            }
            for(pair<int,int> next : v[pos]){
                int npos = next.first, ncost = next.second;
                if(fre >= ncost && dp[npos][fre-ncost] > cost+ncost)    dp[npos][fre-ncost] = cost+ncost, pq.push({-(cost+ncost), {npos, fre-ncost}});
                if(aid[pos]){
                    for(int j = max(fre, ncost); j <= m; j++){
                        if(dp[npos][j-ncost] > cost+ncost+j-fre)    dp[npos][j-ncost] = cost+ncost+j-fre, pq.push({-(cost+ncost+j-fre), {npos, j-ncost}});
                    }
                }
            }
        }
        if(ans == 1<<30)    cout << "Help!" << endl;
        else                cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3356
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int n, p;
    cin >> n >> p;
    vector<long long> d(n);
    vector<long long> g(n);
    g[0] = 1;
    for(int i = 1; i < n; i++){
        g[i] = (g[i-1])*10%p;
    }
    string s;
    cin >> s;
    d[0] = (g[0]*(int(s[n-1]) - '0')) % p;
    for(int i = 1; i < n; i++){
        d[i] = (d[i-1] + (g[i]*(int(s[n-i-1]) - '0')))%p;
    }
    long long ans = 0;
    vector<long long> a(p,0);
    for(int i = 0; i < n; i++){
        a[d[i]]++;
    }
    for(int i = 0; i < p; i++){
        if(i==0){
            ans += a[0] + (a[0]*(a[0]-1))/2;
        }else{
            ans += (a[i]*(a[i]-1))/2;
        }
    }
    if(p!=2&&p!=5) cout << ans << endl;
    else{
        long long as = 0;
        for(int i = 0; i < n; i++){
            if(int(s[i]-'0')%p==0){
                as += i+1;
            }
        }
        cout << as << endl;
    }
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long A[] = new long[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		B b[] = new B[M];
		Main main = new Main();
		for (int i=0;i<M;i++) {
			int count= sc.nextInt();
			long number = sc.nextLong();
			B tempB = main.new B();
			tempB.count = count;
			tempB.number = number;
			b[i] = tempB;
		}
		Arrays.sort(b);
		int count =0;
		long sum =0;
		int tempA = A.length-1;
		int tempB = b.length-1;
		while (count<N) {
			if (tempB<0||A[tempA]>b[tempB].number) {
				count ++;
				sum +=A[tempA];
				tempA--;
			} else {
				if (count+b[tempB].count<=N) {
					count+=b[tempB].count;
					sum  += b[tempB].number*b[tempB].count;
				} else {
					sum +=b[tempB].number*(N-count);
					count =N;
				}
				tempB--;
			}
		}
		System.out.println(sum);
	}

	public class B implements Comparable{
		public int count ;
		public long  number;
		@Override
		public int compareTo(Object o) {
			B b= (B)o;
			if (this.number>b.number)
				return 1;
			else if (this.number==b.number) {
				return 0;
			}
			return -1;
		}
	}
}

Measured memory_bytes: 93692
#include <stdio.h>
#include <algorithm>

using namespace std;

#define N 110000

struct Node {
    int l, r;
    bool operator < (Node u) {
        return r < u.r;
    }
}a[N];

int main() {
    int n, m;
    while (scanf("%d%d", &n, &m) == 2) {
        int res = 0, l, r;
        for (int i = 0; i < m; ++i) scanf("%d%d", &a[i].l, &a[i].r);
        sort(a, a + m);
        if (m > 0) res = 1;
        l = a[0].l; r = a[0].r;
        int i = 1;
        while (i < m) {
            if (a[i].r >= r && a[i].l < r) ++i;
            else {
                l = a[i].l; r = a[i].r;
                res++;
                ++i;
            }
        }
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 1024
import queue

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

def bfs():
    x = 0
    y = 0
    cnt = 0
    Q = queue.Queue()
    check = [[True for i in range(W)] for j in range(H)]
    
    Q.put((x, y, cnt))
    while Q.qsize() > 0:
        x, y , cnt = Q.get()
        for i in range(4):
            if 0 <= x + dx[i] < H and 0 <= y + dy[i] < W and check[x + dx[i]][y + dy[i]]:
                check[x + dx[i]][y + dy[i]] = False
                if field[x + dx[i]][y + dy[i]] == "#":
                    pass
                elif x + dx[i] == H - 1 and y + dy[i] == W - 1:
                    return cnt + 1
             
                else:
                    Q.put((x + dx[i], y + dy[i], cnt + 1))
                    
    return -1

nums=list(map(int,input().split()))
H = nums[0]
W = nums[1]


field = [[None for i in range(W)] for j in range(H)]

black = 0
for i in range(H):
    str1 = input()
    for j in range(W):
        field[i][j] = str1[j]
        if str1[j] == "#":
            black += 1
            
Q = queue.Queue()
res = bfs()
if res >= 0:
    result = H * W - black -(res + 1)
    print(result)
else:
    print(res)













Measured memory_bytes: 45032
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

// GCD : greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	sort.Ints(a)

	gcd := a[0]
	for i := 0; i < N; i++ {
		gcd = GCD(gcd, a[i])
	}
	for i := 0; i < N; i++ {
		a[i] /= gcd
	}

	gcd2 := a[0]
	find := false
	for i := 1; i < N; i++ {
		x := GCD(gcd2, a[i])
		if x == 1 {
			if find == false {
				find = true
			} else {
				gcd2 = x
			}
		} else {
			gcd2 = x
		}
	}

	gcd3 := a[len(a)-1]
	find = false
	for i := N - 1; i >= 0; i-- {
		x := GCD(gcd3, a[i])
		if x == 1 {
			if find == false {
				find = true
			} else {
				gcd3 = x
			}
		} else {
			gcd3 = x
		}
	}
	// out(gcd, gcd2, gcd3)
	out(max(gcd2, gcd3) * gcd)
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	int n;
	cin>>n;
	vi v(n);
	cin>>v;
	int maxlen =0;
	int curr=0;

	forn1(i,n)
	{
		if(v[i]>v[i-1])
			curr=0;
		else
			curr++;
		maxlen = max(maxlen,curr);
		
	}
	cout<<maxlen;
 
	return 0;	
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
const int K = 11;
vector<int> g[N];
int n, m;
int a[N][K];
int q[N][3];

void dfs(int v, int d, int c)
{
    a[v][d] = c;
    if (d == 0) return;
    for (int u : g[v])
    {
        if (a[u][d - 1] == -1)
            dfs(u, d - 1, c);
    }
    return;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d%d", &n, &m);
    while(m--)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        v--;u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
        q[i][0]--;
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < K; j++)
            a[i][j] = -1;
    for (int i = m - 1; i >= 0; i--)
    {
        if (a[q[i][0]][q[i][1]] == -1)
            dfs(q[i][0], q[i][1], i);
    }
    for (int v = 0; v < n; v++)
    {
        int ans = -1;
        for (int i = 0; i < K; i++)
            ans = max(ans, a[v][i]);
        ans = (ans == -1 ? 0 : q[ans][2]);
        printf("%d\n", ans);
    }

    return 0;
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    sort(a.rbegin(), a.rend());
    cout << (a[0] * 10 + a[1]) + a[2] << endl;

    return 0;
}

Measured memory_bytes: 3608
// Template Headers {{{
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	Solver() {}
	int solve();
};
// }}}

int Solver::solve() {
	int h, w; cin >> h >> w;
	int sx, sy; cin >> sx >> sy; sx--, sy--;
	int tx, ty; cin >> tx >> ty; tx--, ty--;
	vector<string> v(h); cin >> v;
	vvi dist(h, vi(w, INF));
	deque<pii> q;
	q.emplace_back(sx, sy);
	dist[sx][sy] = 0;
	while (!q.empty()) {
		auto [ux, uy] = q.front(); q.pop_front();
		for (auto [dx, dy] : {pii{0, 1}, pii{1, 0}, pii{0, -1}, pii{-1, 0}}) {
			int vx = ux + dx, vy = uy + dy;
			if (vx < 0 || vy < 0 || vx >= h || vy >= w) continue;
			if (v[vx][vy] == '#') continue;
			if (ll t = dist[ux][uy]; t < dist[vx][vy]) {
				dist[vx][vy] = t;
				q.emplace_front(vx, vy);
			}
		}
		for (int dx = -2; dx <= 2; dx++) for (int dy = -2; dy <= 2; dy++) {
			int vx = ux + dx, vy = uy + dy;
			if (vx < 0 || vy < 0 || vx >= h || vy >= w) continue;
			if (v[vx][vy] == '#') continue;
			if (ll t = dist[ux][uy] + 1; t < dist[vx][vy]) {
				dist[vx][vy] = t;
				q.emplace_back(vx, vy);
			}
		}
	}
	cout << (dist[tx][ty] >= INF ? -1 : dist[tx][ty]) << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solver.solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 8588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
//  int total_c=0;
  int arr2[n];
  arr2[0]=0;
  arr2[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
    arr2[i]=min(arr2[i-1]+abs(arr[i]-arr[i-1]), arr2[i-2]+abs(arr[i]-arr[i-2]));
  cout<<arr2[n-1]<<endl;
}

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

using namespace std;

long long n, f[200005], a[200005], s, c, mx, x,ss;

int main()
{
    cin>>n;
    for(int i=1; i<=n;i++){
        cin>>x;
        a[i]=x;
        f[x]++;
        if(x>mx){
            mx=x;
        }
    }
    ///suma combinarilor de frecvente
    for(int i=1;i<=mx;i++){
        s+=f[i]*(f[i]-1)/2;
    }
    for(int i=1;i<=n;i++){
        ss=s;
        ss=ss-f[a[i]]*(f[a[i]]-1)/2;
        ss=ss+(f[a[i]]-1)*(f[a[i]]-2)/2;
        cout<<ss<<endl;
    }
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
int main(){
const int M=1e9;
ULL S, a=M, b=0, c=0, d=M; cin >> S;
if(S<1e18){ b=1; c=M-S%M; d=S/M+1; }  
cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << "\n";
}

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

ll knapsack(vector<ll> &val,vector<ll> &wt,ll W,ll n,vector<vector<ll>> &dp)
{
    if(n==0 || W==0)
        return dp[n][W]=0;
    if(dp[n][W]!=-1)
        return dp[n][W];
   
    if(wt[n-1]<=W)
        return dp[n][W]=max(val[n-1]+knapsack(val,wt,W-wt[n-1],n-1,dp),knapsack(val,wt,W,n-1,dp));
   
    else
        return dp[n][W]=knapsack(val,wt,W,n-1,dp);
   
}

int main()
{
    ll n,W;
    cin>>n>>W;
    vector<ll>wt(n),val(n);
    for(ll i=0;i<n;i++)
    cin>>wt[i]>>val[i];
	vector<vector<ll>>dp(n+1,vector<ll>(W+1,-1));
    cout<<knapsack(val,wt,W,n,dp);
    cout<<endl;
    return 0;

}

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

int main() {
    int a[5];
    rep(i, 5) cin >> a[i];

    rep(i, 5) {
        if (a[i] == 0) {
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;

/* {{{ Variables */
ll N;
string s;
map<string, ll> dict;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> N;

  for (ll i = 0; i < N; ++i) {
    cin >> s;

    sort(s.begin(), s.end());
    dict[s]++;
  }
  /* }}} */

  /* {{{ Output */
  ll num = 0;
  for (auto iter: dict) {
    ll value = iter.second;
    num += value*(value-1)/2;
  }

  cout << num << endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
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;
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()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, 0, N) cin >> h[i];

    vector<int> dp(N + 1, inf);
    dp[0] = 0;
    rep(i, 0, N)
    {
        rrep(j, K, 1)
        {
            if (i - j < 0) continue;
            chmin(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
        }
    }
    cout << dp[N - 1] << endl;
}


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

int main() {
    int p=0;
    string s;
    cin >> s;

    rep(i,s.size())
        if(s.at(i) != 'B') {
            s.at(p) = s.at(i);
            ++p;
        } else {
            --p;
            p = max(p,0);
        }

    cout << s.substr(0,p) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = 0;
    //case1
    ans = A * X + B * Y;
    //case2
    ans = min(ans, C * 2 * max(X, Y));
    //case3
    if(X > Y){
        ans = min(ans, C * 2 * min(X, Y) +A *abs(X-Y));
    }
    else{
        ans = min(ans, C * 2 * min(X, Y) + B * abs(X - Y));
    }    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[2][33][33][33][33];
Int cnt[2][33][33][33][33];
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int w,h;
  while(cin>>w>>h,w){
    vector<string> s(h);
    for(Int i=0;i<h;i++) cin>>s[i];
    memset(dp,-1,sizeof(dp));
    memset(cnt,0,sizeof(cnt));
    {
      using T = tuple<Int, Int, Int, Int, Int>;
      queue<T> q;
      Int dy[]={0,0,1,-1,0};
      Int dx[]={1,-1,0,0,0};
      auto in=[&](Int y,Int x){
	return 0<=y&&y<h&&0<=x&&x<w;
      };
      
      for(Int qy=0;qy<h;qy++){
	for(Int qx=0;qx<w;qx++){
	  if(s[qy][qx]=='#') continue;
	  for(Int ay=0;ay<h;ay++){
	    for(Int ax=0;ax<w;ax++){
	      if(s[ay][ax]=='#') continue;
	      // t == 0	      
	      {		
		if(s[qy][qx]=='E'&&!(qy==ay&&qx==ax)){
		  dp[0][qy][qx][ay][ax]=1;
		  q.emplace(0,qy,qx,ay,ax);
		}
		for(Int k=0;k<5;k++){
		  Int ny=qy+dy[k],nx=qx+dx[k];
		  if(!in(ny,nx)||s[ny][nx]=='#') continue;
		  cnt[0][qy][qx][ay][ax]++;
		}
	      }
	      // t == 1
	      {
		for(Int k=0;k<5;k++){
		  Int ny=ay+dy[k],nx=ax+dx[k];
		  if(!in(ny,nx)||s[ny][nx]=='#') continue;
		  if(ny==qy&&nx==qx){		    
		    dp[1][qy][qx][ay][ax]=1;
		    q.emplace(1,qy,qx,ay,ax);		  
		  }
		  cnt[1][qy][qx][ay][ax]++;
		}
	      }
	    }
	  }	
	}
      }
      //cout<<cnt[0][0][0][0][1]<<endl;
      const Int DBG = 0;
      
      while(!q.empty()){
	Int t,qy,qx,ay,ax;
	tie(t,qy,qx,ay,ax)=q.front();q.pop();
	Int d=dp[t][qy][qx][ay][ax];
	if(DBG) cout<<t<<":"<<qy<<" "<<qx<<" "<<ay<<" "<<ax<<":"<<d<<endl;
	
	if(t){
	  for(Int k=0;k<5;k++){
	    Int ny=qy+dy[k],nx=qx+dx[k];
	    if(!in(ny,nx)||s[ny][nx]=='#') continue;
	    if(~dp[!t][ny][nx][ay][ax]) continue;
	    cnt[!t][ny][nx][ay][ax]--;
	    if(!d||cnt[!t][ny][nx][ay][ax]==0){
	      if(DBG) cout<<"->"<<!t<<" "<<ny<<" "<<nx<<" "<<ay<<" "<<ax<<":"<<!d<<endl;
	      dp[!t][ny][nx][ay][ax]=!d;
	      q.emplace(!t,ny,nx,ay,ax);
	    }
	  }
	}else{
	  for(Int k=0;k<5;k++){
	    Int ny=ay+dy[k],nx=ax+dx[k];
	    if(!in(ny,nx)||s[ny][nx]=='#') continue;
	    if(~dp[!t][qy][qx][ny][nx]) continue;
	    cnt[!t][qy][qx][ny][nx]--;
	    if(!d||cnt[!t][qy][qx][ny][nx]==0){
	      if(DBG) cout<<"->"<<!t<<" "<<qy<<" "<<qx<<" "<<ny<<" "<<nx<<":"<<!d<<endl;
	      dp[!t][qy][qx][ny][nx]=!d;
	      q.emplace(!t,qy,qx,ny,nx);
	    }
	  }
	}
      }
      
    }
    
    
    {
      Int qx,qy,ax,ay;
      for(Int i=0;i<h;i++){
	for(Int j=0;j<w;j++){
	  if(s[i][j]=='Q') qy=i,qx=j;
	  if(s[i][j]=='A') ay=i,ax=j;
	}
      }
      if(dp[0][qy][qx][ay][ax]==1)
	cout<<"Queen can escape."<<endl;
      if(dp[0][qy][qx][ay][ax]==0)
	cout<<"Army can catch Queen."<<endl;
      if(dp[0][qy][qx][ay][ax]==-1)
	cout<<"Queen can not escape and Army can not catch Queen."<<endl;
    }
  }
  
  return 0;
}




Measured memory_bytes: 40268
from itertools import permutations

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
a = [a,b,c,d,e]

perms = list(permutations(a))
ans = float('inf')
for x in perms:
    cur = 0 
    x = list(x)
    for i in range(5):
        cur += x[i]
        temp = cur % 10
        if temp != 0 and i != 4:
            cur += (10 - temp)
    ans = min(ans,cur)
print(ans)




Measured memory_bytes: 62260
#include <bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
#define ALL(V) V.begin(),V.end()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define debug(x) cerr<<#x<<": "<<x<<endl
using namespace std;
const long long N=1e6+69, base=1024*1024,mod=1e9+7;
long long a,b,c;
int32_t main(void) {
    boost;
    cin>>a>>b>>c;
    long long wyn=b+min(c,a+b+1);
    cout<<wyn<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    string s;
    int a[26]={0};
    for(int i=0;i<h;i++){
    	cin>>s;
    	for(int j=0;j<w;j++){
    		a[s[j]-'a']++;
    	}
    }
    int c1=0,c2=0;
    for(int i=0;i<26;i++){
    	a[i]%=4;
    	if(a[i]>1)c2++;
    	if(a[i]&1)c1++;
    }
    if(h&1){
    	if(w&1)cout << ((c1>1||c2>(w/2+h/2))?"No":"Yes") <<endl;
    	else cout << ((c1||2*c2>w)?"No":"Yes") <<endl;
    }else{
    	if(w&1) cout << ((c1||2*c2>h)?"No":"Yes") <<endl;
    	else cout << ((c1||c2)?"No":"Yes")<<endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a = N%10;
  if (a==3) {
    cout << "bon" << endl;
  }
  else if (a==0||a==1||a==6||a==8) {
    cout << "pon" << endl;
  }
  else cout << "hon" << endl;
}


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

int main(void){
    string s;
    cin>>s;
    int n = s.size();
    s = "0" + s;
    if(s[1] == '0' || s[n-1] == '0' || s[n] == '1'){
        cout<<-1<<endl;
        return 0;
    }
    
    rep1(i,n/2){
        if(s[i] != s[n-i]){
            cout<<-1<<endl;
            return 0;
        }
    }

    int head = 1;
    rep1(i,n-1){
        cout<<head<<" "<<i+1<<endl;
        if(s[i] == '1') head = i+1;
    }
    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> blue(n);     
	for (int i = 0; i < n; i++)  
	{
		cin >> blue[i];
	}

	int m;
	cin >> m;
	vector<string> red(m);
	for (int i = 0; i < m; i++) {
		cin >> red[i];
	}

	int ans = 0;
	for (string t : blue) {
		int buf = 0;
		for (string s : blue)
			if (t == s) {
				buf++;
			}
		for (string s :red)
			if (t == s) {
				buf--;
			}
		ans = max(ans, buf);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  string s;
  int k, a;
  cin >> s >> k;
  if(k == 1) a = s[0] - '0';
  else{
    a = 1;
    rep(i, k){
      if(s[i] != '1'){
        a = s[i] - '0';
        break;
      }
    }
  }
  cout << a << endl;
  return 0;
}

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

using namespace std;
using Long = long long;

vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

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

  int current_s = 0;

  for (int i = 0; i < 7; i++){
    if (days[i] == s) {
      current_s = i;
      break;
    }
  }

  int cnt = 0;
  while(true) {
    if (cnt != 0 && days[current_s] == "SUN") {
      break;
    }
    // cout << days[current_s] << endl;
    cnt++;
    current_s++;
    if (current_s >= 7) current_s = 0;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while (!S.empty()) {
    int u = S.top(); S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        S.push(v);
        color[v] = c;
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++) {
    color[i] = NIL;
  }
  for (int i = 0; i < n; i++) {
    if (color[i] == NIL) {
      dfs(i, id++);
    }
  }
}

int main() {
  int m, u, v, q;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  assignColor();

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> u >> v;
    if (color[u] == color[v]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 8972
#include<stdio.h>

int main(){
	long long int n,a[100010],b[100010],ans=0;
	scanf("%lld",&n);
	int i,j,tmp=0;
	for(i=0;i<n+1;i++){
		scanf("%lld",&a[i]);
	}
	for(i=0;i<n;i++){
		scanf("%lld",&b[i]);
	}
	for(i=0;i<n;i++){
		if(a[i]>=b[i])
			ans+=b[i];
		else if(a[i]+a[i+1]<=b[i]){
			ans +=a[i]+a[i+1];
			a[i+1]=0;
		}
		else{
			ans +=b[i];
			a[i+1]-=b[i]-a[i];
		}
	}
	
	printf("%lld",ans);
	return 0;
}
			
				

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nCrを返す関数.
long long int comb(long long int n, long long int r){
	if(n < r || n < 0)
		return 0;
	long long int x = 1, y = 1;
	if (n-r < r) r = n - r;
	for (long long int i = 0; i < r; i++)
	{
		x = x * (n - i);
		y = y * (i + 1);
	}
	return x / y;
}


int main(){
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n)
	{
		string s = to_string(i + 1);
		if(s.size()%2==1)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

template <typename F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)) {}
    template <typename... Args>
    constexpr decltype(auto)
    operator()(Args &&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

template <typename F>
static inline constexpr decltype(auto)
make_func(F &&f) noexcept {
    return FixPoint<F>{std::forward<F>(f)};
}

void solve() {
    ll x;
    cin >> x;
    ll a = 0, b = 0;
    while (true) {
        ll res = a * a * a * a * a - x;
        ll sign = res >= 0 ? 1 : -1;
        res = abs(res);
        ll tmp = 0;
        while (tmp * tmp * tmp * tmp * tmp < res)
            ++tmp;
        if (tmp * tmp * tmp * tmp * tmp == res) {
            b = sign * tmp;
            break;
        }
        ++a;
    }
    cout << a << " " << b << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3612
def prime_factorize(n):
    if 2 <= n < 4:
        return [n]
    res = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            res.append(i)
            n //= i
        i += 1
    if n != 1:
        res.append(n)
    # res.sort()
    return res

from itertools import groupby
def resolve():
    N = int(input())
    P = prime_factorize(N)
    ans = 0
    grp_P = groupby(P)
    for v, g in grp_P:
        n = len(list(g))
        for i in range(1, 100000):
            n -= i
            if n >= 0:
                ans += 1
            else:
                break
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9224
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long 
struct look{
	ll a,b;
}m[200005];

bool cmp(look e,look f)
{
	return e.b<f.b;
}

int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		{
			scanf("%lld%lld",&m[i].a,&m[i].b);
		}
		sort(m,m+n,cmp);
		ll num=0;
		int flag=0;
		for(int i=0;i<n;i++)
		{
			num+=m[i].a;
			if(num>m[i].b)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		printf("Yes\n");
		else
		printf("No\n");
	 } 
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    ll all_cnt = 0;
    rep(i, h) rep(j, w) {
        cin >> c[i][j];
        if (c[i][j] == '#') all_cnt++;
    }

    ll ans = 0;
    rep(h_bt, pow(2, h)) {
        rep(w_bt, pow(2, w)) {
            ll cnt = all_cnt;
            rep(i, h) {
                rep(j, w) {
                    if ((1 & h_bt >> i) == 1 || (1 & w_bt >> j) == 1) {
                        if (c[i][j] == '#') cnt--;
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 4104
from sys import stdin,stdout
n,k=map(int,stdin.readline().split())
l=list(map(int,stdin.readline().split()))
l1=[]
for i in range(min(n,k)):
    l1.append(abs(l[i]-l[0]))
for i in range(min(n,k),n):
    cost=10**9
    if k>=i:
        x=i
    else:
        x=k
    for j in range(1,x+1):
        cost=min(cost,abs(l[i]-l[i-j])+l1[-j])
    l1.append(cost)
stdout.write(str(l1[-1])+'\n')   


Measured memory_bytes: 44384
#include<stdio.h>
#include<stdlib.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int main(){

  ll n,k;
  scanf("%lld %lld",&n,&k);

  ll array[100001] = {0};

  for(ll i = 0; i < n; ++i){
    ll a,b;
    scanf("%lld %lld",&a,&b);
    array[a] += b;
  }

  int i = 0;
  while(1){
    k -= array[i];
    if(k <= 0){
      printf("%d",i);
      return 0;
    }
    ++i;
  }

  return 0;

}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll n;cin>>n;
    string s[n];
    ll ans=0;
    rep(i,0,n-1){
        cin>>s[i];
        if(s[i]=="E869120"){
            ans++;
        }
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 3372
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
c = Counter(A)
c = sorted(c.items(), key=lambda x: x[0])

in_num = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            in_num += 1

out_num = 0
cnt = 0
for k, v in c:
    cnt += v
    out_num += (N - cnt) * v

ans = in_num * K + out_num * (K * (K - 1) // 2)
print(ans % MOD)


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

using namespace std;

typedef long long LL;

const int N = 100;

int a, b;

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

    int res = 0, t = 1;
    while(t < b)
    {
        res++;
        t = t - 1 + a;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

val sc = Scanner(System.`in`)
val n = sc.nextInt()

fun main(args: Array<String>) {
    val plist = mutableListOf<Int>()
    var maxValueIdx = 0
    var tmpMaxValue = 0
    for (i in 0 until n) {
        val p = sc.nextInt()
        if (p > tmpMaxValue) {
            maxValueIdx = i
            tmpMaxValue = p
        }
        plist.add(p)
    }
    var total = 0
    for (i in 0 until n) {
        if (maxValueIdx == i) {
            total += plist[i]/2
        } else {
            total += plist[i]
        }
    }
    println(total)
}

Measured memory_bytes: 29480
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans=0
for i in range(n):
    if b[i] > a[i]:
        b[i] -= a[i]
        ans += a[i]
        if b[i] > a[i+1]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]
            a[i+1] -= b[i]
    else:
        ans += b[i]
        b[i]=0
print(ans)

Measured memory_bytes: 18396
n = int(input())
a = list(map(int, input().split()))
b = [0,0,0]
c = 1
for i in a:
  c = c*((b[0]==i)+(b[1]==i)+(b[2]==i))%(10**9+7)
  if b[0]==i:
    b[0] += 1
  elif b[1]==i:
    b[1] += 1
  else:
    b[2] += 1
print(c)

Measured memory_bytes: 53484
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n-1]={0};
    int all[200005]={0};
    for(int i =0;i<n-1;i++)
    {
        cin>>a[i];
        all[a[i]-1]++;
    }
    for(int i=0;i<n;i++)
        cout<<all[i]<<'\n';



}


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

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

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

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

//v.erase(unique(v.begin(),v.end()),v.end());
int n;
int dx[]={1,0,1,-1};
int dy[]={0,1,1,1};
vector<vint> vv;
int foo(int a,int b,int c){
	int ret=0;
	int now=0;
	// return 0;
	while(0<=a&&a<n&&0<=b&&b<n){
		if(vv[a][b]==1){
			now++;
		}
		else{
			now=0;
		}
		// cout<<now<<endl;
		ret=max(ret,now);
		a+=dx[c];
		b+=dy[c];
	}
	return ret;
}




int main(){
	// vector<vint> vv;
	// int n;
	while(cin>>n,n){
		initvv(vv,n,n);
		rep(i,n){
			rep(j,n){
				char t;
				cin>>t;
				vv[i][j]=t-'0';
				// cout<<vv[i][j]<<" ";
			}
			// cout<<endl;
		}
		int ans=0;
		rep(i,n){
			ans=max(ans,foo(0,i,0));
			ans=max(ans,foo(i,0,1));
			ans=max(ans,foo(0,i,2));
			ans=max(ans,foo(i,0,2));
			ans=max(ans,foo(i,0,3));
			ans=max(ans,foo(n-1,i,3));
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
 
using namespace std;


void solve(int N, int x) 
{
    if (x <= 1 || x >= N * 2 - 1) 
    {
        cout << "No" << endl;
        exit(0);
    }
    cout << "Yes" << endl;
    vector<int> ans(N * 2 - 1, -1);
    ans[N - 2] = 1;
    ans[N-1] = x;
    ans[N] = N*2-1;
    int ind = 0;
    for (int i = 2; i < N * 2 - 1; i++) {
        if (i == x) 
        	continue;
        while (ans[ind] != -1) 
        	ind++;
        ans[ind] = i;
    }
    for (int i = 0; i < 2 * N - 1; i++)
    {
    	cout << ans[i] << " ";
    }
}

int main() {
    int N, x;
    cin >> N >> x;
    solve(N, x);
}


Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ld A,B;
  
cin >> A >> B;

cout << ll(A*B) << endl;
  
return 0;

}   


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  int a[4] = {0};
  for(int i = 0; i < s.length(); i++) {
    if(s[i] == 'N') a[0]++;
    else if(s[i] == 'S') a[1]++;
    else if(s[i] == 'W') a[2]++;
    else if(s[i] == 'E') a[3]++;
  }
  if(a[0] == a[1] && a[0] == 0) {
    if(a[2] == 0 && a[2] == a[3]) cout << "Yes" << endl;
    else if(a[2] > 0 && a[3] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else if(a[2] == a[3] && a[2] == 0) {
    if(a[0] == a[1] && a[0] == 0) cout << "Yes" << endl;
    else if(a[0] > 0 && a[1] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else if(a[0] > 0 && a[1] > 0 && a[2] > 0 && a[3] > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }


  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
    int a, b, c, x;
    scanf("%d %d %d %d", &a, &b, &c, &x);
    
    int cnt = 0;
    for (int i=0; i <= a; i++){
        for (int j=0; j <= b; j++){
            for (int k=0; k <= c; k++){
                if (i*500 + j*100 + k*50 == x) cnt++;
            }
        }
    }


    printf("%d\n", cnt);    


    return 0;
} 



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int flag = 0;
  while( n > 0 ){
    int d = n % 10;
    if( d == 7 ) {flag = 1; break;}
    n /= 10;
  }
  if( flag == 1 ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 3100
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var yes=(input[0]<=input[2])&&(input[2]<=(input[0]+input[1]));
  console.log(yes?'YES':'NO');
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7496
n,k = gets.chomp.split(" ").map(&:to_i)
count = 0
if k != 0
  for i in k+1..n
    count += (i-k)*(n/i)
    x = n-(i*(n/i))
    if x >= k && x != 0
      count += x-k+1
    end
  end
else
  count = n**2
end
puts count

Measured memory_bytes: 1788
N,M=map(int,input().split())
a,b=[],[]                       #リストを二つ作ってcountで数えればOK
for i in range(M):
  x,y=input().split()
  a.append(x)
  b.append(y)
for j in range(1,N+1):          #N行出力なのでforとprintで回す
  e1=a.count("{}".format(j))
  e2=b.count("{}".format(j))
  print(e1+e2)

Measured memory_bytes: 3060
#include <iostream>
#include<math.h>
using namespace std;
 
int main() {
	int n,a,b;
	cin>>n>>a>>b;
	int maxa=min(a,b);
	int min=0;
	if(a+b>n){min=a+b-n;}
	cout << maxa << " " << min <<endl;
	return 0;
}

Measured memory_bytes: 256