akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int32_t main() {
	Fast_IO
	int n; cin >> n;
	vector<vector<int>> arr(n, vector<int>(3));
	for (auto &it : arr) {
		for (auto &i : it)
			cin >> i;
	}
	vector<vector<int>> dp(n + 1, vector<int>(3));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (k != j) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + arr[i - 1][j]);
				}
			}
		}
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]});

}

Measured memory_bytes: 14208
fn main() {
    let mut s = String::new();
    let mut t = String::new();
    std::io::stdin().read_line(&mut s).ok();
    std::io::stdin().read_line(&mut t).ok();
    let a = s.trim_right().as_bytes();
    let b = t.trim_right().as_bytes();
    for i in (0..a.len()).rev() {
        if i + b.len() > a.len() { continue; }
        let mut valid = true;
        for j in 0..b.len() {
            if a[i+j] != '?' as u8 && a[i+j] != b[j] {
                valid = false;
                break;
            }
        }
        if valid {
            for j in 0..i {
                print!("{}", if a[j] == '?' as u8 {"a"} else { &s[j..j+1] } )
            }
            print!("{}", t.trim_right());
            for j in i+b.len()..a.len() {
                print!("{}",  if a[j] == '?' as u8 {"a"} else { &s[j..j+1] } )
            }
            println!("");
            return;
        }
    }
    println!("UNRESTORABLE");
}


Measured memory_bytes: 4352
s=input()
n=len(s)
for i in range(n):
    if i%2==0 and s[i]!="h":
        print("No")
        break
    if i%2!=0 and s[i]!="i":
        print("No")
        break
else:
    if n%2==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A, B, C, D;
        D = N % 10;
        N /= 10;
        C = N % 10;
        N /= 10;
        B = N % 10;
        N /= 10;
        A = N;

        if (A + B + C + D == 7) System.out.printf("%d+%d+%d+%d=7", A, B, C, D);
        else if (A + B + C - D == 7) System.out.printf("%d+%d+%d-%d=7", A, B, C, D);
        else if (A + B - C + D == 7) System.out.printf("%d+%d-%d+%d=7", A, B, C, D);
        else if (A + B - C - D == 7) System.out.printf("%d+%d-%d-%d=7", A, B, C, D);
        else if (A - B + C + D == 7) System.out.printf("%d-%d+%d+%d=7", A, B, C, D);
        else if (A - B + C - D == 7) System.out.printf("%d-%d+%d-%d=7", A, B, C, D);
        else if (A - B - C + D == 7) System.out.printf("%d-%d-%d+%d=7", A, B, C, D);
        else if (A - B - C - D == 7) System.out.printf("%d-%d-%d-%d=7", A, B, C, D);
    }
}

Measured memory_bytes: 21844
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

A = defaultdict(int)

for x in a:
	A[x] += 1

#print(A)
ans = 0
for key in A.keys():
	if key > A[key]:
		ans += A[key]
	else:
		ans += A[key] - key

print(ans)



Measured memory_bytes: 19852
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

X = (10**18).bit_length()

def f(a, s, n):
    if s[-1] == "1":
        return 1

    B = [None] * X
    for i in range(n-1, -1, -1):
        ai, si = a[i], s[i]

        if si == "0":
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    B[x] = ai
                    break
                ai ^= B[x]
        else:
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    return 1
                ai ^= B[x]
    return 0


def resolve():
    T = int(input())

    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S  = input()

        ans.append(f(A, S, N))

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


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

#define ll long long
#define ld long double

int n;
int a[100001];
int dp[100001];

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

    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) dp[i] = INT_MAX / 2;
    dp[0] = 0;
    for(int i=0;i<n;i++) {
        if(i < n - 1) dp[i+1] = min(dp[i+1], dp[i] + abs(a[i] - a[i+1]));
        if(i < n - 2) dp[i+2] = min(dp[i+2], dp[i] + abs(a[i] - a[i+2]));
    }
    cout << dp[n-1] << '\n';
    return 0;
}



Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n =int(input())
x = [int(input()) for i in range(n)] 
sousa=0
if x[0] != 0:
    print("-1")
    exit()
for i in range(1,n):
    if x[i] > x[i-1] + 1:
        print("-1")
        exit()
    elif x[i] == x[i-1] + 1:
        sousa += 1
    else:
        sousa += x[i]
print(sousa)



Measured memory_bytes: 20256
#include <iostream>
#include <algorithm>
#include <map>

