akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int a, b;
char M[105][105];
int main()
{
    cin >> a >> b;

    for (int i = 0; i < 100; i++)
        for (int j = 0; j < 100; j++)
            M[i][j] = i < 50 ? '.' : '#';

    for (int i = 1; i < b; i++)
        M[i / 50 * 2][i % 50 * 2] = '#';
    for (int i = 1; i < a; i++)
        M[99 - i / 50 * 2][99 - i % 50 * 2] = '.';

    cout << "100 100\n";
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
            cout << M[i][j];
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	int p,q,r;
	cin>>p>>q>>r;
	int x=p+q;
	int y=q+r;
	int z=p+r;
	cout<<min(x,min(y,z));
}
int main()
{
//code
	
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


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

int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	set<string>ss;
	int l = min(k, (int)s.length());
	for (int i = 1; i <= l; i++) {
		for (int j = 0; j <= s.length() - i; j++)ss.insert(s.substr(j, i));
	}
	int x = 0;
	for (auto a : ss) {
		x++;
		if (x == k) {
			cout << a << endl;
			break;
		}
	}
}

Measured memory_bytes: 1664
A, B, C = map(int, input().split())

cnt_5 = 0
cnt_7 = 0
for x in [A, B, C]:
    if x == 5:
        cnt_5 += 1
    if x == 7:
        cnt_7 += 1

if cnt_5 == 2 and cnt_7 == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cassert>
using namespace std;

int main() {
    int N; cin >> N;
    vector<int> A(N-1);
    for (int i = 0; i < N-1; ++i) {
        cin >> A[i];
        A[i]--;
    }

    vector<int> ans(N);
    for (int i = 0; i < N-1; ++i) {
        ans[A[i]]++;
    }

    for (int i = 0; i < N; ++i) {
        cout << ans[i] << "\n";
    }
}




Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
    }
    else {
        cout << R + 100 * (10 - N) << endl;
    }


    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, D = (int(i) for i in input().split())
X = [[int(i) for i in input().split()] for i in range(N)]
a = np.zeros(D)
b = 0
count = 0
for l in range(N):
  for k in range(N):
    for i in range(D):
      a[i] = (X[l][i]-X[k][i])**2
      b = np.sqrt(sum(a))
    if b != 0 and b - int(b) == 0:
      count += 1
print(count//2)

Measured memory_bytes: 12464
#include<bits/stdc++.h>
using namespace std;
int n,m,du[100010],f[100010];
int cnt,head[100010],to[100010],nxt[100010];
queue<int> q;
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		du[y]++;
	}
	for (int i=1;i<=n;i++)
	{
		if (!du[i])
		{
			q.push(i);
		}
	}
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		for (int i=head[x];i;i=nxt[i])
		{
			int y=to[i];
			du[y]--;
			f[y]=max(f[y],f[x]+1);
			if (!du[y])
			{
				q.push(y);
			}
		}
	}
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		ans=max(ans,f[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2432
n=int(input())
a=input().split(" ")
num=[]
sum_list=[]
for i in range(n):
    num.append(int(a[i]))

num=sorted(num)

for i in range(num[0],num[n-1]+1):
    sum=0
    for j in range(n):
        dis=(num[j]-i)**2
        sum+=dis
    sum_list.append(sum)
sum_list=sorted(sum_list)
print(sum_list[0])

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if(a * n >= b){
		printf("%d\n",b);
	} else if(a*n < b){
		printf("%d\n",a*n);
	}
	return 0;
}	 


Measured memory_bytes: 128
import java.util.*;
    class Main
    {
    	public static void main(String[] args) {
    		Scanner s = new Scanner(System.in);
    		int x = s.nextInt();int a = s.nextInt();int b = s.nextInt();
    		int ans = (x-a);
    		if(ans >= b)
    			ans = ans%b;
    		System.out.println(ans);
    	}
    }

Measured memory_bytes: 21588
n = gets.to_i
taro = 0
hanako = 0
n.times do
  t, h = gets.split
  # puts "#{t} #{h}"
  if t == h
    taro += 1
    hanako += 1
  else
    # len = (t.length <= h.length)? t.length: h.length
    i = 0
    while true do
      # puts "#{t[i, 1]} #{h[i, 1]}"
      break if t[i, 1] != h[i, 1]
      i += 1
    end

    if t[i, 1].nil? || t[i, 1] > h[i, 1]
      taro += 3
    else
      hanako += 3
    end

  end
end
puts "#{taro} #{hanako}"

Measured memory_bytes: 6112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(vector<string> r)
{
    int c1= 0;
    int c2 = 0;
    int c3 = 0;
    int c4 =0;
    for(int i=0;i<r.size();i++)
    {
    
        if(r[i]=="AC")
        {
            c1++;
        }
        else if(r[i]=="WA")
        {
            c2++;
        }
        else if(r[i]=="TLE")
        {
            c3++;
        }
        else{
            c4++;
        }
    }
    cout << "AC" << " " << "x" << " "<< c1 << endl;
    cout << "WA" << " " << "x" << " "<< c2 << endl;
    cout << "TLE" << " " << "x" << " "<< c3 << endl;
    cout << "RE" << " " << "x" << " " << c4 << endl;
}

int main()
{
    vector<string> r;
    int t;
    cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        r.push_back(s);
    }
    solve(r);
}


