akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int K; cin >> K;
  int x = K / 50, y = K % 50;
  vector<int> a(50, 49 + x - y);
  rep(i, 0, y) {
    a[i] += 51;
  }

  cout << 50 << endl;
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    int n, k;
    cin >> n >> k;
    if(k == 1){
        cout << 0;
        return 0;
    }
    cout << n - k;
    return 0;
}


Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	#a = int(input())
	x, y, a, b, c = IN()
	al = list(IN())
	al.sort(reverse=True)
	bl = list(IN())
	bl.sort(reverse = True)
	cl = list(IN())
	cl.sort(reverse=True)
	#s = input()
	tx=x-1
	ty=y-1
	tc=0
	while True:
		if tc == len(cl):
			break
		al_min=al[tx] if tx >= 0 else 10**11
		bl_min=bl[ty] if ty >= 0 else 10**11
		cl_max=cl[tc]
		if al_min >= cl_max and bl_min >= cl_max:
			break
		elif al_min <= bl_min and al_min < cl_max:
			tx -= 1
			tc += 1
		elif bl_min<= al_min and bl_min < cl_max:
			ty -= 1
			tc += 1
		else:
			break
	ret=sum(al[:tx+1])+sum(bl[:ty+1])+sum(cl[:tc])
	print(ret)
			
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

using namespace std;

