akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define ll long long
#define ld long double

int main() {
	int x, n;
	cin >> x >> n;
	int c;
	set<int> a;
	for (int i = 0; i < n; i++) {
		cin >> c;
		a.insert(c);
	}
	int i = 0;
	while (true) {
		if (a.find(x - i) == a.end()) {
			cout << x - i << endl;
			return 0;
		}
		if (a.find(x + i) == a.end()) {
			cout << x + i << endl;
			return 0;
		}
		
		i++;
	}

	return 0;
}

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

constexpr int nax = 3e5;

int n, tab[nax + 1];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n; n *= 3;

    for (int i = 1; i <= n; ++i)
        cin >> tab[i];

    sort(tab + 1, tab + n + 1);

    long long res = 0;

    for (int cnt = 0, i = n - 1; cnt < n / 3; ++cnt, i -= 2)
        res += tab[i];

    cout << res << '\n';
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef vector<ll> vll;

#define rep(var,n)  for(int var=0;var<(n);++var)


int cnt[40][2];

ll uso_desho(int N, ll K, vll& a) {
    for (int i=0; i<N; ++i) {
        for (ll b=0,m=1; b<40; ++b,m<<=1) cnt[b][!!(a[i] & m)]++;
    }

    ll x=0, ans=0;
    for (int b=39; b>=0; --b) {
        ll x_ = x + (1LL << b);
        if (x_ <= K) {
            if (cnt[b][0] > cnt[b][1]) {
                ans = ans*2 + cnt[b][0];
                x = x_;
            } else {
                ans = ans*2 + cnt[b][1];
            }
        } else {
            ans = ans*2 + cnt[b][1];
        }
    }
    return ans;
}

int main() {
    int N; ll K; scanf("%d%lld",&N,&K);
    vll a(N); rep(i,N) scanf("%lld", &a[i]);
    cout << uso_desho(N,K,a) << endl;
    return 0;
}


Measured memory_bytes: 1024
a = Array.new
b = Array.new
a[0], b[0] = gets.split.map(&:to_i)
i = 0
while a[i] != 0 && b[i] != 0 do
	i += 1
	a[i], b[i] = gets.split.map(&:to_i)
end
i = 0
while a[i] != 0 && b[i] != 0 do
	l = 0
	for j in 1..a[i] do
		for k in 1..b[i] do
			if l % 2 == 0
				print "#"
			else
				print "."
			end
			l += 1
		end
		puts
		if j % 2 == 1
			l = 1
		else
			l = 0
		end
	end
	puts
	i += 1
end

Measured memory_bytes: 8656
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		long K=Long.parseLong(br.readLine());
		String []s=br.readLine().split(" ");
		long A=Long.parseLong(s[0]);
		long B=Long.parseLong(s[1]);
		boolean flag=false;
		String ans="";
		
		for(long i=A;i<=B;i++)
		{
			if(i%K == 0)
			{
				flag=true;
				break;
			}
		}
		
		if(flag==true)
			ans="OK";
		else
			ans="NG";
			
		out.println(ans);
		
	}
	
	
}




Measured memory_bytes: 32588
class dice init =
  let rot_n (x1,x2,x3,x4,x5,x6) = (x2,x6,x3,x4,x1,x5) and
      rot_e (x1,x2,x3,x4,x5,x6) = (x4,x2,x1,x6,x5,x3) in
  let rot_s l = rot_n l |> rot_n |> rot_n and
      rot_w l = rot_e l |> rot_e |> rot_e in
  let all_init =
    let rec rotate d list = function
        0 -> list
      | i -> rotate (rot_e d) (d::list) (i-1) in
    let rotate2 n l = rotate n l 4 in
    rotate2 init []
    |> rotate2 (rot_e init |> rot_s)
    |> rotate2 (rot_w init |> rot_s)
    |> rotate2 (rot_n init)
    |> rotate2 (rot_s init)
    |> rotate2 (rot_n init |> rot_n) in