using ll = long long;
using namespace std;

const int MOD = 1e9+7;

int main() {
    int N;
    ll s = 1;
    string S;
    cin >> N;
    cin >> S;
    map<char, int> M;
    for(int i = 0; i < N; i++) {
        if (M.find(S[i]) != M.end()) {
            M[S[i]]++;
        }
        else {
            M[S[i]] = 1;
        }
    }
    for(auto itr = M.begin(); itr != M.end(); itr++) {
        s *= itr->second + 1;
        s %= MOD;
    }
    cout << (s + MOD - 1) % MOD << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
n,p=map(int,input().split())
d={}
num=p
for i in range(2,int(p**(1/2))+1):
  if num%i==0:
    d[i]=1
    num=num//i
  while num%i==0:
    d[i]+=1
    num//=i
d[num]=1
ans=1
for i in d:
  while d[i]>=n:
    ans*=i
    d[i]-=n
print(ans)

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

/*
 * n人が全員kと発言っていることがあり得るか
 * */
bool same(int n, int k) {
    if (k <= 0) return false;
    if (n - 1 == k) return true;
    return n / 2 >= k;
}

/*
 * 全部ユニークじゃない配列
 */
bool same2(int n, int k) {
    if (k <= 0) return false;
    return n / 2 >= k;
}

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

    int N;
    cin >> N;

    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];

    sort(all(a));
    if (a.back() - a.front() > 1) {
        cout << "No" << endl;
        return 0;
    }

    int x = a.front();
    int y = a.back();

    int z = count(all(a), x);

    if (x == y) {
        if (same(N, y)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (same2(N - z, y - z)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 640
while 1:
 m,f,r=map(int,input().split());s=m+f
 if m==f==r==-1:break
 if m*f<-1 or s<30:print('F')
 elif s<50 and r<50:print('D')
 elif s<65:print('C')
 elif s<80:print('B')
 else:print('A')

Measured memory_bytes: 5592
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D;

    cin >> A >> B >> C >> D;

    if (A >= D || C >= B) {
        cout << 0 << endl;
    }
    else if (A <= C && B <= D) {
        cout << B - C << endl;
    }
    else if (A <= C && D <= B) {
        cout << D - C << endl;
    }
    else if (C <= A && B <= D) {
        cout << B - A << endl;
    }
    else if (C <= A && D <= B) {
        cout << D - A << endl;
    }

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='L'){
        cout << "No";
        return 0;
      }
    }else{
      if(s[i]=='R'){
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  string head = "";
  int needleft = 0;
  int pointer = 0;
  rep(i,n){
    if(s[i] == '('){
      pointer++;
    }else {
      if(pointer == 0)needleft++;
      else pointer--;
    }
  }
  int needright = pointer;
  rep(i,needright){
    s += ')';
  }
  rep(i,needleft){
    head += '(';
  }
  head += s;
  cout << head << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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

int main() {

	string o, e;
	cin >> o >> e;

	rep(i, o.size() + e.size()) {
		if (i % 2 == 0) { cout << o[i / 2]; }
		else { cout << e[i / 2]; }
	}
	
	system("PAUSE");
}


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

ll N, K, ans=0;

signed main(){
    cin >> N >> K;
    if(N>=3*K) ans += (N/K)*(N/K-1)*(N/K-2);
    if(N>=2*K) ans += 3*(N/K)*(N/K-1);
    if(N>=K) ans += N/K;
    if(K%2==0) {
        int Neven=N+K/2;
        if(Neven>=3*K) ans += (Neven/K)*(Neven/K-1)*(Neven/K-2);
        if(Neven>=2*K) ans += 3*(Neven/K)*(Neven/K-1);
        if(Neven>=K) ans += Neven/K;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
N,S=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

mod=998244353
cur=defaultdict(lambda: 0)
new=defaultdict(lambda: 0)
cur[0]=1

for a in A:
    for i in cur.keys():
        if i+a<=S:
            new[i+a]+=cur[i]
            new[i+a]%=mod
        new[i]+=cur[i]*2
        new[i]%=mod
    cur=new
    new=defaultdict(lambda: 0)

print cur[S]


Measured memory_bytes: 125028
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

char fi[7][7];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w,k; cin >> h >> w >> k;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> fi[i][j];
        }
    }
    int res=0;
    int n=h+w;
    for(int i=0;i<(1<<n);i++){
        vector<int> hh(h,0),ww(w,0);
        for(int j=0;j<h;j++){
            if((1<<j)&i){
                hh[j]=1;
            }
        }
        for(int j=h;j<n;j++){
            if((1<<j)&i){
                ww[j-h]=1;
            }
        }
        int cnt=0;
        for(int j=0;j<h;j++){
            for(int p=0;p<w;p++){
                if(hh[j]&&ww[p]&&fi[j][p]=='#')cnt++;
            }
        }
        if(cnt==k)res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3652
/*
   Author : tarang
*/
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
int main(){
    ll n ; cin >> n ;
    cout << n/3 << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  ll s;
  cin >> s;
  cout << 0 << ' ' << 0 << ' ';
  ll m=1000000000;
  cout << m << ' ' << 1 << ' ';
  ll y=(m-(s+m)%m)%m;
  ll x=(s+y)/m;
  cout << y << ' ' << x << endl;
return 0;}

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

const int N = 410, inf = 1e18;
int n, a[N], dp[N][N], pref[N];
bool visited[N][N];

int solve(int l, int r) {
	if (visited[l][r])
		return dp[l][r];
	visited[l][r] = true;
	if (r - l == 1)
		return dp[l][r] = 0;
	dp[l][r] = inf;
	for (int i = 1; i < r - l; i++) {
		dp[l][r] = min(dp[l][r], solve(l, l + i) + solve(l + i, r));
	}
	dp[l][r] = dp[l][r] + pref[r - 1] - pref[l - 1];
	return dp[l][r];
}

signed main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	memset(visited, false, sizeof(visited));
	int ans = solve(1, n + 1);
	cout << ans;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;


ll check(ll n){ 
    ll count = 0; 
    for (ll i = 5; n / i >= 1; i *= 5) 
        count += n / i; 
    return count; 
} 

int main(){
	ll n;
	cin>>n;
	if(n%2==0){
		ll g=n/10;
		ll h=check(g);
		cout<<g+h<<endl;
	}
	else cout<<0<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 3000000000000000000;

#include <random>

int score;
vector<int> c, t;
vector<vector<int>> s;
vector<set<int>> S1, S2;

int kaeru_val(int d, int q) {
    int sco = score;
    sco -= s[d][t[d]];
    sco += s[d][q];
    int x = *(S2[t[d]].upper_bound(-d));
    x *= (-1);
    int y = *(S1[t[d]].upper_bound(d));
    sco += c[t[d]] * (d - x - 1) * (d - x) / 2;
    sco += c[t[d]] * (y - d - 1) * (y - d) / 2;
    sco -= c[t[d]] * (y - x - 1) * (y - x) / 2;
    x = *(S2[q].upper_bound(-d));
    x *= (-1);
    y = *(S1[q].upper_bound(d));
    sco += c[q] * (y - x - 1) * (y - x) / 2;
    sco -= c[q] * (d - x - 1) * (d - x) / 2;
    sco -= c[q] * (y - d - 1) * (y - d) / 2;
    return sco;
}

void kaeru(int d, int q) {
    score -= s[d][t[d]];
    score += s[d][q];
    int x = *(S2[t[d]].upper_bound(-d));
    x *= (-1);
    int y = *(S1[t[d]].upper_bound(d));
    score += c[t[d]] * (d - x - 1) * (d - x) / 2;
    score += c[t[d]] * (y - d - 1) * (y - d) / 2;
    score -= c[t[d]] * (y - x - 1) * (y - x) / 2;
    x = *(S2[q].upper_bound(-d));
    x *= (-1);
    y = *(S1[q].upper_bound(d));
    score += c[q] * (y - x - 1) * (y - x) / 2;
    score -= c[q] * (d - x - 1) * (d - x) / 2;
    score -= c[q] * (y - d - 1) * (y - d) / 2;
    S1[t[d]].erase(d);
    S2[t[d]].erase(-d);
    S1[q].insert(d);
    S2[q].insert(-d);
    t[d] = q;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int D;
    cin >> D;
    c = vector<int>(26);
    s = vector<vector<int>>(D, vector<int>(26));
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];
    
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<int> dist1(0, D - 1);
    uniform_int_distribution<int> dist2(0, 25);
    
    t = vector<int>(D, 0);
    rep(i, D) score += s[0][i];
    REP(i, D) score -= (D + 1) * D / 2 * c[i];
    S1 = S2 = vector<set<int>>(26);
    rep(i, D) {
        S1[t[i]].insert(i);
        S2[t[i]].insert(-i);
    }
    rep(i, 26) {
        S1[i].insert(-1);
        S2[i].insert(1);
        S1[i].insert(D);
        S2[i].insert(-D);
    }
    
    rep(_, 100000) {
        int x = dist1(mt);
        int y = dist2(mt);
        if (kaeru_val(x, y) > score) kaeru(x, y);
    }
    
    // cout << "Score: " << score << "\n";
    rep(i, D) cout << t[i] + 1 << "\n";
    
    return 0;
}



Measured memory_bytes: 3744
//=============================================================
// Name        : a
// Date        : Wed Jul  3 22:38:38 CST 2019
// Accepted    : Wed Jul  3 22:39:45 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  string s;
  cin >> s;
  vector<int> cnt(26);
  for (int i = 0; i < sz(s); ++i) {
    cnt[s[i] - 'A']++;
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) {
    if (cnt[i] >= 2) {
      ans++;
    }
  }
  cout << (ans >= 2 ? "Yes" : "No") << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAXNUM 101 /*配列の添字に0を用いないため1増えている*/
#define INF 100000000

typedef struct {
  int gyo;
  int retsu;
} MATRIX;

int matrixChainOrder(MATRIX *, int);

int main()
{
  int i, n;
  MATRIX M[MAXNUM];

  scanf("%d",&n);

  for(i = 1; i <= n; i++) {
    scanf("%d%d",&M[i].gyo,&M[i].retsu);
  }

  printf("%d\n",matrixChainOrder(M, n));
  
  return 0;
}

int matrixChainOrder(MATRIX *M, int n)
{
  int i, j, k, l, q;
  int m[MAXNUM][MAXNUM];
  
  for(i = 1; i <= n; i++) {
    m[i][i] = 0;
  }

  for(l = 2; l <= n; l++) {
    for(i = 1; i <= n-l+1; i++) {
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k <= j-1; k++) {
	q = m[i][k] + m[k+1][j] + M[i].gyo*M[k].retsu*M[j].retsu;
	if(m[i][j] > q) m[i][j] = q;
      }    
    }
  }

  return m[1][n];  
}



Measured memory_bytes: 2112
/* author:hellojim */
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int a[111],b[111];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int n;
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i];
	rep(i,n-2)
	{
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    const int INF = 1e9;
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    rep(i,n-1){
        if(a[i]+a[i+1]<-a[i]-a[i+1]){
            a[i]=-a[i];
            a[i+1]=-a[i+1];
        }
    }
    ll ans=0;
    rep(i,n) ans+=a[i];
    cout << ans << endl;
}




Measured memory_bytes: 3944
import numpy as np 
from numba import njit
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a,np.int64)

@njit('(i8[::1],)', cache=True)
def imo(a):
    imos=np.zeros(n+1,np.int64)
    for i in range(n):
        imos[max(0,i-a[i])]+=1
        imos[min(n,i+a[i]+1)]-=1
    
    immo=np.zeros(n+1,np.int64)
    immo=np.cumsum(imos)
    return immo[:n]


for _ in range(min(k,41)):
    a=imo(a)
    
print(*a)


Measured memory_bytes: 124976
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)

