akhauriyash/Code-Regression huggingface dataset:
import java.lang.Math

fun main(args: Array<String>)
{
    val (m, d) = readInts()

    var ans = 0
    for (i in 1..m) {
        for (k in 1..d) {
            val d1 = k % 10
            val d10 = k / 10
            if (i == d1 * d10 && d1 >= 2 && d10 >= 2) ans += 1
        }
    }

    println(ans)
}

fun readInts(): List<Int> = readLine()!!.split(" ").map(String::toInt)
fun readLongs(): List<Long> = readLine()!!.split(" ").map(String::toLong)

fun readIntArr(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray()
fun readLongArr(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray()

fun readIntArrS(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray().sortedArray()
fun readLongArrS(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray().sortedArray()

fun readIntArrSD(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray().sortedArrayDescending()
fun readLongArrSD(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray().sortedArrayDescending()

fun readString() = readLine()!!


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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y: return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve(N: int, M: int, p: "List[int]", x: "List[int]", y: "List[int]"):
    uf = UnionFind(N)
    for i in range(M):
        uf.union(x[i]-1,y[i]-1)

    answer = 0

    for j in range(N):
        if uf.same(p[j]-1,j):
            answer +=1        
        
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, p, x, y)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

ll h[MAX_N], dp[MAX_N];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> h[i];

    rep(i, n) dp[i] = inf;
    dp[0] = 0;

    rep(i, n) {
        for (int j = 1; j <= k; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1792
n, x = map(int, input().split())

total_counts = [1]
p_counts = [1]
for i in range(1, n + 1):
    total_counts.append(total_counts[-1] * 2 + 3)
    p_counts.append(p_counts[-1] * 2 + 1)


def count(x, n):
    if n == 0:
        return 1 if x > 0 else 0
    if x >= (total_counts[n] + 1) // 2:
        return p_counts[n - 1] + 1 + count(x - total_counts[n - 1] - 2, n - 1)
    else:
        return count(x - 1, n - 1)


print(count(x, n))

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int H = in.i();
        int W = in.i();
        char[][] S = new char[H][];
        for (int i = 0; i < H; i++) {
            S[i] = in.s(W);
        }
        char[][] ans = new char[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (S[i][j] == '#') {
                    ans[i][j] = '#';
                } else {
                    int n = 0;
                    for (int y = i - 1; y < i + 2; y++) {
                        if (y < 0 || H <= y) continue;
                        for (int x = j - 1; x < j + 2; x++) {
                            if (x < 0 || W <= x) continue;
                            if (S[y][x] == '#') {
                                n++;
                            }
                        }
                    }
                    ans[i][j] = (char)(n + '0');
                }
            }
        }
        for (int i = 0; i < H; i++) {
            System.out.println(ans[i]);
        }
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32656
N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

xpys = [x + y for x, y in xys]
dist1 = max(xpys) - min(xpys)
xmys = [x - y for x, y in xys]
dist2 = max(xmys) - min(xmys)
print(max(dist1, dist2))

Measured memory_bytes: 126596
while (line = gets)
  cs = line.chomp.split(" ").map{|s| s.to_i}

  used = (1..10).map{false}
  cs.each{|c| used[c] = true}

  csum = cs[0] + cs[1]
  cnum = 0

  (1..10).select{|c| ! used[c]}.each do |c|
    if csum + c <= 20
      cnum += 1
    end
  end

  puts (cnum >= 4) ? "YES" : "NO"
end

Measured memory_bytes: 6108
#include <sstream>
//#include <fstream>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <set>
//#include <list>
//#include <map>
//#include <unordered_map>
//#include <functional>
//#include <utility>
//#include <bitset>
//#include <cstdlib>
//#include <ctime>
//#include <cstdio>
 
 
#include <stdlib.h>
#include <iostream>
//#include <chrono> //clock
#include <vector>
#include <string>
//#include <iomanip>  //setprecision function
//#include <cmath>	//math
//#include <cstdio>
//#include <vector>	//vector array
//#include <algorithm>	//STL algorithm
//#include <set> //STL library set
//#include <sstream> // for stringstream
 
 
using namespace std;
//using namespace std::chrono; 
 
 
int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	//cout<<setprecision(16);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	
	 // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO 
	 // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
	
	int N;
	cin>>N;
	while(N!=0){
		if(N%10==7) break;
		N=N/10;
	}
	
	if(N%10==7) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
 
	return 0;
}
 
 
 
 


Measured memory_bytes: 3652
#include <iostream>
#include <vector>

#define ll long long

int main() {
    int X, Y;
    int b = 2;
    int t = 4;

    std::cin >> X >> Y;

    if(Y % 2 != 0) {
        std::cout << "No" << std::endl;
    }
    else if(((b*X) > Y) or (Y > (t*X))) {
        std::cout << "No" << std::endl;
    }
    else {
        std::cout << "Yes" << std::endl;
    }
}

Measured memory_bytes: 3584
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).Concat(Enumerable.Repeat(0L, 1)).ToArray();
        var sortedIndex = a.Select((x, y) => new Tuple<long, int>(x, y)).OrderByDescending(x => x.Item1).Select(x => x.Item2).ToArray();
        long[] res = new long[n];

        int minLastIndex = sortedIndex[0];
        for (int i = 1; i < a.Length; i++)
        {
            if (a[sortedIndex[i - 1]] != a[sortedIndex[i]]) res[minLastIndex] += (a[sortedIndex[i - 1]] - a[sortedIndex[i]]) * i;
            minLastIndex = Min(minLastIndex, sortedIndex[i]);
        }
        Console.WriteLine(string.Join("\n", res));
    }
}


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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> p[m];
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    if(a<=m) p[a-1].push_back(b);
  }
  
  ll ans=0;
  priority_queue<int> q;
  rep(i,0,m){
    rep(j,0,p[i].size()) q.push(p[i][j]);
    if(q.size()){
      ans+=q.top();
      q.pop();
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5504
# PDFで解法が4つも書いてある。これはその最初の解法

x,y,z,k =  list(map(int, input().split() ))

aa = list(map(int, input().split() ))
bb = list(map(int, input().split() ))
cc = list(map(int, input().split() ))

aa.sort(reverse = True)
bb.sort(reverse = True)
cc.sort(reverse = True)
# 降順＝大きい方から順

ab = []
for i in aa:
	for j in bb:
		ab.append(i + j)

# ab = [i + j for i in aa for j in bb]
# appendを使うと遅いので、二重の内包記法を使う 
# 外側でaaの要素、内側でbbの要素が動いていく。今回はどっちでも良いけど。
ab.sort(reverse = True)

max_len = min(k, len(ab))
abc = []
for i in ab[:max_len]:
	for j in cc:
		abc.append(i + j)

# abc = [i + j for i in ab[:max_len] for j in cc]
abc.sort(reverse = True)

for i in range(k):
	print(abc[i])


Measured memory_bytes: 155192
#include <bits/stdc++.h>
using namespace std;
const int md=100100;
typedef long long ll;
int djs[200200];
int fi(int x){
	return djs[x]==x?x:djs[x]=fi(djs[x]);
}
void dsu(int x,int y){
	int fx=fi(x),fy=fi(y);
	if(fx!=fy){
		djs[fx]=fy;
	}
	return;
}
int su[200200][2];
int main(){
	for(int i=0;i<200200;i++){
		djs[i]=i;
	}
	int n;
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		dsu(x,y+md);
	}
	for(int i=1;i<200200;i++){
		su[fi(i)][i/100100]++;
	}
	ll ans=0;
	for(int i=1;i<200200;i++){
		ans+=1ll*su[i][0]*su[i][1];
	}
	printf("%lld\n",ans-n*1ll);
	return 0;
}


Measured memory_bytes: 2560
n = int(input())
a = map(int, input().split())

times = {}
for i in a:
    for j in range(i-1, i+2):
        times[j] = times.get(j, 0) + 1

m = 0
for k in times:
    if times[k] > m:
        m = times[k]

print(m)


Measured memory_bytes: 22056
using System;

public class Hello
{
    public static void Main()
    {
        var d = int.Parse(Console.ReadLine().Trim());
        if (d == 25) Console.WriteLine("Christmas");
        if (d == 24) Console.WriteLine("Christmas Eve");
        if (d == 23) Console.WriteLine("Christmas Eve Eve");
        if (d == 22) Console.WriteLine("Christmas Eve Eve Eve");
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		float D = sc.nextInt();
		float T = sc.nextInt();
		float S = sc.nextInt();
      	if (D/S <= T){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
	}
}


Measured memory_bytes: 35832
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  int dx = tx - sx;
  int dy = ty - sy;
  
  string outstr = string(dy, 'U') + string(dx, 'R') + string(dy, 'D') + string(dx, 'L');
  outstr += 'L' + string(dy + 1, 'U') + string(dx + 1, 'R') + 'D';
  outstr += 'R' + string(dy + 1, 'D') + string(dx + 1, 'L') + 'U';
  
  cout << outstr << endl;
  
  return 0;
}


Measured memory_bytes: 764
//{
#include<bits/stdc++.h>
using namespace std;
 
// #define DEBUG

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif
//}


string solve(string s, ll k) {
    
}

void Input() {
    rd1(char, s);
    if((int)s - 'a' >= 0 and (int)s - 'a' <= 25)
        cout << "a";
    else
        cout << "A";
}

int main() {
	
	fastio;

    // rd1(ll, t);
	ll t = 1;

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

Measured memory_bytes: 3608
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char const *argv[]) {
  unsigned long long int a, b, c, d,g;
  cin >> a >> b >> c >> d;
  g=c*d/__gcd(c,d);
  printf("%lld",(b - a + 1) - ((b / c + b / d - b / g) -
                              ((a - 1) / c + (a - 1) / d - (a - 1) / g)));
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

l = []
r = []
for _ in range(m):
    tmp = list(map(int,input().split()))
    l.append(tmp[0])
    r.append(tmp[1])

max_l = max(l)
min_r = min(r)

ans = min_r - max_l + 1

if ans < 0:
    print(0)
else:
    print(ans)


Measured memory_bytes: 56536
c = Array.new
3.times { c.push(gets.chomp.split(" ").map(&:to_i))}

a1 = 0
b1 = c[0][0]
b2 = c[0][1]
b3 = c[0][2]

a2 = c[1][0] - b1
a3 = c[2][0] - b1
if a2 != (c[1][1] - b2) || a2 != (c[1][2] - b3) then
    puts "No"
    exit
end
if a3 != (c[2][1] - b2) || a3 != (c[2][2] - b3) then
    puts "No"
    exit
end

puts "Yes"



Measured memory_bytes: 3836
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int D = sc.nextInt();
		
      	if (D == 22) {
          // 出力
		System.out.println("Christmas Eve Eve Eve");
        } else if (D == 23) {
          System.out.println("Christmas Eve Eve");
        } else if (D == 24) {
          System.out.println("Christmas Eve");
        } else if (D == 25) {
          System.out.println("Christmas");
        }
      
		
}
}


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

int main() {
    int tmp, next = 1, ret = 0, n; // 1 <= n <= 200000
    cin >>n;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        (tmp == next) ? next++ : ret++;
    }
    cout << (next==1 ? -1 : ret) << endl;
    return 0;
}

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

