akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
using namespace std;
typedef long long LL;
int main(){
    int n;
    scanf("%d",&n);
    int a[200005];
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    int ans[200005];
    MEM(ans);
    for(int i=0;i<n;i++)
    ans[a[i]]=ans[a[i]-1]+1;
    int Max=0;
    for(int i=1;i<=n;i++)
    Max=max(Max,ans[i]);
    printf("%d\n",n-Max);
}




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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  vi red;
  vi white;
  
  rep(i, 0, n){
    if(s[i] == 'R'){
      red.push_back(i);
    }
    else
      white.push_back(i);
  }
  reverse(red.begin(), red.end());
  
  int cnt = 0;
  
  if(white.size() == 0){
    cout << cnt << endl;
    return 0;
  }
  
  rep(i, 0, red.size()){
    if(red[i] < white[i])
      break;
    cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
  
}

Measured memory_bytes: 4668
N, K = map(int, input().split())
P = input().split()
P = [int(p) for p in P]

import numpy as np

E = (np.array(P)+1)/2
E = np.cumsum(E)  

ans = E[K-1]
for i in range(0,N-K):
  ans = max(ans, E[i+K]-E[i])
print(float(ans))

Measured memory_bytes: 24680
#include <cstdio>
using namespace std;

int main(void){
    int n, t, mini, minv = 1000000001;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &t);
        if (t < minv) { minv = t, mini = i; }
    }
    printf("%d\n", mini);
    return 0;
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
stack<int> st;
char s[200005];
int main(){
	scanf("%s", s+1);
	int n = strlen(s+1);
	for(int i=1;i<=n;i++){
		if(s[i] == 'S') st.push(0);
		else{
			if(!st.empty() && st.top() == 0) st.pop();
			else st.push(1);
		}
	}
	printf("%d\n", st.size());
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int pos = 0;
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(pos >= S[i]-'A'){
            cnt++;
        }
        pos = S[i] - 'A';
    }
    cout << cnt << "\n";


    return 0;
}


Measured memory_bytes: 3212
n = int(input())
lst = []
count = n

while count >= 26:
    if count%26 == 0:
        lst.append(26)
        count = count // 26 -1
    else:
        lst.append(count%26)
        count = count // 26
if count != 0:
    lst.append(count)
lst = lst[::-1]
# print(lst)

dict = {1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"g",8:"h",9:"i",10:"j",11:"k",12:"l",13:"m",14:"n",15:"o",16:"p",17:"q",18:"r",19:"s",20:"t",21:"u",22:"v",23:"w",24:"x",25:"y",26:"z"}
sentence = ""
for i in lst:
    sentence += dict[i]
print(sentence)

