akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	long long int n;
	int minf = 15;
	cin >> n;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i != 0) {
			continue;
		}
		int j = n / i;
		string si = to_string(i), sj = to_string(j);
		int f = max(si.size(), sj.size());
		minf = min(f, minf);
	}
	cout << minf << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

char c[3][3];

int main(void)
{
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}
	for(int i = 0; i < 3; i++) cout << c[i][i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
#include<deque>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	deque<int> d;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		auto it = lower_bound(d.begin(), d.end(), a[i]);
		if (it == d.begin()) d.push_front(a[i]);
		else *(it - 1) = a[i];
	}
	cout << d.size() << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 100;
ll dp[N][N];
ll find(ll x) {
	while (x) {
		if (x / 10 == 0) {
			return x;
		}
		x /= 10;
	}
}
int main()
{
	ll n;
	cin >> n;
	for (ll i = 1; i <= n; i++) {
		ll h = i;
		ll a1 = h % 10;
		ll a2 = find(h);
		dp[a2][a1]++;
	}
	ll ans = 0;
	for (ll i = 1; i <= 9; i++) {
		for (ll j = 1; j <= 9; j++) {
			ans += dp[i][j] * dp[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <tuple>
#include <queue>
#include <algorithm>
#include <string>
#include <fstream>
#include <math.h>
#include <iomanip>
#include <time.h>
#include <assert.h>
#include <stack>
#include <deque>
#include <bits/stdc++.h>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <sstream>  // istringstream buffer(myString);
// #include <boost/functional/hash.hpp>

using namespace std;

#define endl "\n";
#define bit(x, i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x; example: x=12;  1100 => 100 => 4
#define LL long long
#define ULL unsigned long long
#define inf 1000000007
#define mod 1000000007
#define PII pair<int, int>
#define V vector
#define VI vector<int>
#define VS vector<string>
#define ALL(x) x.begin(), x.end() //handy for function like "sort()"
#define pi 3.14159265358979323846
// set a to the maximum of a and b
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
// conversion
string removeZeros(string str) { return str.erase(0, min(str.find_first_not_of('0'), str.size()-1)); } // remove leading zeros
#define char2int(c) (c-'0')
#define int2char(i) (static_cast<char>(i))
#define bin2int(bin) (bitset< 1001 >(bin).to_ulong())
#define int2bin(i) removeZeros(bitset< 1001 >( i ).to_string())
// str.erase(0, min(str.find_first_not_of('0'), str.size()-1)); // remove leading zeros


// works for unordered_set, unordered_map..
#define HMAP unordered_map
#define SET unordered_set
#define HAS(umap, key) (umap.find(key) != umap.end())
#define COUNTER(m, j) if (HAS(m, j)) { m[j]++; } else { m[j] = 1; }
// loop
#define FOREACH(vec, i) for (auto i = vec.begin(); i!= vec.end(); i++)
// read line
#define READ_INTS(vec, n) vector<LL> vec(n); for (LL i=0; i<n; i++) { cin >> vec[i]; }; cin.ignore();
#define READ_DOUBLES(vec, n) vector<double> vec (n); FOREACH(vec, i) { cin >> *i; }; cin.ignore();
#define READ_STRING(vec) string vec; getline(cin, vec);
#define READ_INT(i) LL i; cin >> i; cin.ignore();
// #define SPLIT_STRINGS(vec, str) istringstream iss(str); vector<string> vec((istream_iterator<string>(iss)), istream_iterator<string>());
// debug
#define dd(var) cerr << #var << "=" << (var) << " | "
#define ddv(vec) FOREACH(vec, i) { cout << *i << " "; } cout << endl;
#define ddvv(vec) for(auto& i:vec) { for(auto& j:i) { cout <<  j << " "; }; cout << endl };

auto diff(int i, int j, vector<LL> &v) {
    return abs(v[i] - v[j]);
}

void solve() {
    READ_INT(t);
    int a, b, c;
    int d, e, f;
    cin >> d >> e >> f;

    for (LL i = 1; i < t; i++) {
        cin >> a >> b >> c;
        tie(d, e, f) = make_tuple(a + max(e, f), b + max(d, f), c + max(d, e));
    }
    cout << max(max(d, e), f) << endl;
}


int main()
{  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
//   READ_INT(t);
//   for (LL i = 0; i < t; i++) {
    solve();
//   }
  return 0;
}


Measured memory_bytes: 256
# 01-BFS
# 参考: White_Pie_46
# https://atcoder.jp/contests/abc176/submissions/16168825
# 01-BFSのちょっと丁寧な解説 - ARMERIA
# https://betrue12.hateblo.jp/entry/2018/12/08/000020

from collections import deque


def main():
    height, width = [int(x) for x in input().split()]
    init_h, init_w = [int(x) - 1 for x in input().split()]
    dest_h, dest_w = [int(x) - 1 for x in input().split()]
    grid = [list(input()) for _ in range(height)]

    can_walk = ((1, 0), (0, 1), (-1, 0), (0, -1))
    gen_warp_can_reach = (
        (h, w, (h, w) in can_walk)  # 移動先，徒歩で行けるか
        for h in range(-2, 3) for w in range(-2, 3) if not h == 0 == w)
    warp_can_reach = tuple(gen_warp_can_reach)
    qu = deque()
    qu.append((init_h, init_w, 0))  # 座標とワープ回数を保持

    while qu:
        h, w, warps = qu.popleft()
        if h == dest_h and w == dest_w:
            return warps
        if grid[h][w] == 'R':
            # 同じマスを複数回キューに追加しているかもしれない。
            continue
        grid[h][w] = 'R'  # reached

        for h_delta, w_delta, walking in warp_can_reach:
            new_h, new_w = h + h_delta, w + w_delta
            if 0 <= new_h < height and 0 <= new_w < width:
                if grid[new_h][new_w] == '.':
                    if walking:
                        qu.appendleft((new_h, new_w, warps))
                    else:
                        qu.append((new_h, new_w, warps + 1))
    return -1


if __name__ == '__main__':
    print(main())


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

template <typename T>
T expt(T a, T n, T mod = std::numeric_limits<T>::max()){
    T res = 1;
    while(n){
        if(n & 1){res = res * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

constexpr ll MOD = 100000;
int M, N;
std::string flag[30];
std::vector<int> v;
int dp[20][20][18000][2];

// pr: (r, c) 以前 N マスにあった"JO"を記録したもの
// flag_j: (r, c) の左隣に"J"があるか
// 条件を満たさない旗の個数を計算する
ll rec(int r, int c, int pr, int flag_j){
    if(r == M){
        return 1;
    }

    int idx = std::lower_bound(v.begin(), v.end(), pr) - v.begin();

    assert(v[idx] == pr);

    if(dp[r][c][idx][flag_j] != -1){
        return dp[r][c][idx][flag_j];
    }

    int nr = r, nc = c + 1;
    if(c + 1 == N){
        nr = r + 1;
        nc = 0;
    }

    ll res = 0;
    if(flag[r][c] == 'J' || flag[r][c] == '?'){
        res = rec(nr, nc, (pr << 1) & ((1 << N) - 1), nr == r);
    }

    if(flag[r][c] == 'O' || flag[r][c] == '?'){
        res = (res + rec(nr, nc, ((pr + flag_j) << 1) & ((1 << N) - 1), 0)) % MOD;
    }

    if(flag[r][c] == 'I' || flag[r][c] == '?'){
        unless(pr >> (N - 1) & 1){
            res = (res + rec(nr, nc, (pr << 1) & ((1 << N) - 1), 0)) % MOD;
        }
    }

    return dp[r][c][idx][flag_j] = res;
}

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

    std::cin >> M >> N;

    for(int i=0;i<(1<<N);++i){
        unless(i & (i >> 1)){
            v.emplace_back(i);
        }
    }

    int numQuestions = 0;
    for(int i=0;i<M;++i){
        std::cin >> flag[i];

        numQuestions += std::count(flag[i].begin(), flag[i].end(), '?');
    }

    memset(dp, -1, sizeof(dp));
    ll res = (expt<ll>(3, numQuestions, MOD) + MOD - rec(0, 0, 0, 0)) % MOD;
    std::cout << res << std::endl;
}



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

int c[10][1005];

int main(void) 
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = INF;

    // 1 << h-1 = 2^(h-1)
    //線を引くor引かないの２通り
    rep(div, 1 << (h-1))
    {
         //2進数でビットが立っているところで分ける(div)
        int group =0;
        vector<int> id(h);
        rep(i,h)
        {
            id[i] = group;
            //シフトして１(線を引く)なら次からのグループをインクリする
            if(div >> i&1) group++;
        }
        //グループ数を表す為にインクリ
        group++;

        //縦グループ数分、横全て初期化
        rep(i,group)rep(j,w) c[i][j] = 0;
        rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j] -'0');
        
        //縦に切っていく
        int num = group - 1;
        vector<int> now(group);
        auto add = [&](int j)
        {
            rep(i,group) now[i] += c[i][j];
            rep(i,group) if(now[i] > k) return false;           
            return true;
        };
        rep(j,w)
        {
            if(!add(j))
            {
                num++;
                now = vector<int>(group);
                if(!add(j))
                {
                    num = INF;
                    break;
                }                
            }         
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N;
    cin >> N;
    int A, B;
    cin >> A >> B;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    rep(i, N) {
        int p;
        cin >> p;
        if (p <= A)c1++;
        else if (p <= B)c2++;
        else c3++;
    }
    cout << min(min(c1, c2), c3) << endl;
    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  string s;
  cin >> s;
  int q;
  cin >> q;
  while (q--) {
    string t;
    cin >> t;
    if (t == "replace") {
      int a, b;
      string w;
      cin >> a >> b >> w;
      copy(all(w), s.begin() + a);
    }
    if (t == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (t == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
  }
}



Measured memory_bytes: 3228
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        String Ans1 = "";
        String Ans2 = "";
            for(int i = 0; i < b; i ++){
                Ans1 = Ans1 + String.valueOf(a);
            }
            for(int i = 0; i < a; i ++){
                Ans2 = Ans2 + String.valueOf(b);
            }
        int ques = Ans1.compareTo(Ans2);
        if(ques < 0) {
            System.out.println(Ans1);
        } else  {
            System.out.println(Ans2);    
        }    
        
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int a[35] = {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}, n;
int main(){
	scanf("%d", &n);
	printf("%d\n", a[n-1]);
}

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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    for(unsigned long i = 0, j = 1, p = 0; i < N; ++i){
        cin >> j;
        if(p < j)--j;
        if(p > j)return 0 & puts("No");
        p = j;
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::cmp::{max, min};

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut max_a: usize = 0;
    let mut min_b: usize = 1_000_000_001;

    for _ in 0..n {
        max_a = max(max_a, iterator.next().unwrap().parse().unwrap());
        min_b = min(min_b, iterator.next().unwrap().parse().unwrap());
    }

    return format!("{}", max_a + min_b);
}


Measured memory_bytes: 6396
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector<int> solve(vector< vector<int> > &G, int u, int v) {
    vector<int> dist(G.size(), INF);
    vector<int> pre(G.size(), -1);
    dist[v] = 0;

    queue< pair<int, int> > que;
    que.emplace(v, 0);
    while(que.size()) {
        auto cur = que.front(); que.pop();
        if(cur.second > dist[cur.first]) continue;
        for(auto to : G[cur.first]) {
            if(dist[to] > cur.second + 1) {
                dist[to] = cur.second + 1;
                pre[to] = cur.first;
                que.emplace(to, dist[to]);
            }
        }
    }

    if(dist[u] == INF) return {};
    vector<int> res;
    int p = u;
    while(p >= 0) {
        res.emplace_back(p + 1);
        p = pre[p];
    }
    return res;
}

int main() {
    int N, M; cin >> N >> M;
    vector< vector<int> > G(N);
    for(int i=0; i<M; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v);
    }

    int min_size = INF;
    vector<int> ans;
    for(int i=0; i<N; i++) {
        for(auto to : G[i]) {
            int u = i, v = to;
            auto vec = solve(G, u, v);
            if(vec.size()) {
                if(min_size > vec.size()) {
                    min_size = vec.size();
                    ans = vec;
                }
            }
        }
    }
    if(min_size == INF) {
        cout << -1 << endl;
    }
    else {
        cout << ans.size() << endl;
        for(auto v : ans) cout << v << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}



int main() {
    string S;
	cin >> S;
	int N = S.length();
	
	ll ans = 0;
	rep(bit, 1 << (N - 1)) {
		ll sm = 0;
		ll a = S[0] - '0';
		rep(i, N - 1) {
			if (bit & (1 << i)) {
				sm += a;
				a = 0;
			}
			a = a * 10 + S[i + 1] - '0';
		}
		sm += a;
		ans += sm;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
package main

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

var rd = bufio.NewReader(os.Stdin)

func readline() string {
	buff := make([]byte, 0)
	for {
		ln, isP, _ := rd.ReadLine()
		buff = append(buff, ln...)
		if !isP {
			break
		}
	}
	return string(buff)
}

func s2i(s string) []int {
	ss := strings.Fields(s)
	tmp := make([]int, len(ss))
	for i, v := range ss {
		tmp[i], _ = strconv.Atoi(v)
	}
	return tmp
}

func check(dist []int, idx, expt int) bool {
	loc := map[int]bool{0: true}
	for idx < len(dist) {
		tmp := map[int]bool{}
		for k, _ := range loc {
			tmp[k+dist[idx]] = true
			if idx > 0 {
				tmp[k-dist[idx]] = true
			}
		}
		loc = tmp
		idx += 2
	}
	_, ok := loc[expt]
	return ok
}

func main() {
	s := readline()
	expt := s2i(readline())

	dist := make([]int, 0)

	fwd := 0
	for _, v := range s {
		if v == 'T' {
			dist = append(dist, fwd)
			fwd = 0
		} else {
			fwd++
		}
	}

	dist = append(dist, fwd)

	if check(dist, 0, expt[0]) && check(dist, 1, expt[1]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 7700
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define pye cout << "Yes" << endl;
#define pno cout << "No" << endl;
#define prin(argument) cout << argument << endl;
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll a[200000];

ll digitsum(ll x) {
    ll res=0;
    while(x>0) {
        res+=x%10;
        x/=10;
    }
    return res;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll i;
    ll ans=0;
    for(i=1; i<=n; i++) {
        if(a<=digitsum(i) && digitsum(i)<=b)
            ans+=i;
    }
    
    prin(ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////
 
#define fs first
#define sc second
#define pb push_back
//#define int long long
#define len(x) (int)(x).size()     
#define all(x) (x).begin(), (x).end()
#define test int _; cin >> _; while(_--)
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
 
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;
 
inline ll gcd(ll a, ll b){while(b){ a %= b; swap(a, b); } return a; }
inline ll mod(ll a, ll b){return ((a%b)+b)%b;}
inline ll expo(ll b, ll p, ll m = MOD){
  ll ans = 1; 
  while(p > 0){
    if(p&1LL) ans = mod(ans*b, m); 
    b = mod(b*b, m); 
    p >>= 1LL;
  } 
  return ans;
}
 
////////////////////////// Solution starts below. //////////////////////////////

const int N = 2e5+5;

ll bit[N];
int n;

ll query(int idx){
  ll ret = 0;
  for(; idx > 0; idx -= (idx & -idx)){
    ret = max(ret, bit[idx]);
  }
  return ret;
}

void updt(int idx, ll value){
  for(; idx <= n; idx += (idx & -idx)){
    bit[idx] = max(bit[idx], value);
  }
}

int32_t main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 0; i < n; i++){
    ll cur;
    cin >> cur;
    ll best = query(h[i]);
    updt(h[i], cur+best);
  }
  cout << query(n) << '\n';
  return 0; 
}

Measured memory_bytes: 5652
using System;

namespace Application
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var abx = Console.ReadLine().Split();
            var x = double.Parse(abx[0]);
            var y = double.Parse(abx[1]);
            var s = double.Parse(abx[2]) / x;

            var a = 2 * (x * y - s) / x;

            if (y < a)
            {
                var ans = Math.Atan2(y, 2 * s / y);
                Console.WriteLine(ans * 180 / Math.PI);
            }
            else
            {
                var ans = Math.Atan2(2 * (x * y - s) / x, x);
                Console.WriteLine(ans * 180 / Math.PI);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
using namespace std;
struct Coordinate {
	long double x;
	long double y;
};
int main() {
	short int n;
	cin >> n;
	vector<bool>l;
	for (int i = 0; i < n; i++){
		Coordinate A, B, C, D;
		cin >> A.x >> A.y >> B.x >> B.y;
		long double Inclination_of_AB = (B.y - A.y) / (B.x - A.x);
		cin >> C.x >> C.y >> D.x >> D.y;
		long double Inclination_of_CD = (D.y - C.y) / (D.x - C.x);
		l.push_back(Inclination_of_AB == Inclination_of_CD);
	}
	for (bool i : l) {
		if (i) cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind
{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> sz;
    UnionFind(ll n) : par(n), rank(n), sz(n)
    {
        for(ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    ll root(ll x)
    {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y])
        {
            par[x] = y;
            sz[y] += sz[x];
        }
        else
        {
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }
    ll size(ll x)
    {
        x = root(x);
        return sz[x];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    for(int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    int ans = 0;
    for(int i = 0; i < m; i++)
    {
        UnionFind tree(n);
        for(int j = 0; j < m; j++)
        {
            if(i == j) continue;
            tree.unite(a[j], b[j]);
        }
        if(tree.size(0) != n) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)

void solve();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main(void) {
    init();
    solve();
    return 0;
}

void solve() {
    int d,t,s;
    cin >> d >> t >> s;
    if (d > t * s) {
        cout << "No" << "\n";
    }else {
        cout << "Yes" << "\n";
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include<math.h>
using namespace std;

int count_yakusuu(int n){
    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        if(n%i==0){
            count += 1;
        }
    }
    return count;
}
int main()
{
    int N;
    cin >> N;

    int count = 0;

    for (int i = 1; i <= N; i += 2)
    {
        if(count_yakusuu(i) == 8){
            count += 1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 2e6 + 10;
const int M = 1e9 + 7;
ll fat[N],inv[N];

ll C(ll n,ll k){
  if(k>n)return 0;
  return mod(fat[n]*mod(inv[k]*inv[n-k],M),M);
}

void init(){
  fat[0] = 1;
  for(int i=1;i<N;i++){
    fat[i] = (i*fat[i-1])%M;
  }
  inv[N-1] = exp(fat[N-1],M-2,M);
  for(int i=N-2;i>=0;i--){
    inv[i] = (inv[i+1]*(i+1))%M;
  }
}

ll go(ll c,ll r){
  ll ans=0;
  for(int i=0;i<=c;i++){
    ans = mod(ans + C(i + r + 1, r ),M);
  
  }
  return ans;
}


int32_t main(){
  fastio; 
  int r1,c1,r2,c2;
  cin>>r1>>c1>>r2>>c2;
  init();

  ll ans = mod(go(c2,r2) - go(c1-1,r2) - go(c2,r1-1) + go(c1-1,r1-1),M);

   cout << ans << endl;


  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 31488
n = gets.to_i
arr = []
n.times do
  arr.push(gets.to_i)
end
max = arr.max
if arr.count(max) != 1
  n.times do
    puts max
  end
else
  arr.freeze
  new_arr = arr.dup
  new_arr.delete(max)
  second = new_arr.max
  arr.each do |num|
    if num == max
      puts second
    else
      puts max
    end
  end
end


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int A[111][111];

int ei[4][3]={
{1,3,2},
{2,3,0},
{3,0,1},
{1,2,0}
};

void solve(int l,int r){
    int n=r-l;

    if(n==4){
        rep(i,4)rep(j,3)A[l+i][j]=ei[i][j]+l;
    return;
    }

    if(n&1){
        for(int i=0;i<n;i++){
            for(int j=0;j<n-1;j++){
                A[i+l][j]=(i+j+1)%n+l;
            }
        }
    }
    else{
        n/=2;
        solve(l,l+n);
        solve(l+n,r);
        rep(i,n){
            rep(j,n){
                A[l+i][n-1+j]=(i+j)%n+l+n;
                A[l+n+i][n-1+j]=(i+n-1-j)%n+l;
            }
        }
    }
}

signed main(){
    int N;cin>>N;
    if(N==2){
        cout<<-1<<endl;
        return 0;
    }

    solve(0,N);
    rep(i,N){
        rep(j,N-1){
            if(j)cout<<" ";
            cout<<A[i][j]+1;
        }cout<<endl;
    }
    return 0;
}


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

int main (){
	int n,min,max;
	while(cin>>n>>min>>max && n){
		min--; max--;
		vector<int> v(n);
		for(int i=0;i<n;i++)cin>>v[i];
		sort(v.begin(),v.end(),greater<int>());

		int ans,gap=0;
		for(int i=min;i<=max;i++){
			if(gap>=v[i+1]-v[i]){
				gap=v[i+1]-v[i];
				ans=i+1;
			}
		}
		cout<<ans<<endl;
	}
}




Measured memory_bytes: 3136
#include<iostream>

using namespace std;

const int MOD = 1e9 + 7;
bool isprime[1005];

int main(){
    for(int i = 2; i <= 1000; ++i){ // Cek bilangan i itu prima atau bukan
        isprime[i] = true;
        for(int j = 2; j * j <= i; ++j){
            if(i % j == 0){ // I bukan prima
                isprime[i] = false;
                break;
            }
        }
    }
    
    long long totalFactor = 1;
    // 2^a1 3^a2 5^a3 ...
    // totalFactor = 1 * (a1 + 1) * (a2 + 1) ...

    int x; cin >> x;
    for(int i = 2; i <= x; ++i){
        if(!isprime[i])continue;
        int cnt = 0; // i ^ cnt
        for(int j = i; j <= x; ++j){
            if(j % i == 0){ // Mengandung faktor prima i
                int tmp = j;
                while(tmp % i == 0){
                    cnt++;
                    tmp = tmp / i;
                }
            }
        }
        
        totalFactor = totalFactor * (cnt + 1) % (MOD);
    }
    
    cout << totalFactor << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
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 ll INF = 1LL<<60;
//const int dy[4] = {0, 1, 0, -1};
//const int dx[4] = {1, 0, -1, 0};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

void solve(){
    ll h, w; cin >> h >> w;
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    vector<vector<ll>> v(h, vector<ll>(w));
    ll pnti = 0, pntj = 0;
    REP(i, n){
        ll rest = a[i];
        ll pnum = i+1;
        while(rest > 0){
            v[pnti][pntj] = pnum;
            rest--;
            if(pnti%2 == 0){
                if(pntj != w-1) pntj++;
                else pnti++;
            }
            else{
                if(pntj != 0) pntj--;
                else pnti++;
            }
        }
    }
    REP(i, h){
        REP(j, w){
            if(j != w-1) cout << v[i][j] << ' ';
            else cout << v[i][j] << endl;
        }
    }
}

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

Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
int N;
int main() {
	cin >> N;
	if (N % 2 == 0) {
		cout << N * (N - 1) / 2 -N/2<< endl;
		for (int i = 1; i <= N; ++i) {
			for (int j = i+1; j <= N; ++j) {
				if (i + j == N + 1)continue;
				cout << i << " " << j << endl;
			}
		}
	}
	else {
		cout << N * (N - 1) / 2 - (N - 1) / 2 << endl;
		for (int i = 1; i < N; ++i) {
			for (int j = i + 1; j <= N; ++j) {
				if (i + j == N)continue;
				cout << i << " " << j << endl;
			}
		}
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 1;
  bool isFirst = true;
  int first_num = 0;
  int last_num = 0;
  int trend = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (first_num == 0) {
      first_num = A;
      last_num = A;
      continue;
    }
    if (trend == 0) {
      if (A - first_num > 0) trend = 1;  // 1: up
      else if (A - first_num < 0) trend = 2;  // 2: down
      last_num = A;
      continue;
    }
    if ((trend == 1 && A < last_num) || (trend == 2 && A > last_num)) {
      first_num = A;
      last_num = A;
      trend = 0;
      ans++;
      continue;
    }
    last_num = A;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
using namespace std;
L n;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	cin>>n;
	i=j=0;
	while(n)
	  {
       if(n%10)
         i=max(i+n%10,j+n%10-1);
       j+=9;
       n/=10;
      }
	printf("%d\n",i);
	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);

		int n = sc.nextInt();//配列の長さ
		int a[] = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = a.length - 1; i >= 0; i--) {
			if (i != 0) {
				System.out.print(a[i] + " ");
			} else {
				System.out.println(a[i]);
			}
		}

	}
}



Measured memory_bytes: 26280
import java.util.*;

public 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();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int[] data = new int[3];
		if (X >= Y) {
			data[0] = (C * Y * 2) + (A * (X - Y));
			data[1] = C * X * 2;
		} else {
			data[0] = (C * X * 2) + (B * (Y - X));
			data[1] = C * Y * 2;
		}
		data[2] = A * X + B * Y;

		int min = data[0];
		for (int i = 1; i < 3; i++) {
			if (min > data[i])
				min = data[i];
		}
		System.out.println(min);

		sc.close();

	}

}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int s01 = Integer.parseInt(s.substring(0,2));
		int s23 = Integer.parseInt(s.substring(2));
		String ans;
		if(s01 == 0) {
			if(s23 == 0) {
				ans = "NA";
			} else if(1 <= s23 && s23 <= 12) {
				ans = "YYMM";
			} else {
				ans = "NA";
			}
		} else if(1 <= s01 && s01 <= 12) {
			if(s23 == 0) {
				ans = "MMYY";
			} else if(1 <= s23 && s23 <= 12) {
				ans = "AMBIGUOUS";
			} else {
				ans = "MMYY";
			}
		} else {
			if(s23 == 0) {
				ans = "NA";
			} else if(1 <= s23 && s23 <= 12) {
				ans = "YYMM";
			} else {
				ans = "NA";
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
/*
ID: 5ak0
PROG: sort
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;

string s;
int ans1, ans2;

int main(){
    ios_base::sync_with_stdio(0);
    #ifndef SAKO
    //freopen("sort.in", "r", stdin);
    //freopen("sort.out", "w", stdout);
    #endif // SAKO
    cin >> s;
    for (int i = 0; i < s.size(); ++i){
        ans1 += s[i] - '0';
        if (i == 0)
            ans2 += s[i] - '0' - 1;
        else
            ans2 += 9;
    }
    cout << max(ans1, ans2);
    return 0;
}


Measured memory_bytes: 256
import sys

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

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

#+++++

def main():
	#a = int(input())
	num_of_boxes , max_candies = IN()
	candies_array = list(IN())
	total_eat_candies = 0
	pre = 0
	for nc in candies_array:
		num_eat = max(0, nc+pre-max_candies)
		total_eat_candies+=num_eat
		pre = nc - num_eat
	print(total_eat_candies)
	
	
	
#+++++
isTest=False

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

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

Measured memory_bytes: 63984
#include<bits/stdc++.h>
#define pb push_back
#define mod int(1e9+7)
#define N int(2e5+100)
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define si second
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
   int n,d;
   cin>>n;
   while(n){
      d=(n%10);
      if(d==7){
         cout<<"Yes\n";
         break;
      }
      n/=10;
   }
   if(!n){
      cout<<"No\n";
   }
   return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

// 提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt(); // int Nを受け取る
		sc.close(); // 標準入力を終了

		if (X >= 30) {
			// 冷房ON
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 35628
n,k=map(int,input().split())
x,y=0,0

if k%2!=0:
    #odd
    ans=(n//k)**3
    
else:
    #even
    for i in range(1,n+1):
        if i%k==k//2:#including 0
            x+=1
    ans=x**3+(n//k)**3    
print(ans)

Measured memory_bytes: 3060
#include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #define MAXN (200000 + 5)
    #define INF (0x7fffffff)
    #define LL long long
    using namespace std;
    int n, a[MAXN];
    LL ans;
    LL solve()
    {
    	LL sum = 0, xsum = 0;
    	int he = 1, ta = 0, lastt = 0;
    	while (true)
    	{
    		sum += a[++ta];
    		xsum ^= a[ta];
    		if (xsum != sum)
    		{
    			LL dqn = ta - he, emm = max(0, (lastt - he + 1));
    			ans += (dqn * (dqn + 1)) >> 1;
    			ans -= (emm * (emm + 1)) >> 1;
    			lastt = ta - 1;
    			while (xsum != sum)
    			{
    				sum -= a[he];
    				xsum ^= a[he++];
    			}
    			if (ta == n)
    			{
    				dqn = n - he + 1, emm = max(0, (lastt - he + 1));
    				ans += (dqn * (dqn + 1)) >> 1;
    				ans -= (emm * (emm + 1)) >> 1;
    				break;
    			}
    		}
    		else if (ta == n)
    		{
    			LL dqn = ta - he + 1, emm = max(0, (lastt - he + 1));
    			ans += (dqn * (dqn + 1)) >> 1;
    			ans -= (emm * (emm + 1)) >> 1;
    			break;
    		}
    	}
    	return ans;
    }
    int main()
    {
    	scanf("%d", &n);
    	for (int i = 1; i <= n; i++)
    		scanf("%d", &a[i]);
    	printf("%lld\n", solve());
    	return 0;
    }

Measured memory_bytes: 1024
N,K = map(int, input().split())

Kmax = (N-2)*(N-1)//2
if K > Kmax:
    print(-1)
    exit()

M = N-1+Kmax-K
print(M)

for i in range(2,N+1):
    print(1,i)

t = Kmax-K
s = 2
while t>0:
    if t > N-s:
        for i in range(N-s):
            print(s,s+1+i)
        t -= N-s
        s += 1
    else:
        for i in range(t):
            print(s,s+1+i)
        exit()

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define allr(v)	     ((v).rbegin()), ((v).rend())
#define sz(v) ((int)(v).size())
#define clr(v, d)        memset(v, d, sizeof(v))
#define JSE ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MP(i,j) make_pair(int i,int j);
typedef long long ll;
typedef unsigned long long ull;
typedef  double ld;
const ll OO = (ll)1e18;
const ll mod = (1e9) + 7;
const double PI = acos(-1.0);
int dx[]{ 0,0,1,-1 ,-1,-1,1,1};
int dy[]{ -1, 1,0,0,-1,1,1,-1};
ld dis(pair<ld, ld>a, pair<ld, ld>b) { return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2)); }
ll pd(ll x) { if (x == 0)	return 1; if (x == 1) return 1; ull ans = 1; for (int i = 2; i <= x; i++) ans *= i; return ans; }
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);  
#endif
}
template<class Int>
Int gcd(Int a, Int b)
{
	return (b == 0 ? abs(a) : gcd(b, a%b));
}
template<class Int>
Int lcm(Int a, Int b)
{
	return abs(a / gcd(a, b)*b);
}
int main()
{
	//cout << setprecision(20) << fixed;
	JSE
		//file();
		//	freopen("friday.in", "r", stdin);
		///////////
		int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	cout << *max_element(all(v)) - *min_element(all(v)) << endl;

}

Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	LinkedList<String> getAdj(String puzzle) {

		LinkedList<String> a = new LinkedList<String>();

		int index = puzzle.indexOf('0');

		int[] adj = { -1, 1, -4, 4 };

		for (int i = 0; i < 4; i++) {

			int ni = index + adj[i];

			if (ni < 0)

				continue;

			if (ni > 7)

				continue;

			if(index == 3 && ni == 4)

				continue;

			if(index == 4 && ni == 3)

				continue;

			char buffer = puzzle.charAt(ni);

			char ch[] = puzzle.toCharArray();

			ch[ni] = '0';

			ch[index] = buffer;

			String str = new String(ch);

			a.add(str);

		}

		return a;

	}



	void run() {

		LinkedList<String> memo = new LinkedList<String>();

		memo.add("01234567");

		HashMap<String, Integer> map = new HashMap<String, Integer>();

		map.put("01234567",0);

		int step = 1;

		int sum = 0;

		for (; !memo.isEmpty();) {

			LinkedList<String> nextMemo = new LinkedList<String>();

			

			for (String str : memo) {

//				System.out.println(str);

				for (String adj : getAdj(str)) {

//					System.out.println(" "+adj);

					if (map.containsKey(adj)) {

						continue;

					}

					if (nextMemo.contains(adj)) {

						continue;

					}

					map.put(adj,step);

					nextMemo.add(adj);

				}

			}

			step++;

			memo = nextMemo;

		}





		for (; sc.hasNextLine();) {

			System.out.println(map.get(sc.nextLine().replace(" ", "")));

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 15000
import java.util.Scanner;

/**
 *  http://abc047.contest.atcoder.jp/tasks/abc047_a
 * @author Cummin
 */
public class Main {
    public static void main(String[] args) {
        int A, B, C ;
        Scanner sc = new Scanner(System.in);
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        if ((A==B+C)||(B==A+C)||(C==A+B)){
            System.out.println("Yes") ;
        } else {
            System.out.println("No") ;
        }

    }
    
}


Measured memory_bytes: 9680
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int [] nk = inputval();
        int k = nk[1];
        Integer [] ll = inputvalInteger();
        Arrays.sort(ll, Collections.reverseOrder());
        int ans = 0;
        for (int i=0; i<k; i++){
            ans += ll[i];
        }

        System.out.println(ans);
        
    }

}



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

double area(int n){
	int d=360,k;
	double sum=0;
	for(int i=1;i<n;i++){
		cin>>k;
		d-=k;
		sum+=sin(M_PI*k/180);
	}
	sum+=sin(M_PI*d/180);
	return sum;
}

int main(){
	int n;
	while(cin>>n,n){
		double a=area(n);
		cin>>n;
		double b=area(n);
		
		if(fabs(a-b)<1e-9)puts("0");
		else if(a>b)puts("1");
		else if(a<b)puts("2");
	}
	
	return 0;
}


Measured memory_bytes: 1152