object (self: 'self)
  val mutable faces:int*int*int*int*int*int = init
  val all:'a list = all_init

  method get_face = faces
  method get_all = all
  method equals (other:'self) = self#contains other#get_face
  method contains fc =
    let rec find l = match l with
        [] -> false
      | h::tl -> if h = fc then true else find tl
    in find all
end;;

let split_int s = Str.split (Str.regexp_string " ") s |> List.map int_of_string;;
let () =
  let f n = (n 0,n 1,n 2,n 3,n 4,n 5) in
  let nth s = split_int s |> List.nth in
  let d1 = new dice (read_line () |> nth |> f) and
      d2 = new dice (read_line () |> nth |> f) in
  if d1#equals(d2) then print_endline "Yes"
  else print_endline "No"
;;

Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll C(ll a){
	return (a*(a-1))/2;
}
int main() 
{
	int mod = 998244353;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;

	ll dp[c+1][d+1];
	REP(i,0,c+1){
		REP(j,0,d+1){
			dp[i][j] = 0;
		}
	}
	dp[a][b] = 1;
	REP(i,b+1,d+1){
		dp[a][i] = (dp[a][i-1]*a) % mod;
	}
	REP(i,a+1,c+1){
		dp[i][b] = (dp[i-1][b]*b) % mod;
	}
	REP(i,a+1,c+1){
		REP(j,b+1,d+1){
			// dp[i][j] = (dp[i-1][j-1]*(C(i+j-1) - C(i-1) - C(j-1)) + mod) % mod;
			dp[i][j] = ((dp[i-1][j]*j) % mod + (dp[i][j-1]*i) % mod - (((dp[i-1][j-1]*(i-1)) % mod)*(j-1)) % mod + mod) % mod;
		}
	}
	// REP(i,1,c+1){
		// REP(j,1,d+1){
			// cout<<dp[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	cout<<dp[c][d]<<endl;

	return 0;
}

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

typedef vector<int>::iterator V;

int main(){
    int n,i,j;
    cin >> n;
    vector< vector<int> > v(3, vector<int>(n));
    vector< vector<int> > cp(3, vector<int>(n));
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            cin >> v[j][i];
            cp[j][i] = v[j][i];
        }
    }
    for(i=0;i<3;i++){
        sort(cp[i].begin(), cp[i].end());
    }
    vector<int> point(n,0);
    for(i=0;i<3;i++){
        for(j=0;j<n;j++){
            V low = lower_bound(cp[i].begin(), cp[i].end(), v[i][j]);
            V up = upper_bound(cp[i].begin(), cp[i].end(), v[i][j]);
            if( up-low == 1 ) point[j] += v[i][j];
        }
    }
    for(i=0;i<n;i++){
        cout << point[i] << endl;
    }
    return 0;
}

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

using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n+1);   
    a[1] = 0;
    b[1] = 0;

    for(int i = 2;i <= n;i++){
    cin >> a[i];
    b[i] = 0;
        }
    for(int i = 2;i <= n;i++){
    b[a[i]]++;
        }
    for(int i = 1;i <= n;i++){
    cout << b[i] << endl;
        }
    return 0;
}

Measured memory_bytes: 4844
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	var a [][]int
	var b []int
	var c []int

	n, m := nextInt(), nextInt()
	a = make([][]int, n)
	b = make([]int, m)
	c = make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			a[i][j] = nextInt()
		}
	}
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			c[i] += a[i][j] * b[j]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d\n", c[i])
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}



Measured memory_bytes: 1340
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

d,n = na()
if d == 0:
    if n == 100:
        print(101)
    else:
        print(n)
elif d == 1:
    if n == 100:
        print(10100)
    else:
        print(n*100)
else:
    if n == 100:
        print(1010000)
    else:
        print(n*10000)


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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<int64_t>> G(H, vector<int64_t>(W, 0));
  for (int i = 0; i < K; i++) {
    int x, y, v;
    cin >> x >> y >> v;
    x--, y--;
    G[x][y] = v;
  }
  vector<vector<vector<int64_t>>> dp(H, vector<vector<int64_t>>(W, vector<int64_t>(4, 0)));
  dp[0][0][1] = G[0][0];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k <= 3; k++) {
        if (i + 1 < H) chmax(dp[i + 1][j][0], dp[i][j][k]);
        if (i + 1 < H) chmax(dp[i + 1][j][1], dp[i][j][k] + G[i + 1][j]);
        if (j + 1 < W) chmax(dp[i][j + 1][k], dp[i][j][k]);
        if (j + 1 < W && k < 3) chmax(dp[i][j + 1][k + 1], dp[i][j][k] + G[i][j + 1]);
      }
    }
  }
  cout << *max_element(dp[H - 1][W - 1].begin(), dp[H - 1][W - 1].end()) << '\n';
  return 0;
}


Measured memory_bytes: 706684
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int i,n,ans=0,a[101]={};
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
        if((i+1)*a[i]%2==1)ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