Measured memory_bytes: 61820
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;
  vector<ll> P(N);
  rep (i, N) cin >> P[i];
  ll ans = 0;
  ll tmp = N + 1;
  rep (i, N) {
    if (P[i] <= tmp) ans++;
    tmp = min(tmp, P[i]);
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

int main(){
  int N;
  string stones;
  cin >> N >> stones;

  vector<int> cumsum(N+1);
  cumsum.at(0)= 0;
  for(int i=1; i<=N; i++){
    cumsum.at(i)= (stones.at(i-1)=='R') ? cumsum.at(i-1)+ 1
                                        : cumsum.at(i-1);
  }

  int ans= cumsum.back()- cumsum.at(cumsum.back());
  
  cout << ans << endl;
}

Measured memory_bytes: 4428
// ABC114_C
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll N, res = 0;

void dfs(ll x, bool f3, bool f5, bool f7) {
    if (x <= N) {
        if (f3 && f5 && f7) res++;
        dfs(10*x + 3, true, f5, f7);
        dfs(10*x + 5, f3, true, f7);
        dfs(10*x + 7, f3, f5, true);
    }
}

int main() {
    // input
    cin >> N;
    
    // calculation
    dfs(0, false, false, false);
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    S = [["*" for _ in range(W + 2)] for _ in range(H + 2)]
    for i in range(1, H + 1):
        S[i][1: W + 1] = input()

    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if S[i][j] == "#":
                continue

            cnt = 0
            if S[i - 1][j - 1] == "#":
                cnt += 1
            if S[i - 1][j] == "#":
                cnt += 1
            if S[i - 1][j + 1] == "#":
                cnt += 1
            if S[i][j - 1] == "#":
                cnt += 1
            if S[i][j + 1] == "#":
                cnt += 1
            if S[i + 1][j - 1] == "#":
                cnt += 1
            if S[i + 1][j] == "#":
                cnt += 1
            if S[i + 1][j + 1] == "#":
                cnt += 1

            S[i][j] = str(cnt)

    for i in range(1, H + 1):
        print("".join(S[i][1: W + 1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9264
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, K; 
  cin >> N >> K;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> sum(N+1, 0);
  REP(i, N){
    sum[i+1] = sum[i]+A[i];
  }

  int cnt = 0;
  vector<int> vec(N*(N+1)/2);
  REP(i, N) FOR(j, i+1, N+1){
    vec[cnt++] = sum[j]-sum[i];
  }

  N = vec.size();

  int ans = 0;
  vector<bool> ng(N, false);
  RREP(i, 61){
    int cnt = 0;
    RREP(j, N){
      if(ng[j]) continue;
      if((vec[j] >> i)&1) cnt++;
    }
    if(cnt >= K){
      RREP(j, N){
        if(ng[j]) continue;
        if(!((vec[j] >> i)&1)) ng[j] = true;
      }
      ans += pow(2, i);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4224
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    map<int, int> m;
    rep(i, n) {
        for(int j = -1; j <= 1; j++) {
            m[a[i] + j]++;
        }
    }

    int ans = 0;
    for(auto p : m) {
        ans = max(ans, p.second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for (int a = 0; a <= A; a++) {
        for (int b = 0; b <= B; b++) {
            int c = (X - (500 * a) - (100 * b)) / 50;
            if (c >= 0 && c <= C) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const double PI = acos(-1.0);

int main() {
	while (1) {
		int h, w;
		cin >> h >> w;

		if (h == 0 && w == 0) {
			return 0;
		}

		for (int i = 0; i < h; i++) {
			for (int i = 0; i < w; i++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}



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

int main(){
  ll Q,H,S,D,N,ans=0,Min1;
  cin >> Q >> H >>S>>D>>N;
  
  Q=Q*4;
  H=H*2;
  Min1=min({Q,H,S});
  
  if(Min1*2<D){
   ans=N*Min1;
  }
  else{
   ans=N/2*D+N%2*Min1; 
  }
  
  cout<< ans<<endl;
}

Measured memory_bytes: 384
S = input()
N = int(input())
flg = 0
L = []
for i in range(N):
    e = input().split()
    if e[0] == '1':
        flg += 1
        flg = flg%2
    else:
        L.append(((flg+int(e[1]))%2, e[2]))

S = ''.join(list(reversed(S))) if flg else S
s1, s2 = '', ''
for f, v in L:
    if (flg+f)%2 == 1:
        s1 += v
    else:
        s2 += v

ans = ''.join(list(reversed(s1))) + S + s2
print(ans)

Measured memory_bytes: 24800
using System;
using System.Collections;
using System.Linq;
class Program
{
    static void Main()
    {
        //以下100000以下の素数の導出
        ArrayList ps = new ArrayList();
        bool[] nums = new bool[100001];
        nums[0] = true;
        nums[1] = true;
        for (int i = 0; i < 100001; i++)
        {
            if (!nums[i])
            {
                nums[i] = true;
                ps.Add(i);
                for (int j = 2; j <= 100000 / i; j++)
                    nums[i * j] = true;
            }
        }
        int[] primes = (int[])ps.ToArray(typeof(int));

        //素数を表示
        //for (int i = 0; i < 50; i++)
        //    Console.Write("{0} ", primes[i]);
        //Console.WriteLine();

        //以下2017liked奇数の個数の累積和を考える
        int[] sum = new int[50001];
        for (int i = 1; i < 50001; i++)
        {
            sum[i] = sum[i - 1];
            if (Array.IndexOf(primes, 2 * i - 1) >= 0 && Array.IndexOf(primes, i) >= 0)
                sum[i]++;
        }

        //累積和を表示
        //for (int i = 0; i < 50; i++)
        //    Console.Write("{0} ", sum[i]);
        //Console.WriteLine();

        //以下入力の受け取り(Qのみ)
        int q = int.Parse(Console.ReadLine());

        //以下各クエリの内容を受け取り解答を出力
        for (int i = 0; i < q; i++)
        {
            string[] lr = Console.ReadLine().Split(' ');
            Console.WriteLine(sum[(int.Parse(lr[1]) + 1) / 2] - sum[(int.Parse(lr[0]) + 1) / 2 - 1]);
        }
    }
}

Measured memory_bytes: 16332
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;

public class Main {
	
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		String string = in.next();
		char arr[] = string.toCharArray();
		int r = 0;//2
		int max = 0;
		for (int i = 0; i < arr.length; i++) {
			if(arr[i]=='R') {
				r++;
			}else {
				if (max<r) {
					max = r;
					r = 0;
				}else {
					r = 0;
				}
			}
		}
		if (max<r) {
			System.out.println(r);
		}else {
		System.out.println(max);
		}
	}

}

Measured memory_bytes: 27016
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;i--)
#define ll long long
using namespace std;
const int N=2e5+5,mo=1e9+7;
int n,x,y;
int a[N],la[N];
ll ans,f[N];
int main(){
	scanf("%d\n",&n);
	f[0]=1;
	fo(i,1,n){
		scanf("%d",&a[i]);
		f[i]=f[i-1];
		if(la[a[i]]&&la[a[i]]<i-1)f[i]=(f[i]+f[la[a[i]]])%mo;
		la[a[i]]=i;
	}
	printf("%lld\n",f[n]);
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,k;
	cin >> a >> b >> k;
	int ans = min(a,b) + 1;
	while(k > 0){
		ans--;
		if(a % ans == 0 && b % ans == 0){
			k--;
		}
	}
	ANS(ans);
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SZ(x) ((int)(x).size())
#define endl '\n'

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    string s;
    cin >> s;

    int ans = 0;

    REP(i, SZ(s)) {
        ans += (s[i]-'0');
    }

    cout << ((ans % 9) ? "No" : "Yes");

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pf push_front
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll n;
deque<ll>arr;

int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		ll x;
		cin >> x;
		if(i&1){
			arr.pf(x);
		}
		else{
			arr.pb(x);
		}
	}
	if(n&1){
		for(int i=arr.size()-1;i>=0;i--){
			cout << arr[i] << ' ';
		}
		cout << '\n';
	}
	else{
		for(auto x:arr){
			cout << x << ' ';
		}
		cout << '\n';
	}
}


Measured memory_bytes: 5308
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

char buf[114514];

int N;
vector<int> imos;

int solve(string &A, string &B) {
  int ret = N * 10000;
  imos.clear();
  imos.assign(3*N, 0);
  rep(i, N) {
    rep(j, 3) {
      imos[N*j + i] = (B[i] == '1');
    }
  }

  reps(i, 1, 3*N) {
    imos[i] += imos[i-1];
  }

  rep(i, N) {
    //printf("shifting: A_%d -> B0\n", i);

    int cand = i;
    priority_queue<pii> que;
  
    rep(j, N) {
      int d = (i+j) % N;
      if (A[d] != B[j]) {
        //printf("A_%d != B_%d\n", d, j);

        cand++;
        int a, b;

        {
          int low = i-1;
          int high = N;
          int idx = N+d;
          while (high - low > 1) {
            int mid = (high+low)/2;
            int val = imos[idx]-imos[idx-mid-1];
            //printf("[%d, %d]: %d\n", idx-mid, idx, val);
            if (val > 0) high = mid;
            else {
              assert(val == 0);
              low = mid;
            }
          }

          a = high - i;
        }

        {
          int low = -1;
          int high = N+1;
          int idx = N+d;
          while (high - low > 1) {
            int mid = (high+low)/2;
            int val = imos[idx+mid]-imos[idx-i-1];
            if (val > 0) high = mid;
            else {
              assert(val == 0);
              low = mid;
            }
          }

          b = high;
        }

        //printf("pushed (a, b) = (%d, %d)\n", a, b);
        que.push(pii(a, b));
      }
    }

    int rw = 0;
    while (!que.empty()) {
      //printf("cand: %d, left: %d, right: %d\n", cand, que.top().X, rw);
      MN(ret, cand + (que.top().X+rw)*2);
      MX(rw, que.top().Y);
      que.pop();
    }

    MN(ret, cand + rw*2);
  }
  return ret;
}

int main() {
  string A;
  string B;

  scanf("%s", buf);
  N = strlen(buf);
  A = buf;
  scanf("%s", buf);
  B = buf;

  if (strchr(buf, '1') == NULL) {
    if (A == B) puts("0");
    else puts("-1");
    return 0;
  }

  int ans = N * 1000;
  MN(ans, solve(A, B));
  reverse(all(A));
  reverse(all(B));
  MN(ans, solve(A, B));
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
using namespace std;

int main(int argc,char** argv)
{


	int n,k;
	cin >> n >> k;
	if(n%k == 0){
		cout << 0 <<endl;
	}
	else{
		cout << 1 <<endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vector<int> Parent;

  UnionFind(int N){
    Parent = vector<int>(N,-1);
  }

  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  int size(int A){
    return -Parent[root(A)];
  }

  //AとBをくっつける
  bool connect(int A, int B){
    // root をくっつける
    A = root(A);
    B = root(B);
    if(A == B) return false;

    // 大きい方(A)に小さい方(B)をくっつける
    if(size(A) < size(B)) swap(A,B);

    Parent[A] += Parent[B];
    Parent[B] = A;

    return true;    
  }
};

int main(){
  ll n,m; cin >> n >> m;
  vi a(m),b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  vl ans(m);
  ans[m-1] = n*(n-1)/2;
  
  UnionFind Uni(n);

  for(int i = m-1; i >= 1; i--) {
    ans[i-1] = ans[i];

    if(Uni.root(a[i]) != Uni.root(b[i])){
      ans[i-1] -= (ll)Uni.size(a[i]) * Uni.size(b[i]);
      Uni.connect(a[i], b[i]);
    }
  }

  rep(i,m) {
    cout << ans[i] << endl;
  } 
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef  long long ll;
const int MAXN=20;
int a[MAXN],b[MAXN],c[MAXN];
int main(){
    int n,ans=0; cin>>n;
    for(int z=0;z<3;z++){
        if(z==2)n--;
     for(int i=0;i<n;i++){
         if(!z)cin>>a[i];
         else if(z==1)cin>>b[i];
         else cin>>c[i];
     }
    }
    for(int i=0;i<n;i++){
        ans+=b[i];
        if(a[i+1]-a[i]==1)
            ans+=c[a[i]-1];
    }
    cout<<ans+b[n];
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

LL p3[31] = {1};

LL solve(LL a, LL b, LL c, LL d){
	if(a > c){
		a = p3[30] - 1 - a;
		c = p3[30] - 1 - c;
	}
	if(b > d){
		b = p3[30] - 1 - b;
		d = p3[30] - 1 - d;
	}

	int l;
	for(l = 29; ; --l){
		if(l < 0){
			return c + d - a - b;
		}
		LL e = c / p3[l], f = d / p3[l];
		if(e % 3 != 1){ --e; }
		if(e % 3 != 1){ --e; }
		if(f % 3 != 1){ --f; }
		if(f % 3 != 1){ --f; }
		if(e >= 0 && f >= 0 && (e + 1) * p3[l] - 1 >= a && (f + 1) * p3[l] - 1 >= b){
			auto calc = [](LL x, LL y, LL z){ return abs(x - z) + abs(y - z); };
			LL ret = 0;
			ret += min(calc(a, c, e * p3[l] - 1), calc(a, c, (e + 1) * p3[l]));
			ret += min(calc(b, d, f * p3[l] - 1), calc(b, d, (f + 1) * p3[l]));
			return ret;
		}
	}
}

void mainmain(){
	for(int i = 1; i <= 30; ++i){ p3[i] = p3[i - 1] * 3; }

	int q;
	scanf("%d", &q);
	for(int i = 0; i < q; ++i){
		LL a, b, c, d;
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		LL ans = solve(a - 1, b - 1, c - 1, d - 1);
		printf("%lld\n", ans);
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pdd pair<double, double>
#define V vector<int>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define db(x) cout << #x << "=" << (x) << endl
#define db2(x, y) cout << #x << "=" << (x) << " " << #y << "=" << (y) << endl
#define db3(x, y, z) cout << #x << "=" << (x) << " " << #y << "=" << (y) << " " << #z << "=" << (z) << endl

using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1007;
const double eps = 1e-9;

int w[maxn], v[maxn];
int dp[1 << 12];

int main()
{
#ifdef AFei
    freopen("in.txt", "r", stdin);
#endif

    int N, M;
    cin >> N >> M;
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    int sum = 0;
    for (int n, i = 0; i < M; ++i)
    {
        cin >> w[i] >> n;
        for (int x, j = 0; j < n; ++j)
        {
            cin >> x;
            v[i] |= 1 << (x - 1);
        }
        sum |= v[i];
    }
    int ans = -1;
    if (sum == (1 << N) - 1)
    {
        for (int i = 0; i < M; ++i)
            for(int j = 0; j < (1<<N); ++ j)
                dp[j | v[i]] = min(dp[j | v[i]], dp[j] + w[i]);
        ans = dp[(1<<N)-1];
    }
    cout << ans << endl;

    return 0;
}

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

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int N,X,T;
    cin>>N>>X>>T;
    cout<<((N/X)+(N%X!=0))*T<<endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, A, B, C, D);
  print(max(A * B, C * D));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;
int m;
vi dp;

int main(){
	cin>>s>>m;
	int n=s.size(),t=0;
	dp=vi(m);
	for(int i=0;i<n;i++){
		vi DP(m);
		for(int j=0;j<10;j++) for(int k=0;k<m;k++) (DP[(j+k)%m]+=dp[k])%=mod;
		for(int j=0;j<s[i]-'0';j++) (DP[(t+j)%m]+=1)%=mod;
		dp=DP;
		t+=s[i]-'0';
	}
	if(t%m==0) dp[0]++;
	cout<<(dp[0]-1+mod)%mod<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		java.util.Scanner sin = new java.util.Scanner(System.in);
		int a = sin.nextInt();
		int b = sin.nextInt();
		if(-1000 <= a && b <= 1000){
			if(a < b){
				System.out.println("a < b");
			}else if(a > b){
				System.out.println("a > b");	
			}else if(a == b){
				System.out.println("a == b");
			}
		}
	}
}


Measured memory_bytes: 26160
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	S, err := strconv.Atoi(scanner.Text())

	if err != nil {
		panic(err)
	}

	scanner.Scan()
	W, err := strconv.Atoi(scanner.Text())

	if err != nil {
		panic(err)
	}

	if W >= S {
		fmt.Println("unsafe")
	} else {
		fmt.Println("safe")
	}
}

Measured memory_bytes: 1776
N, Y = map(int, input().split())
ans = [-1, -1, -1]
for i in range(N+1):
    for j in range(N-i+1):
        if Y == 10000 * i + 5000 * j + 1000 * (N - i - j):
            ans = [i, j, (N-i-j)]
print(*ans)


Measured memory_bytes: 40812
#include<iostream>
using namespace std;
int gcd(int m,int n)
{
    if(n==0)
    return m;
    return gcd(n,m%n);
}

int main()
{
    int W,H,C;
    cin>>W>>H>>C;
    int g = gcd(W,H);
    cout<<W/g*H/g*C<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

// inf
const ll infl = 1LL << 60;
const int inf = 1 << 30;

struct Edge {
    int from, to, cost;

    Edge() {}
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

using Vertex = vector<Edge>;

int main() {
    int N; cin >> N;
    vector<Vertex> edgesOf(N + 1);
    for (int i = 0; i < N - 1; ++i) {
        int u, v, w; cin >> u >> v >> w;
        edgesOf[u].push_back(Edge(u, v, w));
        edgesOf[v].push_back(Edge(v, u, w));
    }

    vector<int> ans(N + 1, -1);
    ans[1] = 1;
    queue<Vertex> q;
    q.push(edgesOf[1]);
    while (!q.empty()) {
        auto v = q.front();
        q.pop();

        for (auto e : v) {
            if (ans[e.to] == -1) {
                ans[e.to] = ans[e.from];
                if (e.cost % 2 == 1) ans[e.to] ^= 1;

                q.push(edgesOf[e.to]);
            }
        }
    }

    for (int i = 1; i <= N; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 9148
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m, x int
	fmt.Scanf("%d %d %d", &n, &m, &x)
	prices := make([]int, n)
	skills := make([][]int, n)
	for i := 0; i < n; i++ {
		nums := scanIntSlice(m + 1)
		prices[i] = nums[0]
		skills[i] = make([]int, m)
		for j := 0; j < m; j++ {
			skills[i][j] = nums[j+1]
		}
	}

	max := int(math.Pow(2, float64(n)))
	minPrice := math.MaxInt64
	for pat := 0; pat < max; pat++ {
		price := 0
		skill := make([]int, m)
		for i := 0; i < n; i++ {
			if (pat>>byte(i))%2 == 1 {
				for j := 0; j < m; j++ {
					skill[j] = skill[j] + skills[i][j]
				}
				price += prices[i]
			}
		}

		valid := true
		for j := 0; j < m; j++ {
			if skill[j] < x {
				valid = false
			}
		}
		if valid && price < minPrice {
			minPrice = price
		}
	}

	if minPrice == math.MaxInt64 {
		fmt.Println("-1")
	} else {
		fmt.Printf("%d\n", minPrice)
	}

}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}


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

#if debug
#include "printer.hpp"
#define dump(a) cerr << #a << "(" << __LINE__ << ") = " << a << endl;
#else
#define dump(...)
#endif

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a, b) for (int i = (b)-1; i >= a; i--)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;

ll pow(ll x, ll y) {
  ll ret = 1, tmp = x;
  while (y) {
    if (y % 2) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    y /= 2;
  }
  return ret;
}

ll inverse(ll x) { return pow(x, mod - 2); }

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

  ll x, y;
  cin >> x >> y;
  if ((x + y) % 3) {
    cout << 0 << endl;
    return 0;
  }

  ll n = (x + y) / 3;
  x -= n;
  y -= n;

  if (x < 0 || y < 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  rep(i, 0, y) {
    ans = ans * (x + y - i) % mod;
    ans = ans * inverse(i + 1) % mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set; */
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define N 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef ONLINE_JUDGE
#define cerr if(true)cerr
#endif

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
	}
};

ll power(ll x, ll y,ll p)
{
    ll res = 1;     // Initialize result
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;  // Change x to x^2
    }
    return res;
}
// int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a,ll p){return power(a,p-2,p);}

/*
 
REMOVE DEBUG STATEMENTS
CHECK FOR DUPLICATES (SET -> MULTISET)
CLEAR EVERYTHING BEFORE EVERY TESTCASE
ceil(x/2.0)
floor(x/2.0)
 
*/
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

void solve(){
    char c;
    cin>>c;
    if (c<='Z' and c>='A')
    {
        cout<<'A'<<nl;
    }
    else cout<<"a"<<nl;
    return ;
}
int main()
{
    IO;
    int T=1;
	// cin >> T;
	f(c,0,T){
		solve();
	}
    return 0;
}//multiset m make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first false erase double priority_queue


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    string s; cin >> s;
    int l[q],r[q];
    rep(i,0,q) cin >> l[i] >> r[i];

    int rui[n+5];
    rui[0] = 0;
    rep(i,1,s.size()){
        rui[i] = rui[i-1];
        if(s[i-1] == 'A' && s[i] == 'C') rui[i]++;
    }

    rep(i,0,q){
        if(l[i]>1)cout << rui[r[i]-1] - rui[l[i]-1] << endl;
        else cout << rui[r[i]-1] << endl;
    }
}

Measured memory_bytes: 2256
class Dice4():
    def check(self,dice,n):
        count=0
        for i in range(n):
            for j in range(n):
                if i != j:
                    for k in range(4):#縦回転
                        dice[i][0],dice[i][1],dice[i][5],dice[i][4]=dice[i][4],dice[i][0],dice[i][1],dice[i][5]
                        for l in range(4):#横回転
                            dice[i][0],dice[i][2],dice[i][5],dice[i][3]=dice[i][3],dice[i][0],dice[i][2],dice[i][5]
                            for m in range(4):#ひねり
                                dice[i][1],dice[i][2],dice[i][4],dice[i][3]=dice[i][2],dice[i][4],dice[i][3],dice[i][1]
                                if dice[i] == dice[j]:
                                    count+=1
        return count

#Dice3
Dice=[]
n = int(input())
for i in range(n):
    Dice.append([int(i) for i in input().split()])
dc4 = Dice4()
counter = dc4.check(Dice,n)
if counter == 0:
    print('Yes')
else :
    print('No')


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

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	int ini = n / 100;
	int fim = n % 100;
	if(ini <= 12 && fim <= 12 && ini >= 1 && fim >= 1){
		printf("AMBIGUOUS\n");
	}else if((ini > 12 || ini == 0) && (fim == 0 || fim > 12)){
		printf("NA\n");
	}else{
		if(ini <= 12 && ini > 0)printf("MMYY\n");
		else printf("YYMM\n");
	}
	return 0;
}

Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto s = sread();
    auto k = lread();
    // writeln(s);
    // writeln(k);
    foreach (i; 0 .. k)
    {
        if (s[i] != '1')
        {
            writeln(s[i]);
            return;
        }
    }
    writeln(1);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3684
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        
        int cnt = 0;
        for (int i = 0; i < n; i += d * 2 + 1) {
            cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
a,b,c = map(int,input().split())
s = int(input())
f = 0
for i in range(s+1):
  for j in range(0,s-i+1):
    for k in range(0,s-i-j+1):
      if i+j+k != s:
        continue
      else:
        A = a*(2**i)
        B = b*(2**j)
        C = c*(2**k)
        if A < B and B < C:
          f += 1
if f == 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 



int main() {
    ll N, K, ans = 0, tmp = 0;
    cin >> N >> K;
    vector<ll> P(N);
    rep(i, N)
        cin >> P[i];
    
    rep(i, K)tmp += P[i];
    ans = tmp;
    //cout << tmp << endl;
    rep(i, N - K){
        tmp += P[i + K] - P[i];
        chmax(ans, tmp);
        //cout << i << " " << tmp << endl;
    }
    fprintf(stdout, "%f\n", (K +ans)/2.0);
    return 0;
}


Measured memory_bytes: 1792
//    ____       ____                 _           
//   |  _ \ _ __|  _ \  ___ _ __   __| |_ __ ___  
//   | | | | '__| | | |/ _ \ '_ \ / _` | '__/ _ \ 
//   | |_| | |_ | |_| |  __/ | | | (_| | | | (_) |
//   |____/|_(_)|____/ \___|_| |_|\__,_|_|  \___/ 
//                                                

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


#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define f first
#define s second
#define pb push_back
#define ll long long

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll LLOO = 1e18+7;
const ll OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 2e5+7;

int a[N];

int main()
{
	
	int k,n;
	scanf("%d %d",&k,&n);
	int ans = OO;
	rep(i,n)
	{
		scanf("%d",a+i);
		if (i == 0) continue;
		ans = min(ans,k-(a[i]-a[i-1]));
	}
	ans = min(ans,k-(k-a[n-1]+a[0]));
	printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
char s[210];
int main(){
	while(scanf("%s",s),strcmp(s,"-")){
		int m;
		scanf("%d",&m);
		int c=0;
		while(m--){
			int t;
			scanf("%d",&t);
			c+=t;
		}
		c%=strlen(s);
		printf("%s",s+c);
		s[c]=0;
		puts(s);
	}
}



Measured memory_bytes: 2036
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(void){

int n,k,w;
int h[100010];
int dp[100010];

cin >> n;
k = 2;
for(int i = 0; i < n; i++) cin >> h[i];

for(int i = 0;i < n; i++){
    if(i == 0) dp[i] = 0;
    else{
        if(i <= k) w = i;  
        int a[100010];
        for(int j = 0; j < w; j++) a[j] = abs(h[i] - h[i - j - 1]) + dp[i - j - 1];        
        sort(a, a + w);
        dp[i] = a[0];
        }
    }
    
cout << dp[n - 1] << "\n";

}

Measured memory_bytes: 1024
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//#include <ext/pb_ds/detail/standard_policies.hpp>
#include<set>
#include<map>
#include <unordered_map>
#include <unordered_set>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <strings.h>
#include <fstream>
#include <random>


#define f first
#define s second
#define pb push_back
#define lp(i,a,n) for(int (i)=(a);(i)<=(int)(n);(i)++)
#define lpd(i,n,a) for(int (i)=(n);(i)>=(a);--(i))
#define mp make_pair
#define clr(a, b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define eps 1e-8
#define infi 1000000107
#define infll 1000000000000000000ll
#define MX 1000000
#define X real()
#define Y imag()
#define left(i) i<<1
#define right(i) (i<<1)|1
#define polar(r,t) ((r)* exp(point(0,(t))))
#define length(a) hypot( (a).X , (a).Y )
#define angle(a) atan2( (a).Y , (a).X )
#define vec(a,b) ( (b) - (a) )
#define dot(a,b) (conj(a)*(b)).X
#define cross(a,b) (conj(a)*(b)).Y
#define lengthsqr(a) dot(a,a)
#define reflect(V,M) (conj((V)/(M)) * (M))
//#define rotate(a, theta) (a) * (polar(1.0, (theta) ))
#define normalize(a)   ((a)/length(a))
#define ccw(a,b,c) cross(vec(a,b) , vec(a,c)) > eps
#define cosRule(a,b,c) (acos(((a)*(a)+(b)*(b)-(c)*(c))/(2*(a)*(b))))
#define cosDot(a,b) (acos(dot(a,b)/length(a)/length(b)))
#define EQ(a,b) (fabs((a) - (b)) <= eps) /* equal to */
#define NE(a,b) (fabs((a) - (b)) > eps)  /* not equal to */
#define LT(a,b) ((a) < (b) - eps)        /* less than */
#define GT(a,b) ((a) > (b) + eps)        /* greater than */
#define LE(a,b) ((a) <= (b) + eps)       /* less than or equal to */
#define GE(a,b) ((a) >= (b) - eps)       /* greater than or equal to */
#define mod1 1000500001ll
#define mod2 1000300001ll
#define base1 137ll
#define base2 31ll
#define PI acos(-1)
#define sz(a) (int) (a).size()
#define isbit(x,k)  ((x) & (1<<(k))) > 0


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef complex<ll> point;
typedef pair<point, point> line;
typedef pair<ld , point> Circle;
typedef pair<point, int> Point;

//const int N = 100002;

int main() {
    int n,k;
    scanf("%d%d",&n,&k);
    
    
    
    ll ans = 1ll*(n/k)*(n/k)*(n/k);
    
    if(!(k&1)) {
        n -= k/2;
        if(n >= 0) ans += 1ll*(n/k+1)*(n/k+1)*(n/k+1);
    }

    printf("%lld\n",ans);
    return 0;
}



/*
 */

//freopen("output.txt","w",stdout);
//freopen("input.txt","r",stdin);
//ios::sync_with_stdio(0);cin.tie(0);

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue<int, vector<int>, greater<int> > q;从小到大
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-7;
//const db pi=acos(-1);
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (int i=be;i<=en;i++)
using namespace std;
const int N=1e6+7;

int T,n,m,fl=0;
int a[N];
ll sum=0,ans=0;
int main(){
    scanf("%d",&n);
    if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9) puts("hon");
    else if(n%10==1||n%10==0||n%10==6||n%10==8) puts("pon");
    else puts("bon");
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e5 + 5;

int dp[maxn];

int main(){
	int n,i,j,k;
	scanf("%d %d",&n,&k);
	int h[maxn];
	fill(dp, dp+maxn, inf);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(i=2;i<n;i++){
		for(j=1;j<=k;j++){
			if(i-j < 0){break;}
			dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]));
		}
	}

	// for(i=0;i<n;i++){
	// 	printf("dp[%d]: %d\n",i,dp[i]);
	// }

	printf("%d\n",dp[n-1]);
	return 0;
};

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

int f(int a, int b, int c){
  int ans = a*a +b*b +c*c +a*b +b*c +c*a;
  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<int> ans(10005,0);
  for(int i=1; i<101; ++i) for(int j=1; j<101; ++j) for(int k=1; k<101; ++k){
    if(f(i,j,k) >10000) continue;
    ++ans[f(i,j,k)];
  }
  for(int i=1; i<=n; ++i){
    printf("%d\n",ans[i]);
  }
}


Measured memory_bytes: 3708
// AOJ 2968 Non-trivial Common Divisor
// 2019.9.23 bal4u

#include <stdio.h>
#include <string.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void outL(ll n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int sz;
ll s[4500], p[4500]; // # of primes [2,MAX] = 3401

#define MAX  31625
#define SQRT 178
char prime[MAX+3] = { 0,0,1,1,0 };

int sz;
void sieve() {
	int i, j;
	memset(prime, 1, sizeof(prime));
	prime[0] = prime[1] = 0, p[sz++] = 2;
	for (i = 4; i <= MAX; i+=2) prime[i] = 0;
	for (i = 3; i <= SQRT; i += 2) if (prime[i]) {
		p[sz++] = i;
		for (j = i*i; j <= MAX; j += i) prime[j] = 0;
	}
	for (; i <= MAX; i += 2) if (prime[i]) p[sz++] = i;
}

int main()
{
	int i, a, A, N; ll ans;
	
	sieve();
	N = in(); while (N--) if ((A = in()) > 1) {
		a = A;
		for (i = 0; i < sz; i++) if (a % p[i] == 0) {
			s[i] += A;
			do a /= p[i]; while (a % p[i] == 0);
			if (a == 1) break;
		}
		if (a > 1) s[sz] += A, p[sz++] = a;
	}
	ans = 0, i = sz; while (i--) if (s[i] > ans) ans = s[i];
	outL(ans);
	return 0;
}


Measured memory_bytes: 2100
import numpy as np
n, k = map(int, input().split())
v = list(map(int, input().split()))

results = []
for backn in range(k + 1):
    at = k - backn

    t = min(n, at)
    for i in range(0, t + 1):
        for shift in range(i + 1):
            p = v[:i - shift] + v[n - shift:]
            p.sort()
            value = sum(p[backn:])
            results.append(value)
print(max(results))


Measured memory_bytes: 14428