akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    def add(i):
        while i <= n:
            bit[i] += 1
            i += i&-i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res
    n,k = LI()
    p = LI()
    if n > k:
        if k%2 == 0:
            print("Yes")
        else:
            a = 0
            bit = [0]*(n+1)
            for i in range(n):
                a ^= (i-sum(p[i]))&1
                add(p[i])
            if a:
                print("No")
            else:
                print("Yes")
        return

    else:
        for i in range(n):
            if p[i] == 1:
                break
        for j in range(n):
            if p[(j+i)%n] != j+1:
                print("No")
                return
        print("Yes")
    return


if __name__ == "__main__":
    solve()



Measured memory_bytes: 18908
// C - 755
#include <bits/stdc++.h>
using namespace std;

int N;//limit value

int dfs(long long now, bool is3, bool is5, bool is7){
	if(now > N) return 0;//exceeded value limit?
	int count = 0;
	if(is3 && is5 && is7) count++;//{3,5,7} all used
	count += dfs(now*10+3, true, is5, is7);
	count += dfs(now*10+5, is3, true, is7);
	count += dfs(now*10+7, is3, is5, true);
	return count;
}

int main(){
	cin>>N;
	cout<< dfs(0, false, false, false) <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        int ans = 0;
        int temp = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'I') {
                temp++;
            } else {
                temp--;
            }
            if (ans <= temp) {
                ans = temp;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, k, q;
    cin >> n >> k >> q;

    vector<int> a(q);
    rep(i, q) cin >> a[i];
    
    vector<int> A(n);
    rep(i, q) A[a[i] - 1]++;


    rep(i, n) {
        yorn(k - (q - A[i]) > 0);
    }

    return 0;
}

Measured memory_bytes: 4020
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int

	fmt.Scan(&n)

	cards := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	alice := 0
	bob := 0
	for i, m := range cards {
		if i%2 == 0 {
			alice += m
		} else {
			bob += m
		}
	}
	fmt.Println(alice - bob)
}


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

