akhauriyash/Code-Regression huggingface dataset:
n = int(input())
li = ["#"*20 if i%4==0 else "0"*10 for i in range(1, 16)]
for _ in range(n):
    b, f, r, v = map(int, input().split())
    h = 4*b-(4-f)-1
    li[h] = li[h].replace(li[h], ''.join([str(int(list(li[h])[r-1])+v) if i == r-1 else list(li[h])[i] for i in range(10)]))
li = [' '+' '.join(li[i]) if (i+1)%4!=0 else li[i] for i in range(len(li))]
print('\n'.join(li))


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ms(x, t) memset(x, t, sizeof(x))
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define endl "\n"
typedef pair<int, int> pll;
typedef pair<int, pll> plll;
typedef vector<int> vl;
typedef vector<vector<int>> vvl;
typedef vector<pll> vpll;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int limit = 1e5 + 1;
const int inf = 1e7;
const int mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;
}

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

int solve(int a, int b){
    int r;
    r = a % b;

    if(r == 0){
        return b;
    }else{
        return solve(b, r);
    }
}

int main(){
    int a, b;
    int gcd, lcm;

    while(cin >> a >> b){
        gcd = solve(a, b);

        cout << gcd << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
double ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		double x;
		char s[10];
		scanf("%lf%s",&x,s+1);
		if(s[1]=='J')
			ans+=x;
		else
			ans+=380000*x;
	}
	printf("%.8lf\n",ans);
	return 0;
}

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

using namespace std;

