akhauriyash/Code-Regression huggingface dataset:
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	ans := "No"
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			if i*j == n {
				ans = "Yes"
			}
		}
	}
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(N: int, R: int):
    if 10 <= N:
        return R
    else:
        return R + (100 * (10 - N))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    print(solve(N, R))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    var min = Int.MAX_VALUE
    var d = 1L
    while (d * d <= n) {
        if (n % d == 0L) {
            min = minOf(min, f(d, n / d))
        }
        d++
    }
    println(min)
}

fun f(a:Long, b:Long):Int {
    return maxOf(a.toString().length, b.toString().length)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34348
#include <iostream>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using namespace std::rel_ops;

#define PAIR pair<double, int>

/**********オーバーロード**********/
bool operator>(const PAIR &a, const PAIR &b){	
	return a.first > b.first;
}
bool operator<(const PAIR &a, const PAIR &b){	
	return a.first < b.first;
}


int main(){
	priority_queue<PAIR, vector<PAIR>, greater<PAIR> > race1, race2, race3, fainal;
	//map<double, int>fainal;

	for(int i = 0; i < 8; i++){
		int player;
		double tim;
		cin >> player >> tim;
		race1.push(PAIR(tim, player));
	}
	for(int i = 0; i < 8; i++){
		int player;
		double tim;
		cin >> player >> tim;
		race2.push(PAIR(tim, player));
	}
	for(int i = 0; i < 8; i++){
		int player;
		double tim;
		cin >> player >> tim;
		race3.push(PAIR(tim, player));
	}

	//上位２位
	for(int i = 0; i < 2; i++){
		cout << race1.top().second << " " << race1.top().first << endl;
		race1.pop();
	}
	for(int i = 0; i < 2; i++){
		cout << race2.top().second << " " << race2.top().first << endl;
		race2.pop();
	}
	for(int i = 0; i < 2; i++){
		cout << race3.top().second << " " << race3.top().first << endl;
		race3.pop();
	}

	//Time抜け
	for(int i = 0; i < 2; i++){
		fainal.push(race1.top());
		race1.pop();
	}
	for(int i = 0; i < 2; i++){
		fainal.push(race2.top());
		race2.pop();
	}
	for(int i = 0; i < 2; i++){
		fainal.push(race3.top());
		race3.pop();
	}
	for(int i = 0; i < 2; i++){
		cout << fainal.top().second << " " << fainal.top().first << endl;
		fainal.pop();
	}

}

Measured memory_bytes: 1300
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

b = a[::-1]

amax = [0] * n
bmax = [0] * n

amax[0] = a[0]
bmax[0] = b[0]
for i in range(1, n):
    amax[i] = max(amax[i-1], a[i])
    bmax[i] = max(bmax[i-1], b[i])

bmax = bmax[::-1]

print(bmax[1])
for i in range(1, n-1):
    print(max(amax[i-1], bmax[i+1]))
print(amax[n-2])

Measured memory_bytes: 17240
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    int n,k;
    cin>>n>>k;
    if(k==1)
    cout<<"0";
    else
    cout<<((n-(k-1))-1);
	return 0;
}

Measured memory_bytes: 256
A, B, C, D = list(input())
operations = [
    ("+", "+", "+"), ("+", "+", "-"), ("+", "-", "+"),
    ("-", "+", "+"), ("-", "-", "+"), ("-", "+", "-"),
    ("+", "-", "-"), ("-", "-", "-")
]

for ope in operations:
    fomula = "{}{}{}{}{}{}{}".format(A, ope[0], B, ope[1], C, ope[2], D)
    result = eval(fomula)
    if result == 7:
        print(fomula+"=7")
        break


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N, M;
vector<vector<int>> vec;
vector<int> cnt;

vector<int> chk;
ll ans = 0;

void func(int swtich) {
	if (swtich == N) {
		bool flag=true;
		for (int i = 0; i < M; i++) {
			int tmp = 0;
			for (int j = 0; j < vec[i].size(); j++) {
				tmp += chk[vec[i][j]];
			}
			if (tmp % 2 != cnt[i]) flag = false;
		}
		if (flag) ans ++;
		return;
	}
	chk[swtich] = 1;
	func(swtich+1);
	chk[swtich] = 0;
	func(swtich + 1);
	return;
}