int y, m, d;
int main()
{
	scanf("%d/%d/%d", &y, &m, &d);
	if (y < 2019
	|| y == 2019 && m < 4
	|| y == 2019 && m == 4 && d <= 30)
		puts("Heisei");
	else
		puts("TBD");

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    vector<tuple<int,int,int>> v;
    for(int i=0;i<m;++i){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        v.emplace_back(a,b,-c);
    }
    vector<ll> dp(n,infl);
    dp[0] = 0;
    for(int i=0;i<n-1;++i){
        for(int j=0;j<m;++j){
            int a,b,c;
            tie(a,b,c) = v[j];
            dp[b] = min(dp[b],dp[a] + c);
        }
    }
    ll ret = -dp[n-1];
    for(int i=0;i<2000;++i){
        for(int j=0;j<m;++j){
            int a,b,c;
            tie(a,b,c) = v[j];
            dp[b] = min(dp[b],dp[a] + c);
        }
    }
    if(ret < -dp[n-1])cout << "inf" << endl;
    else cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(A: int, B: int):
    from math import ceil
    print(ceil((B-A)/(A-1))+1)
    # n = A
    # i = 1
    # while n < B:
    #     n += (A-1)
    #     i += 1

    # print(i)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#define LEN 6378.1
#define PI 3.141592653589793238
using namespace std;
double a, b, c, d, BC, CA, C;
int main() {
	while (true) {
		cin >> a >> b >> c >> d;
		if (a == -1) { break; }
		BC = PI / 180 * (90.0 - a);
		CA = PI / 180 * (90.0 - c);
		C = PI*(d - b) / 180;
		cout << (int)(0.5 + LEN*acos(cos(BC)*cos(CA) + sin(BC)*sin(CA)*cos(C)))<< endl;
	}
}

Measured memory_bytes: 1284
def submit():
    n = int(input())
    xlist = list(map(int, input().split()))

    def cost(lst, p):
        c = 0
        for l in lst:
            c += (l - p) * (l - p)
        return c

    sum_x = sum(xlist)
    if sum_x % n:
        p1 = sum_x // n
        p2 = sum_x // n + 1
        print(min(cost(xlist, p1), cost(xlist, p2)))
    else:
        print(cost(xlist, sum_x // n))


if __name__ == "__main__":
    submit()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
typedef long long ll;
ll x, y;
int main(void){
    // Your code here!
    cin >> x >> y;
    if (x * y < 0) {
        cout << abs(abs(x) - abs(y)) + 1 << endl;
    } else if (x * y == 0) {
        if (x <= y) cout << y - x << endl;
        else cout << x - y + 1 << endl;
    } else {
        if (x <= y) cout << y - x << endl;
        else cout << abs(abs(x) - abs(y)) + 2 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int X;
    cin >> X;
    if (X >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int n;
bool c[4][13];

int main(){
	char ch;
	int m;
	for (int i = 0; i < 4; i++) {
		fill(c[i], c[i] + 13, false);
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ch >> m;
		m--;
		switch (ch)
		{
		case 'S':c[0][m] = true;
			break;
		case 'H':c[1][m] = true;
			break;
		case 'C':c[2][m] = true;
			break;
		case 'D':c[3][m] = true;
			break;
		default:
			break;
		}
	}
	char li[4] = { 'S','H','C','D' };
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (!c[i][j]) {
				cout << li[i] << " " << j + 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3084
import heapq
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    ls = sorted(ls)
    while 1:
        if len(ls)==1:
            break
        now1 = heapq.heappop(ls)
        now2 = heapq.heappop(ls)
        heapq.heappush(ls,(now1+now2)/2)
    print(ls[0])

if __name__ =="__main__":
    main()

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << " " << 2 * a + 2 * b << endl;

    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

const ll INF = 1E18+5;
const ll mod = 1E9+7;

int main(){
    int x;
    cin>>x;
    if(x>=30)
        cout<<"Yes";
    else
        cout<<"No";
}




Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int N, M; cin >> N >> M;
    if(N > M * 2) cout << N - M*2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = []
for i in range(5):
    a.append(INT())

x = min(a)
t = ( n + x - 1 ) // x
ans = 4 + t
print(ans)

Measured memory_bytes: 10152
n, m = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

diff = []

if n >= m:
  print(0)
else:
  for i in range(m-1):
    diff.append(abs(X[i]-X[i+1]))
  diff.sort()
  print(max(X)-min(X)-sum(diff[m-n:]))

# 72

Measured memory_bytes: 13960
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    ll n,k;cin>>n>>k;
    vl t(n);
    ll sum=0;

    for(int i=0;i<k;i++){
        ll d;cin>>d;
        for(int j=0;j<d;j++){
            vl a(d);cin>>a[j];a[j]--;
            t[a[j]]=1;
        }
    }

rep(i,n)if(!t[i])sum++;
    cout<<sum<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

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

    String str = sc.nextLine();
    int q = sc.nextInt();

    for (int i = 0; i < q; i++) {
        String op = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt() + 1;

        switch (op) {
            case "print":
            System.out.println(str.substring(a, b));
            break;
            case "reverse":
            StringBuffer sb = new StringBuffer(str.substring(a, b));
            str = str.substring(0, a) + sb.reverse().toString() + str.substring(b);
            break;
            case "replace":
            String p = sc.next();
            str = str.substring(0, a) + p + str.substring(b);
            break;
        }
    }
  }
}


Measured memory_bytes: 29352
#include<stdio.h>

int n,a[50];

int solve(int p,int t){
    if(p >= n) return 0;
    if(a[p] == t) return 1;
    if(solve(p + 1,t) == 1) return 1;
    if(solve(p + 1,t - a[p]) == 1) return 1;
    
    return 0;    
}

int main(){
    int q,m,i;
    
    scanf("%d",&n);
    
    for(i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    
    scanf("%d",&q);
    
    for(i = 0;i < q;i++){
        scanf("%d",&m);
        
        if(solve(0,m) == 1){
            printf("yes\n");
        }
        else{
            printf("no\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2144
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/* define */
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = a; i < b ; i++)
#define REP(i, n) for ( int i = 0; i < n ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = (int)1e9 + 7;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}

/* main */

int main() {
	ll n, a, b, r = (ll)1e9;
	scanf("%lld", &n);
	for (ll i = 1; i <= sqrt(n); i++) {
		a = 0;
		b = 0;
		if (floor((double)n / (double)i) == ceil((double)n / (double)i)) {
			for (ll j = i; j; j /= 10) a++;
			for (ll c = n / i; c; c /= 10) b++;
			r = min(r, max(a,b));
		}
	}
	printf("%lld",r);
	return 0;
}

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string a, b, s="EQUAL";
	cin >> a >> b;


	if (a.size() > b.size())s = "GREATER";
	else if (a.size() < b.size())s = "LESS";
	else {

		rep(i, a.size()) {
			if ((int)a[i] > (int)b[i]) { s = "GREATER"; break; }
			if ((int)a[i] < (int)b[i]) { s = "LESS"; break; }
		}
			
	}
	cout << s << endl;

}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    for (int i = 1; i < A * B; ++i) {
        if (i * A % B == C) {cout << "YES" << endl; return 0;}
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn solve(ps: Vec<usize>) -> usize {
    let n = ps.len();

    let mut cnt = 0;

    for i in 0..(n - 2) {
        if ps[i] > ps[i + 1] && ps[i + 1] > ps[i + 2] {
            cnt += 1;
        } else if ps[i] < ps[i + 1] && ps[i + 1] < ps[i + 2] {
            cnt += 1;
        }
    }

    cnt
}

fn main() {
    read_line!();
    let ps = parse_vec!(usize);
    println!("{}", solve(ps));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![1, 3, 5, 4, 2]), 2);
    assert_eq!(solve(vec![9, 6, 3, 2, 5, 8, 7, 4, 1]), 5);
}


Measured memory_bytes: 4352
import sys
from operator import itemgetter

n, *aaa = map(int, sys.stdin.buffer.read().split())
aaa_with_index = list(enumerate(aaa, start=1))
aaa_with_index.sort(key=itemgetter(1), reverse=True)
left = list(range(-1, n + 1))
right = list(range(1, n + 3))
ans = 0
for i, a in aaa_with_index:
    li = left[i]
    ri = right[i]
    ans += a * (i - li) * (ri - i)
    left[ri] = li
    right[li] = ri

print(ans)


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

using namespace std;

int main(){
  while(1){
    int H, W;
    cin>>H>>W;
    if(H == 0 && W == 0) break;

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }

}



Measured memory_bytes: 3088
/*Bismillahir Rahmanir Rahim*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector <long long> vll;
typedef pair<int, int> pii;
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Macro Start-*-*-*-*-*-*-*--*-*-*-*-*/

#define Faster_IO              ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F                      first
#define S                      second
#define pb                     push_back
#define MP                     make_pair
#define sf                     scanf
#define pf                     printf
#define PI                     (2*acos(0))
#define to_radian(degree)      ((pi/180)*degree)
#define to_degree(radian)      ((180/pi)*radian)
#define SQ(a)                  (a)*(a)
#define SORT(x)                sort(x.begin(),x.end())
#define rSORT(x)               sort(x.rbegin(),x.rend())
#define SetPrint(a,x)          cout<<fixed<<setprecision(x)<<a<<endl
#define show(vec)              for (int i=0; i<vec.size(); i++)cout << vec[i] << " ";
#define lines                  cout <<"\n" <<"---------------" << "\n";
#define YES                    printf("YES\n")
#define NO                     printf("NO\n")
#define Yes                    printf("Yes\n")
#define No                     printf("No\n")
#define testcase(n)            int n; cin >> n; while(n--)
#define lcm(a,b)               ((a / __gcd(a,b) ) * b)
#define gcd(a,b)               __gcd(a,b)
#define all(vec)               vec.begin(), vec.end()
#define SUM(vec)               accumulate(vec.begin(), vec.end(), 0)
#define gcin(str)              getline(cin, str)
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Macro END-*-*-*-*-*-*-*--*-*-*-*-*/

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Template Start-*-*-*-*-*-*--*-*-*-*-*/

//template <class T> T isPrime(T n){if(n<=1)return 0;for(long long i=2;i*i<=n; i++)if(n%i==0)return 0;return 1;}
//template <class T> T bigmod(T X, T n, T M) {if (n==0) return 1;if (n%2) return ((X%M) * bigmod(X,n-1,M)) %M;else {long long int d = bigmod(X,n/2, M);return ((d%M) * (d%M))%M;}}

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Template END-*-*-*-*-*-*-*--*-*-*-*-*/


int main()
{
    Faster_IO
    #ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
    #endif

    string s, t;
    int cnt=0; 
    cin >> s >> t;

    for(int i=0; i<s.size();i++)
        if(s[i]!=t[i])
            cnt++;

    cout << cnt << "\n";    
    return 0;
}


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

int A, B, C, X, Y;

int main() {
    cin >> A >> B >> C >> X >> Y;

    ll ans = 0;
    if (C < (A+B)/2) {
        if (X < Y) {
            ans += C*2*X;
            if (B/2 < C) {
                ans += B*(Y - X);
            }
            else {
                ans += C*2*(Y - X);
            }
        }
        else {
            ans += C*2*Y;
            if (A/2 < C) {
                ans += A*(X - Y);
            }
            else {
                ans += C*2*(X - Y);
            }
        }
    }
    else {
        ans = min(A*X + B*Y, min(C*2*X + B*(Y - X), C*2*Y + A*(X - Y)));
    }   

    cout << ans << endl;

    return 0;
}


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

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


const ll MOD = 1e9 + 7;


int main2() {
  int N; cin >> N;
  string S; cin >> S;

  map<int, ll> count;
  REP(i, N) count[ S[i] ]++;
  ll ans = 1;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    ans *= (count[ ch ] + 1);
    ans %= MOD;
  }
  ans = (ans - 1 + MOD) % MOD;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	double x[N];
	double sum = 0.0;
	string s[N];

	REP(i, N){
		cin >> x[i] >> s[i];
	}

	REP(i, N){
		if(s[i] == "JPY") sum += x[i];
		else sum += x[i] * 380000.0;
	}
	cout << fixed << setprecision(5);
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
//R:0 L:1 U:2 D:3

int map[11][7];
int type;
int x=2,y=1;
char a[4],b[5];

void init(){
	for(int i=1;i<=9;i++){
		if(i%2){
			cin>>a;
			for(int n=0;n<4;n++)map[i][n+1]=char(a[n])-'0';
		}
		else{
			cin>>b;
			for(int m=0;m<5;m++)map[i][m+1]=char(b[m])-'0';
		}
	}
}

void Right(){
	if(map[y-1][x])type=2, y-=2, cout<<'U';
	else if(map[y][x])type=0, x+=1, cout<<'R';
	else if(map[y+1][x])type=3, y+=2, cout<<'D';
	else  type=1, x-=1, cout<<'L';
}

void Left(){
	if(map[y+1][x])type=3, y+=2, cout<<'D';
	else if(map[y][x-1])type=1, x-=1, cout<<'L';
	else if(map[y-1][x])type=2, y-=2, cout<<'U';
	else type=0, x+=1, cout<<'R';
}

void Up(){
	if(map[y][x-1])type=1, x-=1, cout<<'L';
	else if(map[y-1][x])type=2, y-=2, cout<<'U';
	else if(map[y][x])type=0, x+=1, cout<<'R';
	else type=3, y+=2, cout<<'D';
}

void Down(){
	if(map[y][x])type=0, x+=1, cout<<'R';
	else if(map[y+1][x])type=3, y+=2, cout<<'D';
	else if(map[y][x-1])type=1, x-=1, cout<<'L';
	else type=2, y-=2, cout<<'U';
}

void solve(){
	while(!(x==1&&y==1)){
		switch(type){
			case 0:Right();
				break;
			case 1:Left();
				break;
			case 2:Up();
				break;
			case 3:Down();
				break;
			default: return;
		}
	}
}

int main(){
	init();
	cout<<'R';
	solve();
	cout<<"\n";
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int arr[101];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int c;
            cin>>c;
            arr[c]+=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(arr[i]==0){
            ans+=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

int n, x, t;

int main() {
    n = qr(), x = qr(), t = qr();
    pi(t * (int) ceil((n * 1.0) / (x * 1.0)));
    return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll; 
int main() {
	int K, X;
	cin >> K >> X;
	if (K * 500 >= X) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" <<endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "atcoder/all"
#define rep(i,n)for(int i=0;i<(int)(n);i++)
using namespace std;
using namespace atcoder;
#define all(a) a.begin(),a.end()
typedef long long ll;
#define vi vector<ll>
typedef pair<ll,ll>P;
const ll inf=1ll<<61;
int a[300006];
int dp[300006];
int op(int a,int b){
	return max(a,b);
}
int e(){
	return 0;
}
signed main(){
	int n,k;cin>>n>>k;
	rep(i,n)cin>>a[i];
	segtree<int,op,e>seg(600010);
	dp[0]=1;
	seg.set(a[0],1);
	for(int i=1;i<n;i++){
		int l=a[i]-k,r=a[i]+k;
		if(l<0)l=0;
		int x=seg.prod(l,r+1);
		dp[i]=x+1;
		if(dp[i]>seg.get(a[i])){
			seg.set(a[i],dp[i]);
		}
	}
	int ans=0;
	rep(i,n)ans=max(ans,dp[i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 14908
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*(b/__gcd(a,b))
#define sz(x) (int)x.size()
#define cmp complex<double> 
int power(int x,int y){
    int res=1;
    x=x%mod1;
    while(y>0){
        if(y&1)res=(res*x)%mod1;
        x=(x*x)%mod1;
        y/=2;
    }
    return res;
}
void inline precompute(){
}
// void dfs(vector<int> adj[],int x,int par){
//     intime[x]=t++;
//     for(int i=1;i<=k;i++){
        
//     }
//     for(auto it: adj[x]){
//         if(it!=par){
//             dfs(adj,it,x);
//         }
//     }
//     outtime[x]=t++;
// }
void solve(int tc){
    int n;
    cin>>n;
    vector<int> v(n);
    int prod=1;
    for(int i=0;i<n;i++){
        cin>>v[i];
        if(v[i]==0){
            cout<<0;
            return;
        }
    }
    for(int i=0;i<n;i++){
        int x=v[i];
        if(((int)1e18/prod)<x){
            cout<<-1;
            return;
        }
        prod*=x;
    }
    cout<<prod;
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}

Measured memory_bytes: 3992
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{w:i64, a:i64, b:i64};
    println!("{}", max(0, max(b-a-w, a-b-w)));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
    }
    for (int t = 0; t < n; t++) {
        queue<int> que;
        vector<bool> was(n);
        vector<int> depth(n);
        vector<set<int>> p(n);
        vector<int> q(n);
        que.push(t);
        was[t] = true;
        while (!que.empty()) {
            for (int i = que.size(); i > 0; i--) {
                int v = que.front();
                que.pop();
                set<int> st;
                for (int to : g[v]) {
                    if (was[to]) {
                        st.emplace(to);
                        continue;
                    }
                    was[to] = true;
                    que.push(to);
                    depth[to] = depth[v] + 1;
                    p[to] = p[v];
                    q[to] = v;
                    p[to].emplace(v);
                }
                if (!st.empty()) {
                    int mx = -1, id = -1;
                    for (int to : st) {
                        if (p[v].count(to)) {
                            if (mx < depth[to]) {
                                id = to;
                                mx = depth[to];
                            }
                        }
                    }
                    if (id != -1) {
                        cout << depth[v] - mx + 1 << '\n';
                        cout << v + 1 << '\n';
                        while (id != v) {
                            v = q[v];
                            cout << v + 1 << '\n';
                        }
                        return 0;
                    }
                }
            }
        }
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 23808
import numpy as np
N = int(input())

A = np.array(list(map(int,input().split())))

ans=0
mod = 10**9 +7
for i in range(60):
  cnt = np.count_nonzero(A&1)
  ans+=(N-cnt)*cnt*(2**i)
  ans %= mod
  A>>= 1
print(ans)

Measured memory_bytes: 68652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<double> p(n);
    rep(i, n) cin >> p[i];

    vector<vector<double> > dp(n+1, vector<double>(n+1));

    dp[0][0] = 1.0;

    for (int i=1; i<=n; i++) {
        dp[i][0] = dp[i-1][0]*(1-p[i-1]);
    }
    for (int j=1; j<=n; j++) {
        dp[0][j] = 0;
    }

    rep(i, n) {
        rep(j, n) {
            dp[i+1][j+1] = dp[i][j]*p[i] + dp[i][j+1]*(1-p[i]);
        }
    }

    double ans = 0;
    for (int i=n; i>=(n+1)/2; i--) {
        ans += dp[n][i];
    }

    printf("%.10f\n", ans);

}

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

ll divisor=1e9+7;
int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int count=0;
	rep(i,n){
		if(a[a[i]-1]==i+1)count++;
	}
	puts(count/2);
	
}

Measured memory_bytes: 640
use proconio::input;

fn main (){

let mut _ab : f64;
let mut _bc : f64;
let mut _ca : f64;

input! {
    ab : f64,
    bc : f64,
    ca : f64,

}

let ans : f64 = (bc/2.0)*ab ; 
println!("{}",ans);
}


Measured memory_bytes: 2208
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int N;
  cin >> N;
  int sum = 0;
  vector<int> vec(N);
  for(int i=0; i<N; i++)
  {
    cin >> vec[i];
  }
  for(int i=0; i<N; i++)
  {
    sum += vec[i];
  }
  int K = sum/N;
  int sum1 = 0,sum2 = 0;
  for(int i=0; i<N; i++)
  {
    sum1 += pow(K-vec[i],2.0);
  }
  for(int i=0; i<N; i++)
  {
    sum2 += pow(K+1-vec[i],2.0);
  }
  cout << min(sum1,sum2) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner; // 文字列を標準入力からscanする

public class Main { 

  static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  }

  static long return_bigger(long a, long b){
    if(a > b){
      return a;
    }
      return b;
  }
    
  public static void main(final String[] args) {
    int N = 0;
    int W = 0;
    int i = 0;
    int value = 0;

    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    N = Integer.parseInt(strs2[0]);
    W = Integer.parseInt(strs2[1]);

    int[] wi = new int[N+1];
    int[] vi = new int[N+1];

    for(i=1; i<=N; i++){
      str = scan.nextLine();
      String[] strs3 = str.split(" ");
      wi[i] = Integer.parseInt(strs3[0]);
      vi[i] = Integer.parseInt(strs3[1]);
    }
    scan.close();

    int V = Arrays.stream(vi).sum();
    long oo = 1L << 60;
    long[][] dp = new long[N+1][V+1];
    for(i=0; i<=N; i++){
      Arrays.fill(dp[i], oo);
    }
    dp[0][0] = 0;

    for(i=1; i<=N; i++){
      for(value = 0; value <= V; value++){
        dp[i][value] = return_smaller(dp[i][value], dp[i-1][value]);

        if(value >= vi[i]){
          dp[i][value] = return_smaller(dp[i][value], dp[i-1][value - vi[i]] + wi[i]);
        }
      }
    }

    int ans = 0;
    for(value = V; value >= 0; value--){
      if(dp[N][value] <= W){
        ans = value;
        break;
      }
    }

    System.out.println(ans);

  }
}

Measured memory_bytes: 141292
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B,C;
  cin >> A >> B >> C;
  cout << 10*max(A,max(B,C))+A+B+C-max(A,max(B,C)) << endl;
  return 0;
}


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

#define mod 1000000007
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (1ll << 60)
#define inf (((1 << 30) - 1) << 1)
const double eps = 0.000000001;
#define leps 1e-18
#define mkp make_pair
#define pnode Node*
#define mpi unordered_map<int, int>
std::random_device rd;
std::mt19937 mt(rd());
using namespace std;

int binpow(int a, int u) {
    if(u <= 0)
        return 1;
    int ans = 1;

    while (u) {
        if (u & 1) {
            ans = (1ll * ans * a) % mod;
            u--;
        } else {
            a = (1ll * a * a) % mod;
            u >>= 1;
        }
    }
    return ans;
}

long long h(int n, int x) {
    int lsb = __builtin_ctz(n);
    if ((x & n) > (1 << lsb)) return 0;

    int u = 0;
    int mask = (x & ((1 << lsb) - 1)) ^((1 << lsb) - 1);

    u = 1 << (__builtin_popcount(mask));

    if (x & (1 << lsb)) {
        return u;
    }

    return u + 1;
}

long long g(int n, int x) {
    if (n == 0)
        return 1;
    int lsb = __builtin_ctz(n);
    int d = n - n ^(1 << lsb);
    if (d == 0) return h(n, x);
    return h(x, n) + g(d, x);
}

long long f(int l, int r) {
    if (l == 0 && r == 0) return 1;
    if (l == r) return 0;
    if (l % 2 == 0 && r % 2 == 0) return 3 * f(l >> 1, r >> 1);
    if (l % 2 == 1) return f(l + 1, r) + 2 * (g(l, r) - g(l, l));
    if (r % 2 == 1) return f(l, r - 1) + 2 * (g(r - 1, r) - g(r - 1, l));
}

void solve() {
    int L, R;
    cin >> L >> R;
    cout << f(L, R) << endl;
}

int main() {

    string s;
    cin >> s;


    int n = s.length() - 1;

    int ans = 0;

    int N = n;
    s += '1';
    int ones = 0;

    for (int i = 0; i <= n + 1; i++) {
        if (s[i] == '1') {
            ans = (ans + (1ll * binpow(3, N) * binpow(2, ones) % mod)) % mod;
            ones++;
        }
        N--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 1<<29
using namespace std;

vector<pair<int,double> > v[10001];
int x[10001],y[10001];
int n,m;
double ans=0.0;
bool visited[10001]={};

double getdis(int a,int b){
  return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}

void prim(int start){
  double d[10001];
  for(int i=0;i<n;i++)d[i]=-1;

  priority_queue<pair<double,int> > pq;
  pq.push(mp(0,start));
  d[start]=0;

  while(!pq.empty()){
    pair<double,int> u=pq.top();
    pq.pop();
    double dis=u.f;
    int now=u.s;
    if(dis<d[u.s])continue;

    for(int i=0;i<v[now].size();i++){
      pair<int,double> e=v[now][i];
      if(d[e.f]<e.s && !visited[e.f]){
	d[e.f]=e.s;
	pq.push(mp(e.s,e.f));
      }
    }
    visited[now]=true;
  }
  double sum=0.0;
  for(int i=0;i<n;i++){
    if(d[i]!=-1)sum+=d[i];
  }
  ans-=sum;
}

int main()
{
  int a,b;

  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;b--;
    double dis=getdis(a,b);
    ans+=dis;
    v[a].push_back(mp(b,dis));
    v[b].push_back(mp(a,dis));
  }

  for(int i=0;i<n;i++){
    if(!visited[i])prim(i);
  }

  printf("%.5f\n",ans);

  return 0;
}

Measured memory_bytes: 3376
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define For(i,a,b) for (ll i = (a); i!=(b); i = (a)<(b)? i+1 : i-1)
#define pb push_back
#define mod 1000000007
ll dp[2002][2002];
int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    memset(dp,0,sizeof(dp));
    pair<ll,ll> ae[n+1];
    For(i,1,n+1)
    {cin>>a[i];
    ae[i]=make_pair(a[i],i);}
    sort(ae+1,ae+n+1);
    reverse(ae+1,ae+n+1);
    ll ans=0;
    For(i,1,n+1)
    For(j,0,i)
     {
        if(i-j>=0)
        dp[j][i-j]=max(dp[j][i-j],dp[j][i-j-1]+ae[i].first*abs(ae[i].second-(n-(i-j-1))));
        if(j+1<=n)
        dp[j+1][i-j-1]=max(dp[j+1][i-j-1],dp[j][i-j-1]+ae[i].first*abs(ae[i].second-(j+1)));
        if(i-j>=0)
        ans=max(ans,dp[j][i-j]);
        if(j+1<=n)
        ans=max(ans,dp[j+1][i-j-1]);
     }
     cout<<ans;
}


Measured memory_bytes: 34956
def main():
    N, M = map(int, input().split())
    if N >= 3 and M >= 3:
        ans = (N-2)*(M-2)
    elif N == 2 or M == 2:
        ans = 0
    elif N == 1 and M == 1:
        ans = 1
    else:
        S = max(N, M)
        ans = max(0, S-2)
    print(ans)

if __name__ == "__main__":
    main()


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    i64 n, a, b;
    cin >> n >> a >> b;

    i64 p, q;
    p = n / (a + b);
    q = n % (a + b);
    cout << p * a + min(q, a) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int A,B,C;
	cin >> A >> B >> C;

	string ans;
	if(A+B+C>=22){
		ans = "bust";
	}else{
		ans = "win";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// Problem : B - Frog 2
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#define FOR(i,n) for(long long int i=0;i<n;i++)
#define FORR(i,n) for(long long int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<long long int>
#define slli set<long long int>
#define mlli map<long long int,long long int>
#define lli long long int 
#define test lli tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define MOD 1000000007
using namespace std;
lli n,arr[100006],dp[100001];

int main() {
    lli K;
	cin>>n>>K;
	rep(i,2,n+1) dp[i]=INT_MAX;
	dp[1]=0;
	dp[0]=0;
	rep(i,1,n+1)cin>>arr[i];
	rep(i,2,n+1){
		rep(k,1,K+1){
			if((i-k)>=1)
				dp[i]=min(dp[i],(abs(arr[i]-arr[i-k])+dp[i-k]));
			else break;
		}
	}
	cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3

output:
0 0
1 2
2 2
3 1
4 3
"""

import sys
import heapq as hp

WHITE, GRAY, BLACK = 0, 1, 2


class SingleSourceShortestPath(object):
    __slots__ = ('adj_table', 'distance', 'parent', 'visited')

    def __init__(self, in_data):
        """

        :param in_data:
        """
        v_num = int(in_data[0])
        vertices = map(lambda x: x.split(), in_data[1:])
        adj_table = tuple(dict() for _ in range(v_num))

        for v_info in vertices:
            source, v_adj_length, *v_adj_list = map(int, v_info)
            # assert len(v_adj_list) == v_adj_length * 2
            for target, cost in zip(v_adj_list[::2], v_adj_list[1::2]):
                adj_table[source][target] = cost

        self.adj_table = adj_table
        self.distance = [float('inf')] * v_num
        self.parent = [-1] * v_num
        self.visited = [WHITE] * v_num

    def path_heap_Dijkstra(self, root):
        # path search init
        self.distance[root] = 0
        path_heap = list()
        # heapq: rank by tuple[0], at here it's d[u]
        hp.heappush(path_heap, (0, root))

        while path_heap:
            current = hp.heappop(path_heap)[1]
            self.visited[current] = BLACK

            for adj, cost in self.adj_table[current].items():
                if self.visited[adj] is not BLACK:
                    # alt: d[u] + w[u,v]
                    alt_path = self.distance[current] + cost
                    if alt_path < self.distance[adj]:
                        # update path_list
                        self.distance[adj] = alt_path
                        # update heap
                        hp.heappush(path_heap, (alt_path, adj))
                        self.visited[adj] = GRAY
                        self.parent[adj] = current

        return self.distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    case = SingleSourceShortestPath(in_data=_input)
    ans = case.path_heap_Dijkstra(root=0)
    for i, v in enumerate(ans):
        print(i, v)

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

int main()
{
    long long int a,b,c,d,p1,p2,p3,p4,maximum;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    maximum=max(max(a*c,a*d),max(b*c,b*d));
    printf("%lld",maximum);
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    ll n,m;
    cin >> n >> m;
    if(n == 1 && m == 1){
        cout << 1 << endl;
    }else if (n >=2  && m >= 2){
        cout << (n - 2) * (m - 2) << endl;
    }else{
        cout << max(n, m) - 2 << endl;
     }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int s[201];
int main()
{
	int i,j,n,m,a,b,k,a1,b1;
	bool yes,no;
	while(cin>>n)
	{
		if(n==0)break;
		memset(s,0,sizeof(s));
		for(i=1;i<=n;i++)
		{
			cin>>m;
			s[m]=1;
		}
		a=0;
		b=0;
		m=0;
		while(a!=n&&b!=n)
		{
			no=false;
			if(m==0)
			{
				for(i=1;i<=2*n;i++)
				{
					if(s[i]==1)
					{
						s[i]=2;
						m=i;
						no=true;
						a++;
						break;
					}
				}
			}
			else 
			{
				for(i=m;i<=2*n;i++)
				{
					if(s[i]==1)
					{
						s[i]=2;
						m=i;
						no=true;
						a++;
						break;
					}
				}
			}
			if(a==n)break;
			if(no==false)m=0;
			no=false;
			if(m==0)
			{
				for(i=1;i<=2*n;i++)
				{
					if(s[i]==0)
					{
						s[i]=2;
						m=i;
						no=true;
						b++;
						break;
					}
				}
			}
			else 
			{
				for(i=m;i<=2*n;i++)
				{
					if(s[i]==0)
					{
						s[i]=2;
						m=i;
						no=true;
						b++;
						break;
					}
				}
			}
			if(no==false)m=0;
			
		}
		a1=0;
		b1=0;
		if(a>b)
		{
			for(i=1;i<=2*n;i++)
			{
				if(s[i]==0)a1++;
			}
		}
		else 
		{
            for(i=1;i<=2*n;i++)
            {
            	if(s[i]==1)b1++;
			}
		}
		cout<<a1<<endl<<b1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int A,B,C,temp,temp2;
    cin>>A>>B>>C;
    temp=A;
    A=B;
    B=temp;
    temp2=A;
    A=C;
    C=temp2;
    cout<<A<<" "<<B<<" "<<C<<" "<<"\n";


    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++) cout << 'x';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256