int main(){
    int N,Q;
    cin >> N >> Q;
    vector<vector<int>> v(N+1);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector<int> q(N+1);
    for(int i=0;i<Q;i++){
        int p,x;
        cin >> p >> x;
        q[p] += x;
    }
    vector<int> ans(N+1);
    function<void(int,int,int)> dfs = [&](int n,int m,int value){
        ans[n] = value+q[n];
        for(auto x:v[n]) if(x!=m){
            dfs(x,n,value+q[n]);
        }
    };
    dfs(1,0,0);
    for(int i=1;i<=N;i++) cout << ans[i] << (i!=N? " ":"\n");
}


Measured memory_bytes: 33664
n = int(input())
B = list(map(int, input().split()))


A0 = B[0]
An = B[-1]
A = []
A.append(A0)
for i in range(n - 2):
    a = min(B[i], B[i + 1])
    A.append(a)
A.append(An)

print(sum(A))


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

int main()
{

    string s, hitachi = "";
    cin >> s;

    for(int i=0; i<5; i++)
    {
        hitachi += "hi";
        if(hitachi == s)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = 1, old_mode = 0;
  for (int i = 0; i < n - 1; i++) {
    int cur_mode = 0; // a[i] == a[i + 1]
    if (a[i] < a[i + 1]) cur_mode = 1;
    if (a[i] > a[i + 1]) cur_mode = 2;
    if (cur_mode == 0) continue;
    if (old_mode == 0) {
      old_mode = cur_mode;
    }
    else if (old_mode != cur_mode) {
      ans++;
      old_mode = 0;
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 4000
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define REP(i,a,n) for(int i = (a); i < (n); i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int A, B, T;
	cin >> A >> B >> T;
	cout << T / A * B << endl;
}

Measured memory_bytes: 764
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    int long long a,b,h,m;
    cin >> a >> b >> h >> m;

    double degh = 30*h+0.5*m;
    double degm = 6*m;
    double rad = abs(degh-degm);
    double pi = 3.141592653589793238;

    double c = a*a+b*b-2*a*b*cos(rad/180*pi);
    printf("%.12f\n", sqrt(c));
    //cout << sqrt(c) << endl;
    return 0;
}

Measured memory_bytes: 4156
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<map>
#include<queue>
#include<assert.h>
#include<stdio.h>
#include<stack>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
#define FAST_IO std::ios::sync_with_stdio(false),std::cout.tie(0),std::cin.tie(0)
const int N= 200010,M=200010;
int head[N],ver[M],edge[M],Next[M],d[N];
int n,m,tot;
queue<int> q;
bool v[N];
void add(int x,int y,int z){
	ver[++tot]=y;
	edge[tot]=z;
	Next[tot]=head[x];
	head[x]=tot;
}
void spfa(){
	memset(d,0x3f3f,sizeof(d));
	memset(v,0,sizeof(v));
	d[1]=0;
	v[1]=1;
	q.push(1);
	while(q.size()){
		int x=q.front();
		q.pop();
		v[x]=0;
		for(int i=head[x];i;i=Next[i]){
			int y=ver[i],z=edge[i];
			if(d[y]>d[x]+z){
				d[y]=d[x]+z;
				if(!v[y])q.push(y),v[y]=1;
			}
		}
	}
}
int main()
{
	FAST_IO;
	while(cin>>n>>m){
		for(int i=1;i<=m;i++){
			int x,y,z;
			cin>>x>>y;
			add(x,y,1);
		}
		spfa();
		if(d[n]>2)cout<<"IMPOSSIBLE"<<endl;
		else cout<<"POSSIBLE"<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 100000

inline ll C1(ll n) { return n; }
inline ll C2(ll n) { return n*(n-1)/2; }
inline ll C3(ll n) { return n*(n-1)*(n-2)/6; }
inline ll f(ll n) { return C1(n) + 6*C2(n) + 6*C3(n); }

int main() {
	ll n, k;
	scanf("%lld%lld", &n, &k);

	if(k&1) {
		ll d = n/k;
		printf("%lld\n", f(d));
	} else {
		ll d = n/(k/2);
		printf("%lld\n", f(d/2) + f((d+1)/2));
	}
}

Measured memory_bytes: 256
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int b,r,g,c,s,t;
    while(cin>>b>>r>>g>>c>>s>>t){
        if(b||r||g||c||s||t);else break;
        int br=b*5+r*3;
        t-=br;
        int ans=100;
        ans-=3*(t-s)+2*(br);
        ans+=g*7;
        ans+=br*15;
        ans+=c*2;
        ans+=(b+r)*15;
        cout<<ans<<endl;
    }
    return 0;
}

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

tunagari = [[] for i in range(n)]
sirusi = [-1 for i in range(n)]
sirusi[0] = 0

for i in range(m):
    a,b = map(lambda x : int(x)-1, input().split())
    tunagari[a].append(b)
    tunagari[b].append(a)

que = [0]
while que:
    for i in tunagari[que[0]]:
        if sirusi[i] == -1:
            sirusi[i] = que[0]
            que.append(i)
    que.pop(0)

sirusi.pop(0)
print("Yes")
for i in sirusi:
    print(i+1)


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

#define mod 1000000007

#define rep(i, n) for(int i=0; i<n; ++i)

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

int main(void){
	
	int N;
	
	cin >> N;
	
	int count = N;
	
	rep(i, N + 1){
		int cc = 0;
		int t = i;
		while(t > 0){
			cc += t % 6;
			t /= 6;
		}
		t = N - i;
		while(t > 0){
			cc += t % 9;
			t /= 9;
		}
		count = min(count, cc);
	}
	
	cout << count << endl;
	
	return 0;
}

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

int main() {
    long long n;
    cin >> n;
    string res = "";
    while (n) {
        n--;
        res += (char)('a' + (n % 26));
        n /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3600
while 1:
    n=int(input())
    if not n:break    
    t=0
    cnt=0
    for i in range(2,n+1):
        o=n//i
        t+=(i-1) 
        p=n-(i*o-t)
        if o+p//i+1-i<1:break
        if p%i==0:cnt+=1
    print(cnt)



Measured memory_bytes: 5592
/*input
*/
#define debug 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
const int N = 1e7 + 5, M = 1e9 + 7; const db eps = 1e-8;
typedef vector<ll> vi; typedef vector<vi> vii;
void solve();
void print(){cout<<'\n';}template<class T,class ...U>void print(T x, U ...y){cout<<x<<' ';print(y...);}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << setprecision(2) << fixed;
  if(debug){freopen("main.cpp","r",stdin);string x;cin>>x;}
  solve();
}
//

void solve() {
  int a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  for (int i = 0; i < b; i++) {
    cout << a;
  }
}


Measured memory_bytes: 256
from numpy import int64, bitwise_xor

N, *A = map(int, open(0).read().split())
A = int64(A)

x = bitwise_xor.reduce(A)
A &= ~x

res = 0
while A.any():
    ma = A.max()
    msb = 1 << (int(ma).bit_length() - 1)

    A[(A & msb) > 0] ^= ma

    res ^= ma * (not res & msb)

print(x + 2 * res)

Measured memory_bytes: 24028
/*c++11*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;
    
vector<int> table;

int solve1(){
  int count=1,res=0;
  int a=*table.begin(),b;
  for(auto it=table.begin()+1;it!=table.end();it++){
    b=*it;
    if(b==a+1)
//      cout<<"b:"<<b<<" ",
      count++;
    else {
      if(count>res)
        res=count;
      count=1;
    }
    a=b;
  }
  return res;
}
int solve2(){
  int count=1,res=0;
  vector<int> len;
  vector<bool> canConnect;
  
  int a=*table.begin(),b;
  for(auto it=table.begin()+1;it!=table.end();it++){
    b=*it;
    if(b==a+1)
      count++;
    else{
      len.push_back(count);
      count=1;
      if(b==a+2)
        canConnect.push_back(true);
      else canConnect.push_back(false);
    }
    a=b;
  }
  len.push_back(count);
  
  vector<int> connect;
  connect.push_back(len[0]);
  for(int ix=0;ix<canConnect.size();ix++){
    if(canConnect[ix]==true)
      connect.push_back(len[ix]+len[ix+1]);
    else
      connect.push_back(len[ix]);
  }

  int maxium=0;
  for(auto ix=connect.begin();ix!=connect.end();ix++)
    if(*ix>maxium)
      maxium=*ix;
  res=maxium+1;

/*
  cout<<endl<<"table:"<<endl;
  for(auto i:table)
    cout<<i<<" ";
  cout<<endl<<"len:"<<endl;
  for(auto i:len)
    cout<<i<<" ";
  cout<<endl<<"canConnect:"<<endl;
  for(auto i:canConnect)
    cout<<i<<" ";
  cout<<endl<<"connect:"<<endl;
  for(auto i:connect)
    cout<<i<<" ";
  cout<<endl;
 */ 
  
  return res;
}

int main(int args, char *argc[]){
  static int n,k;
  while(cin>>n>>k,n&&k){
//    cout<<n<<" "<<k<<endl;
    bool flag=false;
    int tmp;
    table.clear();
    for(int i=0;i<k;i++){
      cin>>tmp;
      table.push_back(tmp);
      if(tmp==0) flag=true;
    }
    sort(table.begin(),table.end());
    if(flag)
      tmp=solve2();
    else 
      tmp=solve1();
    cout<<tmp<<endl;
  }
  return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define minit(a, b) memset(a, b, sizeof(a))

int H, board[11][6];
const int NIL = -1;

bool fall(int x, int y) {
	if (board[y][x] == NIL) return false;
	
	if (board[y-1][x] == NIL) {
		board[y-1][x] = board[y][x];
		board[y][x] = NIL;
		return true;
	}
	
	return false;
}

void erase(int x, int y, int len) {
	for_(xx,x,x+len) board[y][xx] = NIL;
}

int vanish(int y) {
	int x = 0, cur = board[y][0], len = 1;
	
	while (x <= 2) {
		if (cur != NIL) {
			while (cur == board[y][x+len]) ++len;
		}
		
		if (len >= 3) break;
		x += len;
		cur = board[y][x];
		len = 1;
	}
	
	if (len < 3) return 0;
	erase(x, y, len);
	return cur * len;
}

void solve() {
	int score = 0;
	
	while (1) {
		int add = 0;
		
		for_(y,0,H) add += vanish(y);
		
		for_(y,1,H) {
			for_(x,0,5) {
				if (fall(x, y)) {
					y = 0;
					break;
				}
			}
		}
		
		if (add == 0) break;
		score += add;
	}
	
	cout << score << endl;
}

int main() {
	while (cin >> H, H) {
		minit(board, NIL);
		for_rev(y,H-1,0) for_(x,0,5) cin >> board[y][x];
		solve();
	}
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  for(int i=0; i < n; ++i) scanf("%d",&a[i]);
  for(int i=0; i < n; ++i) scanf("%d",&b[i]);

  int not,not_min,min_index; //not = とらないアメ
  min_index = 0; //a[0] -> b[0] -> b[1] -> ...
  not = 0;
  for(int i=1; i < n; ++i) not += a[i];
  not_min = not;
  for(int i=0; i < n-1; ++i){
    not += b[i];
    not -= a[i+1];
    if(not < not_min){
      not_min = not;
      min_index = i + 1;
    }
  }
  
  int sum = 0;
  for(int i=0; i <= min_index; ++i) sum += a[i];
  for(int i = min_index; i < n; ++i) sum += b[i];
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
	int N; cin >> N;
	int A[100010];
	for (int i = 1; i <= N; ++i) cin >> A[i];
	int S = abs(A[1]);
	int T = 0;
	for (int i = 1; i <= N; ++i) {
		S += abs(A[i] - A[i + 1]);
	}
	for (int i = 1; i <= N; ++i) {
		T = S + abs(A[i - 1] - A[i + 1]) - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]);
		cout << T << endl;
	}
}


Measured memory_bytes: 1664
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let n: usize = read_as_vec()[0];
    let c = read_as_string();
    let r_num = c.chars().filter(|x| *x == 'R').count();
    let w_num = n - r_num;

    println!("{}", c.chars().take(r_num).filter(|x| *x == 'W').count());
}


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

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

    int counter = 0;
    int INF = 100000000;
    for (int i = 0; i < INF; i++){
        N /= K;
        counter++;
        if (N == 0)break;
    }

    cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    ll n,k; cin >> n >> k;
    ll ans = 0;
    while(n > 0){
        n/=k;
        ans++;
    }
    cout << ans;
}


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

const int maxn = 1e5+10;

int n, a, b, c, cnt[3][maxn];
string str[maxn];
vector<char> ans;

int main() 
{
    cin>>n>>a>>b>>c;
    for(int i = 0; i < n; i++) {
    	cin>>str[i];
	} 
    for(int i = 0; i < n; i++) {
    	string s = str[i];
    	if(s == "AB") {
    		if(a == 0 && b == 0) {
    			cout<<"No"<<endl;
    			return 0;
			}else {
				if((a < b) || (a == b &&str[i+1]=="AC")) {
					++a, --b;
					ans.push_back('A');
				}else {
					--a, ++b;
					ans.push_back('B');
				}
			}
		}else if(s == "AC") {
    		if(a == 0 && c == 0) {
    			cout<<"No"<<endl;
    			return 0;
			}else {
				if((a < c) || (a == c && str[i+1]=="AB")) {
					++a, --c;
					ans.push_back('A');
				}else {
					--a, ++c;
					ans.push_back('C');
				}
			}
		}else {
    		if(b == 0 && c == 0) {
    			cout<<"No"<<endl;
    			return 0;
			}else {
				if((b < c) || (b == c &&str[i+1]=="AB")) {
					++b, --c;
					ans.push_back('B');
				}else {
					--b, ++c;
					ans.push_back('C');
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i = 0; i < ans.size(); i++) {
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 6888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  //ll n, m;
  string a, b;
  cin>>a>>b;
  ll m=a.size(), n=b.size();
  vector< vector<ll> >lcs(n+1, vector<ll>(m+1,0));
  for(ll i=1;i<=n;i++)
  {
    for(ll j=1;j<=m;j++)
    {
     if((b[i-1])==(a[j-1]))
      lcs[i][j]=lcs[i-1][j-1]+1;
     else
       lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
     //cout<<lcs[i][j]<<" ";
    }
    //cout<<"\n";
  }
  ll k=0;
  vector<ll>ind;
  ll x=n,y=m;

  while(k<lcs[n][m])
  {
    if(((b[x-1])==(a[y-1])) && (lcs[x][y]==lcs[x-1][y-1]+1))
    {
      ind.push_back(y-1);
      k++;
      x--;y--;
    }
    else{
      if(lcs[x][y]==lcs[x][y-1])
        y--;
      else
        x--;
    }
  }
  for(ll i=k-1;i>=0;i--)
    cout<<a[ind[i]];
    
  return 0;
}

Measured memory_bytes: 70784
/**
*    author:  souzai32
*    created: 01.08.2020 22:48:50
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    string s;
    cin >> s;
    int n=s.size();
    vector<char> key(7);
    bool ans=false;

    for(int i=0; i<=7; i++){
        for(int k=0; k<i; k++){
            key.at(k)=s.at(k);
        }
        for(int k=0; k<7-i; k++){
            key.at(i+k)=s.at(n-7+i+k);
        }
        if(key.at(0)=='k'&&key.at(1)=='e'&&key.at(2)=='y'&&key.at(3)=='e'&&key.at(4)=='n'&&key.at(5)=='c'&&key.at(6)=='e') ans=true;
        if(ans) break;
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int h, w;
	cin >> h >> w;
	vector<string> field(h);
	for (int i = 0; i < h; ++i) cin >> field[i];
	bool ok = true;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			bool sharp = false;
			if (field[i][j] == '#') {
				if (i - 1 >= 0) if (field[i - 1][j] == '#') sharp = true;
				if (j - 1 >= 0) if (field[i][j - 1] == '#') sharp = true;
				if (i + 1 <  h) if (field[i + 1][j] == '#') sharp = true;
				if (j + 1 <  w) if (field[i][j + 1] == '#') sharp = true;
			}
			if (field[i][j] == '#' && sharp == false) ok = false;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

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

    int x = c[0][0] + c[1][1] + c[2][2];
    int y = c[0][1] + c[1][2] + c[2][0];
    int z = c[0][2] + c[1][0] + c[2][1];

    if (x == y && x == z && y == z)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall AISing2019B.cpp -o .\out\AISing2019B.out
.\out\AISing2019B.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if (500*i+100*j+50*k==x) ++ans;
      }
    }
  }
  cout << ans << "\n";
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

#define Max 10000000

ll fact[Max],fact_inv[Max];

ll power(ll a,ll b){
  ll res=1;
  while(b>0){
    if(b&1)res=res*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return res;
}

ll comb(ll n,ll r){
  return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

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

  fact[0]=1;
  for(ll i=0;i<Max-1;i++)fact[i+1]=fact[i]*(i+1)%MOD;
  fact_inv[Max-1]=power(fact[Max-1],MOD-2);
  for(ll i=Max-2;i>=0;i--)fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
  ll X,Y;
  cin>>X>>Y;
  ll D=X+Y;
  if(D%3){
    cout<<0<<endl;
    return 0;
  }
  D/=3;
  ll DD=abs(X-Y);
  ll n=(D+1-DD)/2+DD;
  if(n<0||n>D){
    cout<<0<<endl;
    return 0;
  }
  cout<<comb(D,n)<<endl;
  return 0;
}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    string S;
    cin >> S;
    string acgt = "ACGT";
    int ans = 0;
    int cnt = 0;
    rep(i, S.size())
    {
        bool flag = false;
        rep(j, 4)
        {
            if (S[i] == acgt[j])
            {
                flag = true;
            }
        }
        if (flag)
            cnt++;
        else
        {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
 
        signed main() {
 
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin>>n;

        string str;
        cin>>str;
        vector<int> v;
        int ans=0;
        int r=0;
        for(int i=0;i<n;i++){
            if(str[i]=='R')
                r++;
        }

        for(int i=0;i<r;i++){
            if(str[i]=='W')
                ans++;
        }
        cout<<ans;

        return 0;
    }
    

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 2e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n;
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >>  n;
	int ans = 0;
	for(int i=1; i<=n; i++) ans += i*(n-i+1);
	for(int i=1; i<n; i++){
		int u, v; cin >> u >> v;
		if (u > v) swap(u, v);
		ans -= u*(n-v+1);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3656
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)

	a := next()
	b := next()

	p, _ := strconv.Atoi(a + b)

	for i := 0; i < 1000; i++ {
		if i * i == p {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

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

int checku[100001];
int checkv[100001];
vector <int> adj[100001];

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

    int n,u,v;

    memset(checkv,-1,sizeof(checkv));
    memset(checku,-1,sizeof(checku));

    cin >> n >> u >> v;

    for(int i=0;i<n-1;i++)
    {
    	int a,b;
    	cin >> a >> b;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }

    checku[u] = 0;
    queue <int> que;
    que.push(u);

    while(!que.empty())
    {
    	int now = que.front();
    	que.pop();

    	for(auto next : adj[now])
    	{
    		if(checku[next]==-1)
    		{
    			checku[next] = checku[now] + 1;
    			que.push(next);
    		}
    	}
    }

    int res = 0;
    checkv[v] = 0;
    que.push(v);

    while(!que.empty())
    {
    	int now = que.front();
    	que.pop();
    	bool isleaf = true;
    	for(auto next : adj[now])
    	{
    		if(checkv[next]==-1)
    		{
    			isleaf = false;
    			checkv[next] = checkv[now] + 1;
    			/*
    			if(checku[next] >= checkv[next])
    			{
    				continue;
    			}
    			*/
    			que.push(next);
    		}
    	}
    	if(isleaf)
    	{
    		if(res < checkv[now] - 1 && checku[now]<checkv[now])
    		{
    			res = checkv[now] - 1;
    		}
    	}
    }  

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 6656
import java.util.Scanner;
import java.util.Vector;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        shellSort(a, a.length);
    }

    static Vector<Integer> ve = new Vector<Integer>();
    static long cut=0;

    private static void shellSort(int[] a, int length) {
        int h=1;
        while(h<=length){
            ve.add(h);
            h=3*h+1;
        }
        for (int i=ve.size()-1;i>=0;i--){
           insertSort(a,length,(Integer)ve.get(i));
        }
        System.out.println(ve.size());
        for (int  i= ve.size()-1;i>=0;i--){
            System.out.print(ve.get(i)+" ");
        }
        System.out.println("\n"+cut);
        for (int i=0;i<a.length-1;i++){
            System.out.println(a[i]);
        }
        System.out.print(a[a.length-1]);
    }

    private static void insertSort(int[] a, int length, Integer n) {
        for(int i=0;i<n;i++){
            for (int j=i+n;j<length;j=j+n){
                int m= a[j];
                int l =j-n;
                while (l>=i&&a[l]>m){
                    a[l+n]=a[l];
                    l-=n;
                    cut++;
                }
                a[l+n]=m;
            }
        }
    }
}