void solve() {
	cin >> N >> M;
	vec.resize(M);
	chk.resize(N, 0);
	rep(i, M) {
		int k;
		cin >> k;
		vector<int> tmp(k);
		rep(j, k) {
			cin >> tmp[j];
			tmp[j]--;
		}
		vec[i] = tmp;
	}
	cnt.resize(M);
	rep(i, M) cin >> cnt[i];

	func(0);

	cout << ans;

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int A, B, total;
	int sc, sd, se;

	cin >> A >> B >> sc >> sd >> se;

	total = 0;
	if (A < 0 && B > 0){
		total += sd;
	}

	for (int i = A; i < B; i++){
		if (i < 0){
			total += sc;
		}
		else {
			total += se;
		}
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	string s1;
	k = k - 1;
	if (s.substr(k,1) == "A") {
		s1 = "a";
	}
	else if (s.substr(k, 1) == "B") {
		s1 = "b";
	}
	else if (s.substr(k, 1) == "C") {
		s1 = "c";
	}
	cout << s.replace(k,1,s1) << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  sort(a.begin(), a.end(), [&](int x, int y) {
    return x > y;
  });
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i++) {
    if(i % 2 == 0) Alice += a.at(i);
    else Bob += a.at(i);
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vpll vector<pair<ll,ll> >
//assign() assignes new value
//emplace(position,x) inserting
//erase(position) to remove an element
//swap() for swapping
//reverse(position,position) for reversing
# define pb push_back
# define popb pop_back
# define pf push_front
# define popf pop_front
# define sll set<ll>
//find()
//erase(x) removes element x
//erase(position,position)
# define qll queue<ll>
# define qstr queue<str>
//front(),back()
# define stll stack<ll>
# define ststr stack<str>
//top()
# define dll deque<ll>
//at()
# define mll map<ll,ll>
# define msl map<str,ll>
# define mls map<str,ll>
# define mstr map<str,str>
# define mcl map<char,ll>
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define fr(x,y,z) for(int x=y;x<z;x++)
# define rr(x,y,z) for(int x=y;x>z;x--)
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,n,i,j,k,l,c,c1,cnt,flag,m1,m,m2,maxi,mini,x,y,z;
    vll a,b;
    str s,s1,s2;
    cin>>n>>k;
    a=inp(n);
    f(i,n){
        b.pb(INT_MAX);
    }
    b[0]=0;
    for(i=1;i<n;i++){
        m=i-k;
        if(m<0){
            m=0;
        }
        for(j=m;j<i;j++){
            if(b[i]>b[j]+abs(a[i]-a[j])){
                b[i]=b[j]+abs(a[i]-a[j]);
            }
        }
    }
    cout<<b[n-1]<<endl;
}

Measured memory_bytes: 2548
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
        int n, k;
        cin >> n >> k;
        unsigned long long ans = k;
        for (int i = 0; i < n - 1; i++) {
                ans *= k - 1;
        }
        cout << ans << endl;
        return 0;
}


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

string R, S;
set<string> X;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;
    
    for(int i=0; i<N; i++)
    {
        cin >> R;
        
        if(X.find(R) != X.end())
        {
            cout << "No\n";
            return 0;
        }
        
        X.insert(R);
        
        if(i != 0 && R[0] != S.back())
        {
            cout << "No\n";
            return 0;
        }
        
        S = R;
    }
    
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
use std::io::*;

const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        let end_index = match self.bytes_buffer.last() {
            Some(byte) => {
                if *byte == delimiter {
                    len - 1
                } else {
                    len
                }
            }
            None => len,
        };

        &self.bytes_buffer[0..end_index]
    }

    fn scan_u(&mut self, delimiter: u8) -> u32 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u32 + accumulator * 10
            })
    }

    fn scan_u_vec(&mut self, n: usize, separator: u8, delimiter: u8) -> Vec<u32> {
        let mut vector = Vec::with_capacity(n as usize);
        for _i in 0..n - 1 {
            vector.push(self.scan_u(separator));
        }
        vector.push(self.scan_u(delimiter));
        vector
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}

fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}

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

fn count_smaller_numbers(slice: &[u32], max_value: u32) -> usize {
    slice.iter().filter(|&&v| v < max_value).count()
}

fn safe_add(a: usize, b: usize) -> usize {
    (a + b) % 1000000007
}