//string s = to_string(i);

//char→小文字のほうが大きい数値　　&&　その差は32

//大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[0])

//pow(a,b) → aのb乗を求める

int a = 0, b = 0, c = 0, d = 0, x = 0, y = 0
   , z = 0, n = 0, sum = 0, i = 0;
string s = ""; asas; cncn;

int main(void) {
	cin >> n;
	int max=0, min=1000000000;
	vint a(n);
	vcin(a, n);
	rep(i, n) {
		if (max < a[i])max = a[i];
		if (min > a[i])min = a[i];
	}
	cout << max - min << rt;
	please AC;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define U 1000
#define NIL -1
#define WHITE 0
#define BLACK 1
#define MAX 3000
int d[U];
int parent[U];
int color[U];

int main()
{
    int cost = 0;
    int mincost;
    int i, j, k, u, v;
    int n;
    int A[105][105];
    scanf("%d", &n);

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

    for (u = 0; u < n; u++)
    {
        d[u] = MAX;
        parent[u] = NIL;
        color[u] = WHITE;
    }
    d[0] = 0; //最初の島のコストは０

    while (1)
    {
        mincost = MAX;

        for (i = 0; i < n; i++)
        {
            if (color[i] != BLACK && d[i] < mincost)
            {
                mincost = d[i];
                u = i;
            }
        }

        // printf("aiueo\n");

        if (mincost == MAX)
            break;

        color[u] = BLACK;

        for (v = 0; v < n; v++)
        {
            if (color[v] != BLACK && A[u][v] < d[v] && A[u][v] != NIL)
            {
                parent[v] = u;
                d[v] = A[u][v];
            }
        }
    }

    for (v = 0; v < n; v++)
        cost += d[v];

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

    return 0;
}



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

using namespace std;
typedef long long ll;
int main()
{
    ll a[5],n;
    cin>>n;
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
    }
    sort(a,a+5);
    if(a[0]==1)
        cout<<n/a[0]+4;
    else
    cout<<n/a[0]+5;
    return 0;
}



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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const ll INF = 1LL<<58;
VL s, t;