int main() {
  int N;
  cin>>N;
  int ans=0;
  for(int i=0; i<N; i++){
    int l,r;
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  ll l, r;
  cin >> l >> r;
  ll min1 = 2020;
  ll min2 = 2021;
  ll ans = 10000000000;
  ll tmp;
  if(r - l > 2019){
    cout << 0 << endl;
    return 0;
  }
  // vector<ll > a(r - l + 1);
  // for(ll i = 0; i <= r - l; i++ ){
  //   a[i] = (l + i)%2019;
  // }
  // sort(all(a));
  // cout << (a[0]*a[1])%2019 << endl;

  for(ll i = l; i <= r; i++ ){
    for(ll j = i + 1; j <= r; j++ ){
      tmp = i%2019;
      if(tmp == 0){
  	cout << 0 << endl;
  	return 0;
      }else{
  	ans = min(ans, (i*(j%2019))%2019);
      }
    }
  }
  cout << ans << endl;
} 


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N,M; cin >> N >> M;
	vector<vector<char>> A(N,vector<char>(N)),B(M,vector<char>(M));
	rep(i,N)rep(j,N) cin >> A[i][j];
	rep(i,M)rep(j,M) cin >> B[i][j];
	rep(i,N-M+1)rep(j,N-M+1){
		bool ok = true;
		rep(k,M)rep(l,M){
			if(A[i+k][j+l] != B[k][l]) ok = false;
		}
		if(ok){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}



Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Data.Ord
import Control.Monad


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

data City = C { num :: Int,
                pref :: Int,
                year :: Int } deriving Show

main :: IO ()
main = do
    [n,m] <- r'
    pys <- V.generateM m (\i -> do
        [p,y] <- r'
        return C {num = i, pref = p, year = y}
        )
    let srtd = sortBy (comparing pref `mappend` comparing year) (V.toList pys)
    let rnkd = rankize (pref (head srtd), 1) srtd
    let fin  = sortOn (num.fst) rnkd
    mapM_ (C.putStrLn . showCity) fin

rankize :: (Int, Int) -> [City] -> [(City, Int)]
rankize _ [] = []
rankize (cPref, ac) (city:xs)
    | pref city==cPref  = (city,ac):(rankize (pref city,ac+1) xs)
    | otherwise         = (city,1 ):(rankize (pref city, 1+1) xs)

showCity :: (City,Int) -> C.ByteString
showCity (city,rank) =
    let pS = C.pack $ show (pref city)  :: C.ByteString
        rS = C.pack $ show rank         :: C.ByteString
        pI = 6 - (C.length pS)          :: Int 
        rI = 6 - (C.length rS)          :: Int
    in  C.concat [  (C.replicate pI '0'), pS, 
                    (C.replicate rI '0'), rS ]



Measured memory_bytes: 53116
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int n;
    cin>>n;
    vi p(n);
    rep(i,n)cin>>p[i];
    int ans=0;
    for(int i=1;i<n-1;i++){
        if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]))ans++;
    }
    fin(ans);
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
bool same(vector<int>v) {
	return all_of(v.begin(), v.end(), [&](const int a) {
		return a == v[0]; });

}
int main() {
	vector<int>as(12);
	for (int i = 0; i < 12; ++i)cin >> as[i];
	sort(as.begin(), as.end());
	if (same(vector<int>(as.begin(),as.begin()+4))&&
		same(vector<int>(as.begin()+4, as.begin() + 8))&&
		same(vector<int>(as.begin()+8, as.begin() + 12))) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3152
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

//階乗
vector<ll>fact;
//逆元
vector<ll>inv;
//逆元階乗
vector<ll>finv;

pii extgcd(ll a, ll b){
    //前提：aとbが互いに素であること．
    pii x(make_pair(1,0), a);
    pii y(make_pair(0,1), b);

    ll div = 0;

    //終了条件:(GCD(a,b), 0)または(0,GCD(a,b))
    while(true){
        if(y.second == 0) return x;
        
        div = x.second / y.second;
        x.second = x.second  - div * y.second;
        x.first.first = x.first.first - div * y.first.first;
        x.first.second = x.first.second - div * y.first.second;

        if(x.second == 0) return y;

        div = y.second / x.second;
        y.second = y.second - div * x.second;
        y.first.first = y.first.first - div * x.first.first;
        y.first.second = y.first.second - div * x.first.second;
    }
}

ll modinv(ll a, ll m = MOD){
    //前提：aとmが互いに素であること．
    pii ans;
    ans = extgcd(a, m);

    ll invNum = 0;
    invNum = ans.first.first;
    invNum %= m;
    //C++特有の剰余がマイナスになってしまう対策
    if(invNum < 0) invNum += m;

    return invNum;
}

ll warizan_mod(ll warareru, ll waru, ll m = MOD){
    //割られる数に逆元をかけるだけ
    warareru %= m;
    return warareru * modinv(waru, m) % m;
}

//階乗と逆元を列挙
void combination(ll num, ll m = MOD){
    fact.assign(num + 1919, 0);
    finv.assign(num + 1919, 0);
    inv.assign(num  + 1919, 0);

    //初期化
    fact[0] = 1; inv[0] = 1;
    //テーブルに列挙
    for(ll i = 1; i < fact.size(); i++){
        fact[i] = fact[i - 1] * i % m;
        inv[i]  = modinv(fact[i]);
    }
}

//階乗 n!
ll factrial(ll n){
    return fact[n];
}

//順列 nPk n!/(n-k)!
ll nPk(ll n, ll k, ll m = MOD){
    if(n < 0 || k < 0 || n < k) return 0;
    return fact[n] * inv[n - k] % m;
}

//二項係数 nCk n!/(k!*(n-k)!)
ll nCk(ll n, ll k, ll m = MOD){
    if(n < 0 || k < 0 || n < k) return 0;
    return fact[n] * (inv[k] * inv[n - k] % m) % m;
}

//重複組み合わせ n+k-1Ck
ll nHk(ll n, ll k, ll m = MOD){
    return nCk(n+k-1, k);
}

map<ll, ll> primeFactor(ll num){

    //素因数と指数部の並び
    map<ll, ll > PF;

    ll i = 2;

    while(num >= i * i){
        if(num % i == 0){
            PF[i]++;
            num /= i;
        }else{
            i++;
        }
    }
    //1は素因数分解できない
    if(num != 1){
        PF[num]++;
    }
    
    return PF;
}

int main(){

    ll N, M;
    cin >> N >> M;

    //準備
    combination(100000);
    map<ll, ll> PF = primeFactor(M);

    ll ans = 1;

    //素因数ごとに独立して考える！！
    auto begin = PF.begin(), end = PF.end();
    for (auto iter = begin; iter != end; iter++) {
        //素因数の数
        ll num = iter->second;
        ans *= nHk(N, num);
        ans %= MOD;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dist (P x, P y) {
    return abs(x.first-y.first) + abs(x.second-y.second);
}
int main() {
    int h, w, d; cin >> h >> w >> d;
    vector<vector<int>> a(h+1, vector<int>(w+1));
    vector<P> id(h*w+1);
    rep(i, h) rep(j, w) {
        cin >> a[h][w];
        id[a[h][w]].first = i+1;
        id[a[h][w]].second = j+1;
    }
    vector<vector<int>> ruisekiwa(d+1);
    rep(i, d) {
        int x = i+1;
        ruisekiwa[i+1].push_back(0);
        while (x+d <= h * w) {
            ruisekiwa[i+1].push_back(dist(id[x+d],id[x])+ruisekiwa[i+1].back());
            x += d;
        }
    }
    /*rep(i, d) {
        rep(j, ruisekiwa[i].size()) {
            printf("%d ",ruisekiwa[i][j]);
        }puts("");
    }*/
    int q; cin >> q;
    ll ans = 0;
    rep(i, q) {
        int L, R; cin >> L >> R;
        int r = L % d;
        if(r==0) r=d;
        //printf("r:%d %d %d\n", r, (R-r)/d, (L-r)/d);
        cout << ruisekiwa[r][(R-r)/d] - ruisekiwa[r][(L-r)/d] << endl;
    }
}


Measured memory_bytes: 6400
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#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;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //文字列入力
    string s;
    cin >> s;

    ll ans = 0;
    REP(i, 4)
    {
        if (s[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    int n;
    cin >>n;
    
    bool ok = false;
    //全部偶数個だったらsecond
    //1種類でも奇数個だったらfirst
    
    int a;
    for(int i=0; i<n; i++){
        cin >> a;
        if(a%2)ok = true;
    }
    
    if(ok)cout << "first" << endl;
    else  cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

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

  bool c = false;
  bool f = false;

  for(char e : s) {
    c |= (e == 'C');
    f |= (c && e == 'F');
  }

  puts(f? "Yes" : "No");

  return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.rbegin(), a.rend());
  if(sum-a[0] > a[0]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265358979323846
const ll MAX = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

vector<ll> a[MAX];
ll dp[MAX][2];
ll visited[MAX];

void dfs(int node)
{
  visited[node]=1;
  for(int i=0;i<a[node].size();i++)
  {
    if(visited[a[node][i]]==1)
      continue;
   	dfs(a[node][i]);
    ll k = a[node][i];
    ll w = dp[k][0]+dp[k][1];
    ll b = dp[k][0];
    dp[node][0]=(dp[node][0]*w)%MOD;
    dp[node][1]=(dp[node][1]*b)%MOD;
  }
}

int main()
{
  ll n,i,j,k,l,p,q,x,y;
  cin >> n;
  for(i=0;i<n-1;i++)
  {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for(i=0;i<MAX;i++)
  {
    dp[i][0]=1;dp[i][1]=1;
  }
  dfs(1);
  p = dp[1][0]+dp[1][1];
  p = p%MOD;
  cout << p;
}



Measured memory_bytes: 12288
#!/usr/bin/env python3
# -*- coding: utf-8-*-
if __name__ == '__main__':
    s = input()
    r = 1000
    for i in range(len(s)-2):
        t = int(s[i:i+3])
        t -= 753
        if t < 0:
            t = t * -1
        if t < r:
            r = t
    print(r)


Measured memory_bytes: 2940
import math

a, b, n = [int(x) for x in input().split()]
# a = 10 ** 6
# b = 10 ** 12
# n = 10 ** 12

m = 0
if (n < b):
    # math.floor(x / b) = 0
    m = math.floor(a * n / b) # - a * math.floor(n / b)
else:
    m = math.floor(a * (b - 1) / b) - a * math.floor((b - 1) / b)
    #for i in range(n // b - 1, n + 1, b):
    # for i in range(n):
    #     print(i, math.floor(a * i / b),  a * math.floor(i / b), math.floor(a * i / b) - a * math.floor(i / b))
    #     m = max(m, math.floor(a * i / b) - a * math.floor(i / b))

print(m)


Measured memory_bytes: 9164
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    string s; cin >> s;
    int m=1000,a;
    for (int i=0; i<s.size()-2; i++){
        a = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
        m = min(m,abs(a-753));
    }
    cout << m << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var ABCD = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = ABCD[0];
            var B = ABCD[1];
            var C = ABCD[2];
            var D = ABCD[3];
            bool isTaka = true;
            while (true)
            {
                if (isTaka)
                {
                    C -= B;
                    if (C <= 0)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
                else
                {
                    A -= D;
                    if (A <= 0)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                isTaka = !isTaka;
            }
        }
    }
}

Measured memory_bytes: 28292
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int count=0;
  for(int i=1;i<n+1;i++){
    string x = to_string(i);
    if(x.length()%2!=0) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]){
    int n,a0, a1, a2;
    cin >> n >> a0 >> a1;
    int cnt = 0;
    for (int i=2;i<n;i++){
        cin >> a2;
        if ((a0<a1)&(a1<a2)) cnt++;
        if ((a0>a1)&(a1>a2)) cnt++;
        a0 = a1;
        a1 = a2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#include <limits>

template <typename T>
void vc(T t) {
    std::cout << t << " ";
}

template<typename T, typename... Args>
void vc(T t, Args... args) {
// recursive variadic function
    std::cout << t << " ";
    vc(args...) ;
}

const int N = 1;
int a[N];
void once() {
  int s, w;
  std::cin >> s >> w;
  if (w >= s) {
    std::cout << "unsafe" << std::endl;
  } else {
    std::cout << "safe" << std::endl;
  }
}

int
main() {
  int n = 1;
  std::ios::sync_with_stdio(false);
  // std::cin >> n;
  while (n--) {
    once();
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> used(30, 0);
    for(int i = 0; i < 28; i++)
    {
        int x; cin >> x;
        used[x - 1] = 1;
    }
    for(int i = 0; i < used.size(); i++)
    {
        if(not used[i]) cout << i + 1 << endl;
    }
    return 0;
}




Measured memory_bytes: 3164
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    double a,b,c,d,e,f,x,y;
    while(cin>>a>>b>>c>>d>>e>>f){
        y=(c*d-f*a)/(b*d-e*a);
        x=(c*e-f*b)/(a*e-d*b);
        cout<<fixed<<setprecision(3)<<x+0.00005<<" "<<y+0.00005<<endl;
    }
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1001001000;

int main(){
   int a[5];
   rep(i,5)cin >> a[i];
   int Min = INF;
   int minNum = -1;
   rep(i,5){
      if((a[i]%10 < Min) && a[i]%10 != 0){
         minNum = i;
         Min = a[i]%10;
      }
   }
   int ans = 0;
   for(int i=0;i<5;i++){
      ans += a[i];
      if((a[i]%10 != 0) && i != minNum)ans += (10 - a[i]%10);
   }
   cout << ans;
   return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int L;
vector<int> sum;
int N = 1;
vector<int> A, B, C;

signed main(){
    cin >> L;
    L--;

    sum.pb(0);
    int x = 1;
    while(sum.back()+x <= L){
        A.pb(N); B.pb(N+1); C.pb(0);
        A.pb(N); B.pb(N+1); C.pb(x);
        sum.pb(sum.back()+x);
        x *= 2;
        N++;
    }
    x /= 2;

    int n = sum.back() + 1;
    for(int i=sum.size()-1; i>=0; i--){
        if(n+sum[i] <= L){
            A.pb(i+1); B.pb(N); C.pb(n);
            n = n + sum[i] + 1;
        }
    }

    cout << N << " " << A.size() << endl;
    rep(i, A.size()){
        cout << N+1-B[i] << " " << N+1-A[i] << " " << C[i] << endl;
    }
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
struct BinaryIndexedTree {
	int n;
	vector<int>d;
	BinaryIndexedTree(int m) :n(m) {
		d.assign(m + 1, 0);
	}
	void add(int i, int x) {
		for (int j = i; j <= n; j += j&(-j))d[j] += x;
	}
	int getsum(int s, int t) {
		return getsum(t) - getsum(s - 1);
	}
	int getsum(int i) {
		int ret(0);
		for (int j = i; j > 0; j -= j&(-j))ret += d[j];
		return ret;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	BinaryIndexedTree<int> bit(n);
	rep(i, 0, q) {
		int com, x, y; cin >> com >> x >> y;
		if (com)cout << bit.getsum(x, y) << endl;
		else bit.add(x, y);
	}
	return 0;
}

Measured memory_bytes: 3244
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    C, S, F = map(int, input().split())
    c.append(C)
    s.append(S)
    f.append(F)
for i in range(n-1):
    t = 0
    for j in range(i,n-1):
        if t < s[j]:
            t = s[j]
        elif t % f[j] == 0:
            pass
        else:
            t += f[j] - t % f[j]
        t += c[j]
    print(t)
print(0)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        string s = sc.next();
        string s_l = s.ToLower();
        char[] ans_c = s.ToCharArray();
        for (int i = 0; i < n; i++)
        {
            if (i == k - 1) ans_c[i] = s_l[i];
        }
        string ans = new string(ans_c);
        Console.WriteLine(ans);

    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
import math
import itertools
from functools import reduce
from operator import mul
import collections
N = int(input())
l =list(itertools.combinations_with_replacement(range(1,N+1),3))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in l:
    c=collections.Counter(i)
    if len(c)==1:
        ans+=gcd_list(i)
    elif len(c)==2:
        ans+=3*gcd_list(i)
    elif len(c)==3:
        ans+=6*gcd_list(i)
print(ans)

Measured memory_bytes: 193220
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

vector<int> adj[222222];
int D[222222];

void go(int v, int p = -1, int d = 0) {
  D[v] = d;
  for (auto u: adj[v]) if (u != p) go(u, v, d+1);
}

int main() {
  // ios_base::sync_with_stdio(0);

  int N;
  scanf("%d", &N);
  REP(i,N-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].pb(b);
    adj[b].pb(a);
  }

  go(0);
  int v = 0;
  REP(i,N) if (D[i] > D[v]) v = i;
  go(v);

  int diam = 0;
  REP(i,N) diam = max(diam, D[i]);
  printf(diam % 3  == 1 ? "Second\n" : "First\n");
}


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

int main()
{
	int n;
	cin >> n;
	int a[n+1], b[n+1], c[n+1];
	for(int i=1; i<=n; i++)	cin >> a[i];
	for(int i=1; i<=n; i++){
		cin >> b[i];
		c[i]=a[i]-b[i];
	}
	sort(c+1, c+n+1);
	int sum=0;
	if(c[n]<=0){
		cout<<0<<endl;
		return 0;
	}
	else{
		for(int i=n; i>=1; i--){
			if(c[i]<0)break;
			sum+=c[i];
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;


int main()
{
    long long N;
    long long ans = 0;
    cin >> N;
    for(long long i = 1;i <= N;i++)
    {
        if(i % 3 != 0 && i % 5 != 0)
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3192
// Probably getting a WA/Tle
// Still trying
// Apna time ayega

#include<bits/stdc++.h>
#define ll long long int
#define FastRead ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    string n,l,a,b,m,k,i,j;
    cin>>a>>b;
    cout<<b<<a<<endl;


    return 0;
}


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

using namespace std;

int main() {
	int a;
	scanf("%d", &a);
	string str;
	cin >> str;
	int x = 0, mayor = 0;
	for (int i = 0; i < a; ++i) {
		if (str[i] == 'I') {
			x++;
		}else {
			x--;
		}
		mayor = max(mayor, x);
	}
	printf("%d\n", mayor);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int i;
    long long int num[3]; // num={N,A,B}
    long long int p,r,ans;
    
    for(i=0;i<3;i++) cin >> num[i];
    
    p=num[0]/(num[1]+num[2]);
    r=num[0]%(num[1]+num[2]);
    
    ans=num[1]*p+min(num[1],r);

    std::cout << ans << endl;    
    return 0;    
}


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

int main(void){
    // Your code here!
    string s;
    cin >> s;
    long long wc[s.size()+1];
    

    long long cnt = 0;
    for(int i = s.size()-1; i >=0; i--){
        if(s[i] == 'W'){
            cnt++;
            wc[i] = cnt; 
        } else {
            wc[i] = cnt;
        }
    }
    
    
    long long ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'B'){
            ans += wc[i];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 2180
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int sz;
int solve(vector<int> &A, vector<int> &B, int o) {
	int N = A.size();
	set<pair<int, int> > st;
	vector<vector<int> > Xs(sz);
	int res = 0;
	for (int i = 0; i < N; i++) {
		Xs[A[i] + B[i]].push_back(A[i] - B[i]);
		st.emplace(A[i] + B[i], A[i] - B[i]);
	}
	for (int i = 0; i < Xs.size(); i++) {
		sort(Xs[i].begin(), Xs[i].end());
	}
	int m, x;
	int d;
	for (int i = 0; i < Xs.size(); i++) {
		for (int j = 0; j < Xs[i].size(); j++) {
			for (int k = 0; k < j; k++) {
				m = (Xs[i][j] - Xs[i][k]);
				for (int t = -1; t <= 1; t += 2) {
					x = i + t*m;
					if (x >= 0 && x < Xs.size()) {
						
						res += upper_bound(Xs[x].begin(), Xs[x].end(), Xs[i][j] - o)
							- lower_bound(Xs[x].begin(), Xs[x].end(), Xs[i][k] + o);
					/*	d = upper_bound(Xs[x].begin(), Xs[x].end(), Xs[i][j] - o)
							- lower_bound(Xs[x].begin(), Xs[x].end(), Xs[i][k] + o);
						if (d > 0) {
							cerr << (i + Xs[i][j]) / 2 << " " << (i - Xs[i][j]) / 2 << endl;
							cerr << (i + Xs[i][k]) / 2 << " " << (i - Xs[i][k]) / 2 << endl;
						}*/
					}
				}
			}
		}
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	sz = H + W - 1;
	vector<string> S(H);
	int res = 0;
	vector<int> X;
	vector<int> Y;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				X.push_back(i);
				Y.push_back(j);
			}
		}
	}
	res = solve(X, Y, 0);
	//cerr << res << endl;
	for (int i = 0; i < X.size(); i++)(X[i] = H - 1 - X[i]);
	res += solve(X, Y, 1);
	cout << res << endl;
}

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

void call(int n){
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0){
      cout << " " << i;
      continue;
    }
    for (int x = i; x > 0; x /= 10) {
      if ( x % 10 == 3 ){
        cout << " " << i;
        break;
      }
    }
  }

  cout << endl;
}

int main() {
  int n;
  cin >> n;
  call(n);
}

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

int main(){
    vector<int> x = {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};
    int n;
    cin >> n;
    cout << x[n-1] << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
T = gets.chomp.split.map(&:to_i)
M = gets.chomp.to_i
D = []
M.times do
  D.push(gets.chomp.split.map(&:to_i))
end

sum_time = 0
T.each do |t|
  sum_time += t
end

D.each do |d|
  tmp = sum_time
  tmp += d[1] - T[d[0]-1]
  puts tmp
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

int main() {
	fread(cn, 1, cm, stdin);
	ci = cn;

	int N = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	int A[200001] = {};

	int mae = 0;
	int kotae = 1;
	int mod = 1e9 + 7;
	rep(i, N) {
		int C = 0;
		if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') C = C * 10 + ct - '0';
		else while ((ct = *ci++) >= '0') C = C * 10 + ct - '0';
		if (mae != C) kotae = (kotae + *(A + C)) % mod;
		*(A + C) = kotae;
		mae = C;
	}

	int keta = 0;
	char C[10];
	while (kotae) {
		C[keta] = '0' + kotae % 10;
		kotae /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(C[i]);
	putchar('\n');

	Would you please return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100500
int vis[N],fa[N],s[N],v[N],n,m,a,b,head[N],cnt,is[N];
long long su[N],dp[N];
struct edge{int t,next;}ed[N*2];
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
int finds(int x){return fa[x]==x?x:fa[x]=finds(fa[x]);}
priority_queue<pair<long long,int> > tp;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&s[i],&v[i]),tp.push(make_pair(-s[i]*2000000000ll+v[i],i));
	for(int i=1;i<=m;i++)scanf("%d%d",&a,&b),adde(a,b);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		int s1=tp.top().second;tp.pop();dp[s1]=1e17;is[s1]=1;
		for(int j=head[s1];j;j=ed[j].next)if(finds(ed[j].t)!=s1&&is[finds(ed[j].t)])vis[finds(ed[j].t)]=1,dp[s1]=min(dp[s1],max(1ll*s[s1],dp[finds(ed[j].t)]+v[s1])-su[finds(ed[j].t)]),su[s1]+=su[finds(ed[j].t)],fa[finds(ed[j].t)]=s1;
		dp[s1]+=su[s1];su[s1]+=v[s1];
		dp[s1]=min(dp[s1],max(s[s1],v[s1])+su[s1]-v[s1]);
	}
	printf("%lld\n",dp[finds(1)]);
}//

Measured memory_bytes: 8688
#include "bits/stdc++.h"
using namespace std;

void update(int &a, int b) {
	if (a < b)a = b;
}

int main() {
	string st; cin >> st;
	int K; cin >> K;
	vector<vector<int>>dp_l(st.size() + 1, vector<int>(K + 1, -10000));
	vector<vector<int>>dp_r(st.size() + 1, vector<int>(K + 1, -10000));
	vector<vector<int>>dp_u(st.size() + 1, vector<int>(K + 1, -10000));
	vector<vector<int>>dp_d(st.size() + 1, vector<int>(K + 1, -10000));
	dp_l[0][0] = 0;
	dp_r[0][0] = 0;
	dp_u[0][0] = 0;
	dp_d[0][0] = 0;
	for (int i = 0; i < st.size(); ++i) {
		char c = st[i];
		for (int magic_use = 0; magic_use <= K; ++magic_use) {
			bool rev = magic_use % 2;
			if ((c == 'L'&&!rev) || (c == 'R'&&rev)) {
				if (magic_use != K) {
					update(dp_r[i + 1][magic_use + 1], dp_r[i][magic_use] + 1);
				}
				update(dp_r[i + 1][magic_use], dp_r[i][magic_use] - 1);
				update(dp_l[i + 1][magic_use], dp_l[i][magic_use] + 1);
				update(dp_u[i + 1][magic_use], dp_u[i][magic_use]);
				update(dp_d[i + 1][magic_use], dp_d[i][magic_use]);
			}
			else if ((c == 'R'&&!rev) || (c == 'L'&&rev)) {
				if (magic_use != K) {
					update(dp_l[i + 1][magic_use + 1], dp_l[i][magic_use] + 1);
				}
				update(dp_r[i + 1][magic_use], dp_r[i][magic_use] + 1);
				update(dp_l[i + 1][magic_use], dp_l[i][magic_use] - 1);
				update(dp_u[i + 1][magic_use], dp_u[i][magic_use]);
				update(dp_d[i + 1][magic_use], dp_d[i][magic_use]);
			}
			else if ((c == 'U'&&!rev) || (c == 'D'&&rev)) {
				if (magic_use != K) {
					update(dp_d[i + 1][magic_use + 1], dp_d[i][magic_use] + 1);
				}
				update(dp_r[i + 1][magic_use], dp_r[i][magic_use]);
				update(dp_l[i + 1][magic_use], dp_l[i][magic_use]);
				update(dp_u[i + 1][magic_use], dp_u[i][magic_use] + 1);
				update(dp_d[i + 1][magic_use], dp_d[i][magic_use] - 1);
			}
			else {
				if (magic_use != K) {
					update(dp_u[i + 1][magic_use + 1], dp_u[i][magic_use] + 1);
				}
				update(dp_r[i + 1][magic_use], dp_r[i][magic_use]);
				update(dp_l[i + 1][magic_use], dp_l[i][magic_use]);
				update(dp_u[i + 1][magic_use], dp_u[i][magic_use] - 1);
				update(dp_d[i + 1][magic_use], dp_d[i][magic_use]+ 1);
			}
		}
	}
	int ans = 0;
	for (int y = 0; y <= K; ++y) {
		for (int x = 0; x <= K; ++x) {
			if (x + y <= K) {
				for (int i = 0; i < 4; ++i) {
					int sum = 0;
					if (i % 2)sum += dp_l[st.size()][x];
					else sum += dp_r[st.size()][x];

					if (i / 2)sum += dp_u[st.size()][y];
					else sum += dp_d[st.size()][y];

					update(ans, sum);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 65740
#include<iostream>
#include<algorithm>
#include<cmath>
#include <iomanip>

using namespace std;

int main(){
  long long n,m,d;
  cin >> n >> m >> d;
  double res;
  if(d==0){
    res = (double)(m-1)/n;
  }else{
    res = (double)(m-1.0)*2*(n-d)/pow(n,2.0);
  }
  cout << fixed << setprecision(10) << res << endl;
}

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

int main() {
 int N;
 cin >> N;
 char S;
 int kaunto = 0;
 for (int i = 0; i < N; i++){
   cin >> S;
   if (S == 'Y'){
     kaunto = 1;
     break;
   }
 }
 if (kaunto == 1){
   cout << "Four" << endl;
 }else{
   cout << "Three"<< endl;
 }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int a[444],sum[444],dp[444][444],n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i],sum[i+1]=sum[i]+a[i];
	for(int i=n;i--;){
		for(int j=i+2;j<=n;j++){
			dp[i][j]=9e18;
			for(int k=i;k++<j;)
			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+sum[j]-sum[i]);
		}
	}
	cout<<dp[0][n]<<endl;
}

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

int main() {
  int x,y,z, N, count=0, ans=0;
  ll Y;
    
  cin >> N >> Y;
  Y/=1000;
  
  for(x=0;x<N+1;x++){
    for(y=0;x+y<N+1;y++){
      z=N-x-y;
      if(x*10+y*5+z==Y) {
        cout << x << " " << y << " " << z;
        return 0;
      }
    }
  }
  
  cout << "-1 -1 -1";
}
  

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int k,x;
    cin>>k>>x;

    int l = x-k;
    int r = k+x;

    rep(i,l+1,r)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String l=sc.next();
		long mod=1000000007;
		// dp[][1]の時小さいことが確定
		long[][] dp=new long[l.length()+1][2];
		dp[0][0]=1;
		for(int i=1; i<=l.length(); i++){
			if(l.charAt(i-1)=='1'){
				dp[i][0]=(dp[i-1][0]*2)%mod;
				dp[i][1]=dp[i-1][0];
			}else{
				dp[i][0]=dp[i-1][0];
			}
			dp[i][1]+=(dp[i-1][1]*3)%mod;
			dp[i][1]%=mod;
		}
		System.out.println((dp[l.length()][1]+dp[l.length()][0])%mod);
	}
}




Measured memory_bytes: 29780
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Measured memory_bytes: 19948
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#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=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   ll k;
   cin>>k;
   ll a=k/50,b=k%50;
   cout<<50<<endl;
   rep(i,b)cout<<100-b+a<<" ";
   rep(i,50-b)cout<<49-b+a<<" ";
   cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, K;
    cin >> N >> K;
    int ind = -1;
    rep(i, N) {
        int a;
        cin >> a;
        if(a == 1) ind = i;
    }
//    output(ind);
    
    int ans = 0;
//    int tmp = ind;
//    while(tmp > 0) {
//        tmp -= K - 1;
//        ans++;
//    }
//    tmp = ind;
//    while(tmp < N - 1) {
//        tmp += K - 1;
//        ans++;
//    }
    ans = (N - 1 + K - 2) / (K - 1);
    output(ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a + b >= c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23764
(n,m),q,*c=$<.map{|s|s.split.map &:to_i}
P=*0..n
F=->x{x==P[x]?x:P[x]=F[P[x]]}
c.map{|x,y|
  x=F[x]
  y=F[y]
  P[x]=P[y]
}
p q.count{|x|
  x==q[x-1]||F[x]==F[q[x-1]]
}

Measured memory_bytes: 13940
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
N = int(input())
i, j = 1, 1
l = make_divisors(N)
len_l = len(l)
if len_l % 2 == 1:
    idx = int((len_l-1)/2)
    print((l[idx]-i) + (l[idx]-j))
else:
    idx = int(len_l / 2)
    print(sum(l[idx-1:idx+1])-2)


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

int main()
{
  int H, W; cin >> H >> W;
  string board[50];
  rep(i,H) cin >> board[i];
  
  //8 directions
  int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
  
  rep(i,H)
  {
    rep(j,W)
    {
      if(board[i][j] == '#') continue;
      int count = 0;
      rep(k,8)
      {
        int posX = j + dx[k];
        int posY = i + dy[k];
        if(posX < 0 || posX >= W) continue;
        if(posY < 0 || posY >= H) continue;
        if(board[posY][posX] == '#') count++;
      }
      board[i][j] = char(count + '0');
    }
  }
  rep(i,H) cout << board[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const lint INF = 1LL << 60;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vec c(n);
    int a[15][15];
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    lint res = INF;

    bool can2 = false;

    rep(i, 1 << n) {
        vec r(m, 0);

        lint p = 0;

        rep(j, n) {
            if ((i >> j) & 1) {
                p += c[j];
                rep(k, m) {
                    r[k] += a[j][k];
                }
            }
        }

        bool can = true;

        rep(j, m) {
            if (r[j] < x) can = false;
        }

        if (can) {
            res = min(res, p);
            can2 = true;
        }
    }

    if (can2) cout << res << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

int main()
{
  int N, M;
  scanf("%d%d", &N, &M);

  vector<int> A(N+1), B(M+1);
  const int MAX_N = N*M;
  constexpr long long int MOD = 1000000007;
  for(int i = 0; i < N; ++i) scanf("%d", &A[i]);
  for(int j = 0; j < M; ++j) scanf("%d", &B[j]);

  sort(begin(A), end(A), greater<int>());
  sort(begin(B), end(B), greater<int>());
  
  long long int ba = 0, bb = 0;
  long long int ans = 1;
  for(long long int i = MAX_N; i > 0; --i){
    if(A[ba] == i && B[bb] == i){
      ++ba, ++bb;
    }else if(A[ba] == i && B[bb] != i){
      ++ba;
      ans = (ans*bb) % MOD;
    }else if(A[ba] != i && B[bb] == i){
      ++bb;
      ans = (ans*ba) % MOD;
    }else{
      ans = (ans*(ba*bb-MAX_N+i)) % MOD;
    }

    if(ans <= 0){
      ans = 0;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=2e3+10;
int n,m,dp[maxn][maxn];
int Pow(int a,long long k)
{
	int ret=1;
	if(k==-1)return 1;
	while(k)
	{
		if(k&1)ret=ret*1LL*a%mod;
		k>>=1,a=a*1LL*a%mod;
	}
	return ret;
}
int main()
{
	scanf("%d%d",&n,&m);
	dp[0][n+1]=1;
	for(int i=1;i<=m;i++)
	{
		int sum=dp[i-1][n+1];
		for(int j=n;j>=1;j--)
		{
			sum+=dp[i-1][j],sum%=mod;
			if(n-i+1>=j)dp[i][j]=sum;
		}
	}
	int ret=(dp[m][1]-dp[m-1][1]+mod)%mod;
	printf("%lld\n",ret*1LL*Pow(2,n-m-1)%mod);
	
	
}

Measured memory_bytes: 15360