akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, std::vector<long long> a){
    sort(a.begin(), a.end());
    cout << a[N - 1] - a[0] << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
        long int n;
        long int i;
        long long int num;
        long long int max=-1000000;
        long long int min=1000000;
        long long int sum=0;
        cin>>n;
        for(i=0;i<n;i++){
                cin>>num;
                if(num>max){
                        max=num;
                }
                if(num<min){
                        min=num;
                }   
                sum=sum+num;
        }
        cout<<min<<" "<<max<<" "<<sum<<endl;
        return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long int n,k;
long int num=0;

int main(void){
	scanf("%lld %lld", &n, &k);
	if(k==0)	printf("%lld", n*n);
  	else{
		for(int b=k+1;b<=n;b++){
			if(n%b<k)	num += (n/b)*(b-k);
          	else	num += (n/b)*(b-k) + (n%b-k+1);
		}
		printf("%lld", num);
    }

	return 0;
}


Measured memory_bytes: 128
mod = int(1e9) + 7


def main():
    S = input()
    a_sum = 0
    ab_sum = 0
    abc_sum = 0
    pattern = 1
    for i in range(len(S)):
        s = S[i]
        if s == "A":
            a_sum = (a_sum + pattern) % mod
        if s == "B":
            ab_sum = (ab_sum + a_sum) % mod
        if s == "C":
            abc_sum = (abc_sum + ab_sum) % mod
        if s == "?":
            abc_sum = (abc_sum * 3 + ab_sum) % mod
            ab_sum = (ab_sum * 3 + a_sum) % mod
            a_sum = (a_sum * 3 + pattern) % mod
            pattern = pattern * 3 % mod
    print(abc_sum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y;
  cin>>x>>y;
  int a[12]={1,3,1,2,1,2,1,1,2,1,2,1};
  if(a[x-1]==a[y-1]){
  cout<<"Yes"<<endl;
  }
  else{
  
  cout<<"No"<<endl;
  }
}


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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long ll; 
inline bool chkmax(ll &a, ll b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    return x * fh;
}

void File() {
#ifdef zjp_shadow
	freopen ("c.in", "r", stdin);
	freopen ("c.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3;

struct Item {
	int a, b, c;

	bool operator < (const Item &rhs) const {
		return a - b > rhs.a - rhs.b;
	}

} lt[N];

int n, X, Y, Z;

ll f[N], g[N], ans = 0;

struct Cmpac {
	inline bool operator () (const int &lhs, const int &rhs) {
		return lt[lhs].c - lt[lhs].a < lt[rhs].c - lt[rhs].a;
	}
};

struct Cmpbc {
	inline bool operator () (const int &lhs, const int &rhs) {
		return lt[lhs].c - lt[lhs].b < lt[rhs].c - lt[rhs].b;
	}
};

priority_queue<int, vector<int>, Cmpac> Pac;
priority_queue<int, vector<int>, Cmpbc> Pbc;

int main () {

	File();
	X = read(); Y = read(); Z = read();
	n = X + Y + Z;
	For (i, 1, n)
		lt[i] = (Item) {read(), read(), read()};
	sort(lt + 1, lt + n + 1);

	ll tot = 0;
	For (i, 1, X) Pac.push(i), tot += lt[i].a; f[X] = tot;
	For (i, X + 1, n - Y) {
		Pac.push(i); tot += lt[i].a;
		int id = Pac.top(); Pac.pop();
		tot += lt[id].c - lt[id].a; f[i] = tot;
	}

	tot = 0;
	Fordown (i, n, n - Y + 1) Pbc.push(i), tot += lt[i].b; g[n - Y + 1] = tot;
	Fordown (i, n - Y, X + 1) {
		Pbc.push(i); tot += lt[i].b;
		int id = Pbc.top(); Pbc.pop();
		tot += lt[id].c - lt[id].b; g[i] = tot;
	}

	For (i, X, n - Y)
		chkmax(ans, f[i] + g[i + 1]);
	printf ("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#include<unordered_set>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin),freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX  2000005
#define v_n 5005
#define LL long long
#define ULL unsigned long long 
#define e_n 50005
#define eps 1e-12
#define Blen 32
const LL MOD = 998244353;
using namespace std;
vector<string> work[4];
int get(string& a)
{
	if (a[0] == 'B')
	{
		if (a.back() == 'A')
		{
			return 0;
		}
		else
		{
			return 1;
		}
	}
	else
	{
		if (a.back() == 'A')
		{
			return 2;
		}
		else
		{
			return 3;
		}
	}
}
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	int N;
	cin >> N;
	string a;
	up(i, 1, N)
	{
		cin >> a;
		work[get(a)].push_back(a);
	}
	string ans;
	while (work[0].size())
	{
		ans += work[0].back();
		work[0].pop_back();
	}
	if (work[2].size())
	{
		ans = work[2].back()+ans;
		work[2].pop_back();
	}
	if (work[1].size())
	{
		ans += work[1].back();
		work[1].pop_back();
	}
//	cout << ans << endl;
	while(true)
	{
		bool gg = 1;
		if (work[2].size())
		{
			gg = 0;
			ans += work[2].back();
			work[2].pop_back();
		}
		if (work[1].size())
		{
			gg = 0;
			ans += work[1].back();
			work[1].pop_back();
		}
		if (gg)
			break;
	
	}
	while (work[3].size())
	{
		ans += work[3].back();
		work[3].pop_back();
	}
	int cnt = 0;
	for (int i = 0; i < ans.size() - 1; i++)
	{
		if (ans[i] == 'A'&&ans[i + 1] == 'B')
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

sunukes = [False] * N

for i in range(K):
    d = int(input())
    As = list(map(int, input().split()))

    for a in As:
        sunukes[a-1] = True    

cnt = 0
for v in sunukes:
    if not v:
        cnt += 1

print(cnt)


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

if n == 0 and a[0] > 1:
    print( -1 )
    exit()

sum_a = [ sum( a ) ]
for d in range( 1, n + 1 ):
    sum_a_next = sum_a[ -1 ] - a[ d - 1 ]
    sum_a.append( sum_a_next )

d_vertex = [ 0 for d in range( n + 1 ) ]

d_vertex[ 0 ] = 1
num_of_v = d_vertex[ 0 ]
for d in range( 1, n + 1 ):
    d_vertex[ d ] = min( sum_a[d], ( d_vertex[ d - 1 ] - a[ d - 1 ] ) * 2 )
    if d_vertex[ d ] <= 0:
        print( -1 )
        exit()
    num_of_v += d_vertex[ d ]

if d_vertex[ n ] < a[ n ]:
    print( -1 )
    exit()

print( num_of_v )

Measured memory_bytes: 20568
#include<stdio.h>

int main(){
	int i;
	int data[10000];
	for(i = 0;i < 10000;i++){
		scanf("%d", &data[i]);
		if(data[i] != 0){
			printf("Case %d: %d\n", i + 1, data[i]);
		}else {
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1776
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
type node struct {
	c    byte
	next *node
}

func main() {
	defer stdout.Flush()

	s := readString()
	b := []byte(s)
	root := new(node)

	for i := len(b) - 1; i >= 0; i-- {
		nd := new(node)
		nd.c = b[i]
		nd.next = root.next
		root.next = nd
	}

	var n int
	changed := true
	for changed {
		i := root.next
		j := i.next
		k := j.next
		changed = false
		for k != nil {
			if i.c != k.c {
				i.next = k
				j = i.next
				k = j.next
				n++
				changed = true
			} else {
				i = i.next
				j = i.next
				k = j.next
			}
		}
	}
	if n%2 == 1 {
		println("First")
	} else {
		println("Second")
	}
}


Measured memory_bytes: 2688
N = int(input())
Data = list(map(int, input().split()))
T = Data[0]
A = Data[1]
H = list(map(int, input().split()))

X = T-A
Min = abs(X - H[0] * 0.006)
Num = 0
for i in range(1,N):
  temp = abs(X - H[i] * 0.006)
  if Min > temp:
    Min = temp
    Num = i
print(Num+1)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import numpy as np

N = int(input())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))

#print(AB)
point = np.zeros(N)
for i in range(N):
    point[i] = AB[i][0] + AB[i][1]
#for Ai, Bi in AB:
 #   point.append(Ai+Bi)

#print(point)

pointMaxIndex = np.argsort(-point)
#print(pointMaxIndex)

Tpoint = 0
Apoint = 0
for i in range(N):
    if i % 2 == 0:
        Tpoint += AB[pointMaxIndex[i]][0]
    else:
        Apoint += AB[pointMaxIndex[i]][1]

ans = Tpoint - Apoint

print(ans)

Measured memory_bytes: 38696
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

void func(std::array<std::array<int, 20>, 20>& maze, int x, int y, int step)
{
    if (x < 0 || y < 0 || x >= 20 || y >= 20) return;
    if (maze[y][x] == -100) return;
    if (maze[y][x] != -1 && maze[y][x] <= step) return;
    maze[y][x] = step;
    func(maze, x + 1, y, step + 1);
    func(maze, x - 1, y, step + 1);
    func(maze, x, y + 1, step + 1);
    func(maze, x, y - 1, step + 1);
}

int main()
{
    int h{}, w{};
    std::cin >> h >> w;

    std::array<std::array<int, 20>, 20> maze{};
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
            maze[i][j] = -100;
        }
    }
    char x{};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> x;
            if (x == '.') {
                maze[i][j] = -1;
            }
        }
    }

    int result{};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (maze[i][j] == -1) {
                auto hoge = maze;
                func(hoge, j, i, 0);
                const auto p = &(hoge[0][0]);
                const auto tmp = *(std::max_element(p, p + 400));
                result = std::max(tmp, result);
            }
        }
    }

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


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define lli long long int
#define ld long double
#define vec vector
#define forn(a) for(lli a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main(){
  IOS;

  int a, b, c; cin>>a>>b>>c;

  int cont = 0;

  for(int desde=a; desde<=c; desde+=a){
    cont += b;
  }

  cout<<cont<<endl;

  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1
#define j0 gray_cat_j0

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 16;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

char s[MAXN];

map<pii, int> cnt;

vector<pair<pii, int> > vv;

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%s", &s[0]);
		ll v = 0;
		int l = strlen(s);
		int pos = l;
		REP(j, 0, l) {
			if (s[j] == '.') {
				pos = j;
			} else {
				v = v * 10 + s[j] - '0';
			}
		}
		pii pp = {0, 0};
		for(; v % 2 == 0; v /= 2) {
			pp._2++;
		}
		for(; v % 5 == 0; v /= 5) {
			pp._1++;
		}
		if (pos < l) {
			pp._1 -= (l - pos - 1);
			pp._2 -= (l - pos - 1);
		}
		cnt[pp]++;
	}
	FA(it, cnt) {
		vv.pb(mp(it->_1, it->_2));
	}
	ll ans = 0;
	REP(i, 0, SZ(vv)) {
		ll cnt = vv[i]._2;
		ll add = cnt * (cnt - 1) / 2;
		if (vv[i]._1._1 >= 0 && vv[i]._1._2 >= 0) {
			ans += add;
		}
		REP(j, i + 1, SZ(vv)) {
			if (vv[j]._1._1 + vv[i]._1._1 >= 0 && vv[j]._1._2 + vv[i]._1._2 >= 0) {
				ans += cnt * vv[j]._2;
			}
		}
	}
	cout << ans << endl;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main()
{
	int n;
	cin >> n;
	int array[n];
	long long sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> array[i];
		sum += array[i];
	}
	long long a = array[0];
	long long b = sum - array[0];
	long long answer = abs(a-b);
	for (int i = 1; i < n - 1; ++i)
	{
		a += array[i];
		b -= array[i];
		long long temp = abs(a-b);
		answer = min(answer, temp);
	}
	cout << answer;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
ll MOD = 1e9+7;
ll MOD2 = 998244353;
int inf = 1e8;
ll INF = 1e16;
string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int H, W;
    cin >> H >> W;
    string s[H];
    rep(i, H) cin >> s[i];
    set<int> sx, sy;
    rep(i, H){
        bool able = true;
        rep(j, W){
            if(s[i][j] == '#'){
                able = false;
            }
        }
        if(able) sx.insert(i);
    }
    rep(j, W){
        bool able = true;
        rep(i, H){
            if(s[i][j] == '#'){
                able = false;
            }
        }
        if(able) sy.insert(j);
    }
    rep(i, H){
        if(sx.count(i)) continue;
        rep(j, W){
            if(!sy.count(j)) cout << s[i][j];
        }
        cout << endl;
    }
}

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

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

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	ll ans =0;
	rep(i, n) if(i%2==0 && a[i]%2) ans++;
	cout <<ans <<"\n";
	return 0;
}


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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = ["; __print(x)


vector<int> adj[200005];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    i64 a, b;
    for(int i = 0; i < n; i++) {
        scanf("%lld%lld", &a, &b);
        if(m-a>=0) adj[m-a].push_back(b);
    }
    priority_queue<i64> p;
    i64 ans = 0;
    for(int i = m-1; i >= 0; i--) {
        for(i64 k : adj[i]) {
            // dbg(i, k);
            p.push(k);
        }
        if(p.size()) {
            ans += p.top();
            // dbg(i, p.top());
            p.pop();
        }
    }
    printf("%lld\n", ans);
}


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