ll f2(ll x,  int sh){
	const VL& v = sh? t: s;
	int ps = lower_bound(all(v), x) - v.begin();
	ll cnd = abs(x - v[ps]); 
	if(ps>0){
		cnd = min(cnd, abs(x-v[ps-1]));
	}
	return cnd;
}

ll f(ll x,  int sh){
	const VL& v = sh? t: s;
	int ps = lower_bound(all(v), x) - v.begin();
	ll cnd = abs(x - v[ps]) + f2(v[ps], !sh); 
	if(ps>0){
		cnd = min(cnd,  abs(x - v[ps-1]) + f2(v[ps-1], !sh));
	}
	return cnd;
}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,q;
	cin >>a >>b >>q;
	s.resize(a+2), t.resize(b+2);
	rep(i, a) cin >>s[i+1];
	rep(i, b) cin >>t[i+1];
	s.front() = t.front() = -INF;
	s.back() = t.back() = INF;
	rep(i, q){
		ll ans = INF;
		ll x; cin >>x;
		ans = min(ans, f(x, 0));
		ans = min(ans, f(x, 1));
		cout << ans <<"\n";
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
void in(T& x) {
	cin >> x;
}

template<class T1,class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class T>
void in(vector<T>& v,LL st=-1,LL en=-1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

//空vectorを要素数NのsegTreeとしてzで初期化
template<class T>
void segTree_init(vector<T>& vec, int N, T z) {
	int RN = 1;
	while (RN < N)RN *= 2;
	vec.resize(2 * RN, z);
}

//vecをsegTreeとしてn番目をxに
template<class T>
void segTree_set(vector<T>& vec, int n, T x, function<T(T, T)> f, int k = -1) {
	int RN = (vec.size() + 1) / 2;
	if (k == -1) {
		k = n + RN;
		vec[k] = x;
		segTree_set(vec, n, x, f, k / 2);
	}
	else if (k != 0) {
		vec[k] = f(vec[2 * k], vec[2 * k + 1]);
		segTree_set(vec, n, x, f, k / 2);
	}
}

//vecがsegTreeの時の、n番目の要素
template<class T>
T segTree_at(vector<T>& vec, int n) {
	int RN = (vec.size()) / 2;
	return vec[RN + n];
}

//get [a,b]
template<class T>
T segTree_get(vector<T>& vec, int a, int b, function<T(T, T)> f, T e, int k = 1, int l = 0, int r = -1) {
	if (r == -1)r = vec.size() / 2 - 1;
	if (b < l || r < a)return e;
	else if (a <= l && r <= b)return vec[k];
	else return f(
		segTree_get(vec, a, b, f, e, 2 * k, l, (l + r) / 2),
		segTree_get(vec, a, b, f, e, 2 * k + 1, (l + r) / 2 + 1, r)
	);
}

function<LL(LL,LL)> lambda = [](LL a, LL b) {
	return a + b;
};

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, D, A;
	cin >> N >> D >> A;
	vector<PLL> en(N+1);   //位置、体力
	en[0] = PLL(-1, 0);
	for (LL n = 1; n <= N; n++) {
		in(en[n]);
	}
	sort(en.begin(), en.end(), [](PLL a, PLL b) {
		return a.first < b.first;
	});
	VLL seg;
	segTree_init(seg, N,(LL)0);
	LL ans = 0;
	for (LL n = 1; n <= N; n++) {
		LL s = -1, e = n;
		while (e - s > 1) {
			LL m = (e + s) / 2;
			if (en[m].first < en[n].first - 2 * D)s = m;
			else e = m;
		}
		LL t = segTree_get(seg, e, n, lambda, (LL)0);
		LL left = en[n].second - A * t;
		if (left <= 0)continue;
		LL time = ceil((LD)left / A);
		ans += time;
		segTree_set(seg, n, time, lambda);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 7552
K,S = list(map(int,input().split()))
counter = 0
for i in range(K+1):
    for j in range(K+1):
            if 0<=S-i-j<=K:
                counter +=1
               # print(str(i)+' '+str(j)+ ' ' + str(S-i-j))
print(counter)


Measured memory_bytes: 8996
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int N;
  cin >> N;
  auto v = vector<int>(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  v.emplace_back(0);
  int s = accumulate(v.begin(), v.end(), 0);
  sort(v.begin(), v.end());
  for (int i = 0; i < N; i++) {
    if ((s - v[i]) % 10 != 0) {
      cout << s - v[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}


Measured memory_bytes: 3228
#include <vector>
#include <string>
using namespace std;

//  Z[i] = |LCP(S, S[i:])|
//  https://snuke.hatenablog.com/entry/2014/12/03/214243
vector<int> z_algorithm(string S)
{
    int n = (int)S.size();
    vector<int> Z(n);
    Z[0] = n;
    int j = 0;
    for (int i=1; i<n;)
    {
        while (i+j<n && S[j]==S[i+j])
            j++;
        Z[i] = j;
        if (j==0)
        {
            i++;
            continue;
        }
        int k;
        for (k=1; i+k<n && k+Z[k]<j; k++)
            Z[i+k] = Z[k];
        i += k;
        j -= k;
    }
    return Z;
}

#include <iostream>
#include <functional>
#include <algorithm>

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

    string tmp = s;
    while (s.length() < t.length())
        s += tmp;

    string s2 = s+s;
    vector<int> Z = z_algorithm(t+s2);

    vector<bool> f(s.size());
    for (int i=0; i<(int)s.size(); i++)
        f[i] = Z[t.size()+i] >= t.size();

    vector<int> memo(s.size(), -1);
    function<int(int)> BT = [&](int p)
    {
        if (memo[p]==-2)
            return -1;
        if (memo[p]!=-1)
            return memo[p];
        memo[p] = -2;
        if (!f[p])
            return memo[p]=0;
        int r = BT((p+t.size())%s.size());
        if (r==-1)
            return -1;
        return memo[p] = r+1;
    };
    int ans = 0;
    for (int i=0; i<(int)s.size(); i++)
    {
        int r = BT(i);
        if (r==-1)
        {
            cout<<-1<<endl;
            return 0;
        }
        ans = max(ans, r);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 33664
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int a;
    in(a);

    outl(a + a * a + a * a * a);
    return 0;
}

Measured memory_bytes: 3616
# coding: utf-8
# Your code here!

S = input()
first = int(S[0:2])
last = int(S[2::])
 
if first >= 1 and first <= 12:
    if last >= 1 and last <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if last >= 1 and last <= 12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define mema(a) mem(a,127)
#define memi(a) mem(a,128)
#define mem0(a) mem(a,0)
#define mem1(a) mem(a,-1)
#define Qclear(q) while(!q.empty())q.pop()
#define LL long long
#define EPS 1e-6
#define PI (acos(-1))
#define E exp(1.0)
#pragma comment (linker,"/STACK:102400000,102400000")
#define true false
#define false true
template<class T> T lcm(T a, T b){return a/__gcd(a,b)*b;}
template <class T>
inline bool scan_d(T &ret)
{
    char c;
    int sgn;
    if (c=getchar(),c==EOF) {
        return false;
    }
    while (c!='-'&&(c<'0'||c >'9')) {
        c=getchar();
    }
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') {
        ret=ret*10+(c - '0');
    }
    ret*=sgn;
    return true;
}
template <class T>
inline void print_d(T x)
{
    if(x>9)
    {
        print_d(x/10);
    }
    putchar(x%10+'0');
}
const int maxn=100000+5;
const int MOD=1E9+7;
const int INF=0x3f3f3f3f;
const int dx[]={0,0,1,-1,0,0};
const int dy[]={1,-1,0,0,0,0};
const int dz[]={0,0,0,0,1,-1};
int a[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    a[0]=0;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=abs(a[i]-a[i-1]);
    }
    a[n+1]=0;
    sum+=abs(a[n+1]-a[n]);
    for(int i=1;i<=n;i++){
        //cout<<sum<<abs(a[i]-a[i-1])<<abs(a[i]-a[i+1])<<abs(a[i+1]-a[i-1])<<endl;
        cout<<(sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))<<endl;
    }
}
/*

*/


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

public class ABC0125_A3v9 {
    private static void Main(string[] args) {
        var inputs = new List<string>(){
            Console.ReadLine().Trim(),
            Console.ReadLine().Trim(),
        };
        Prepare(inputs);
    }

    private static void Prepare(List<string> inputs) {
        var length = int.Parse(inputs[0]);
        var numbers = inputs[1].Split()
          .Select(x => int.Parse(x))
          .OrderBy(n => n)
          .ToArray();
        Compute(length, numbers);
    }

    private static void Compute(int length, int[] numbers) {
        var candidateA = GetCandidateAGCD(numbers, 0);
        var candidateB = GetCandidateAGCD(numbers, 1);
        OutputAnswer(Math.Max(candidateA, candidateB).ToString());
    }

    private static void OutputAnswer(string text) => Console.WriteLine(text);

    private static int GetCandidateAGCD(int[] numbers, int index) {
        var standard = numbers[index];
        var tempAGCD = 1;

        for (int divisor = 1; divisor * divisor < standard; divisor++) {
            if (standard % divisor == 0) {
                tempAGCD = GetACD(tempAGCD, numbers, divisor);
                tempAGCD = GetACD(tempAGCD, numbers, standard / divisor);
            }
        }

        return tempAGCD;
    }

    private static int GetACD(int tempGCD, int[] numbers, int divisor) {
        if (tempGCD < divisor && IsACD(numbers, divisor))
            return divisor;
        else
            return tempGCD;
    }

    private static bool IsACD(int[] numbers, int divisor) {
        if (divisor <= 0) {
            return false;
        }

        var count = 0;

        foreach (var number in numbers) {
            if (number % divisor != 0) {
                count++;

                if (count > 1)
                    return false;
            }
        }

        return true;
    }
}

Measured memory_bytes: 30428
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int a,b;
    cin >> a >> b;
    int n = min(a,b);
    REP(i,max(a,b)){
        cout << n;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
expected_value_dic = {}

def get_expected_value(x):
    return (1 + x) / 2

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

P = list(map(int, input().split()))
expected_values = [get_expected_value(p) for p in P]
cumulative_values = [expected_values[0]]
for expected_value in expected_values[1:]:
    cumulative_values.append(cumulative_values[-1] + expected_value)

result = cumulative_values[k-1]
for i in range(k, n):
    temp = cumulative_values[i] - cumulative_values[i - k]
    if temp > result:
        result = temp

print(result)


Measured memory_bytes: 26236
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;

int N = 11;
std::vector<std::vector<int>> nums(N, std::vector<int>(10, 0));
std::vector<std::vector<int>> sum(N, std::vector<int>(10, 0));

void make_nums(){
    for(int i = 0; i < 10; ++i){
        nums[0][i] = 1;
    }

    for(int i = 1; i < N; ++i){
        nums[i][0] = nums[i-1][0] + nums[i-1][1];

        for(int j = 1; j < 9; ++j){
            nums[i][j] = nums[i-1][j-1] + nums[i-1][j] + nums[i-1][j+1];
        }

        nums[i][9] = nums[i-1][8] + nums[i-1][9];
    }
}


void make_sum(){
    for(int i = 1; i < 10; ++i){
        sum[0][i] = sum[0][i-1] + nums[0][i];
    }

    for(int i = 1; i < N; ++i){
        sum[i][0] = sum[i-1][9];

        for(int j = 1; j < 10; ++j){
            sum[i][j] = sum[i][j - 1] + nums[i][j];
        }
    }
}

long long answer(int n, int p, int K, long long res)
{
    if(n == 0){
        return res;
    }
    res *= 10;
    int next_p;

    int start = -1;
    int end = 1;
    if(p == 0){
        start = 0;
    }
    if(p == 9){
        end = 9;
    }

    for(int i = start; i <= end; ++i){
        if(K - nums[n-1][p + i] <= 0){
            next_p = p + i;
            break;
        }
        else{
            K -= nums[n-1][p + i];
        }
    }

    return answer(n-1, next_p, K, res + next_p);
}


long long aa(int K)
{
    make_nums();
    make_sum();

    int n, p;

    for(n = 0; n < N; ++n){
        for(p = 1; p <= 9; ++p){
            if(sum[n][p] >= K){
                K -= sum[n][p-1];
                return answer(n, p, K, p);
            }
        }
    }

}



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

    cout << aa(K) << endl;

}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int a, b, n, sum = 0, temp = 0, t;
	
	scanf("%d %d %d", &n, &a, &b);
	
	for(int i = 1; i <= n; i++){
		t = i;
		while(t / 10 || t % 10){
			temp += t % 10;
			t /= 10;
		}
		
		if(temp >= a && temp <= b){
			sum += i;
		}
		
		temp = 0;
	}
	
	printf("%d", sum);
	
	return 0;
}


Measured memory_bytes: 128
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

A = list()
A.append("")
A.extend(A1)
A.extend(A2)
A.extend(A3)

n = int(input())
B = list()
for _ in range(n):
    B.append(int(input()))

holes = [A.index(b) for b in B if (b in A)]
bingos = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
print("Yes" if any([(len(set(holes) & set(bingo)) == 3) for bingo in bingos]) else "No")

Measured memory_bytes: 9252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int x = stdin.nextInt();
		int y = stdin.nextInt();
		System.out.println((x-1)*(y-1));


	}

}


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