Measured memory_bytes: 9528
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

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

    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

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

using namespace std;

int N;
vector<int> ans;

int main(void)
{
	cin >> N;
	
	if(N == 3){
		ans.push_back(2), ans.push_back(5), ans.push_back(63);
	}
	else if(N == 4){
		ans.push_back(2), ans.push_back(5), ans.push_back(63), ans.push_back(20);
	}
	else if(N == 6){
		ans.push_back(2), ans.push_back(4), ans.push_back(6), 
		ans.push_back(3), ans.push_back(9), ans.push_back(12);
	}
	else if(N >= 15000){
		for(int i = 2; i <= 30000; i += 2) if(i % 6) ans.push_back(i);
		for(int i = 3; i <= 30000; i += 3) if(i % 6) ans.push_back(i);
		for(int i = 1; i <= N - 15000; i++) ans.push_back(i*6);
	}
	else{
		int X = N/5*2, Y = N/5*2, Z = N/5;
		Z += N%5;
		int cnt = 0;
		for(int i = 2; i <= 30000; i += 2){
			if(i % 6){
				ans.push_back(i);
				cnt++;
			}
			if(cnt >= X) break;
		}
		cnt = 0;
		for(int i = 3; i <= 30000; i += 3){
			if(i % 6){
				ans.push_back(i);
				cnt++;
			}
			if(cnt >= Y) break;
		}
		cnt = 0;
		for(int i = 6; i <= 30000; i += 6){
			if(ans.size() >= N && cnt >= Z) break;
			ans.push_back(i);
			cnt++;
		}
	}
	
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i];
		if(i != ans.size()-1) cout << " ";
	}
	cout << endl;
	//cout << ans.size() << endl;
	return 0;
}

Measured memory_bytes: 512
import bisect
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]
for i in x:
    si = bisect.bisect_left(s,i)
    ti = bisect.bisect_left(t,i)
    sl = 100000000000 if si == 0 else i - s[si-1]
    sr = 100000000000 if si == a else s[si] - i
    tl = 100000000000 if ti == 0 else i - t[ti-1]
    tr = 100000000000 if ti == b else t[ti] - i
    print(min(max(sl,tl), max(sr,tr), max(sl,tr) + min(sl, tr)*2, max(sr,tl) + min(sr,tl)*2))


Measured memory_bytes: 17956
import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    for i in range(q):
        d = int(input())
        ds.append(d)

    ans = [-1] * q
    jump = [-1] * q

    for x, s, t in xst:
        i = bisect_left(ds, s)
        fi = bisect_left(ds, t)
        while i < fi:
            if jump[i] != -1:
                i = jump[i]
            else:
                ans[i] = x
                jump[i] = fi
                i += 1

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

n, q = map(int, input().split())
f(n, q)


Measured memory_bytes: 62324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc052_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  string S;
  cin >> S;

  ll ans = 0;
  ll tmp = 0;
  rep(i, N) { if (S[i] == 'I') {
      tmp++;
    } else {
      tmp--;
    }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main()
{
  int N;
  std::cin >> N;
  std::vector<std::tuple<int, std::string, int>> vec(N);
  for (int i = 0; i < N; ++i)
  {
    auto& t = vec[i];
    std::get<0>(t) = i + 1;
    std::cin >> std::get<1>(t) >> std::get<2>(t);
  }
  std::sort(vec.begin(),
            vec.end(),
            [](auto& x, auto& y) { return std::get<1>(x) == std::get<1>(y) ? std::get<2>(x) > std::get<2>(y) : std::get<1>(x) < std::get<1>(y); });
  for (auto& t: vec)
    std::cout << std::get<0>(t) << "\n";
  std::cout << std::flush;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int H, W, K;
    cin >> H >> W >> K;
    int dp[H + 1][W];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    int mod = 1e9 + 7;

    rep(i, 0, H) rep(j, 0, W) {
        for(int mask = 0; mask < 1 << (W - 1); mask++) {
            bool flag = true;
            rep(l, 0, W - 2) {
                if(mask & 1 << l and mask & 1 << (l + 1)) flag = false;
            }
            if(flag) {
                if(j - 1 >= 0 and mask & 1 << (j - 1)) {
                    (dp[i + 1][j - 1] += dp[i][j]) %= mod;
                } else if(j + 1 < W and mask & 1 << j) {
                    (dp[i + 1][j + 1] += dp[i][j]) %= mod;
                } else {
                    (dp[i + 1][j] += dp[i][j]) %= mod;
                }
            }
        }
    }

    cout << dp[H][K - 1] << endl;

}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for _ in range(h)]