#define what_is(x) cerr << #x << " is " << x << endl;

const ll LMAX = (1LL<<61);
const int IMAX = (1<<29);
const int BIG = 104206970;
const int PRIME = 104206969;

const int N = 2001;
const ll MOD = 1e9+7;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// cout.precision(9); cout << fixed;
	int n, y; cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (n-i-j >= 0 and 10000*i+5000*j+1000*(n-i-j) == y) {
				cout << i << ' ' << j << ' ' << n-i-j << endl;
				return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    set<ll> c[26];
    for(ll i = 0; i < s.length(); ++i) {
        c[s[i]-'a'].insert(i);
    }
    ll rep = 0;
    ll cur = -1;
    for(auto ti: t) {
        ll x = ti - 'a';
        auto y = c[x].upper_bound(cur);
        if (y != c[x].end()) {
            cur = *y;
        } else {
            if(c[x].empty()) {
                cout << -1 << endl;
                return 0;
            } else {
                ++rep;
                cur = *c[x].begin();
            }
        }
    }
    cout << rep * s.length() + cur + 1 << endl;
    return 0;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(){
    int n,k; cin >> n >> k;
    ll ans = 1e10;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];

    sort(h.begin(),h.end());
    vector<ll> hd(n-1);
    rep(i,n-1){
        hd[i] = h[i+1] - h[i];
    }

    vector<ll> ruiwa(n);
    for(int i=1;i<n;i++){
        ruiwa[i] = ruiwa[i-1] + hd[i-1];
    }

    for(int i=k-1;i<n;i++){
        ans = min(ans,ruiwa[i] - ruiwa[i-k+1]);
    }

    cout << ans << endl;
    
}
    

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n,m; vector<int> ht; cin >> n >> m;
    for(int i = 0; i < n; i++){
        int x; cin >> x; ht.push_back(x);
    }
    long long cost[100010]= {0};
    for(int i = 2; i <= n; i++){
        cost[i] = pow(2,30);
    }
    for(int i = 1; i <= n; i++){
        for(int k = 1; k <= m; k++){
            if(i+k-1 < n)
                cost[i+k] = min(cost[i+k],cost[i] + abs(ht[i+k-1] - ht[i-1]));
                
        }
    }
    cout << cost[n] << endl;
    return 0;
}