Measured memory_bytes: 299612
s = input()
if s[0] == "A" and s[2:-1].count("C") == 1:
  i = s.index("C")
  ss = s[1:i] + s[i+1:]
  if ss.islower() == True:
    print("AC")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3060
#include <iostream>
#include <assert.h>

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

    int64_t N,M;
    std::cin >> N >> M;
    assert(1 <= N);
    int64_t num_odd = 0;
    if(N == 1 && M == 1){
        num_odd = 1;
    }
    else if(N == 1){
        num_odd = M - 2;
    }
    else if(M == 1){
        num_odd = N -2;
    }
    else{
        num_odd = (N - 2) * (M - 2);
    }
    std::cout << num_odd << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,m,q; cin >> n >> m >> q;
    int num[n][n];
    rep(i,n)rep(j,n)num[i][j]=0;
    
    rep(i,m){
        int l,r; cin >> l >> r;
        l--; r--;
        num[l][r]++;
    }
    repp(i,n){
        repp(j,n){
            if(i+1<n)num[i][j]+=num[i+1][j];
        }
    }
    rep(i,n){
        rep(j,n){
            if(j>0)num[i][j]+=num[i][j-1];
        }
    }
    rep(i,q){
        int l,r; cin >> l >> r;
        l--; r--;
        cout << num[l][r] << endl;
    }
}