int main()
{
	string s, t;
  	cin >> s >> t;
  
  	int res = 0;
  
  	for(int i = 0; i < (int)s.size(); ++i)
    {
    	 if(s[i] != t[i])
           ++res;
    }
  
  	cout << res << '\n';
}

Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){

    ll n, num;
    cin >> n;
    ll ans = 0;

    rep(i,n){
        num = n / (i + 1);
        ans += (i + 1)  * (num * (num + 1)  / 2);
    }

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(ll b, ll n) { return (n < b ? n : f(b, n / b) + n % b); }
int main() {
    ll n, s;
    cin >> n >> s;
    if (s == n) { cout << n + 1 << endl; return (0); }
    for (ll i = 2; i * i <= n; i++) {
        if (f(i, n) == s) { cout << i << endl; return (0); }
    }
    for (ll i = ceil(sqrt(n)); i > 0; i--) {
        ll rem = s - i;
        if (rem < 0) continue;
        ll l = max(i, rem), r = n + 1;
        while (l + 1 < r) {
            ll m = (l + r) / 2;
            if (m * i + rem >= n) r = m;
            else l = m;
        }
        if (r * i + rem == n) {
            cout << r << endl;
            return (0);
        }
    }
    cout << -1 << endl;
    return (0);
}


Measured memory_bytes: 384
#include <iostream>

int main()
{
        int k,a,b;
        std::cin >> k >> a >> b;

        bool flag = false;
        for(int i=a;i<=b;i++)
                if(i%k == 0)
                        flag = true;

        if(flag)
                std::cout << "OK" << std::endl;
        else
                std::cout << "NG" << std::endl;

}

Measured memory_bytes: 3620
from itertools import permutations


def main():
    n = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))

    for i, per in enumerate(permutations(range(1, n + 1), n)):
        if per == P:
            a = i
        if per == Q:
            b = i

    print(abs(a - b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 66996
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
#define PI pair<int,int>
char m[14][14];
int main()
{
  int n,i,j,k,x,y;
  scanf("%d",&n);
  for(k=1;k<=n;k++){
    scanf("\n");
    memset(m,0,sizeof(m));
    for(i=3;i<11;i++){
      scanf("%s",&m[i][3]);
    }
    scanf("%d%d",&x,&y);
    stack< PI > st;
    m[y+2][x+2] = '0';
    st.push(PI(x+2,y+2));
    while(!st.empty()){
      PI p = st.top();
      st.pop();
      for(i=-3;i<=3;i++){
	if(m[p.second+i][p.first] == '1'){
	  m[p.second+i][p.first] = '0';
	  st.push(PI(p.first,p.second+i));
	}
	if(m[p.second][p.first+i] == '1'){
	  m[p.second][p.first+i] = '0';
	  st.push(PI(p.first+i,p.second));
	}
      }
    }
    printf("Data %d:\n",k);
    for(i=3;i<11;i++){
      for(j=3;j<11;j++){
	printf("%c",m[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
int main(void)
{
	LL n,dist[114][114],i,j,k,sum;
	while(1) {
		cin>>n;
		if(!n)break;
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) {
				cin>>dist[i][j];
				sum+=dist[i][j];
			}
			dist[i][n]=sum;
		}
		for(i=0;i<=n;i++) {
			sum=0;
			for(j=0;j<n;j++) {
				sum+=dist[j][i];
			}
			dist[n][i]=sum;
		}
		for(i=0;i<=n;i++) {
			for(j=0;j<=n;j++) {
				printf("%5d",dist[i][j]);
			}
			cout<<endl;
		}
	}
	return 0;
}

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

int c[51][51];
void dfs(int x,int y){
  int i,j;
  c[x][y]=0;
  for(i=-1;i<=1;++i){
    for(j=-1;j<=1;++j){
      if(c[x+i][y+j]==1){
	dfs(x+i,y+j);
      }
    }
  }
}

int main(){
  int w,h;
  int i,j;

  while(1){
    cin >>w >>h;
    if(w==0 && h==0) break;
    int cnt=0;
    for(i=0;i<h;++i){
      for(j=0;j<w;++j)
	cin >>c[i][j];
    }
    for(i=0;i<h;++i){
      for(j=0;j<w;++j){
	if(c[i][j]==1){
	  dfs(i,j);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
     

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 X; cin >> X;

    i64 cnt = (X / 11) * 2;
    if (X % 11 > 6) {
        cnt += 2;
    } else if (X % 11 > 0) {
        cnt += 1;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define H 105
#define W 105

int main() {
	int h,w;
	char masu[H][W];
	cin >> h >> w;
	//表示させるなら1させないなら0
	int ans[H][W] = {};

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> masu[i][j];
		}
	}

	for (int i = 0; i < h; ++i) {
		//seiは横一列すべて同じならtrue
		bool sei = true;
		for (int j = 0; j < w; ++j) {
			if(masu[i][j] == '#') {
				sei = false;
				break;
			}
		}
		if(sei == true)
			for (int j = 0; j < w; ++j)
			{
				ans[i][j] = 1; 
			}
	}
	for (int j = 0; j < w; ++j) {
		//seiは横一列すべて同じならtrue
		bool sei = true;
		for (int i = 0; i < h; ++i) {
			if(masu[i][j] == '#') {
				sei = false;
				break;
			}
		}
		if(sei == true)
			for (int i = 0; i < h; ++i)
			{
				ans[i][j] = 1; 
			}
	}
	for (int i = 0; i < h; ++i)
	{
		int counter = 0;
		for (int j = 0; j < w; ++j)
		{
			if(ans[i][j] == 0)
			{
				cout << masu[i][j];
				counter++;
			}
		}
		if(counter != 0)
			cout << endl;	
	}

	return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] x; readA(n, x);
  int l; readV(l);

  auto m = (n-1).bsr+2;

  auto y = new int[](n);
  foreach (i; 0..n) y[n-i-1] = -x[i];

  auto build(int[] x)
  {
    auto s = new int[][](n, m);

    foreach (j; 0..m)
      s[n-1][j] = n-1;

    foreach_reverse (i; 0..n-1) {
      s[i][0] = x.assumeSorted.lowerBound(x[i]+l+1).length.to!int-1;
      foreach (j; 1..m)
        s[i][j] = s[s[i][j-1]][j-1];
    }

    return s;
  }

  auto s1 = build(x), s2 = build(y);

  auto calc(int[][] s, int a, int b)
  {
    auto c = a, r = 0;
    while (c < b) {
      auto t = s[c].assumeSorted.lowerBound(b);
      if (t.empty) {
        ++r;
        break;
      } else {
        r += (1<<(t.length-1));
        c = t.back;
      }
    }
    return r;
  }

  int q; readV(q);
  foreach (_; 0..q) {
    int a, b; readV(a, b); --a; --b;
    if (a < b)
      writeln(calc(s1, a, b));
    else
      writeln(calc(s2, n-a-1, n-b-1));
  }
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }

  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }

  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}


Measured memory_bytes: 37172
T = int(input())
import heapq

for _ in range(T):
    n = int(input())
    ans = 0
    
    lamount,ramount = 0,0
    k,l,r = [0]*n,[0]*n,[0]*n
    
    ll,rr = [],[]
    for i in range(n):
        k[i],l[i],r[i] = map(int,input().split())
        if l[i] >= r[i]:
            lamount += 1
            ans += r[i]
            ll.append(i)
        else:
            ramount += 1
            ans += l[i]
            rr.append(i)
            
    ldek = [[] for _ in range(lamount)]
    rdek = [[] for _ in range(ramount)]
    
    for i in ll:
        ldek[min(lamount-1,k[i]-1)].append(l[i]-r[i])
    
    for i in rr:
        if n != k[i]:
            rdek[min(ramount-1,n-1-k[i])].append(r[i]-l[i])
        
    cur = []
    heapq.heapify(cur)
    
    for l in range(lamount-1,-1,-1):
        for k in ldek[l]:
            heapq.heappush(cur, k*(-1))
            
        if cur != []:
            mi = heapq.heappop(cur)
            ans += mi * (-1)
            
    cur = []
    heapq.heapify(cur)
    
    for l in range(ramount-1,-1,-1):
        for k in rdek[l]:
            heapq.heappush(cur, k*(-1))
            
        if cur != []:
            mi = heapq.heappop(cur)
            ans += mi * (-1)
            
    print(ans)

Measured memory_bytes: 112896
void main()
{
    int n = readln.chomp.to!int;

    int[] a = new int[n], b = new int[n];
    foreach (i; 0 .. n)
    {
        int[] tmp = readln.split.to!(int[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }
    zip(a, b).sort!((x, y) => x[0] > y[0]);

    writeln(a[0] + b[0]);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4092
package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	max := 1<<byte(n) - 1

	cond := [][]int{}
	for i := 1; i <= n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		for j := 1; j <= a; j++ {
			var x, y int
			fmt.Scanf("%d %d", &x, &y)
			cond = append(cond, []int{i, x, y})
		}
	}

	maxHonest := 0
	for bits := 0; bits <= max; bits++ {
		valid := true
		for _, c := range cond {
			ith := (bits >> (byte(c[0]) - 1)) % 2
			x := (bits >> (byte(c[1]) - 1)) % 2
			valid = valid && ((ith == 0) || (x == c[2]))
		}
		if valid && countHonest(bits) > maxHonest {
			maxHonest = countHonest(bits)
		}
	}

	fmt.Printf("%d\n", maxHonest)
}

func countHonest(c int) int {
	count := 0
	for c > 0 {
		count += c % 2
		c = c >> 1
	}
	return count
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
#define pb push_back
#define fi first
#define sc second
#define MAX_H 514
int R;
int W[2],H[2],X[2],Y[2];
int L[2][MAX_H][MAX_H];
bool F[2][MAX_H][MAX_H];
vector<iP>data[2];
int need[2][MAX_H*MAX_H];
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
int main()
{
	while(true){
	for(int i=0;i<2;i++){
		data[i].erase(data[i].begin(),data[i].end());
		for(int j=0;j<514;j++){
			for(int k=0;k<514;k++){
				F[i][j][k]=false;
			}
		}
	}
	
	scanf("%d",&R);
	if(R==0)break;
	for(int i=0;i<2;i++){
		scanf("%d%d%d%d",&W[i],&H[i],&X[i],&Y[i]);X[i]--;Y[i]--;
		for(int j=0;j<H[i];j++){
			for(int k=0;k<W[i];k++){
				scanf("%d",&L[i][j][k]);
				if(j==Y[i]&&k==X[i]){continue;}
				data[i].pb(iP(L[i][j][k],P(j,k)));
			}
		}
	}
	for(int i=0;i<2;i++){
		sort(data[i].begin(),data[i].end());
		for(int j=0;j<=W[i]*H[i];j++){
			need[i][j]=(1<<30)-1;
		}
	}
	for(int i=0;i<2;i++){
		F[i][Y[i]][X[i]]=true;
		need[i][0]=0;
		int cou=1;need[i][1]=1;
		for(int j=0;j<(int)data[i].size();j++){
			int x=data[i][j].sc.fi;
			int y=data[i][j].sc.sc;
			if(F[i][x][y])continue;
			bool flag=false;
			for(int k=0;k<4;k++){
				if(x+dx[k]<0||x+dx[k]>=H[i]||y+dy[k]<0||y+dy[k]>=W[i]){continue;}
				if(F[i][x+dx[k]][y+dy[k]])flag=true;
			}
			if(!flag){
				continue;
			}
			queue<P>que;
			que.push(P(x,y));
			while(!que.empty()){
				P p=que.front();que.pop();
				if(F[i][p.fi][p.sc])continue;
				F[i][p.fi][p.sc]=true;
				//printf("%d %d\n",p.fi,p.sc);
				cou++;
				for(int k=0;k<4;k++){
					if(p.fi+dx[k]<0||p.fi+dx[k]>=H[i]||p.sc+dy[k]<0||p.sc+dy[k]>=W[i]){continue;}
					if(F[i][p.fi+dx[k]][p.sc+dy[k]]){continue;}
					if(L[i][p.fi+dx[k]][p.sc+dy[k]]<=data[i][j].fi){
						que.push(P(p.fi+dx[k],p.sc+dy[k]));
					}
				}
			}
			need[i][cou]=L[i][x][y];
			//printf("%d:%d %d\n",cou,x,y);
		}
	}
	for(int i=0;i<2;i++){
		for(int j=W[i]*H[i]-1;j>=0;j--){
			need[i][j]=min(need[i][j],need[i][j+1]);
		}
	}
	/*
	for(int i=0;i<2;i++){
		for(int j=0;j<=W[i]*H[i];j++){
			printf("need[%d][%d]=%d\n",i,j,need[i][j]);
		}
	}*/
	
	int ans=1<<30;
	for(int i=0;i<=W[0]*H[0];i++){
		int k=R-i;
		if(k>W[1]*H[1]||k<0){
			continue;
		}
		ans=min(need[0][i]+need[1][k],ans);
	}
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 15452
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector< vector<int> > abc(26, vector<int>(n, 0));
	int j = 0;
	while (true) {
		for (int i = j; i < n; i++) {
			abc[s[i] - 'a'][i - j] = 1;
		}
		bool h = true;
		for (int i = 0; i < 26; i++) {
			int p = 0;
			for (int jj = 0; jj < n - j; jj++) {
				p += abc[i][jj];
			}
			if (p == n - j) {
				cout << j << endl;
				h = false;
				break;
			}
		}
		if (h) {
			j++;
		}
		else {
			break;
		}

	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int x[100];
	for (int i = 0;i < n;i++)cin >> x[i];
	int ans = 0;
	for (int i =0 ;i < n;i++) {
	    ans+=min(x[i],abs(x[i]-k))*2;
	}
	cout << ans << endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

int main() {
    string s[3];
    rep(i, 3) cin >> s[i];

    rep(i, 3) cout << (char)(s[i][0] + ('A' - 'a'));
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int R=0,B=0,W=0,G=0;
			R = sc.nextInt();
			B = sc.nextInt();
			W = sc.nextInt();
			G = sc.nextInt();
			System.out.println((R+B+W+G));
	}
}


Measured memory_bytes: 26308
N = int(input())
A = list(map(int,input().split(' ')))

total=0
mins=999999999999
mcnt=0

for i in range(N):
    total+=abs(A[i])
    if abs(A[i]) != A[i]:
        mcnt+=1
    if mins >= abs(A[i]):
        mins = abs(A[i])

if mcnt%2 == 0:
    print(total)
else:
    print(total - mins*2)


Measured memory_bytes: 14252
import sys

def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()

N,K = map(int,S().split())
S = LI2()

A = []
count = 0
for i in range(N):
    if i == 0:
        count = 1
    else:
        if S[i] == S[i-1]:
            count += 1
        else:
            A.append(count)
            count = 1
A.append(count)

if len(A) <= 2*K-1:
    print(N)
    exit()

if S[0] == 1:
    A = [1] + A
if S[-1] == 1:
    A = A + [1]
# 両端は0だと考えてよい

from itertools import accumulate

M = (len(A)-1)//2
A = list(accumulate([0]+A))

ans = 0
for i in range(M-K+2):
    if i == 0:
        ans = max(ans,A[2*(K+i)]-A[2*i])
    elif i == M-K+1:
        ans = max(ans,A[2*(K+i)-1]-A[2*i-1])
    else:
        ans = max(ans,A[2*(K+i)]-A[2*i-1])

print(ans)

Measured memory_bytes: 83256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 110;
int c[4], v[MAXN];
vector<int> a[4];
int main() {
	int N;
	long long W;
	cin >> N >> W;
	long long w1;
	int v;
	cin >> w1 >> v;
	c[0]++;
	a[0].push_back(v);
	for (int i = 2; i <= N; i++) {
		long long w;
		cin >> w >> v;
		c[w - w1]++;
		a[w - w1].push_back(v);
	}	
	for (int i = 0; i <= 3; i++) {
		sort(a[i].begin(), a[i].end(), greater<int>());
	}
	long long ans = 0;
	long long sv[4] = {0, 0, 0, 0};
	for (int i = 0; i <= c[0] && i*w1 <= W; i++) {
		if (i > 0) sv[0] += a[0][i-1];
		sv[1] = 0;
		for (int j = 0; j <= c[1] && i*w1+j*(w1+1) <= W; j++) {
			if (j > 0) sv[1] += a[1][j-1];
			sv[2] = 0;
			for (int k = 0; k <= c[2] && i*w1+j*(w1+1)+k*(w1+2) <= W; k++) {
				if (k > 0) sv[2] += a[2][k-1];
				sv[3] = 0;
				for (int l = 0; l <= c[3] && i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3) <= W; l++) {
					if (l > 0) sv[3] += a[3][l-1];
					ans = max(ans, sv[0]+sv[1]+sv[2]+sv[3]);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct unionfind {
    vector<int> data;
    unionfind(int size) : data(size, -1) { }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

struct edge {
    int from,to,cost;
};

vector<edge> kruscal(vector<edge> & es){
    sort(es.begin(), es.end(), [](edge a, edge b){
            return a.cost < b.cost;
        });
    unionfind uf(es.size());
    vector<edge> res;
    rep(i,es.size()){
        const edge &e = es[i];
        if(!uf.same(e.from, e.to)){
            uf.unite(e.from,e.to);
            res.push_back(e);
        }
    }
    return res;
}

int main(){
    vector<edge> es;
    int n; cin>>n;
    rep(i,n)rep(j,n){
        int c; cin>>c;
        if(c!=-1) es.push_back({i,j,c});
    }
    auto v = kruscal(es);
    int ans = 0;
    rep(i,v .size()){
        ans += v[i].cost;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int ans=a;
  k-=a;
  if(k<=0)cout<<k+a<<endl;
  else {
    k-=b;
    if(k<=0)cout<<a<<endl;
    else cout<<ans-k<<endl;
  }
  return 0;
}


Measured memory_bytes: 3628
/************************************************
 *Author*        :skyNebula
 *Created Time*  : 六  5/12 20:03:29 2018

*********************************************/

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>


using namespace std;
#define debug(x) cout << #x << " " << "=" << (x) << endl;
typedef pair<int, int> pii;
typedef long long LL;
const int mod = 1e9 + 7;
const int MaxN = 1e6;


int a,b,c,d;

int main()
{
    cin >> a >> b >> c >> d;
    if(abs(c - a) <= d)
        cout << "Yes" << endl;
    else 
    {
        if(abs(b-a) <= d && abs(c-b) <= d)
            cout << "Yes" << endl;
        else 
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

const int bound = 100010;
vector<int> graph[bound];

string mode = "right";

int sz = 0;
vector<int> l;
vector<int> r;
bool bscht[100010];

void dfs( int node ){
	bscht[node] = true;
	++sz;
	if( mode == "right" ) r.push_back(node);
	else if ( mode == "left" ) l.push_back(node);
	for( auto &next : graph[node] ){
		if( bscht[next] ) continue;
		dfs(next);
		break;
	}
}

int main(){
	int n, m; cin >> n >> m;
	for( int i = 0; i < m; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(0);
	bscht[0] = false;
	mode = "left";
	dfs(0);
	reverse( l.begin(), l.end() );
	cout << sz-1 << endl;
	for( int i = 0; i < l.size()-1; ++i ) cout << l[i]+1 << ' ';
	for( int i = 0; i < r.size(); ++i  ) cout << r[i]+1 << ' ';
	cout << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b;
  if((a+b) % 2 != 0)
  {
  	c = (a+b) / 2 + 1;
  }else
  {
  	c = (a+b) / 2;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int a[maxn];
bool book[maxn];
int b[maxn];
int cnt;
map<int,int> mp; 
typedef long long ll;
int main(void){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(book[a[i]]==0){
			b[cnt++] = a[i];
			book[a[i]] = 1;
		}
		mp[a[i]]++;
	}
	ll sum = 0;
	for(int i = 0; i < cnt; i++){
		ll m = mp[b[i]];
		m -= 1;
		sum += (1+m)*m/2;
	}
	for(int i = 0; i < n; i++){
		ll m = mp[a[i]];
		m--;
		ll p = (1+m)*m/2;
		m--;
		ll q = (1+m)*m/2;
		cout<<sum-p+q<<endl;
	} 
	return 0;
}

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

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

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 998244353;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

vector<int64_t> fct, inv;
void finit(int cmx, ll mod =MD){
	fct.resize(cmx+20); inv.resize(cmx+20);
	fct[0] = fct[1] = inv[1] = inv[cmx] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	for(ll x=fct[cmx], n=mod-2; n > 0; n >>=1, x = x*x %mod)
		if(n & 1) inv[cmx] = inv[cmx] * x %mod;
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nCk(ll n, ll k, ll mod =MD) {
	if(k > n || n <0 || k <0) return 0;
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}
ll bin_pow(ll x, ll n, ll mod=MD){
	ll res = 1LL;
	for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
	return res;
}
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >>n >>m >>k;
	finit(n+1000, MD);
	ll ans =0;
	rep(i,  k+1){
		ll sm = m * bin_pow(m-1, n-i-1) %MD *  nCk(n-1, i);
		(ans += sm) %=MD;
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 6280
#include<bits/stdc++.h>
using namespace std;
int main(){
  long H,W,M;cin>>H>>W>>M;
  vector<long>X(W),Y(H);
  vector<pair<long,long>>s;
  
  for(long i=0;i<M;i++){
    long h,w;cin>>h>>w;
    Y[h-1]++;X[w-1]++;
    s.push_back(pair<long,long>(h-1,w-1));
  }
  long x=0;for(long t:X)x=max(x,t);
  long y=0;for(long t:Y)y=max(y,t);
  set<long>IX,IY;
  for(long i=0;i<W;i++)if(x==X[i])IX.insert(i);
  for(long i=0;i<H;i++)if(y==Y[i])IY.insert(i);
  
  long c=0;
  for(long i=0;i<M;i++){
    if(IY.find(s[i].first)!=IY.end()
       &&IX.find(s[i].second)!=IX.end())
      c++;
    
  }
  cout<<(c<IX.size()*IY.size()?x+y:x+y-1);
}

Measured memory_bytes: 40828
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define T pair<int, int>
#define ordered_set tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
set<int> st;
void bfs(int s){
    queue<int> q;
    q.push(s);
    int c=0;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        if(u >= 6000000000) break;
        st.ins(u);
        int lastDigit = u%10;
        int A = u*10 + lastDigit;
        int B = u*10 + lastDigit + 1;
        int C = u*10 + lastDigit - 1;
        if(lastDigit == 0){
            q.push(B);
            q.push(A);
        }
        else if(lastDigit == 9){
            q.push(C);
            q.push(A);
        }
        else{
            q.push(A);
            q.push(B);
            q.push(C);
        }
    }
}
signed main(){
    fast();
    int k;
    cin >> k;
    for(int i=1; i<=9; i++){
        bfs(i);
    }
    // cout << st.size() << endl;
    vector<int> arr(100001);
    int j = 1;
    for(auto i: st){
        arr[j++] = i;
        if(j == 100001) break;
    }
    cout << arr[k] << endl;
    // for(auto i: arr)    cout << i << " ";
    // cout << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
  bool operator==(const mint rhs) const { return x == rhs.x; }
  bool operator!=(const mint rhs) const { return x != rhs.x; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<mint> F(s+5, 0);
  mint ans = 0;
  rep(i,n) {
    for (int j = s; j-a[i] >= 0; --j) {
      F[j] += F[j-a[i]];
    }
    F[0] += 1;
    if (a[i] <= s) F[a[i]] += 1;
    ans += F[s];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    bool ans = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                ans = true;
            }
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

int main(){
    int a,s,d;
    cin >>a>>s>>d;
    if((a!=s)&&(a!=d)&&(s==d)){
        cout << "Yes" << endl;
    }
    else if((s!=a)&&(s!=d)&&(a==d)){
        cout << "Yes" << endl;
    }
    else if((d!=a)&&(d!=s)&&(a==s)){
        cout << "Yes" << endl;
    }
    else{
        cout <<"No"<<endl;
    }
    return 0;
}

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

int main()
{
  int64_t N;
  cin >> N;
  
  int64_t T;
  
  if((N % 2) == 1){cout << '0' << endl;}
  else
  {
    N -= N % 10;
    N /= 10;
    T += N;
    while(N != 0)
    {
      T += N / 5;
      if((N / 25) == 0){N = 0;}
      else{N /= 5;}
    }
    cout << T << endl;
  }
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
using namespace std;

#define N 100010
typedef long long ll;

const ll INF=1e18;

int n,E,T;
int dis[N];
ll Dp[N];


inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int main()
{
    n=read();E=read();T=read();
    for(int i=1;i<=n;i++)
        dis[i]=read();
    Dp[0]=0;
    int pos=0;ll Min=INF;
    for(int i=1;i<=n;i++)
    {
        Dp[i]=Dp[i-1]+T;
        while(pos+1<=i&&2*(dis[i]-dis[pos+1])>T)
        {
            Min=min(Min,Dp[pos]-2*dis[pos+1]);
            pos++;
        }
        Dp[i]=min(min(Dp[i],Dp[pos]+T),Min+2*dis[i]);
    }
    cout<<Dp[n]+E<<endl;
    return 0;
}


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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(void){
int n,k;
cin >> n >> k;
vector<int> x(n),y(n);
vector<int> xary,yary;

for(int i = 0; i < n; ++i){
cin >> x[i] >> y[i];
xary.push_back(x[i]);
yary.push_back(y[i]);
}
sort(begin(xary),end(xary));
sort(begin(yary),end(yary));

ll ans = 1LL * (xary[n-1] - xary[0]) * (yary[n-1] - yary[0]);

for(int xi = 0; xi < n; ++xi){
for(int xj = xi + 1; xj < n;++xj){
for(int yi = 0; yi < n; ++yi){
for(int yj = yi + 1; yj < n;++yj){

ll num = 0;
ll lx = xary[xi],rx = xary[xj];
ll by = yary[yi],uy = yary[yj];

for(int i = 0; i < n;++i){
if(lx <= x[i] and x[i] <= rx and by <= y[i] and y[i] <= uy){
num++;
}
}

if(num >= k) ans = min(ans,1LL * (rx - lx) * (uy - by));
}
}
}
}

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


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x,y,r,a;
  scanf("%d %d",&x,&y);
  if(x < y){
    while(1){
    r = y % x;
    if(r==0)break;
    y = x;
    x = r;
    }
    a = x;
  }
  else{
    while(1){
    r = x % y;
    if(r==0)break;
    x = y;
    y = r;
    }
    a = y;
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const int mod = 1e9+7;
ll dp[100005][2];
int main(){
    string l; cin >> l;
    int n = l.size();
    rep(i,n+1){
        rep(j,2){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = 1;

    rep(i,n){
        if(l[i] == '0'){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1]*3LL;
        }
        else{
            dp[i+1][0] = dp[i][0]*2LL;
            dp[i+1][1] = dp[i][1]*3LL + dp[i][0];
        }
        dp[i+1][0] %= mod;
        dp[i+1][1] %= mod;
    }

    ll ans = dp[n][0] + dp[n][1];
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 2048
s = input()
rs = "".join(list(reversed(s)))

if s != rs:
    print("No")
    quit()

n = len(s)
lefts = s[:(n-1)//2]
rlefts = "".join(reversed(lefts))

if lefts != rlefts:
    print("No")
    quit()

rights = s[(n-1)//2+1:]
rrights = "".join(reversed(rights))

if rights != rrights:
    print("No")
    quit()

print("Yes")


Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 10000
#define NIL -1

typedef struct{
  int parent,left,right;
}Node;

void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);

Node T[MAX];
int n,D[MAX],H[MAX];


int main() {

  int i,v,l,r,root=0;
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].parent = NIL;

  for(i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(i=0;i<n;i++) if(T[i].parent == NIL) root = i;

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++) print(i);

  return 0;

}

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0,h2 = 0;
  if(T[u].left != NIL) h1 = setHeight(T[u].left)+1;
  if(T[u].right != NIL) h2 = setHeight(T[u].right)+1;

  H[u] = ( h1 > h2 ? h1 : h2 );

  return H[u];
}

int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL) printf("root\n");
  else if(T[u].left == NIL && T[u].right == NIL) printf("leaf\n");
  else printf("internal node\n");

}


Measured memory_bytes: 2128
import itertools
N = int(input())
A = list(enumerate([int(input()) for _ in range(N)]))
B = [iv[0] for iv in sorted(
    enumerate([i for i, v in sorted(A, key=lambda xs: xs[1])]),
    key=lambda xs: xs[1])]
print(sum(b % 2 for b in B[::2]))


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

using namespace std;

const double eps=1e-8;
const double Pi=acos(-1.0);
struct node{
    double x,y;
    node (double xx=0,double yy=0) {
        x=xx; y=yy;
    }
};
node p[100005];

node operator +(const node &a,const node &b) {return node(a.x+b.x,a.y+b.y);}
node operator -(const node &a,const node &b) {return node(a.x-b.x,a.y-b.y);}
node operator *(const node &a,const double &b) {return node(a.x*b,a.y*b);}
node operator /(const node &a,const double &b) {return node(a.x/b,a.y/b);}

double Dot(node a,node b) {return a.x*b.x+a.y*b.y;}
double Cross(node a,node b) {return a.x*b.y-a.y*b.x;}
double lenth(node a) {return sqrt(Dot(a,a));}

int n;
double r;
node c;

int dcmp(double x) {
    if (fabs(x)<eps) return 0;
    else if (x>0) return 1;
    else return -1;
}

node rotate(node a,double t) {
    return node(a.x*cos(t)-a.y*sin(t),a.x*sin(t)+a.y*cos(t));
}

node jiao(node P,node v,node Q,node w) {
    node u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}

node get_c(node a,node b,node c) {
    node P=(a+b)/2.0;
    node Q=(a+c)/2.0;
    node v=rotate(b-a,Pi/2.0),w=rotate(c-a,Pi/2.0);
    if (dcmp(lenth(Cross(v,w)))==0) {
        if (dcmp(lenth(a-b)+lenth(b-c)-lenth(a-c))==0)
            return (a+c)/2.0;
        if (dcmp(lenth(a-c)+lenth(c-b)-lenth(a-b))==0)
            return (a+b)/2.0;
        if (dcmp(lenth(b-a)+lenth(a-c)-lenth(b-c))==0)
            return (b+c)/2.0;
    }
    return jiao(P,v,Q,w);
}

void min_circular() {
    random_shuffle(p+1,p+1+n);
    c=p[1]; r=0;
    for (int i=2;i<=n;i++) 
        if (dcmp(lenth(p[i]-c)-r)>0) {
            c=p[i],r=0;
            for (int j=1;j<i;j++)
                if (dcmp(lenth(p[j]-c)-r)>0) {
                    c=(p[i]+p[j])/2.0;
                    r=lenth(p[i]-c);
                    for (int k=1;k<j;k++) 
                        if (dcmp(lenth(p[k]-c)-r)>0) {
                            c=get_c(p[i],p[j],p[k]);
                            r=lenth(p[i]-c);
                        }
                }
        }
}

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
    min_circular();
    printf("%.7lf\n",r);
    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int x,y,z;scanf("%d %d %d",&x,&y,&z);
    swap(x,y);swap(x,z);
    printf("%d %d %d\n",x,y,z);
    return 0;
}


Measured memory_bytes: 256
import math

def perms(n, li, result):
	li_l = len(li)
	result_l = len(result)
	if n == 0:
		return result
	if result_l == 0:
		for elem in li:
			result.append(str(elem))
		n -= 1
	else:
		for elem in li:
			for r in result[:result_l]:
				flag = True
				
				for r_e in r:
					if str(elem) == r_e:
						flag = False
						break
				if flag:
					r += str(elem)
					result.append(r)
				
		result = result[result_l:]
		n -= 1
	return perms(n, li,result)

def total(N, result, towns):
	total_dist = 0
	for elem in result:
		for ind in range(N-1):
			total_dist += dist(towns[int(elem[ind])], towns[int(elem[ind+1])])
	return total_dist

def dist(p1, p2):
	x1, y1 = p1
	x2, y2 = p2
	return math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))


if __name__ == '__main__':
  N = int(input())
  li = list(range(N))
  result = []
  towns = []
  for n in range(N):
  	x, y = map(float, input().split())
  	towns.append((x,y))
  result = perms(N, li, result)
  total_dist = total(N, result, towns)
  print(total_dist/len(result))

Measured memory_bytes: 11200
S=input()
N=len(S)
A="abcdefghijklmnopqrstuvwxyz"

if N<26:
    for a in A:
      if a not in S:
        S+=a
        break
else:
  if S==A[::-1]:
    S="-1"
  else:
    for i in range(N-1,-1,-1):
      s=S[i:]
      ss=list(S[i:])
      ss.sort(reverse=True)
      ss="".join(ss)
      #print(i,s,ss)
      if s!=ss:
        S=S[:i]+ss[ss.index(S[i])-1]
        break
print(S)

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        k: i32,
        h: [i32; n],
    }
    println!("{}", h.iter().filter(|&&x| x >= k).count());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h> 
#define ll long long 
#define ld long double
#define ull unsigned long long
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
using namespace std;
const double pi=3.14159265358979323846;
const int MAX_CHARS = 256; 
  
// This function receives text and shift and 
// returns the encrypted text 
string encrypt(string text, int s) 
{ 
    string result = ""; 
  
    // traverse text 
    for (int i=0;i<text.length();i++) 
    { 
        // apply transformation to each character 
        // Encrypt Uppercase letters 
        if (isupper(text[i])) 
            result += char(int(text[i]+s-65)%26 +65); 
  
    // Encrypt Lowercase letters 
    else
        result += char(int(text[i]+s-97)%26 +97); 
    } 
  
    // Return the resulting string 
    return result; 
} 
  
// Driver program to test the above function 
int main() 
{ 
    int n;
    cin>>n;
    if(n>=30)
    yes;
    else 
    no;
} 

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

long long a, b, s;
int main() {
	cin >> a >> b;
	if(a%2==1) s ^= a, a++;
	if(b%2==0) s ^= b, b--;
	s ^= max(0LL, b-a+1) / 2 % 2;
	cout << s;
	return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int k, x;
    cin >> k >> x;
    k--;
    for(int i = x - k; i <= k + x; i++)
    {
        cout << i;
        if(i != k + x) { cout << " "; }
        else { cout << endl; }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a[500005];
void mh(int tm){
  int l=2*tm,r=2*tm+1,b;
  if(l<=n&&a[l]>a[tm]) b=l;
  else b=tm;
  if(r<=n&&a[r]>a[b]) b=r;
  if(b-tm){
    swap(a[tm],a[b]);
    mh(b);
  }
}
int main(){
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=n/2;i>=1;i--) mh(i);
  for(int i=1;i<=n;i++) cout<<" "<<a[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 5040
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int j = n - 1; j >= 0; j--){
        cout << a[j];
        if (j > 0){
            cout << " ";
        }
    }
    cout << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <limits>
#include <cmath>
#include <typeinfo>


using namespace std;

bool comp(int a, int b) 
{ 
    return (a < b); 
}

int main() {
	int p = 0, q = 0, r = 0;
	cin >> p >> q >> r;
	int total = p + q;
	int total1 = q + r;
	int total2 = r + p;
	int sum = min(total, total1, comp);
	if(sum > total2) {
		sum = total2;
	}
	cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
struct card{
	int n;
	char m;
}num[60];
bool s[14],h[14],c[14],d[14];
int main()
{
	int k;
	cin>>k;
	for(int i=1;i<=k;i++)
	{	
		cin >> num[i].m >> num[i].n; 
		switch(num[i].m)
		{
			cout << num[i].n << endl;
			case 'S':
				s[num[i].n]=1;
				break;
			case 'H':
				h[num[i].n]=1;
				break;
			case 'C':
				c[num[i].n]=1;
				break;
			case 'D':
				d[num[i].n]=1;	
				break;							
			}	
	}
	for(int i=1;i<=13;i++)
	{
		if(!s[i])
		printf("S %d\n",i);
	}
	for(int i=1;i<=13;i++)
	{
		if(!h[i])
		printf("H %d\n",i);
	}
	for(int i=1;i<=13;i++)
	{
		if(!c[i])
		printf("C %d\n",i);
	}
	for(int i=1;i<=13;i++)
	{
		if(!d[i])
		printf("D %d\n",i);
	}
	return 0;
}


Measured memory_bytes: 3184