using namespace std;

typedef long long LL;

const int mod = 1e9 + 7;

LL qpow(int a, int b) {
    LL res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1; 
    }
    return res;
}

int main() {
    LL n;
    cin >> n;
    if (n == 1) cout << 0 << '\n';
    else cout << (qpow(10, n) - qpow(9, n) * 2 % mod + qpow(8, n) + mod) % mod << '\n';
    return 0; 
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(k,n) for(auto i =k; i<n; i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie();
#define test ll t; cin>>t;


int main(){
    IOS
    ll n , k =0; cin>>n;  ll a[n]; f(0,n){cin>>a[i];}
    f(0,n){
        if((a[i]%2 == 0) && (a[i]%3 && a[i]%5)){cout<<"DENIED"<<endl; return 0;} 
    }
    cout<<"APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

int a[41] = {};
int b[41] = {};
int c[41] = {};
int dp[41][410][410] = {};

const int INF = 100000;

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

  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  REP(i, N) {
    cin >> a[i] >> b[i] >> c[i];
  }

  REP(i, N) {
    REP(j, 410) {
      REP(k, 410) {
        dp[i][j][k] = INF;
      }
    }
  }

  REP(i, N) {
    REP(j, 410) {
      REP(k, 410) {
        if (i > 0 && dp[i - 1][j][k] < INF) {
          dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k]);
          dp[i][j + a[i]][k + b[i]] = min(dp[i][j + a[i]][k + b[i]],
                                          dp[i - 1][j][k] + c[i]);
        }
      }
    }
    dp[i][a[i]][b[i]] = min(dp[i][a[i]][b[i]], c[i]);
  }
  int c = INF;
  for (int i = 1; i < 410; i++) {
    if (i * Ma >= 410 || i * Mb >= 410) break;
    c = min(c, dp[N - 1][i * Ma][i * Mb]);
  }

  if (c == INF) {
    cout << -1 << endl;
  } else {
    cout << c << endl;
  }
  return 0;
}


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

void pri(string s,int a,int b){
  cout << s.substr(a,b-a+1) << endl;
}

string rep(string s,int a, int b, string r){
  for(int i=a; i<=b; i++){
    s[i] = r[i-a];
  }
  return s;
}

string rev(string s, int a, int b){
  string tmp = s;
  for(int i=a; i<=b; i++){
    s[i] = tmp[b+a-i];
  }
  return s;
}

int main(){

  int n;
  string s;
  cin >> s >> n;
  for(int i=0; i<n; i++){
    string ope,tar; cin >> ope;
    int a,b;
    //    cout << ope <<endl;
    if(ope == "replace"){
      cin >> a >> b >> tar;
      s = rep(s,a,b,tar);
    }
    if(ope == "print"){
      cin >> a >> b;
      pri(s,a,b);
    }
    if(ope == "reverse"){
      cin >> a >> b;
      s = rev(s,a,b);
    }
  }
}

Measured memory_bytes: 1224