Measured memory_bytes: 1920
import sys

def main():
  input = sys.stdin.readline
  A, B, C, X, Y = map(int, input().split())
  ans = float('INF')
  for i in range(max(X, Y)+1):
    cur = C * 2 * i + max(0, X - i) * A + max(0, Y - i) * B
    ans = min(ans, cur)
  print(ans)


if __name__ == '__main__':
  main()

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

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> p(n);
    for(int i = 0; i < n; i++){
        std::cin >> p[i];
    }
    bool flag, flag2;
    flag = 0;
    flag2 = 0;
    for(int k = 0; k < n-1; k++){
        if(p[k] > p[k+1]){
            flag = 1;
            break;
        }
    }
    if(!flag){
        std::cout << "YES" << std::endl;
        flag2 = 1;
    }
    if(!flag2){
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                flag = 0;
                std::swap(p[i], p[j]);
                for(int k = 0; k < n-1; k++){
                if(p[k] > p[k+1]){
                    std::swap(p[i], p[j]);
                    flag = 1;
                    break;
                }
                }
                if(!flag){
                std::cout << "YES" << std::endl;
                flag2 = 1;
                }
            }
        }
    }

    if(!flag2){
        std::cout << "NO" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);

rep(i, n){
    cin >> a[i];
    a[i] = a[i]-(i + 1);
}
sort(a.begin(), a.end());
ll median;
if(a.size()%2!=0){
    median = a[(n - 1) / 2];
}
else{
    median = (a[n / 2 - 1] + a[n / 2])/2;
}
ll ans = 0;
rep(i,n){
    ans += abs(median - a[i]);
}
cout << ans << endl;
//system("pause");
return 0;
}