# 準備
row = [[0] * w for _ in range(h)]
col = [[0] * w for _ in range(h)]
for i in range(h):
    prev_wall = -1
    for j in range(w + 1):
        if j == w:
            for k in range(prev_wall+1, j):
                row[i][k] = j - prev_wall - 1
        elif s[i][j] == '#' and j - prev_wall > 0:
            for k in range(prev_wall+1, j):
                row[i][k] = j - prev_wall - 1
            prev_wall = j

for j in range(w):
    prev_wall = -1
    for i in range(h + 1):
        if i == h:
            for k in range(prev_wall+1, i):
                col[k][j] = i - prev_wall - 1
        elif s[i][j] == '#' and i - prev_wall > 0:
            for k in range(prev_wall+1, i):
                col[k][j] = i - prev_wall - 1
            prev_wall = i

# 全探索
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, row[i][j] + col[i][j] - 1)
print(ans)


Measured memory_bytes: 123224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1)
            rem = (rem * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 1000000 + 5;
const int LEN = 50;
const ll MOD = 1000000007;

int cnt[30];

int main() {
    //read,write;
    string s;
    string input;
    while(getline(cin,input)){
        if(input=="^D") break;
        s+=input;
    }
    int sz = s.size();
    for(int i=0;i<sz;i++){
        if(s[i]>='a' && s[i]<='z') cnt[s[i]-'a']++;
        else if(s[i]>='A' && s[i]<='Z') cnt[s[i]-'A']++;
    }
    for(int i=0;i<26;i++){
        cout << char('a'+i) << " : " << cnt[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3172
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int a, b, n, tmp = 0;
	cin >> a >> b;
	n = b - a;
	REP1(i,n) tmp += i;
	cout << tmp - a << endl;
	return 0;
}


Measured memory_bytes: 256
int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    int sum = 0;
    int i = 0;
    while(i < 2){
        if(a > b){
            sum += a;
            a--;
        }else{
            sum += b;
            b--;
        }
        i++;
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 128
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = float('inf')
for i in range(n-k+1):
    l = x[i]
    r = x[i+k-1]
    w1 = abs(l)+abs(r-l)
    w2 = abs(r)+abs(l-r)
    ans = min(ans, min(w1,w2))
print(ans)

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
		int H = sc.nextInt();
		int W = sc.nextInt();
		if(H==0 && W==0) break;
		for(int i = 1;i <= H;i++){
			for(int j = 1;j <= W;j++){
				System.out.print("#");
			}
			System.out.println();
		}
		System.out.println();
		}
	}
}

Measured memory_bytes: 34576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int sigma(int n, int r) {
    int sigma = 0;
    for (int i = 1; i <= n; i++) {
        sigma += pow(i, r);
    }
    return sigma;
}

int main() {
  int n;
  cin >> n;
  cout << sigma(n,1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    int N;
    cin >> N;
    ll A[N];
    REP(i,N)cin>>A[i];
    REP(i,N)REP(j,N){
        if (i!=j){
            ans=max(abs(A[i]-A[j]),ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string k;
	cin>>k;
	int d;
	cin>>d;
	int n = k.length();
	int dp[n+1][d];
	memset(dp, 0, sizeof(dp));
	dp[0][0]=0;
	int pm = 0;
	for(int i=1;i<=n;i++) {
		for(int j=0;j<k[i-1]-'0';j++) {
			dp[i][(pm+j)%d]++;
		}
		pm=(pm+k[i-1]-'0')%d;
		for(int j=0;j<d;j++) {
			for(int num=0;num<10;num++) {
				dp[i][(j+num)%d]+=dp[i-1][j];
				dp[i][(j+num)%d]%=MOD;
			}
		}
	}	
	if(pm==0) {
		dp[n][0]++;
	}
	cout<<(dp[n][0]+MOD-1)%MOD;

	return 0;
}

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

int  main()
{
	int n; cin >> n;
	int ans = 0;
	rep1(i, n)
	{
		int cnt = 0;
		if (i >= 105 && i % 2)
		{
			for (int j = 1; j <= i; j++)
			{
				if (i % j == 0)
					cnt++;
			}
			if (cnt == 8)
				ans ++;
		}

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


Measured memory_bytes: 256
import sys
n,k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ma = []
pu = []
for i in range(n):
    if a[i] < 0:
        ma.append(a[i])
    else:
        pu.append(a[i])
for i in range(len(ma)):
    ma[i] = -ma[i]
ma.sort()
ans = float("inf")
for i in range(len(ma)):
    kota = 0
    kota += ma[i]
    if k <= i+1:
        ans = min(kota,ans)
    else:
        kota += ma[i]
        if len(pu) >= k- i-1:
            kota += pu[k-i-2]
            ans = min(kota,ans)
for i in range(len(pu)):
    kota = 0
    kota += pu[i]
    if k <= i+1:
        ans = min(kota,ans)
    else:
        kota += pu[i]
        if len(ma) >= k- i-1:
            kota += ma[k-i-2]
            ans = min(kota,ans)
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b;
  cin>>a>>b;
  int ans = 0;
  if(a>b)ans+=a,a--;
  else ans+=b,b--;
  ans += max(a,b);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	merge_sort(A, N);
	
	int l, r, tmp[100001];
	if (N == 2) {
		printf("%d\n%d %d\n", A[1] - A[0], A[1], A[0]);
	} else if (A[0] >= 0) {
		tmp[0] = A[0];
		tmp[1] = A[0] - A[N-1];
		for (i = 2; i < N - 1; i++) tmp[i] = tmp[i-1] - A[i-1];
		tmp[N-1] = A[N-2] - tmp[N-2];
		printf("%d\n%d %d\n", tmp[N-1], A[0], A[N-1]);
		for (i = 2; i < N - 1; i++) printf("%d %d\n", tmp[i-1], A[i-1]);
		printf("%d %d\n", A[N-2], tmp[N-2]);
	} else if (A[N-1] <= 0) {
		tmp[0] = A[N-1];
		tmp[1] = A[N-1] - A[0];
		for (i = 2; i < N - 1; i++) tmp[i] = tmp[i-1] - A[i-1];
		tmp[N-1] = tmp[N-2] - A[N-2];
		printf("%d\n%d %d\n", tmp[N-1], A[N-1], A[0]);
		for (i = 2; i < N - 1; i++) printf("%d %d\n", tmp[i-1], A[i-1]);
		printf("%d %d\n", tmp[N-2], A[N-2]);
	} else {
		tmp[0] = A[N-1];
		for (l = 1; A[l] <= 0; l++) tmp[l] = tmp[l-1] - A[l];
		tmp[l] = A[0];
		for (r = N - 2, i = l + 1; A[r] > 0; r--, i++) tmp[i] = tmp[i-1] - A[r];
		tmp[N] = tmp[l-1] - tmp[N-1];
		printf("%d\n", tmp[N]);
		for (i = 1; i < l; i++) printf("%d %d\n", tmp[i-1], A[i]);
		for (r = N - 2, i = l + 1; i < N; r--, i++) printf("%d %d\n", tmp[i-1], A[r]);
		printf("%d %d\n", tmp[l-1], tmp[N-1]);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N,M, X,cou0,couN;
	cou0 = 0;
	couN = 0;
	cin >> N >> M >> X;
	vint A(M);
	for (int i = 0; i < M; i++)cin >> A[i];

	for (int i = X; i != N; i++) {
		for (int j = 0; j < M; j++) {
			if (i == A[j]) {
				couN++;
				break;
			}
		}
	}

	for (int i = X; i != 0; i--) {
		for (int j = 0; j < M; j++) {
			if (i == A[j]) {
				cou0++;
				break;
			}
		}
	}

	cout << min(couN, cou0) << endl;


}


Measured memory_bytes: 256
# include <iostream>
# include <vector>
# include <algorithm>
# include <set>
# include <map>
# include <iomanip>
# include <string>
# include <cmath>

using namespace std;

const int N = 1e5 + 100;
int n, a[N];

int main()
{
    cin >> n;
    for( int i = 1; i <= n; i ++ ){
        cin >> a[i];
    }
    int l = 0, r = n;
    while ( r - l > 1 ){
        int m = ( l + r ) >> 1;
        int b[m] = {};
        b[0] = a[1];
        int len = 0, T = true;

        for( int i = 2; i <= n; i ++ ){
            int ll = -1, rr = len;

            while( rr - ll > 1 ){
                int mm = ( ll + rr ) >> 1;
                if( b[mm] < a[i] )rr = mm;
                else ll = mm;
            }

            if( b[rr] >= a[i] ){
                if( len == m-1){
                    T = false;
                    break;
                }
                b[++len] = a[i];
            }
            else{
                b[rr] = a[i];
            }
        }
        if( T ) r = m;
        else l = m;
    }
    cout << r;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;
  cout<<(all_of(begin(a),end(a),[](auto ai){return ai%2==0;})?"second":"first")<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  ll count=0,sum=0;
  int si=s.size();
  rep(i,si){
    if(s[i]=='B'){
      count++;
    }
    else{
      sum+=count;
    }
  }
  cout<<sum<<'\n';
  return(0);
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
queue < P > Q;
vi G[5001];
int D[5001][5001];
int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    rep(i,N){
        int c,r;
        scanf("%d%d",&c,&r);
        Q.push(P(Pii(c,r),Pii(i,i)));
    }
    rep(i,K){
        int s,e;
        scanf("%d%d",&s,&e);
        s--;e--;
        G[s].PB(e);
        G[e].PB(s);
    }
    fill((int *)D,(int *)(D + lengthof(D)),INF);
    
    while(!Q.empty()){
        P p = Q.front();Q.pop();
        if(p.fr.sc == 0)continue;
        rep(i,G[p.sc.sc].size()){
            if(D[p.sc.fr][G[p.sc.sc][i]] > p.fr.fr){
                D[p.sc.fr][G[p.sc.sc][i]] = p.fr.fr;
                Q.push(P(Pii(p.fr.fr,p.fr.sc-1),Pii(p.sc.fr,G[p.sc.sc][i])));
            }
        }
    }
    int d[5001];
    fill(d,d+5001,INF);
    bool used[5001];
    fill(used,used+5001,false);
    d[0] = 0;
    while(true){
        int v = -1;
        rep(u,N){
            if(!used[u] && (v == -1 || d[u] < d[v]))v = u;
        }
        if(v == -1)break;
        used[v] = true;
        rep(u,N){
            if(d[u] > d[v] + D[v][u]){
                d[u] = d[v] + D[v][u];
            }
        }
    }
    printf("%d\n",d[N-1]);
    return 0;
}

Measured memory_bytes: 179252
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
//grobal var
//------------------------------------------
const int MAX = 2*10e5+2;
 
 
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N;
  while(cin >> N ){
    int ans=0;
    ans = (N-2)*180;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
struct DSU {
    vector<ll> par;
    vector<ll> sz;
    vector<list<ll>> parts;
    DSU(int n) {
        REP(i, 0, n) {
            par.PB(i);
            sz.PB(1);
            parts.PB({i});
        }
    }

    ll find(ll a) {
        return par[a] = par[a] == a ? a : find(par[a]);
    }

    bool same(ll a, ll b) {
        return find(a) == find(b);
    }

    void unite(ll a, ll b) {
        a = find(a);
        b = find(b);
        if(a == b) return;
        if(sz[a] > sz[b]) swap(a, b);
        // sz[a] <= sz[b]
        sz[b] += sz[a];
        sz[a]+=sz[b];
        par[a] = b;
        parts[b].splice(parts[b].end(), parts[a]);
    }
};

int vis[100005];
int32_t main(){
	ios::sync_with_stdio(false);
    int n, m;
    memset(vis,0,sizeof(vis));
    cin>>n>>m;
    DSU d(n+1);
    REP(i,0,m){
        int X, Y, Z;
        cin>>X>>Y>>Z;
        if(!d.same(X,Y)){
            d.unite(X,Y);
        }
    }
    int ans=0;

    for(int i=1;i<=n;i++){
        // deb(i);
        int A=d.find(i);
        // deb(A);
        if(vis[A]==0){
            ans+=1;
            // deb("yes");
            // deb(d.sz[A]);
            vis[A]=1;
        }
    }

    cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 7736
#include<cstdio>
#include<iostream>
using namespace std;
#define MAX 150
int main(){
    int r,c=0;
    int A[MAX][MAX];
    int sum_a=0;
    int sum_b=0;
    int sum =0;
    scanf("%d %d", &r,&c);
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            sum_a += A[i][j];
        
        }
        A[i][c] = sum_a;
        sum_a =0;
    }
    for(int i=0;i<c;i++){
        for(int j=0;j<r;j++){
            sum_b += A[j][i];
        
        }
        A[r][i] = sum_b;
        sum_b =0;
    }
    for(int i= 0; i<r;i++){
        A[r][c] += A[i][c];
    }
     
    
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(j == c)printf("%d",A[i][j]);
            else printf("%d ",A[i][j]);
        }
        putchar('\n');
    }
   
return 0;
}


Measured memory_bytes: 3240
N,T=map(int,input().split())
a=list(input().split())
ts=[]
for _ in range (len(a)):
    ts.append(int(a[_]))

YU=T

for i in range(1,N):
    if ts[i]-ts[i-1]<T:
        YU+=T-(T-(ts[i]-ts[i-1]))
    else:
        YU+=T
print (YU)

Measured memory_bytes: 26864
s=input()
ans=0
if('R' in s):
  ans=1
  if(s[0]=='R' and s[1]=='R' and s[2]=='R'):
    ans=3
  elif(s[0]=='R' and s[1]=='R'):
    ans=2
  elif(s[1]=='R' and s[2]=='R'):
    ans=2
  else:
    ans=1
print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define ld          long double
#define endl        "\n"

const int mod = 998244353;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

void solve() {
    int N, S; cin >> N >> S;
    int a[N+1];
    for(int i=1; i<=N; i++) cin >> a[i];
    int d[N+1][3003];    memset(d, 0, sizeof d);
    int pd[N+1][3003];   memset(pd, 0, sizeof pd);
    for(int i=1; i<=N; i++) {
        d[i][a[i]] = i;
        //pd[i][a[i]] = add(pd[i-1][a[i]], d[i]a[i]);
        for(int j=0; j<=S; j++) {
            if(j > a[i]) {
                d[i][j] = add(d[i][j], pd[i-1][j-a[i]]);
            }
            pd[i][j] = add(pd[i-1][j], d[i][j]);
        }
    }
    int ans = 0;
    for(int i=1; i<=N; i++) ans = add(ans, mul(N-i+1, d[i][S]));
    cout << ans << endl;
}


signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

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

Measured memory_bytes: 141056
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>

using namespace std;

int N;

int main() {
	int x, y, s, t;
	cin >> x >> y >> s >> t;
	cout << s - (t - y) << ' ' << t + (s - x) << ' ' << x - (t - y) << ' ' << y + (s - x) << endl;
	return 0;
}



Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [n] <- readInt
  [s] <- readString
  print $ solve n s

solve :: Int -> String -> Int
solve n s = length $ filter (\b -> f b s) bit
 where
  bit = [ [a, b, c] | a <- ['0' .. '9'], b <- ['0' .. '9'], c <- ['0' .. '9'] ]

f [] _  = True
f _  [] = False
f (a : as) (n : ns) | a == n    = f as ns
                    | otherwise = f (a : as) ns


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for (int i = (a); i < (b); i++)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define N 1234567

int n, a[N];
int main() {
	scanf("%d", &n);
	fo(i,0,n) scanf("%d", a+i), a[i]--;
	int ans = 0;
	fo(i,0,n) if (a[a[i]] == i) ans++;
	printf("%d\n", ans/2);

	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		int n = sc.nextInt();
		int m = sc.nextInt();
		Cake[] cakes = new Cake[n];
		for (int i = 0; i < n; i++) {
			cakes[i] = new Cake(sc.nextLong(), sc.nextLong(), sc.nextLong());
		}
		long max = 0;
		for (int type = 0; type < 4; type++) {
			Arrays.sort(cakes, new MyComparator(type));
			long x = 0;
			long y = 0;
			long z = 0;
			for (int i = 0; i < m; i++) {
				x += cakes[i].x;
				y += cakes[i].y;
				z += cakes[i].z;
			}
			long total = abs(x) + abs(y) + abs(z);
			if (total > max) {
				max = total;
			}
			x = 0;
			y = 0;
			z = 0;
			total = 0;
			for (int i = 0; i < m; i++) {
				x += cakes[n - i - 1].x;
				y += cakes[n - i - 1].y;
				z += cakes[n - i - 1].z;
			}
			total = abs(x) + abs(y) + abs(z);
			if (total > max) {
				max = total;
			}
		}
		System.out.println(max);
	}
	
	public static long abs(long x) {
		if (x > 0 ) {
			return x;
		} else {
			return -x;
		}
	}
	
	public static class MyComparator implements Comparator<Cake> {
		int type;
		
		public MyComparator(int type) {
			this.type = type;
		}
		
		public MyComparator() {
			this(0);
		}
		public int compare(Cake c1, Cake c2) {
			long a;
			long b;
			if (type == 0) {
				a = c1.x + c1.y + c1.z;
				b = c2.x + c2.y + c2.z;
			} else if (type == 1) {
				a = -c1.x + c1.y + c1.z;
				b = -c2.x + c2.y + c2.z;
			} else if (type == 2) {
				a = c1.x - c1.y + c1.z;
				b = c2.x - c2.y + c2.z;
			} else {
				a = c1.x + c1.y - c1.z;
				b = c2.x + c2.y - c2.z;
			}
			if (a == b) {
				return 0;
			} else if (a > b) {
				return 1;
			} else {
				return -1;
			}
		}
	}
	
	public static class Cake {
		public long x;
		public long y;
		public long z;
		
		public Cake (long x, long y, long z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}
	}
}


Measured memory_bytes: 25940
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        String a=sc.next();
        String b=sc.next();
        String c=sc.next();
        int ans=0;
        for (int i = 0; i < n; i++) {
            HashSet<Character> set=new HashSet<>();
            set.add(a.charAt(i));
            set.add(b.charAt(i));
            set.add(c.charAt(i));
            if(set.size()==2)ans+=1;
            if(set.size()==3)ans+=2;
        }
        out.println(ans);
    }
}

Measured memory_bytes: 23124
n = gets.to_i

class Node
  attr_accessor :id, :parent, :left, :right, :sibling, :degree, :depth, :height, :node_type
  def initialize(i)
    @id = i
    @parent = -1
    @left = -1
    @right = -1
    @depth = 0
    @height = 0
    @sibling = -1
    @degree = -1
  end
end

nodes = {}
# 大きさが分かるので初期化しておく
n.times do |i|
  nodes[i] = Node.new(i)
end
# 階層
levels = []

def heightrec(par, nodes)
  l, r = 0, 0
  if nodes[par].left >= 0
    tmp_left = nodes[par].left
    l = heightrec(tmp_left, nodes) + 1
  end
  if nodes[par].right >= 0
    tmp_right = nodes[par].right
    r = heightrec(tmp_right, nodes) + 1
  end
  nodes[par].height = [r, l].max
end

def depthrec(par, nodes)
  left_child = nodes[par].left
  if left_child >= 0
    nodes[left_child].depth = nodes[par].depth + 1
    depthrec(left_child, nodes)
  end
  right_child = nodes[par].right
  if right_child >= 0
    nodes[right_child].depth = nodes[par].depth + 1
    depthrec(right_child, nodes)
  end
end

n.times do |i|
  data = gets.chomp.split.map(&:to_i)
  my_id = data[0]
  child_l = data[1]
  child_r = data[2]
  # 子データをセット
  nodes[my_id].left = child_l
  nodes[my_id].right = child_r
  # 子に親と兄弟データをセット
  if child_l >= 0
    nodes[child_l].parent = my_id
    if child_r >= 0
      nodes[child_l].sibling = child_r
    end
  end
  if child_r >= 0
    nodes[child_r].parent = my_id
    if child_l >= 0
      nodes[child_r].sibling = child_l
    end
  end
  # 子の数をセット
  nodes[my_id].degree = [child_l, child_r].select{|c|c!=-1}.size
  # 深さ更新
  depthrec(my_id, nodes)
end

# 高さ計算とタイプ
# root、internal node、leaf 
nodes.each do |k, node|
  heightrec(k, nodes)
  if node.parent == -1
    node.node_type = "root"
  elsif node.degree.zero? 
    node.node_type = "leaf"
  else
    node.node_type = "internal node"
  end
end

# 出力
# node id: parent = p , sibling = s , degree = deg, depth = dep, height = h, type
nodes.each do |k, node|
  puts "node #{node.id}: parent = #{node.parent}, sibling = #{node.sibling}, degree = #{node.degree}, depth = #{node.depth}, height = #{node.height}, #{node.node_type}"
end


Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int r;
cin>>r;
if(r<1200) cout<<"ABC"<<endl;
else if(r<2800) cout<<"ARC"<<endl;
else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  FOR(i, 1, sqrt(n) + 1) {
    if (i <= sqrt(n)) ans = i * i;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int child[100001];
int marker[100001];
int maximumm=0;
int dfs(int head,vector<int> v[])
{
    child[head]=1;
    int maxi=0;
    for(int i=0;i<v[head].size();i++)
    {
       // maxi=0;
        if(marker[v[head][i]]==0)
        {
            marker[v[head][i]]=1;
            int x=dfs(v[head][i],v);
            if(x>maxi)
            maxi=x;
        }
        else
        {
            int k=child[v[head][i]];
            if(k>maxi)
            maxi=k;
        }
    }
    child[head]+=maxi;
    return child[head];
}
 
int main()
{
    for(int i=0;i<=100001;i++)
    {
    child[i]=0;
    marker[i]=0;
    }
    int n,m;
    cin>>n;
    cin>>m;
    vector<int> v[n+1];
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a;
        cin>>b;
        v[a].push_back(b);
    }
    for(int i=1;i<=n;i++)
    {
    if(marker[i]==0)
    {
    marker[i]=1;
    int y=dfs(i,v);
    if(y>maximumm)
    maximumm=y;
    }
    }
    cout<<maximumm-1<<endl;
    return 0;
}

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

#define ll long long
#define pb push_back
#define MP make_pair
#define PLL pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()
{
  ll t;
  t=1;
  while(t--)
  {
     ll k,x,d;
     cin >> x>>k>>d;

     x= abs(x);
     if(x/d < k)
     {
       ll r1,r2;
       r2=x-(x/d)*d;
       r2=abs(r2);

         if((k-(x/d)) % 2 == 0)
         cout << r2 << '\n';
         else
         cout << min(abs(r2-d),abs(r2+d)) << '\n';

     }
     else if(x/d == k)
     {
       ll r=x-(x/d)*d;

       r=abs(r);
       cout << min(r,x) << '\n';

     }
     else
     {
       ll r=x-k*d;
       r=abs(r);
       cout << min(x,r) << '\n';
     }

  }
}


Measured memory_bytes: 3672
//8 may 2020
//count of solved problems : 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
int n, a[N];
int main(){
	cin>>n;
	vector<int>pos,neg;
	for(int i = 0 ;i<n;i++){
		cin>>a[i];
		(a[i]>0?pos.push_back(a[i]):neg.push_back(a[i]));
	}	
	ll ans=0;
	sort(neg.begin(),neg.end());
	sort(pos.begin(),pos.end());
	if(((int)neg.size())%2==0)
		for(int i=0;i<n;i++)ans+=abs(a[i]);
	else {
		for(int i=1;i<(int)pos.size();i++)ans+=pos[i];
		for(int i=0;i<(int)neg.size()-1;i++)ans+=neg[i]*-1;
		if(pos.size()>0)ans+=max(pos[0],neg.back()*-1)-min(pos[0],neg.back()*-1);
		else ans+=neg.back();
	}
	cout<<ans;

}



Measured memory_bytes: 1276
n = [int(c) for c in input()]
k = int(input())
dp0 = [1, n[0] - 1] + [0 for j in range(2, k + 1)]
dp1 = [0, 1] + [0 for j in range(2, k + 1)]
for i in range(2, len(n) + 1):
    for j in range(k, 0, -1):
        dp0[j] = (dp0[j - 1] * 9 + dp0[j] + dp1[j - 1] * max(n[i - 1] - 1, 0)
                  + dp1[j] * int(n[i-1] != 0))
    if n[i - 1] != 0:
        dp1 = [0] + dp1[:-1]
print(dp0[-1] + dp1[-1])


Measured memory_bytes: 3064
def draw
   mp=gets.split(' ').map(&:to_i)
   if mp[0]==0 && mp[1]==0 then return -1 end
   for y in 1..mp[0] do
      for x in 1..mp[1] do
         if x==1 || x==mp[1] || y==1 || y==mp[0] then
            print "#"
         else
            print "."
         end
      end
      print "\n"
   end
   print "\n"
   return 0
end

ret=draw
until ret==-1 do
    ret=draw
end

Measured memory_bytes: 8696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=1<<29,MOD=1e9+7;

int main(){
	int n,C; cin>>n>>C;
	int d[C][C]; rep(i,C)rep(j,C) cin>>d[i][j];
	int c[n][n]; rep(i,n)rep(j,n) cin>>c[i][j];

	int sum[3][C]; rep(i,3)rep(j,C) sum[i][j]=0;
	rep(i,n)rep(j,n){
		rep(k,C){
			if((i+1+j+1)%3==0) sum[0][k]+=d[c[i][j]-1][k];
			if((i+1+j+1)%3==1) sum[1][k]+=d[c[i][j]-1][k];
			if((i+1+j+1)%3==2) sum[2][k]+=d[c[i][j]-1][k];
		}
	}

	int ans=INF;
	rep(i,C)rep(j,C){
		if(i==j) continue;
		rep(k,C){
			if(i==k||j==k) continue;
			int s=sum[0][i]+sum[1][j]+sum[2][k];
			if(s<ans) ans=s;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include<string>
using namespace std;
#define ll long long int


int main ()
{
     long long int  n,t,i,k,sum=0,flag=0,z,cnt=0,m,b,a1,a2,k1,k2,neg=0,pos=0,j;
     string s;
     cin>>s;
     for(i=0;i<s.size();i=i+2)
     {
         if(s[i]=='L')
         {
             sum++;
             break;
         }
     }
     for(i=1;i<s.size();i=i+2)
     {
         if(s[i]=='R')
         {
             flag++;
             break;
         }
     }
     if(flag==0&&sum==0)
     {
         cout<<"Yes";
     }
     else
     {
         cout<<"No";
     }



return 0;
}


Measured memory_bytes: 760
n, k = map(int, input().split())
h_l = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
    from_jump = max(0,i-k)
    dp[i] = min(dp[j]+abs(h_l[i]-h_l[j]) for j in range(from_jump,i))
print(dp[n-1])

Measured memory_bytes: 20648