Measured memory_bytes: 1528
N = int(input())
S = input()
r = 0
for w in S[1:]:
    if w == 'E':
        r += 1
m = r
for i in range(1,len(S)):
    if S[i] == 'E':
        r -= 1
    if S[i-1] == 'W':
        r += 1
    if r < m:
        m = r
print(m)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int a, b, t;

    cin >> a >> b >> t;

    cout << t / a * b << endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b&&a==c) printf("No");
    else if(a==b&&c!=a) printf("Yes");
    else if(a!=b&&a!=c&&b!=c) printf("No");
    else if(a==c&&b!=a) printf("Yes");
    else if(b==c&&a!=b) printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int convert(char x){
	switch(x){
	case 'I':return 1;
	case 'V':return 5;
	case 'X':return 10;
	case 'L':return 50;
	case 'C':return 100;
	case 'D':return 500;
	case 'M':return 1000;
	default: return 0;
	}
}

int main(void){
	char arb[101];
	int i,a,b,ans;

	while(scanf("%s",arb)!=EOF){
		i=0;ans=0;
		a=convert(arb[0]);
		while(1){
			b=convert(arb[i+1]);
			if(a<b)ans-=a; else ans+=a;
			if(b==0)break; else {a=b;i++;}
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 540
#include <algorithm>  // sort, 二分探索(lower_bound)など
#include <cmath>      // pow, logなど
#include <complex>    // 複素数
#include <deque>      // 両端アクセスのキュー
#include <iostream>   // 入出力
#include <iterator>
#include <map>
#include <numeric>  // iota(整数列の生成), gcd, lcm
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>  // 順序保持しないmap
#include <unordered_set>  // 順序保持しないset
#include <utility>        // pair
#include <vector>

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()
#define MAX(x) *max_element(ALL(x))  // 最大値を求める
#define MIN(x) *min_element(ALL(x))  // 最小値を求める

using namespace std;
typedef long long ll;

constexpr int INF = 1e9;
constexpr int MOD = 1000000007;

int main() {
  size_t N, K;
  cin >> N >> K;
  vector<size_t> A(N);
  for (size_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<size_t> visited;
  vector<int> ord(N + 1, -1);  // 訪問順序(何番目に訪れたか)
  size_t cur = 1;
  while (ord[cur] == -1) {
    ord[cur] = visited.size();
    visited.push_back(cur);
    cur = A[cur - 1];
  }
  size_t period = visited.size() - ord[cur];  // 周期
  size_t rem    = ord[cur];                   // 周期に入らない例外部分

  if (K < rem) {
    cout << visited[K] << endl;
  } else {
    cout << visited[rem + ((K - rem) % period)] << endl;
  }

  return 0;
}


Measured memory_bytes: 7716
#include <iostream>

using namespace std;

long long GCD(long long a, long long b){
    long long m = min(a, b);
    long long M = max(a, b);

    while(M % m != 0){
        long long num = m;
        m = M % m;
        M = num;
    }
    return m;
}

long long LCD(long long a, long long b){
    long long G = GCD(a, b);
    long long ans = a / G * b;
    return ans;
}


int main(){

    int N; cin >> N;
    long long ans; cin >> ans;

    for (int i = 0; i < N - 1; i++){
        long long num; cin >> num;
        ans = LCD(ans, num);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[4];
int main()
{
	int x,ans=0;

	for(int i=0;i<3;i++)
		 cin>>a[i];
	cin>>x;
	sort(a,a+3);
	while(x--)
	{
		a[2]*=2;
	}	
	cout<<a[0]+a[1]+a[2];
	return 0;
}


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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	int p = n;
	int cnt = 0;
	while (p > 0) {
		cnt++;
		p /= 10;
	}
	if (cnt == 1) {
		cout << n;
		return 0;
	}
	int ans = 9;
	bool e = 0;
	if (cnt % 2 == 1) {
		ans += (n - pow(10,cnt - 1)) + 1;
		//cnt--;
		e = 1;
	}
	//cnt--;
	cnt = (cnt + 1)/ 2;
	cnt--;
	if (e)
		cnt--;
	int z = 900;
	while (cnt--) {
		ans += z;
		z *= 100;
	}
	cout <<ans;
}



















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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a;
    bool isPrime = true;
    cin >> a;
    while (1) {
        isPrime = true;
        for (int i = 2; i < a; i++) {
            if (a % i == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime)break;
        a++;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ta[399999];

int main()
{
    long long n;
  	cin >> n;
    vector<long long> l(n);
    vector<long long> r(n);
    long long i;
    for(i=0;i<n;i++){
        cin >> l.at(i) >> r.at(i);

    }

    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    long long answer=0;
    long long now = 0;
    for(i=0;i<n;i++){
        if(r.at(i) < now){
            answer += (now - r.at(i) );
            now = r.at(i);
//            cout << now <<endl;
        }else{
            answer += abs(now);
            break;
        }
        if(l.at(n-i-1) > now){
            answer += (l.at(n-i-1) - now);
            now = l.at(n-i-1);
//            cout << now <<endl;
        }else{
            answer += abs(now);
            break;
        }
    }
    long long ans1 = answer;
    answer =0;
    now = 0;
for(i=0;i<n;i++){
        if(l.at(n-i-1) > now){
            answer += (l.at(n-i-1) - now);
            now = l.at(n-i-1);
//            cout << now <<endl;
        }else{
            answer += abs(now);
            break;
        }
        if(r.at(i) < now){
            answer += (now - r.at(i) );
            now = r.at(i);
//            cout << now <<endl;
        }else{
            answer += abs(now);
            break;
        }
    }
    long long ans2 = answer;
    answer = ans1 < ans2 ? ans2 : ans1;
    cout << answer ;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  double n;
  while(cin>>n,n!=-1){
    double q=n;
    n/=2;
    while(fabs(n*n*n-q)>=0.00001*q)
      n=n-(n*n*n-q)/(3*n*n);
    printf("%.6f\n",n);
  }
}

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

int main() {
    int N;
    int count=0;
    int a,b;
    int num2[10][10]={0};
    int ans=0;
  	int i,j;
    scanf("%d",&N);


    for(int i=1; i<=N; i++){
            count=i;
            while(count>=10){
                count/=10;
            }
            num2[count][i%10]++;
    }
    
     for(i=1; i<10; i++){
        for(j=1; j<10; j++){
           ans+=num2[i][j]*num2[j][i];
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c = sc.nextInt()
  val divisors = getDivisorList(c,1)
  val range = (a to b).toList
  println(range.intersect(divisors).size)

  def getDivisorList(target: Int, start: Int): List[Int] = {
    if (target == start)
      List(target)
    else if (target % start == 0)
      start :: getDivisorList(target, start + 1)
    else
      getDivisorList(target, start + 1)
  }
}

Measured memory_bytes: 46924
import glob
import numpy as np
import sys
import time


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'smbc2019\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):
        start_time = time.time()

        N = int(self.input_data())
        S = self.input_data()
        lucky_nums = [int(s) for s in S]

        array_first = [0 for i in range(10)]
        array_last =[0 for i in range(10)]

        for i in range(10):
            index = S.find(str(i))
            array_first[i] = index
            index = S.rfind(str(i))
            array_last[i] = index

        count = 0
        for i in range(10):
            if array_first[i] == -1:
                continue
            for j in range(10):
                if array_first[i]+1 >= array_last[j]:
                    continue
                for k in range(10):
                    if k in lucky_nums[array_first[i]+1:array_last[j]]:
                        count += 1

        print(str(count))

solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 13012
import math

N = int(input())
A_list = list(map(int, input().split()))

num_split = 1
sign = None
len_A_list = len(A_list)

for i in range(len_A_list-1):
    if sign == None:
        if A_list[i+1] - A_list[i] == 0:
            continue
        sign = (A_list[i+1] - A_list[i]) / math.fabs(A_list[i+1] - A_list[i])

    if (A_list[i+1] - A_list[i]) *  sign >= 0:
        continue

    num_split += 1
    sign = None

print(num_split)


Measured memory_bytes: 15020
n=int(input())
s=input()
ans=0
 
for i in range(1, n):
    a=s[:i]
    b=s[i:]
    dic=[]
    dic2=[]
    for j in range(len(a)):
        if a[j] not in dic:
            dic.append(a[j])
    for k in range(len(b)):
        if b[k] not in dic2:
            dic2.append(b[k])
    cnt=0
    for i in range(len(dic)):
        if dic[i] in dic2:
            cnt+=1
    ans=max(ans, cnt)
    
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long iSum = 0;
            for (int i = 1; i <= iN; i++)
            {
                for (int j = 1; j <= iN; j++)
                {
                    for (int k = 1; k <= iN; k++)
                    {
                        if (j < i) { continue; }
                        if (k < j) { continue; }
                        long iOne = 0;                                          // 最大公約数
                        if (i == 1 || j == 1 || k == 1) { iOne = 1; }
                        else
                        {
                            iOne = Gcd(i, j);
                            iOne = Gcd(iOne, k);
                        }
                        if (i == j && j == k) { }                               // i=j=k
                        else if (i != j && j != k && k != i) { iOne *= 6; }     // i≠j≠k
                        else { iOne *= 3; }                                     // それ以外
                        iSum += iOne;
                        //string sOut = "";
                        //sOut += i.ToString() + " " + j.ToString() + " " + k.ToString() + " " + iOne.ToString() + " " + iTmp.ToString();
                        //System.Console.WriteLine("{0}", sOut.ToString().Trim());
                    }
                }
            }

            // 出力
            System.Console.WriteLine("{0}", iSum.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 最小公倍数取得
        private static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // 最大公約数取得
        private static long Gcd(long a, long b)
        {
            if (a < b) { return Gcd(b, a); }
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

}


Measured memory_bytes: 27552
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int[] a = { 3, 1, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3 };

    if (a[x - 1] == a[y - 1]) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 35384
unittest
{
	assert( [ "5 2", "1 1", "3 4" ].solve == 4 );
	assert( [ "5 2", "3 3", "5 5" ].solve == 0 );
	assert( [ "5 1", "1 2" ].solve == 5 );
	assert( [ "60 3", "5 8", "1 3", "10 15" ].solve == 221823067 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	auto lrs = new long[ 2 ][ k ];
	foreach( ref lr; lrs )
	{
		input.popFront;
		lr = input.front.split.to!( long[] );
		lr[ 1 ]++;
	}
	
	// dp[ iマス目 ] = パターン数
	const M = 998244353L;
	auto dp = new ModWorld!M[ n ];
	dp[ 0 ] = 1;
	auto ts = new ModWorld!M[ n ];
	foreach( i; 1L .. dp.length.signed )
	{
		ts[ i ] = ts[ i - 1 ] + dp[ i - 1 ];
		foreach( lr; lrs )
		{
			dp[ i ] += ts[ max( 0L, i + 1 - lr[ 0 ] ) ] - ts[ max( 0L, i + 1  - lr[ 1 ] ) ];
		}
	}
	return dp[ $ - 1 ];
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	this( long n ){ this.n = n % M; }
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	auto opEquals( ModWorld r ){ return this.n == r.n; }
	
	void opAssign( long r ){ this.n = r % M; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


Measured memory_bytes: 5880
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

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

void solve(){
	int n = rint, m = rint;
	
	P[] ps;
	foreach(_; 0 .. m){
		int l = rint - 1, r = rint - 1;
		long c = rlong;
		ps ~= P(l, r, c);
	}
	ps.sort!"a.l<b.l"();
	log("ps:", ps);
	
	auto seg = new SegTree!long(0, n, (long x, long y) => min(x, y), 1_000_000_000_000_000);
	
	seg.setValue(0, 1, 0);
	
	foreach(p; ps){
		seg.setValue(p.l, p.r + 1, seg.getValue(p.l) + p.c);
	}
	
	long ans = seg.getValue(n - 1);
	if(ans >= 1_000_000_000_000_000) "-1".writeln;
	else ans.writeln;	
	
}

struct P{
	int l, r;
	long c;
}

class SegTree(T){
	T delegate(T, T) apply;
	T neutral;
	int a, b; // a <= x < b を担当する
	bool isTerminal;
	SegTree left, right; // 左の子(a <= x < c)、右の子(c <= x < b)
	T value;
	this(int a, int b, T delegate(T, T) apply, T neutral = T.init){
		this.a = a, this.b = b;
		this.apply = apply;
		this.neutral = neutral;
		this.value = neutral;
		if(b - a == 1){
			this.isTerminal = 1;
		}
		else{
			int c = (a + b) / 2;
			this.left = new SegTree(a, c, apply, neutral);
			this.right = new SegTree(c, b, apply, neutral);
		}
	}
	
	// [a, b) に値を設定する ※[a, b) はこのノードの担当区間とかぶっていなくてもよい
	void setValue(int a, int b, T value){
		if(b <= this.a || this.b <= a) return;
		if(a <= this.a && this.b <= b){
			this.value = apply(this.value, value);
		}
		else{
			divideValue();
			left.setValue(a, b, value);
			right.setValue(a, b, value);
		}
	}
	
	// 自分の持っていた値を子に引き継ぐ
	void divideValue(){
		left.value = apply(left.value, this.value);
		right.value = apply(right.value, this.value);
		this.value = neutral;
	}
	
	// iにおける値 ※iは必ずこのノードの担当区間内である前提
	T getValue(int i){
		assert(a <= i && i < b);
		if(this.isTerminal) return this.value;
		else divideValue();
		if(i < left.b) return left.getValue(i);
		else return right.getValue(i);
	}
	
	// 配列に変換したもの（デバッグ用）
	T[] array(){
		T[] res;
		foreach(i; a .. b) res ~= this.value;
		return res;
	}
	
	// 文字列に変換したもの（デバッグ用）
	override string toString(){
		if(this.isTerminal) return this.array.to!string;
		else	return this.array.to!string ~ "\n" ~ left.toString ~ right.toString ~ "\n";
	}
}


Measured memory_bytes: 29180
a = list(input())
b = list(input())
c = list(input())

human = [a,b,c]
dic1 = {0:'A', 1:'B', 2:'C'}
dic2 = {'a':0, 'b':1, 'c':2}
turn_id = 0

while True:
    if not human[turn_id]:
        print(dic1[turn_id])
        break
    else:
        temp_turn_id = dic2[human[turn_id][0]]
        del human[turn_id][0]
        turn_id = temp_turn_id

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int64_t n,k,r=0,ans=0,sum=0;
int64_t a[100010];

bool sushu(int64_t x)
{
    if(x<=2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)return false;
    }
    return true;
}

int main()
{
    int n;cin>>n;
    int sum=0;
    REP(i,n)
    {
        int64_t x;
        cin>>x;
        if(sushu(x))sum++;
    }
    cout<<sum<<endl;;
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
#define INF 0x7FFFFFFF



int main(){
  string s;
  cin >> s;
  mp::cpp_int f=0;
  while(s.size()){
    f=0;
    for(int i=0;i<10;i++){
      string a,b,c,ab;
      int t;
      for(t=0;t<int(s.size())&&s[t]!='+';t++){
        if(s[t]!='X'){
          a.push_back(s[t]);
        }
        else{
          a.push_back(i+'0');
        }
      }
      for(t++;t<int(s.size())&&s[t]!='=';t++){
        if(s[t]!='X'){
          b.push_back(s[t]);
        }
        else{
          b.push_back(i+'0');
        }
      }
      for(t++;t<int(s.size());t++){
        if(s[t]!='X'){
          c.push_back(s[t]);
        }
        else{
          c.push_back(i+'0');
        }
      }
      reverse(a.begin(),a.end());
      reverse(b.begin(),b.end());
      reverse(c.begin(),c.end());
      int j;
      int k=0;
      int l=0;
      for(j=0;j<int(a.size())&&j<int(b.size());j++){
        k=0;
        if(a[j]-'0'+b[j]-'0'+l>=10){
          k++;
          ab.push_back(a[j]-'0'+b[j]+l-10);
        }
        else{
          ab.push_back(a[j]-'0'+b[j]+l);
        }
        l=k;
      }
      for(;j<int(a.size());j++){
        k=0;
        if(a[j]-'0'+l>=10){
          k++;
          ab.push_back(a[j]+l-10);
        }
        else{
          ab.push_back(a[j]+l);
        }
        l=k;
      }
      for(;j<int(b.size());j++){
        k=0;
        if(b[j]-'0'+l>=10){
          k++;
          ab.push_back(b[j]+l-10);
        }
        else{
          ab.push_back(b[j]+l);
        }
        l=k;
      }
      if(l>0){
        ab.push_back(l+'0');
      }
      if(ab==c){
        f++;
        cout << i << endl;
        break;
      }
    }
    if(f==0){
      cout << "NA" << endl;
    }
    s="";
    cin >> s;
  }
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	int ans = -1,cnt = MOD;
	int n;
	cin >> n;
	vector<int> v(n);
	cu(i,0,n)cin >> v[i];

	fu(i,-100,100){
		int sum = 0;
		cu(j,0,n){
			sum += (v[j] - i) * (v[j] - i);
		}
		if(sum < cnt){
			cnt = sum;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}
const ll MOD = 1000000007;
int h, w;
char v[55][55], ans[55][55];
int dx[8] = {1,1,0,-1,-1,-1,0,1}, dy[8] = {0,1,1,1,0,-1,-1,-1};
int solve(int i, int j)
{
    int rec = 0;
    for(int k = 0; k < 8; k++){
        int l = i+dx[k], r = j+dy[k];
        if(l >= 0 && l < h && r >= 0 && r < w){
            if(v[l][r] == '#'){
                rec++;
            }
        }
    }
    return rec;
}

int main()
{
    
    cin >> h >> w;
    rep(i, h){
        rep(j, w){
            cin >> v[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(v[i][j] != '#'){
                ans[i][j] = char(solve(i, j)+'0');
            }
            else{
                ans[i][j] = '#';
            }
            cout << ans[i][j];
        }
        cout << endl;
    }
}

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

typedef pair<int, int> P;

int H, N;
vector<P> M;
int DP[40000][1000];

int main() {
    cin >> H >> N;
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        M.push_back(P(a, b));
    }
    for (int j = 0; j < N; ++j) {
        int a = M[j].first;
        int b = M[j].second;
        for (int low = 0; true; low += a) {
            int up = low + a;
            int prev = INT_MAX;
            int now = DP[low][j] + b;
            int pn = INT_MAX;
            int nn = INT_MAX;
            for (int i = low + 1; i <= up; ++i) {
                if (j > 0) {
                    prev = DP[i][j - 1];
                    if (i >= a) pn = DP[i - a][j - 1] + b;
                    if (i >= a) nn = DP[i - a][j] + b;
                }
                DP[i][j] = min({ prev, now, pn, nn });
            }
            if (up > H) break;
        }
    }
    /*for (int i = H*2; i >= 0; --i) {
        for (int j = 0; j < N; ++j) {
            //cout << DP[i][j] << ' ';
        }
        //cout << endl;
    }*/
    cout << DP[H][N-1] << endl;
    return 0;
}
#endif


Measured memory_bytes: 43392
#include<stdio.h>
#include<vector>
#include<string.h>
//15 15
//1 2 1 10 2 3 2 8 3 4 3 5 5 6 5 7 8 9 10 12 10 13 10 11 12 14 12 15
//全くやる気が出ないので適当に
//昔は会津大学オンラインジャッジで問題正答数30位以内に入ったが世間的評価が0という現実に直面
//昔は競技プログラムの問題を解くときすごく脳が活発になっていましたが
//今は評価0の現実に打ちのめされて凄く低いやる気です、脳も少ししか働きません、よってこの問題も全然ダメダメな不正解を重ねています。

int n,k;
std::vector<int> vec[2001];
int cs2[2001][2001];
int cs4[2001][2001];
int ans=2;

void f(int p,int oya){
	cs2[p][0]=1;
	int first=1;
	for(int i=0;i<vec[p].size();i++){
		int p2=vec[p][i];
		if(p2==oya)continue;
		f(p2,p);
		for(int i=0;i<n;i++){
			cs2[p][i+1]+=(first+cs2[p2][i]);
		}
		first=0;
	}
	int up=0;
	//printf("\n%d",p);
	for(int i=0;i<=n;i++){
		if(up<cs2[p][i]){
			up=cs2[p][i];
		}
		cs2[p][i]=up;
		//printf(" %d ",cs2[p][i]);
	}
	
}

void g(int p,int oya){
	int cs5[2001];
	cs4[p][0]=1;
	for(int i=0;i<vec[p].size();i++){
		int p2=vec[p][i];
		if(p2==oya)continue;
		g(p2,p);
		memcpy(cs5,cs2[p],sizeof(cs5));
		//printf("\n(%d %d)",p,p2);
		//for(int j=0;j<=n;j++){
		//	printf("%d ",cs5[j]);
		//}
	
		for(int j=0;j<n;j++){
			cs5[j+1]=cs5[j+1]-cs2[p2][j];	
			
		}
		//printf("\n(%d %d)",p,p2);
		//for(int j=0;j<=n;j++){
		//	printf("%d ",cs5[j]);
		//}
		//printf("\n");
		for(int j=0;j<k;j++){
			int a=j;
			int b=k-j-1;
			if(b>a+1){
				b=a+1;
			}
			
			int c=cs2[p2][a]+cs5[b];
			if(cs4[p][a+1]<c){
				cs4[p][a+1]=c;
			}
			if(ans<c){
				ans=c;
			}
		}
	}
	int up=0;
	for(int i=0;i<=n;i++){
		if(up<cs4[p][i]){
			up=cs4[p][i];
		}
		cs4[p][i]=up;
	}
	memcpy(cs2[p],cs4[p],sizeof(cs4[p]));
}

int main(){
	
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	memset(cs2,0,sizeof(cs2));
	memset(cs4,0,sizeof(cs4));
	f(1,-1);
	g(1,-1);
	printf("%d\n",n-ans);
}

Measured memory_bytes: 44160
#include <cstdio>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

typedef long long LL;

map<LL, LL> ar;
int n;
int main() {
	while(scanf("%d", &n) != EOF) {
		ar[0] = 1;
		LL sum = 0, num = 0;
		int tmp;

		for(int i = 0; i < n; i++) {
			scanf("%d", &tmp);
			sum += (long long)tmp;

			if(ar[sum]) {
				num += ar[sum];
				ar[sum]++;
			} else {
				ar[sum] = 1;
			}
		}

		printf("%lld\n", num);
	}

	return 0;
}

Measured memory_bytes: 12800