// nCr mod p(n<p)をキビキビ計算する
// 構築:O(n), クエリ:O(1)
struct combination_mod {
    using lint = long long int;
    int sz;
    lint mod;
    vector<lint> fac;
    vector<lint> finv;
    combination_mod(int _sz, lint _mod) : sz(_sz), mod(_mod) {
        fac.assign(sz + 1, 1);
        finv.assign(sz + 1, 1);
        vector<lint> inv(sz + 1, 1);
        for (int i = 2; i <= sz; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    lint query(int n, int r) {
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
    lint perm(lint n, lint r) {
        return fac[n] * finv[n - r] % mod;
    }
};

lint n, m;

int main() {
    cin >> n >> m;
    lint mod = 1e+9 + 7;
    combination_mod comb(m, mod);
    lint err = 0;
    // i:被り
    for (lint i = 1; i <= n; i++) {
        lint add = 1;
        add = (add * comb.perm(m - i, n - i)) % mod;
        add = (add * comb.query(n, i)) % mod;
        if (i % 2 == 0) {
            add = mod - add;
        }
        err = (err + add) % mod;
    }
    lint pertial = (comb.perm(m, n));
    lint ans = (pertial - err) % mod;
    ans = (ans * comb.perm(m, n)) % mod;
    if (ans < 0) {
        ans = (ans % mod + mod) % mod;
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;
const int maxn=200005;

int a[maxn],sum[maxn];

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	int MAX=0;
	for(int i=k;i<=n;i++){
		MAX=max(MAX,sum[i]-sum[i-k]);
	}
	printf("%lf\n",(MAX+k)/2.0);
	return 0;
}

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

using namespace std;

int const MMM = 3005;
string s , z , a , b;
int dp[MMM][MMM] , n , m;

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

    cin >> a >> b;
    n = a.size() , m = b.size();
    s += '0';
    s += a;
    z += '0';
    z += b;

    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            if(s[i] == z[j])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
        }
    }
    vector < char > mimo;
    int q = n , e = m;
    while(q > 0 && e > 0){
        if(s[q] == z[e]){
            mimo.push_back(s[q]);
            q--;
            e--;
        }
        else{
            if(dp[q - 1][e] > dp[q][e - 1])
                q--;
            else
                e--;
        }
    }

    reverse(mimo.begin() , mimo.end());
    for(int i = 0 ; i < mimo.size() ; i++)
        cout << mimo[i];

    return 0;
}


Measured memory_bytes: 35456
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long a[444],sum[444],dp[444][444];
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
import math
n = int(input())
max = int(math.sqrt(n))

a = [0] * (n + 1)

for x in range(1,max+1):
    for y in range(1,max+1):
        for z in range(1,max+1):
            f = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if f <= n:
                a[f] += 1


for i in range(1,n+1):
    print(a[i])


Measured memory_bytes: 9136
n, m = gets.chomp.split.map(&:to_i)
tree = gets.chomp.split.map(&:to_i)
tree.unshift 0

lr = (0..n).to_a
m.times{
    l, r = gets.chomp.split.map(&:to_i)
    lr[r] = l if lr[r] > l
    }
(n - 1).downto(0){|i| lr[i] = [lr[i + 1], lr[i]].min}

dp = [0]
1.upto(n){|i| dp[i] = [dp[i - 1], dp[lr[i] - 1] + tree[i]].max}
puts dp.last


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

int main(void){
    int a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k <= a){
        cout << k << endl;
    }else if(a < k && k <= a + b){
        cout << a << endl;
    }else if(a + b < k && k <= a + b + c){
        cout << 1 * a + - 1 * (k - a - b) << endl;
    }else{
        cout << "error" << endl;
    }

    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

string S;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> vec(N);
    for(ll i=0;i<N;i++){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    vector<ll> vec_kind(N);
    int cnt;
    int insert_cnt=0;
    for(int i=0;i<N;i++){
        cnt=1;
        if(i==N){
            vec_kind[insert_cnt]=cnt;
            break;
        }
        while(vec[i]==vec[i+1]){
            cnt++;
            i++;
        }
        vec_kind[insert_cnt]=cnt;
        insert_cnt++;
    }
    sort(vec_kind.begin(),vec_kind.end());
    ll ans=0;
    for(int i=0;i<N-K;i++){
        ans+=vec_kind[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h> 
using namespace std;
 
#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define debug cout<<"debug";
#define mp make_pair 
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

int main()
{
    ll t_c; t_c = 1;
    // cin >> t_c;
    for(ll t_i=0; t_i<t_c; ++t_i){
        ll h,w; cin >> h >> w;
        char mat[h+1][w+1];
        for(ll i=1; i<=h; ++i){
            for(ll j=1; j<=w; ++j)
                cin >> mat[i][j];
        }

        ll dp[h+1][w+1];
        memset(dp,0,sizeof(dp));
        dp[0][1] = 1;
        for(ll i=1; i<=h; ++i){
            for(ll j=1; j<=w; ++j){
                if(mat[i][j] == '#') continue;
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
            }
        }
        cout << dp[h][w];
    }
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define MAXN 100005
#define maior 100000
using namespace std;

int dp[MAXN];
int n;
vector<int> v;

int solve(int i)
{
	if(dp[i] >= 0)
	{
		return dp[i];
	}

	int res1 = abs(v[i] - v[i-1]) + solve(i - 1);
	int res2 = abs(v[i] - v[i-2]) + solve(i - 2);

	dp[i] = min(res1, res2);

	return dp[i];

}





int main()
{
    
	int num;
	cin >> n;
	
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		v.push_back(num);
	}

	dp[0] = 0;
	dp[1] = abs(v[0] - v[1]); 

	cout << solve(n - 1) << endl;



    return 0;
}

Measured memory_bytes: 8760
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int a[110000],dp[110000];
const int INF = 1001001001;
int k;
int dfs(int x){
	//1 - x
	if(x == 1)return 0;
	if(dp[x] != -1)return dp[x];
	int ret = INF;
	for(int i = 1;i <= k;i++){
		if(x-i >= 1)ret = min(ret,dfs(x-i)+ abs(a[x] - a[x-i]));
	}
	return dp[x] = ret;
}
signed main(){
	int n;cin >> n >> k;
	rep(i,n)cin >> a[i+1];
	rep(i,110000)dp[i] = -1;
	cout << dfs(n) << endl;
	return 0;
}

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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
   string sa, sb, sc;
   cin >> sa >> sb >> sc;
   char s = sa[0];
   sa.erase(0, 1);
   int n = sa.size() + sb.size() + sc.size();
   rep(i, 0, n){
       if(s == 'a'){
           if(sa.size()==0){
               cout << "A" << endl;
               return 0;
           }
           s = sa[0];
           sa.erase(0, 1);
           //cout<< s << " " << endl;
           continue;
       }
       if(s == 'b'){
           if(sb.size()==0){
               cout << "B" << endl;
               return 0;
           }
           s = sb[0];
           sb.erase(0, 1);
           //cout<< "b" << " " << endl;
           continue;
       }
       if(s == 'c'){
           if(sc.size()==0){
               cout << "C" << endl;
               return 0;
           }
           s = sc[0];
           sc.erase(0, 1);
           //cout<< "c" << " " << endl;
           continue;
       }
   }
}

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

template <typename T>
string ToString(const T& n) {
  ostringstream stm;
  stm << n;
  return stm.str();
}

string injection(string x, int k, string a) {
  x.insert(k, a);
  return x;
}

void addPtoSet(unordered_set<string>& s, string p, int n) {
  bool three = false, five = false, seven = false;
  for(int i = 0; i < p.size(); i++){
    if(p[i] == '3'){
      three = true;
    } else if(p[i] == '5'){
      five = true;
    } else if(p[i] == '7'){
      seven = true;
    }
  }
  int P = stoi(p);
  if (n >= P && three && five && seven) {
    s.insert(p);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  string N;
  cin >> N;
  int n = stoi(N);
  vector<unordered_set<string>> s(10);
  s[2].insert("35");
  s[2].insert("53");
  int ans = 0;
  for (int i = 3; i <= N.length(); i++) {
    for (auto x : s[i - 1]) {
      for (int j = 0; j <= x.length(); j++) {
        addPtoSet(s[i], injection(x, j, "3"), n);
        addPtoSet(s[i], injection(x, j, "5"), n);
        addPtoSet(s[i], injection(x, j, "7"), n);
      }
    }
    ans += s[i].size();
  }
  cout << ans << endl;
}


Measured memory_bytes: 5396
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(ll i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//        freopen("output.txt","w",stdout);
//    #endif
}
const int mxN= int(1e5)+100;
ll kc[mxN];
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    ll ans=0LL;
    rloop(i,k,1)
    {
        ll factors=k/i;
        ll count=P(factors,n,mod);
        count%=mod;
        for(ll j=2*i; j<=k; j+=i)
        {
            count=((count%mod)-(kc[j]%mod)+mod)%mod;
        }
        kc[i]=count%mod;
        ans=((ans%mod)+((kc[i]%mod)*(i%mod))%mod)%mod;
    }
    OUT ans%mod<<endl
    return 0;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,m;
string s,t;

int main(){
  cin >> n >> m;
  cin >> s >> t;
  lli gcd = 0;
  for(lli i = 1;i <= min(n, m);i++){
    if(n%i == 0 && m%i == 0){
      gcd = i;
    }
  }
  for(lli i = 0, j = 0;i < s.size(), j < t.size();i += n/gcd, j += m/gcd){
    if(s[i] != t[j]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n*m/gcd << endl;
}


Measured memory_bytes: 512
//インクルード
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>

//型宣言
typedef long long ll;
typedef unsigned long long ull;
typedef std::string string;
typedef string answerType;

//変数宣言
boost::multiprecision::cpp_int A;
boost::multiprecision::cpp_int B;
std::vector<string> Ai;
std::vector<string> Bi;
answerType answer;

//関数のプロトタイプ宣言
//入力の取得
void getInput();
//答えを求める
answerType calcAnswer();

//メイン関数
int main() {
	//入力の取得
	getInput();

	//答え
	answerType answer = calcAnswer();

	//答えの出力
	std::cout << answer << std::endl;

	//正常終了
	return EXIT_SUCCESS;
}

//入力の取得
void getInput() {
	std::cin >> A >> B;
}

//答えを求める
answerType calcAnswer() {
	if(A > B) {
		return "GREATER";
	}
	if(A < B) {
		return "LESS";
	}
	return "EQUAL";
}


Measured memory_bytes: 256
def main() -> None:
    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    sum_A = sum(A)
    cnt = sum(a * 4 * M >= sum_A for a in A)
    print("Yes" if cnt >= M else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
package main

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

func main() {
	sc := newInputScanner(true)
	N := sc.nextUInt64()
	A := sc.nextUInt64()
	B := sc.nextUInt64()
	if A == 0 {
		fmt.Println(0)
		return
	}
	countOneTime := A + B
	times := N / countOneTime
	remainder := N - times*countOneTime
	redCount := times * A
	if remainder < A {
		redCount += remainder
	} else {
		redCount += A
	}
	fmt.Println(redCount)
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	inputSc.Scan()
	i, e := strconv.Atoi(inputSc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	inputSc.Scan()
	i, e := strconv.ParseUint(inputSc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}


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

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

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

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

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
//        string s, t;
//        cin >> s >> t;
//        cout << t << s << endl;

        Int A, B, K;
        cin >> A >> B >> K;
        Int dec = min(A, K);
        A -= dec;
        K -= dec;
        dec = min(B, K);
        B -= dec;
        K -= dec;

        cout << A << " " << B << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
N,L = map(int,input().split(" "))
T = L - 1
list = []
for i in range(N):
    list.append(T + i + 1)
#print(list)
#print(sum(list))
#SUMMER = sum(list)
if list[0] < 0 and list[N-1] > 0:
    pass
elif list[0] < 0:
    list[N-1] = 0
elif list[0] > 0:
    list[0] = 0
print(sum(list))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
 
int main(){
  long long A,B,K;
  cin >> A >> B >> K;
  
  if(A+B <= K){
    cout << 0 << " " << 0;
  }else if(A >= K){
    cout << A-K << " " << B;
  }else{
    cout << 0 << " " << B-(K-A);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#define N 100

int order(int, int *);

int main(){

  int i;
  int n, p[N + 1];

  scanf("%d", &n);

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

  //for(i = 0; i <= n; i++) printf("%d\n", p[i]);

  printf("%d\n", order(n, p));

  return 0;
}

int order(int n, int *p){

  int i, j, k;
  int t, q, m;
  int a[N][N];

  for(i = 1; i <= n; i++){
    a[i][i] = 0;
  }

  for(i = 2; i <= n; i++){
    for(j = 1; j <= n - i + 1; j++){
      t = i + j - 1;
      a[j][t] = 114514;
      for(k = j; k < t; k++){
	q = a[j][k] + a[k + 1][t] + p[j - 1] * p[k] * p[t];
	if(j == k) m = q;
	  else if(m > q) m = q;
      }
      a[j][t] = m;
    }
  }
  
  return a[1][n]; 
}

Measured memory_bytes: 1060
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
T = [t - h[i]*0.006 for i in range(len(h))]
T_diff = [abs(a -T[j]) for j in range(len(h))]
ans = T_diff.index(min(T_diff))
print(ans+1)

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

typedef long long ll;

typedef pair<ll, pair<int, int> > p;

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

    int N;
    cin >> N;

    vector<bool> b(8);

    int o = 0;

    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if(a >= 3200) {
            o++;
            continue;
        }
        for(int j = 0; j < 8; j++) {
            if(a < 400 * (j + 1)) {
                b[j] = true;
                break;
            }
        }
    }

    int c = 0;

    for(int i = 0; i < 8; i++) {
        if(b[i]) c++;
    }

    cout << max(1, c) << " " << c + o << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

#define keta setprecision(10) //10桁表示


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

	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> ruiseki(n,0);

	rep(i, n)
	{
		cin >> a[i];
		ruiseki[i] = a[i];
	}
	rep(i, n-1)
	{
		ruiseki[i + 1] += ruiseki[i];
	}
	ll sa = LINF;
	for (int i = 0; i < n; i++)
	{
		sa = min(sa, abs(ruiseki[i] - (ruiseki[n - 1] - ruiseki[i])));
	}
	cout << sa << endl;
	



	return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
#include<stdlib.h>
int chai(int n)
{
    int sum=0;
    while (n!=0) {
    sum+=n%10;
       n=n/10;
    }
    return sum;
}

int main(){
   int i,j,k,sum,tmp;
   sum=0;
   scanf("%d%d%d",&i,&j,&k);
   tmp=j;
   while (tmp<=i) {

      if(chai(tmp)>=j&&chai(tmp)<=k)
      {
          sum+=tmp;
      }
       tmp++;
   }
   printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll dp[101][4][4][4]={};
int main(){
    cin>>N;
    dp[0][3][3][3]=1;
    for(ll i=1;i<=N;i++){
        char c[5]={"ACGT"};
        for(ll j=0;j<4;j++)
        for(ll k=0;k<4;k++)
        for(ll l=0;l<4;l++){
            if(dp[i-1][j][k][l]==0)continue;

            string s={c[j],c[k],c[l]};
            if(s.substr(0,2)=="GA" || s.substr(1,2)=="GA" 
            ||(s[0]=='G' && s[2]=='A') || s.substr(0,2)=="AG"){
                for(ll m=0;m<4;m++){
                    if(c[m]=='C'){continue;}
                    dp[i][m][j][k]=(dp[i][m][j][k]+dp[i-1][j][k][l])%MOD;
                }
            }else if(s.substr(0,2)=="CA"){
                for(ll m=0;m<4;m++){
                    if(c[m]=='G'){continue;}
                    dp[i][m][j][k]=(dp[i][m][j][k]+dp[i-1][j][k][l])%MOD;
                }
            }else{
                for(ll m=0;m<4;m++){
                    dp[i][m][j][k]=(dp[i][m][j][k]+dp[i-1][j][k][l])%MOD;
                }
            }
        }
    }
    ll ans=0;
    for(ll j=0;j<4;j++)
    for(ll k=0;k<4;k++)
    for(ll l=0;l<4;l++){
        ans=(ans+dp[N][j][k][l])%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >>N;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      int t;
      if(j!=0){
        if(A.at(j)>A.at(j-1)){
          t=A.at(j-1);
          A.at(j-1)=A.at(j);
          A.at(j)=t;
        }
      }
    }
  }
  
 
  int point,asum=0,bsum=0;
  
  for(int i=0;i<N;i++){
    if(i%2!=0)
      bsum+=A.at(i);
    else
      asum+=A.at(i);
  }
  
  point=asum-bsum;

  cout<<point<<endl;
 
 
}
        

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll a,b;
  cin>>a>>b;

  cout << max( {a+b,a-b,a*b} ) << endl;


  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int s[4];

int main(void){
	string str;
	cin >> str;
	for(int i=0;i<str.size();i++){
		if(str[i]=='K')s[0]++;
		if(str[i]=='U')s[1]++;
		if(str[i]=='P')s[2]++;
		if(str[i]=='C')s[3]++;
	}
	cout << min(min(s[0],s[1]),min(s[2],s[3])) << endl;
    return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;

int main() {
    lli N, Q;
    map<lli, lli> val;
    vector<lli> A, B, C;
    cin >> N;
    for (lli i = 0; i < N; i++) {
        lli a;
        cin >> a;
        A.push_back(a);
        val[a] = 0;
    }
    cin >> Q;
    for (lli i = 0; i < N; i++) {
        val[A[i]]++;
    }
    for (lli i = 0; i < Q; i++) {
        lli b, c;
        cin >> b;
        cin >> c;
        B.push_back(b);
        C.push_back(c);
    }
    lli S = 0;
    for (lli i = 0; i < Q; i++) {
        if (i == 0) {
            val[C[i]] += val[B[i]];
            val[B[i]] = 0;
            for (auto itr = val.begin(); itr != val.end(); ++itr) {
                S += (itr->first) * (itr->second);
            }
        } else {
            lli dif;
            dif = (C[i] - B[i]) * val[B[i]];
            S += dif;
            val[C[i]] += val[B[i]];
            val[B[i]] = 0;
        }

        cout << S << endl;
    }
    return 0;
}

Measured memory_bytes: 11600
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean dp[] = new boolean[55552];
		dp[0] = dp[1] = true;
		List<Integer> prime = new LinkedList<Integer>();
		prime.add(2);
		for(int i = 2; i <= 55551; i++) {
			if(dp[i] == false) {
				for(int j = i * 2; j <= 55551; j += i) {
					dp[j] = true;
				}
				if(i % 5 == 1) prime.add(i);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(prime.get(i) + " ");
		}
	}
}

Measured memory_bytes: 20820