Measured memory_bytes: 1024
# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n-1):
    if a[i] > a[i+1]:
        ans += a[i] - a[i+1]
        a[i+1] = a[i]

print(ans)

Measured memory_bytes: 32184
import sys
import os
S = input()
lenght = len(S)
flg = 0
if lenght == 2 and S[0] == S[1]:
    print(1,2)
    sys.exit()

for i in range(lenght-2):
    if S[i] == S[i+1]:
        print(i+1,i+2)
        sys.exit()
    if S[i] == S[i+2]:
        print(i+1,i+3)
        sys.exit()
print(-1,-1)


Measured memory_bytes: 3188
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    while 1:
        n = int(readline())
        if not n:
            exit()

        pre = [0] * (n+1)
        now = [0] * (n+1)
        maximum = 0

        for _ in range(n):
            for x, c in enumerate(readline().rstrip(), 1):
                if c == '.':
                    now[x] = min(pre[x-1], pre[x], now[x-1]) + 1
                    if maximum < now[x]:
                        maximum = now[x]

            for x in range(1, n+1):
                pre[x] = now[x]
                now[x] = 0

        print(maximum)


main()

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> v;
    for (int i = 0; i < N; i++) v.push_back(0);
    for (int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            a -= 1;
            v.at(a) += 1;
        }
    }
    int ret = 0;
    for(int s : v){
        if (s == 0) ret += 1;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  if (A == B && B == C) {
    cout << 0 << endl;
    return 0;
  }

  if (K == 0) {
    cout << A - B << endl;
    return 0;
  }


  if (K % 2 == 0) {
    cout << A - B << endl;
  } else {
    cout << B - A << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H, W;
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        for(int h = 0; h < H; h++){
            for(int w = 0; w < W; w++){
                if(h != 0 && h != H - 1 && w != 0 && w != W - 1){
                    printf(".");
                }else{
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2096
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;

int main() {
	int N, M, cnt = 0;double all = 0; cin >> N >> M;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
		all += A[i];
	}
	all = all / (double)(4 * M);
	rep(i, N) {
		if (A[i] >=all) {
			cnt++;
		}
	}
	if (cnt >= M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())


a=II()
print(a*a)


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n = s_in()
if '7' in n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61840
n=int(input())
if(n==2):
  print(n)
  exit()
if(n==3):
  print(n)
  exit()
for i in range(10000):
  hoge=n+i
  ans=0
  for j in range(int(hoge**0.5)):
    if(hoge%(j+2)!=0):
      ans+=1
  if(ans==int(hoge**0.5)):
    print(hoge)
    exit()

Measured memory_bytes: 3060
import math
a, b, h, m = map(int,input().split())
pi = 0

#円周率
for i in range(1, 100, 2):
    pi += (-1) ** (i // 2) * (1 / 2 ** i + 1 / 3 ** i) / i
pi = pi * 4 

x = (30 * h + 0.5 * m - 6 * m) * pi / 180

d = a * a + b * b - 2 * a * b * math.cos(x)
print(d ** 0.5)


Measured memory_bytes: 9472