fn create_safe_product_table(base_value: usize, length: usize) -> Vec<usize> {
    let mut table = Vec::<usize>::with_capacity(length + 1);
    table.push(0);

    let mut acc: usize = 0;
    for _ in 0..length {
        acc = safe_add(acc, base_value);
        table.push(acc);
    }

    table
}

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 64);

    let n = cin.scan_u(SP) as usize;
    let k = cin.scan_u(LF) as usize;
    let a = cin.scan_u_vec(n, SP, LF);

    let k_triangular = k * (k + 1) / 2;
    let k_triangular_table = create_safe_product_table(k_triangular, n);
    let k_minus_one_triangular = (k - 1) * k / 2;
    let k_minus_one_triangular_table = create_safe_product_table(k_minus_one_triangular, n);

    let count: usize = (0..n).fold(0, |acc, i| {
        let current_value = a[i];
        let former_count = count_smaller_numbers(&a[0..i], current_value);
        let latter_count = count_smaller_numbers(&a[i + 1..n], current_value);
        let count_to_add = safe_add(
            k_minus_one_triangular_table[former_count],
            k_triangular_table[latter_count],
        );
        safe_add(acc, count_to_add)
    });

    println(count);
}


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

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    while(t--){
       ll n; cin >> n;
       ll ans = 0;
       for(ll i = 1; i <= n; i++){
          ll val = (n - 1) / i;
          ans += val;
       }
       cout << ans << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
"""
Created on Fri May 25 22:23:44 2018
Knapsack by memorized recursive call
@author: maezawa
"""

n, maxw = list(map(int, input().split()))
w = []
v = []
dp = [[None for _ in range(maxw+1)] for _ in range(n)]

for i in range(n):
    i, j = list(map(int, input().split())) 
    v.append(i)
    w.append(j)

def total_value(i, wi):
    if i == n:
        return 0
    if dp[i][wi] != None:
        return dp[i][wi]
    if wi < w[i]:
        dp[i][wi] = total_value(i+1,wi)
    else:
        dp[i][wi] = max(total_value(i+1,wi), total_value(i+1,wi-w[i])+v[i])
    return dp[i][wi]

print(total_value(0, maxw))



Measured memory_bytes: 23972
/*...Part - 01...*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/

ll dp[1005][1005] ;
char s[1005][1005] ;

int main(){
    int test = 1 , tc = 0 ;
    while(test--){
        int h = Int, w = Int ;
        for(int i = 1 ; i <= h ; ++i){
        	scanf("%s",s[i] + 1) ;
        }
        dp[1][1] = 1 ;
        for(int i = 2 ; i <= h ; ++i){
        	if(s[1][i] == '.')dp[1][i] = dp[1][i - 1] ;
        }
        for(int i = 2 ; i <= w ; ++i){
        	if(s[i][1] == '.')dp[i][1] = dp[i - 1][1] ;
        }
        for(int i = 2 ; i <= h ; ++i){
        	for(int j = 2 ; j <= w ; ++j){
        		if(s[i][j] == '.'){
        			dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % Mod ;
        			dp[i][j] %= Mod ;
        		}
        		//cout << dp[i][j] << ' ' ;
        	}
        }
        cout << dp[h][w] << '\n' ;
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/




Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n;
	cin >> n;
	vector<int> A(n);
	vll pre(n + 1);
	vvll dp(n, vll(n));
	REP(n) {
		cin >> A[i];
		pre[i + 1] = pre[i] + A[i];
	}
	for(int p = 1; p < n; p++) {
		for(int i = 0; i < n - p; i++) {
			int j = i + p;
			ll temp = LLONG_MAX;
			for(int k = i; k < j; k++)
				temp = min(temp, dp[i][k] + dp[k + 1][j]);
			dp[i][j] = temp + pre[j + 1] - pre[i];
		}
	}
	cout << dp[0][n - 1] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  while(a>0 and c>0){
    a-=d;
    c-=b;
  }
  
  if(c>0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3640
from collections import Counter

n,t = map(int,input().split())
a = list(map(int,input().split()))
a_min = [0] * n
a_min[0] = a[0]
for i in range(1,n):
    a_min[i] = min(a_min[i-1],a[i])

profit = [a[i] - a_min[i] for i in range(n)]

comb = Counter(profit)
print(sorted(comb.items(),reverse = True)[0][1])

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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();

        char[] cs = s.toCharArray();
        Arrays.sort(cs);
        if (cs[0] == cs[1] && cs[2] == cs[3] && cs[0] != cs[2]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

int main() {
  ll n;
  cin >> n;
  vector <ll> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << v.at(n-1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n,ans,jc[1000001]={1};
int qpow(int i,int j){return j?j&1?qpow(i*i%mod,j>>1)*i%mod:qpow(i*i%mod,j>>1):1;}
int c(int i,int j)
{
	return jc[i]*qpow(jc[j]*jc[i-j]%mod,mod-2)%mod;
}
signed main()
{
	for(int i=1;i<=1000000;i++)jc[i]=jc[i-1]*i%mod;
	scanf("%lld",&n);
	for(int i=2;i<=n;i++)ans=(ans+(mod+qpow(2,i)-2)*qpow(8,n-i)%mod*c(n,i))%mod;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 11628
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
 		
 		
int main() {

int N;
cin>>N;
  int ans=1;
  fx(N){
    fyg(N,2){
      int k=1;
      int j=y;
      while(j-->0){
        k*=x;
      }
      if(k<=N)
      ans=max(ans,k);
      else continue;
    }
  }
  ce(ans)
}


Measured memory_bytes: 256
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
    // br = black_row, bc = black_column
    // 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    // マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
	
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            // マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        // 上から1行ずつ出力していく
        // 黒が1マスも含まれない行(すべて白の行)はループで飛ばす
        if(br[i] == 0)
            continue;
        // このfor文が実行される行には黒が少なくとも1マス含まれている
        for(j = 0; j < col; j++){
            // 黒が1マスも含まれない列(すべて白の列)はループで飛ばす
            if(bc[j] == 0)
                continue;
            // マス目を出力
            printf("%c", sq[i][j]);
        }
        // 1行出力し終えたので改行
        printf("\n");
    }
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int xp[2020][2020], yp[2020][2020];

int main() {
  int H, W; cin >> H >> W;
  vector<string> F(H);
  rep(i, H) cin >> F[i];

  rep(i, H) rep(j, W) {
    if (F[i][j] == '#') continue;
    if (j == 0 || F[i][j - 1] == '#') {
      xp[i][j] = 1;
    }
    else {
      xp[i][j] = xp[i][j - 1] + 1;
    }
  }
  rep(i, H) {
    int max = 0;
    for (int j = W - 1; j >= 0; j--) {
      if (F[i][j] == '#') continue;
      if (j == W - 1 || F[i][j + 1] == '#') {
        max = xp[i][j];
      }
      else {
        xp[i][j] = max;
      }
    }
  }

  rep(j, W) rep(i, H) {
    if (F[i][j] == '#') continue;
    if (i == 0 || F[i - 1][j] == '#') {
      yp[i][j] = 1;
    }
    else {
      yp[i][j] = yp[i - 1][j] + 1;
    }
  }
  rep(j, W) {
    int max = 0;
    for (int i = H - 1; i >= 0; i--) {
      if (F[i][j] == '#') continue;
      if (i == H - 1 || F[i + 1][j] == '#') {
        max = yp[i][j];
      }
      else {
        yp[i][j] = max;
      }
    }
  }

  int ans = 0;
  rep(i, H) rep(j, W) {
    if (F[i][j] == '#') continue;
    ans = std::max(ans, xp[i][j] + yp[i][j] - 1);
  }
  cout << ans << endl;
}









Measured memory_bytes: 36096
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,n);
  VEC(int,a,n);
  VEC(int,b,n);
  VEC(int,c,n-1);

  REP(i,n){
    a[i]--;
  }
  
  int ans = 0;
  REP(i,n){
    int sel = a[i];
    ans += b[sel];
    if (i>0){
      if (a[i] == a[i-1]+1) {
        ans += c[a[i-1]];
      }
    }

  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int N, L;
    cin >> N >> L;
    int tar_idx = -1;
    int min_abs = INT_MAX;
    int acc = 0;
    for(int i = 0; i < N; i++) {
        if (abs(L+i) < min_abs) {
            min_abs = abs(L+i);
            tar_idx = i;
        }
        acc += (L+i);
    }
    cout << acc - (L+tar_idx) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
using Grid = vector<vector<char>>;
#define vc vector<char>
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//UF
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll H,W;
    cin>>H>>W;
    if(H==1||W==1){
        cout<<1<<endl;
        return 0;
    }
    cout<<(H*W+1)/2<<endl;
}

Measured memory_bytes: 256
def readinput():
    s=int(input())
    return s

def main(s):
    hist=[0]*1000001
    i=1
    n=s
    hist[n]+=1
    while hist[n]<=1:
        if n%2==0:
            n=n//2
        else:
            n=3*n+1
        i+=1
        hist[n]+=1
    return i

if __name__=='__main__':
    s=readinput()
    ans=main(s)
    print(ans)


Measured memory_bytes: 16632
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.List hiding (insert)
import qualified Data.ByteString.Char8 as BS

data Tree = Empty
          | Bin {- key (yen) -} {-# UNPACK #-} !Int64
                {- value (number of drink) -} {-# UNPACK #-} !Int
                {- total cost (yen) -} {-# UNPACK #-} !Int64
                {- total number of drink -} {-# UNPACK #-} !Int
                Tree Tree

insert :: Int64 -> Int -> Tree -> Tree
insert !k !v Empty = Bin k v (k * fromIntegral v) v Empty Empty
insert !k !v (Bin k' v' tc tn s t) = case compare k k' of
  LT -> Bin k' v' tc' tn' (insert k v s) t
  EQ -> Bin k (v + v') tc' tn' s t
  GT -> Bin k' v' tc' tn' s (insert k v t)
  where tc' = tc + k * fromIntegral v
        tn' = tn + v

toList :: Tree -> [(Int64,Int)]
toList = go []
  where
    go xs Empty = xs
    go xs (Bin k v _ _ s t) = go ((k,v) : go xs t) s

total :: Tree -> (Int64,Int)
total Empty = (0,0)
total (Bin _ _ tc tn _ _) = (tc,tn)

main = do
  [n,m] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  ab <- fmap (foldl' (flip $ uncurry insert) Empty) $ sequence $ replicate n $ do
    [a,b] <- map (read . BS.unpack) . BS.words <$> BS.getLine
    return (a :: Int64, fromIntegral b :: Int) -- (a :: Int64, b :: Int)
  let solve !k !yen (Bin a b _ _ s t) | k < ln = solve k yen s
                                      | k <= ln + b = yen + lc + a * fromIntegral (k - ln)
                                      | otherwise = solve (k - ln - b) (yen + lc + a * fromIntegral b) t
        where (lc,ln) = total s
  print $ solve m 0 ab


Measured memory_bytes: 47740
#pragma GCC optimize("Ofast")
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i*i<=n; i++){
        if(n%i == 0){
            res.emplace_back(i);
            if(i*i != n) res.emplace_back(n/i);
        }
    }
    sort(res.begin(),res.end());
    return res;
}
bool isprime(ll n){return divisor(n).size()==2;}
#pragma endregion library

int main(){
    int n; cin >> n;
    vector<string> v(n); rep(i,n) cin >> v[i];
    vector<pll> frac;
    rep(i,n){
        int syou=0;
        int idx = -1;
        rep(j,v[i].length()){
            if(v[i][j]=='.') {
                syou=v[i].length()-(j+1);
                idx = j;
                break;
            }
        }
        ll bunbo = 1;
        rep(j, syou) bunbo*=10;
        ll bunshi;
        if(idx==-1) bunshi = stoll(v[i]);
        else{
            v[i].erase(idx,1);
            bunshi = stoll(v[i]);
        } 
        ll g = gcd(bunbo,bunshi);
        bunbo/=g; bunshi/=g;
        if(bunbo>10000005) continue;
        frac.emplace_back(bunshi,bunbo);
    }
    map<pll,ll> mp;

    ll ans = 0;
    rep(i,frac.size()){
        vll div = divisor(frac[i].first);
        rep(j,div.size()){
            pll p = {div[j],frac[i].second};
            if(mp.find(p)!=mp.end()){
                ans += mp[p];
            }
        }
        rep(j,div.size()){
            pll p = {frac[i].second,div[j]};
            mp[p] = mp[p]+1;

        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 29316
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

////////////////////////////////////////////////////////////////////

struct UnionFind {
	vector<ll> par,siz; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(ll N) : par(N),siz(N, 1LL) { //最初は全てが根であるとして初期化
		for (ll i = 0; i < N; i++) par[i] = i;
	}
   


	ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(ll x, ll y) { // xとyの木を併合
		ll rx = root(x); //xの根をrx
		ll ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

    ll size(ll x){
        return siz[root(x)];
    }
};

int main() {
ll n,m;
cin>>n>>m;
UnionFind tree(n);
int a[100000], b[100000];

for(ll i=0;i<=m-1;i++){
cin>>a[i]>>b[i];
--a[i], --b[i];

}

ll ans=n;
ans=ans*(ans-1)/2;

ll ret=0;
ll cnt[m+1];
cnt[m-1]=ans;


for(ll i=m-1;i>=1;i--){
ll p=a[i]; ll q=b[i];
if(tree.same(p, q)){
    cnt[i-1]=cnt[i];
}
else{
cnt[i-1]=cnt[i]-tree.size(p)*tree.size(q);
tree.unite(p,q);


}

}

for(ll i=0;i<=m-1;i++){
    cout<<cnt[i]<<endl;
    
}




return 0;
}


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

ll dp[1000003][3];
ll n;
char pre='x';
int main(){
   cin>>n;
   ll happy[n][3];
   rep(i,n) cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
    rep(i,n)
        rep(j,3) dp[i][j] = -INF;
    rep(j,3)  dp[0][j] = 0;
    rep(i, n){
        rep(j, 3){
            rep(k, 3){
                if (j == k) continue;
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + happy[i][j]);
            }
        }
    }
    ll ans = -INF;
    rep(i, 3) ans = max(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6656
// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define int long long
#define endl "\n"
#define deb(x) cout << #x << " -> " << x << endl;
#define print(x)                         \
    for (auto x_ : x) cout << x_ << " "; \
    cout << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define mod 1000000007  // 1e9 + 7
#define prec(x, y) fixed << setprecision(y) << x

void solve() {
    int n;
    cin >> n;
    int sum = 0;
    int prefix[n] = {};
    int a[n];
    for (auto &x : a) cin >> x, sum += x;
    prefix[0] = a[0];
    for (int i = 1; i < n; ++i) prefix[i] = ((prefix[i - 1] + a[i]));
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int t = ((a[i] % mod) * ((prefix[n - 1] - prefix[i]) % mod)) % mod;
        res = (t + res) % mod;
    }
    cout << (res % mod) << endl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
}

Measured memory_bytes: 6688
fun main(args: Array<String>) {
    while(true)
    {
        var list = readLine()!!.split(" ").map(String::toInt)
        if ((list[0]==0) and (list[1]==0))
        {
            return
        }
        list = list.sorted()
        println("%d %d".format(list[0],list[1]))
    }
}


Measured memory_bytes: 38904
#include <cstdio>
#define DEBUG(d,n) {for (int i = 0; i < n; i++) {\
                        if (i != n-1)   printf("%d ", d[i]);\
                        else            printf("%d", d[i]);\
                    }   printf("\n");}
#define SWAP(d,a,b) {	int t = d[a];\
						d[a] = d[b];\
						d[b] = t;}
const int MAX = 100;

void selectSort(int d[], int len) {
	static int lps = 0;
	// firstly, we sort i-th before
	for (int i = 0; i < len; i++) {
		//DEBUG(d, len);
		
		int pos = 0, min = 1000000000;	// pos indicate selecting minimun value fron i-th to end
		for (int j = i; j < len; j++) {
			if (min > d[j])	{
				min = d[j];
				pos = j;
			}
		}
		// Swap
		SWAP(d,i,pos);
		if (i != pos)	// wtf????? ?£( ?°????°|||)
			lps++;
	}

	DEBUG(d, len);
	printf("%d\n", lps);
}

int main() {
    int n, d[MAX];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &d[i]);
     
    selectSort(d, n);

    return 0;
}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main(){
    ll n, K; cin >> n >> K;
    ll res = 0;
    for(ll k=K; k<=n+1; ++k){
        ll a = (k-1)*k/2, b = (2*n-k+1)*k/2;// cout << a << "," << b << endl;
        res += (b-a+1)%mod;
    }
	res %= mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    int N;
    LL K;
    cin >> N >> K;

    vector<int> nrs(N + 1);
    for (int i = 1; i <= N; ++i)
    {
        cin >> nrs[i];
    }

    vector<int> path(N + 1), last_idx(N + 1);
    for (int cur_nr = nrs[1], i = 1; ; ++i)
    {
        if (i == K)
        {
            cout << cur_nr;
            return 0;
        }
        if (last_idx[cur_nr])
        {
            int mod = i - last_idx[cur_nr];
            cout << path[last_idx[cur_nr] + (mod - last_idx[cur_nr] % mod + K % mod) % mod];
            return 0;
        }

        path[i] = cur_nr;
        last_idx[cur_nr] = i;
        cur_nr = nrs[cur_nr];
    }
}


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

int ggg[10000007];
void fun(int n)
{

   

    memset(ggg, 0, sizeof ggg);
  for (int i = 1; i <= n; i++) {

        
        for (int j = 1; j * i <= n; j++)
            ggg[i * j]++;
    }

    

}
int main()
{
      fun(10000005);
      int n;
      cin>>n;
      long long ans=0;

      for(int i=0;i<n;i++)
      {
          ans+=((i+1)*1LL*ggg[i+1]);
      }
      cout<<ans<<endl;
}



Measured memory_bytes: 42692
n,k = map(int,input().split())
ab_inputs = [[int(j) for j in input().split()]for i in range(n)]

dic = {}
for ab in ab_inputs:
    a,b = map(int,ab)
    dic[a]=dic.get(a,0)+b

for s in sorted(dic.items(),key=lambda x:x[0]):
    k-=s[1]
    if k<=0:
        ans=s[0]
        break
print(ans)

Measured memory_bytes: 31196
N=int(input())
a=list(map(int,input().split()))

l=[]
r=[]
s=[]

for i,x in enumerate(a):
  left=i
  while len(s)>0 and x<s[-1][0]:
    left=s[-1][-1]
    s.pop()
  l.append(left)
  s.append([x,left])
  #print(l)
  #print(s)
s=[]
for i in range(N-1,-1,-1):
  right=i
  x=a[i]
  while len(s)>0 and x<s[-1][0]:
    right=s[-1][-1]
    s.pop()
  r.append(right)
  s.append([x,right])
r=r[::-1]
ans=0
for i,(x,le,ri) in enumerate(zip(a,l,r)):
  ans+=x*(i-le+1)*(ri-i+1)
print(ans)

Measured memory_bytes: 43616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<int> signal(n+2);
        vector<bool> broken(n+2, false);
        for(int i=1; i<=n; i++){
            string str;
            cin >> str;
            if(str == "x"){
                broken[i] = true;
            }else{
                signal[i] = stoi(str);
            }
        }
        signal[0] = 1e9+10;
        signal[n+1] = (n%2==0)? -(1e9+10) :1e9+10;

        int upper = 1e9+10, lower = -(1e9+10);
        bool none = false;
        for(int i=1; i<=n; i++){
            if(broken[i]){
                if(broken[i-1] || broken[i+1]){
                    none = true;
                    break;
                }
                if(i%2==0){
                    lower = max(lower, max(signal[i-1], signal[i+1])+1);
                }else{
                    upper = min(upper, min(signal[i-1], signal[i+1])-1);
                }
            }else{
                if(i%2==0){
                    if((!broken[i-1] && signal[i] < signal[i-1]) ||
                       (!broken[i+1] && signal[i] < signal[i+1])){
                        none = true;
                    }
                }else{
                    if((!broken[i-1] && signal[i] > signal[i-1]) ||
                       (!broken[i+1] && signal[i] > signal[i+1])){
                        none = true;
                    }
                }
            }
        }

        if(lower > upper) none = true;
        if(none){
            cout << "none" << endl;
        }else if(lower == upper){
            cout << lower << endl;
        }else{
            cout <<  "ambiguous" << endl;
        }

    }
    return 0;
}

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

int a, b, c;

int main()
{
    cin >> a >> b >> c;
    if (a > b)
    {
        swap(a, b);
    }
    if (a > c)
    {
        swap(a, c);
    }
    if (b > c)
    {
        swap(b, c);
    }

    int ans = 0;
    if ((b - a) % 2)
    {
        ++b;
        ++c;
        ans++;
    }
    ans += c - b;
    ans += (b - a) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256