akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int tem;
    vector<int> v;
    for(int i=0;i<3;i++)
    {
        cin>>tem;
        v.push_back(tem);
    }
    
    sort(v.begin(),v.end());
    cout<<v[0]<<" "<<v[2]<<endl;
}


Measured memory_bytes: 3160
/*input
3 3
1 7 11
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long

int a[100001];
int i,j;
int ans;

signed main(){
  int n,x;
  cin >> n >> x;
  for(i = 0;i < n;i++){
  	cin >> a[i];
  	a[i] = abs(a[i]-x);
  }
  ans = a[0];
  for(i = 1;i < n;i++){
  	ans = __gcd(ans,a[i]);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1024
N=int(input())

def b26(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        if X_dumy%26==0:
            out=str(26)+' '+out
            X_dumy=int(X_dumy/n)-1
        else:
            out = str(X_dumy%n)+' '+out
            X_dumy = int(X_dumy/n)
    return out

for a in b26(N,26).split():
    print(chr(96+int(a)),end='')
print('')

Measured memory_bytes: 8964
#include<stdio.h>

int main() {
    char c[3][100];

    for(int i = 0; i < 3; i++) {
        scanf("%s", c[i]);
    }

    char x[4];
    for(int i = 0; i < 3; i++) {
        x[i] = c[i][0];
    }

    x[3] = '\0';

    printf("%s", x);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=998244353;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll n;
    cin >> n;
    for(ll a=1;a<=3500;a++){
        for(ll b=1;b<=3500;b++){
            ll t = n * a * b;
            ll t2 = 4 * a * b - n * (a + b);
            if(t2<=0) continue;
            if(t%t2!=0) continue;
            ll w = t/t2;
            cout << a << " " << b << " " << w << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0 
if N %2 ==1:
    ans += A[0]
    k = 0
    for j in range(1, N//2):
        k += 1
        ans += 2*A[k]
    ans += A[k+1]
if N%2 == 0:
    ans += A[0]
    k = 0
    for j in range(1, N//2):
        k += 1
        ans += 2*A[k]
print(ans)


Measured memory_bytes: 31436
#include<bits/stdc++.h>
using namespace std; 
char s[1010101];
int main()
{
	int N;
	scanf("%d", &N);
	scanf("%s", s);
	
	bool flag = 0;
	int ans = 0;
	for(int i = 0; i < N; i++)
	{
		if(s[i] == '2')
			flag = 1;
		if(((N-1)&i) == i)
			ans ^= s[i] - '1';
	}
	if(flag)
		printf("%d\n", ans & 1);
	else
		printf("%d\n", ans & 2);
		
	return 0;
}

Measured memory_bytes: 4792
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
count = 0
for i in range(n):
  if a_list[i]+a_list[i+1] <= b_list[i]:
    count += a_list[i]+a_list[i+1]
    a_list[i+1] = 0
  else:
    count += b_list[i]
    if a_list[i] < b_list[i]:
      a_list[i+1] = a_list[i]+a_list[i+1] - b_list[i]
    

print(count)

Measured memory_bytes: 18624
#include<stdio.h>
#define N 100001

int binarysearch(int * ,int ,int);

int main (){
  int n,i,S[N],q,key,num=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    //if(linersearch(S,n,key)!=0)
    num=num+binarysearch(S,n,key);
  }
  printf("%d\n",num);
 
  return 0;
}

int binarysearch(int A[],int n,int key){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==key)
      return 1;
    else if (key<A[mid])
      right=mid;
    else left=mid+1;
  }
  return 0;
}



Measured memory_bytes: 2188
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  if n == 0:
    print(0)
    sys.exit()
  ans = ''
  while n!=0:
    if n%2==0:
      ans = '0' + ans
      n = n//(-2)
    else:
      ans = '1' + ans
      n=(n-1)//(-2)
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 14560
# -*- coding: utf-8 -*-

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

dp = []
for i in range(n):
    dp.append(abs(a-(t-h[i]*0.006)))

#print(dp)
print(dp.index(min(dp))+1)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from bisect import bisect_left
    n=int(input())
    L=list(map(int,input().split()))
    L.sort()
    ans=0
    for i in range(1,n):
        for j in range(i+1,n):
            k=bisect_left(L,L[j]-L[i]+1)
            ans+=max(0,i-k)
    print(ans)
resolve()

Measured memory_bytes: 44892
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

int n, a[1111111][2], nyaa=0, nyan[1111111];
char s[1111111];

int cmp3(const int *x, const int *y){
    int i = *x, j = *y;
    if(a[i][1] - a[i][0] > 0){
        if(a[j][1] - a[j][0] > 0){
            return a[i][0] - a[j][0];
        }else /*if(a[j][1] - a[j][0] < 0)*/{
            return -1;
        }
    }else if(a[i][1] - a[i][0] < 0){
        if(a[j][1] - a[j][0] < 0){
            return a[j][1] - a[i][1];
        }else /*if(a[j][1] - a[j][0] > 0)*/{
            return 1;
        }
    }else {
        if(a[j][1] - a[j][0] > 0)return 1;
        return -1;
    }
}

main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%s", s);
        int l = strlen(s);
        int b=0,c=0,d=0,e=0;
        for(int j=0; j<l; j++){
            if(s[j]==')')d++;
            else d--;
            if(s[l-1-j]=='(')e++;
            else e--;
            b = max(b,d);
            c = max(c,e);
        }
        a[i][0] = b;
        a[i][1] = c;
        nyan[i] = i;
    }
    qsort(nyan, n, 4, cmp3);
    //for(int i=0; i<n; i++)printf("%d ", nyan[i]);putchar(10);
    if(a[nyan[0]][0] != 0){
        puts("No");
        return 0;
    }
    for(int i=0; i<n; i++){
        nyaa -= a[nyan[i]][0];
        if(nyaa < 0)break;
        nyaa += a[nyan[i]][1];
    }
    puts(nyaa?"No":"Yes");
    return 0;
}

Measured memory_bytes: 16032
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto nmq = readln.chomp.split.to!(long[]);
    long N = nmq[0];
    long M = nmq[1];
    long Q = nmq[2];
    long[] L = new long[](M);
    long[] R = new long[](M);
    long[] Qp = new long[](Q);
    long[] Qq = new long[](Q);

    foreach (i; 0 .. M)
    {
        auto lr = readln.chomp.split.to!(long[]);
        L[i] = lr[0];
        R[i] = lr[1];
    }
    foreach (i; 0 .. Q)
    {
        auto pq = readln.chomp.split.to!(long[]);
        Qp[i] = pq[0];
        Qq[i] = pq[1];
    }

    long[][] table = new long[][](N + 1, N + 1);
    foreach (t; zip(L, R))
        table[t[0]][t[1]]++;

    foreach (ref r; table[1 .. $])
        foreach (i, ref elm; r[1 .. $])
            elm += r[i];

    foreach (i, ref r; table[1 .. $])
        r[] += table[i][];

    // table.writeln;

    foreach (query; zip(Qp, Qq))
    {
        long result = table[query[1]][query[1]];
        result -= table[query[1]][query[0] - 1];
        result -= table[query[0] - 1][query[1]];
        result += table[query[0] - 1][query[0] - 1];
        result.writeln;
    }
}


Measured memory_bytes: 10620
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;


int main() {
	int a[3][3];
	bool f = true;
	for (int i = 0; i < 3;i++){
		for (int j = 0; j < 3; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < 2; i++){
		if (a[0][i] - a[0][i+1] != a[1][i] - a[1][i+1] || a[1][i] - a[1][i+1] != a[2][i] - a[2][i+1]){
			cout << "No";
			return 0;
		}
	}
	if (a[0][0] - a[0][2] != a[1][0] - a[1][2] || a[1][0] - a[1][2] != a[2][0] - a[2][2]){
		cout << "No";
		return 0;
	}
	for (int i = 0; i < 2; i++){
		if (a[i][0] - a[i+1][0] != a[i][1] - a[i+1][1] || a[i][1] - a[i+1][1] != a[i][2] - a[i+1][2]){
			cout << "No";
			return 0;
		}
	}
	if (a[0][0] - a[2][0] != a[0][1] - a[2][1] || a[0][1] - a[2][1] != a[0][2] - a[2][2]){
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main()
{
    using namespace std;
    int A,B,C;
    cin >> A>>B>>C;
    
    const int CONTAINER1_CAPA =A-B;
    
    //移動後残る分
    const int CONTAINER2_LEFT=C>CONTAINER1_CAPA?C-CONTAINER1_CAPA:0;
    cout<<CONTAINER2_LEFT<<std::endl;
    
    return 0;
}


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

const int MAX_N = 100000;

int main() {
  std::string S;
  std::cin >> S;

  int N = S.length();

  int even = 0;
  for(int i = 0; i < N; ++i) {
    if(i % 2 == 0 and S[i] != '0') ++even;
    if(i % 2 == 1 and S[i] != '1') ++ even;
  }

  int odd = 0;
  for(int i = 0; i < N; ++i) {
    if(i % 2 == 1 and S[i] != '0') ++odd;
    if(i % 2 == 0 and S[i] != '1') ++odd;
  }

  std::cout << std::min(even, odd) << std::endl;
}


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

int N,K,M;
int pool[100001];
bool vis[100001];
int main(void)
{
    cin>>N>>M;
    int num = 0;
    int pen = 0;
    for(int i = 0;i < M;i ++){
        int x;
        char str[3];
        cin>>x>>str;
        if(vis[x])
            continue;
        if(str[0]=='W')
            pool[x] ++;
        else {
            num ++;pen += pool[x];
            vis[x] = true;
        }
    }
    cout<<num<<" "<<pen<<endl;;
    return 0;
}


Measured memory_bytes: 768
def outerProduct(ax, ay, bx, by)
    return ax * by - bx * ay
end
    while l = gets
    x1, y1, x2, y2, x3, y3, px, py = l.split.map(&:to_f)
    #p x1, y1, x2, y2, x3, y3, px, py
    
    z1 = outerProduct((x2-x1), (y2-y1), (px-x1), (py-y1))
    z2 = outerProduct((x3-x2), (y3-y2), (px-x2), (py-y2))
    z3 = outerProduct((x1-x3), (y1-y3), (px-x3), (py-y3))
    
    if (z1 > 0 && z2 > 0 && z3 > 0) || (z1 < 0 && z2 < 0 && z3 < 0)
        puts "YES"
    else
        puts "NO"
    end
end


Measured memory_bytes: 6884
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    writeln((n - 1) * (m - 1));
}

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: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vll = vector<long long>;

int main(){
  ll a, b, c;
  cin >> a >> b >> c;

  ll k = c - a - b;
  ll p = 4*a * b;
  ll q = k * k;

  if(k < 0){
    cout << "No" << endl;
  }
  else{
    if(p < q){
      cout << "Yes" << endl;
    }
    else{
       cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int n;
	cin>>n;
	vector<ll> h(100002, 0);
	REP(i, n) {
		ll a, b;
		cin>>a>>b;
		h[a] += 1;
		if(b + 1 < 100002) h[b + 1] -= 1;
	}
	FOR(i, 1, 100002) {
		h[i] += h[i - 1];
	}
	ll ans = 0;
	REP(i, 100002) {
		if(h[i] >= i - 1) ans = max(ans, i - 1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3

N, M, S = map(int, input().split())
S = min(S, 2500)  # 2500枚持っていれば必ずどこにでも行ける

# UVABを読み込む
uvab_list = []
for i in range(M):
    U, V, A, B = map(int, input().split())
    uvab_list.append((U, V, A, B))

cd_list = []
for i in range(N):
    C, D = map(int, input().split())
    cd_list.append((C, D))

edge = { }
for U, V, A, B in uvab_list:
    for j in range(2501):  # 各辺に対して残りコストの分だけループ?
        if j - A >= 0:
            if not (U, j) in edge:
                edge[(U, j)] = []
            edge[(U, j)].append((B, (V, j - A)))
            if not (V, j) in edge:
                edge[(V, j)] = []
            edge[(V, j)].append((B, (U, j - A)))

# edge[V,c] <- 点Vでコストcのときに行ける辺のリスト、至る先と至ったあとでのコストを記録している

for i in range(N):
    C, D = cd_list[i]
    for j in range(2501):
        if not (i + 1, j) in edge:
            edge[(i + 1, j)] = []
        jj = min(2500, j + C)
        edge[(i + 1, j)].append((D, (i + 1, jj)))

import heapq
def dijkstra_heap(p):
    vlist=[]
    for i in range(1,N+1):
        for j in range(2501):
            vlist.append((i,j))
    d = {}
    used = {}
    INF = float("inf")
    for v in vlist:
        used[v] = True
        d[v] = INF
    # スタート地点
    d[p] = 0
    used[p] = False

    edgelist = []
    for e in edge[p]:
        heapq.heappush(edgelist,e)

    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False

        for e in edge[v]:
            if used[e[1]]: # 行き先に行ったことなかったら追加
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))

    return d



# 両替所を自己ループとして解決している
res = dijkstra_heap((1,S))
final_result = [float("inf")]*N

for p in res:
    if final_result[p[0]-1] > res[p]:
        final_result[p[0]-1] = res[p]

for r in final_result[1:]:
    print(r)

Measured memory_bytes: 175072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
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;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

ll a[110];
mint dp[110][110000];
mint sdp[110][110000];

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

    ll N, K; cin >> N >> K;
    rep(i, N) cin >> a[i+1];

    dp[0][0] = 1;
    rep(i, 110000) sdp[0][i] = 1;
    for(ll i = 1; i <= N; i++) {
        for(ll j = 0; j <= K; j++) {
            dp[i][j] = sdp[i-1][j];
            if(j-a[i]-1 >= 0) dp[i][j] -= sdp[i-1][j-a[i]-1];

            if(j-1 >= 0) sdp[i][j] = sdp[i][j-1] + dp[i][j];
            else sdp[i][j] = dp[i][j];
        }
    }
    cout << dp[N][K] << endl;
}


Measured memory_bytes: 176256
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private int N;
  private int[] a;

  private void solve(Scanner sc, PrintWriter out) {
    N = sc.nextInt();
    a = new int[N];

    int sum = 0;
    for (int i = 0; i < N; ++i) {
      a[i] = sc.nextInt();
      sum += a[i];
    }
    int t = (int)Math.round(1.0 * sum / N);
    int cost = 0;
    for (int i = 0; i < N; ++i) {
      cost += (a[i] - t) * (a[i] - t);
    }
    out.println(cost);
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

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

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

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

  vector<int> Nums;
  int now = 1;
  int cnt = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( S[i] == (char)('0' + now) ) cnt++;
    else {
      Nums.push_back(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  if ( cnt != 0 ) Nums.push_back(cnt);
  /*
  for ( int i = 0; i < Nums.size(); i++ ) {
    cout << Nums[i] << " ";
  }
  cout << endl;
  */
  //if ( Nums.size() % 2 == 0 ) Nums.push_back(0);

  int Add = 2 * K + 1;
  int ans = 0;
  int left = 0,right = 0,tmp = 0;
  for ( int i = 0; i < Nums.size(); i += 2 ) {
    int Nextleft = i;
    int Nextright = min( i + Add, (int)Nums.size() );

    while( Nextleft > left ) {
      tmp -= Nums[left];
      left++;
    }

    while( Nextright > right ) {
      tmp += Nums[right];
      right++;
    }
    ans = max(tmp, ans);
  }
  
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
ll d[200001];
ll mod = 998244353;
ll tree[200001];
int n;

void Update(int x, ll y){
    while(x <= n){
        tree[x] += y;
        tree[x] %= mod;
        x +=(x & (-x));
    }
}

ll Quary(int x){
    ll cnt = 0;
    while(x > 0){
        cnt += tree[x];
        cnt %= mod;
        x -= (x & (-x));
    }
    return cnt;
}

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

    int k; cin >> n >> k;
    vector<pair<int,int>> v;

    for(int i =0 ; i < k; i++){
        int x, y; cin>> x>> y;
        v.push_back({x, y});
    }
    d[1] = 1;
    Update(1, d[1]);

    for(int i = 2; i <= n; i++){
        for(int j = 0; j < k; j++){
            int Left = max(1, i - v[j].second);
            int Right = i - v[j].first;
            if(Right < 1)continue;
            ll cnt = (Quary(Right) - Quary(Left - 1));
            while(cnt < 0)cnt += mod;
            cnt %= mod;
            d[i] += cnt;
            d[i] %= mod;
        }
        Update(i, d[i]);
    }

    cout << d[n] << '\n';
}


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

static const int MAX = 1050;

ll N;
ll T[MAX],A[MAX];

int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> T[i] >> A[i];

  ll t = 1, a = 1;

  for(int i=0;i<N;i++){
    ll x,y;
    if(t%T[i]==0) x = t/T[i];
    else x = t/T[i]+1;
    if(a%A[i]==0) y = a/A[i];
    else y = a/A[i]+1;

    ll nmax = max(x,y);
    t = nmax * T[i];
    a = nmax * A[i];
  }
  ll ret = t+a;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    int K = 0;
    int check = 0;
    
    if((A+B)%2 == 0){
      K = (Math.abs(A)+Math.abs(B))/2;
      check++;
    }
    
    if(check == 0){
      System.out.println("IMPOSSIBLE");
    } else {
      System.out.println(K);
    }
    
  }
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(b==1) return 0 * printf("0");

	for(int i=1;;i++)
		if((a-1)*(i-1)+a>=b) return 0 * printf("%d",i);
}

Measured memory_bytes: 256
import math.max
object Main extends App {
    val n = io.StdIn.readInt
    val s = io.StdIn.readLine

    def rec(str: String, count: Int, max_count: Int): Int = {
        if (str.isEmpty) max_count
        else str.head match {
            case 'I' => rec(str.tail, count+1, max(count+1, max_count))
            case 'D' => rec(str.tail, count-1, max(count-1, max_count))
        }
    }

    val result = rec(s, 0, 0)
    println(result)
}

Measured memory_bytes: 25416
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n,ans,a[100005],b[100005],c[100005];


int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    fort (i,n)
    {
        cin >> a[i] >> b[i];
        c[i]=a[i]+b[i], ans-=b[i];
    }
    sort (c+1,c+n+1);
    reverse (c+1,c+n+1);
    for (int i = 1; i <= n; i+=2)
        ans+=c[i];
    cout << ans;
}


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

int main(){
    long long n;
    string s, t, ans="";
    cin >> n;
    cin >> s >> t;
    for(int i=0;i<n;i++){
        ans = ans + s[i] + t[i];
    }

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



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int a, b;
    struct node *next;
} node;

int main()
{
    int a, b;
    node *head = NULL, *cur = NULL;

    while( scanf("%d%d", &a, &b), a | b ){
        //確保と格納
        node *new = (node *)malloc(sizeof(node));
        if( new == NULL ) exit(-1);
        if( a < b ){ new->a = a; new->b = b; }
        else { new->a = b; new->b = a; }
        new->next = NULL;

        //連結
        if( head == NULL ){ head = new; }
        else { cur->next = new; }
        cur = new;
    }

    cur = head;
    while( cur ){
        printf("%d %d\n", cur->a, cur->b);
        cur = cur->next;
    }

    return 0;
}

Measured memory_bytes: 660
while n=gets.to_i
	exit if n==0
	sum=1
	num=[1,2,3,4,5,6] 
	n.times do
		dire=gets.chomp("")
		case dire
		when "North" then
			a=num[0]
			num[0]=num[1]
			num[1]=num[5]
			num[5]=num[4]
			num[4]=a
		when "East" then
			a=num[0]
			num[0]=num[3]
			num[3]=num[5]
			num[5]=num[2]
			num[2]=a
		when "West" then
			a=num[0]
			num[0]=num[2]
			num[2]=num[5]
			num[5]=num[3]
			num[3]=a
		when "South" then
			a=num[0]
			num[0]=num[4]
			num[4]=num[5]
			num[5]=num[1]
			num[1]=a
		when "Right" then
			a=num[1]
			num[1]=num[2]
			num[2]=num[4]
			num[4]=num[3]
			num[3]=a
		when "Left" then
			a=num[1]
			num[1]=num[3]
			num[3]=num[4]
			num[4]=num[2]
			num[2]=a
		end
		sum+=num[0]
	end
	puts sum
end
 

Measured memory_bytes: 8816
import Control.Monad
import qualified Data.ByteString.Char8 as B  
import qualified Data.Vector.Unboxed as VU
import Data.Char

solve :: VU.Vector Int -> Int -> Int
solve xs acc
    | VU.null xs || VU.all (==0) xs = acc 
    | otherwise = solve (VU.map (subtract 1) ts) (acc+1) + (solve ds' 0)
    where
        ds = VU.dropWhile (<=0) xs 
        ts = VU.takeWhile (>0) ds
        ds' = VU.drop (VU.length ts) ds

main = do
    n <- readLn :: IO Int
    hs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ solve hs 0

Measured memory_bytes: 1020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String n = br.readLine();

		String nums;

		int count=0;
		for(int i=0; i<Integer.parseInt(n); i++){
			 nums = br.readLine();
			if(new BigInteger(nums).isProbablePrime(10)){
				count++;
			}
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 47432
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int main() {
	while (true) {
		string S;
		cin >> S;
		if (S == "#")
			break;
		int cou = 0;
		for (int i = 0; i < (int) S.length(); i++) {
			if (S[i] == '.')
				cou++;
		}
		if (cou == 2) {
			int y = 0, m = 0, d = 0;
			cou = 0;
			for (int i = 0; i < (int) S.length(); i++) {
				if (S[i] == '.') {
					cou++;
					continue;
				}
				if (cou == 0) {
					y *= 10;
					y += S[i] - '0';
				} else if (cou == 1) {
					m *= 10;
					m += S[i] - '0';
				} else {
					d *= 10;
					d += S[i] - '0';
				}
			}
			ll sumday = 0;
			int y1 = 2013;
			int m1 = 1;
			if (y == 2012) {
				sumday = (ll) (d - 21);
			} else {
				sumday = 11;
				while (y1 < y - 400) {
					y1 += 400;
					sumday += (ll) (366 * 97 + 365 * 303);
				}
				while (y1 < y) {
					if (y1 % 400 == 0)
						sumday += (ll) 366;
					else if (y1 % 100 == 0)
						sumday += (ll) 365;
					else if (y1 % 4 == 0)
						sumday += (ll) 366;
					else
						sumday += (ll) 365;
					y1++;
				}
				while (m1 < m) {
					if (m1 == 2) {
						if (y1 % 400 == 0)
							sumday += (ll) 29;
						else if (y1 % 100 == 0)
							sumday += (ll) 28;
						else if (y1 % 4 == 0)
							sumday += (ll) 29;
						else
							sumday += (ll) 28;
					} else {
						sumday += (ll) days[m1 - 1];
					}
					m1++;
				}
				sumday += (ll) (d - 1);
			}
			ll b1, ka1, t1, w1, ki1;
			ki1 = sumday % (ll) 20;
			sumday /= (ll) 20;
			w1 = sumday % (ll) 18;
			sumday /= (ll) 18;
			t1 = sumday % (ll) 20;
			sumday /= (ll) 20;
			ka1 = sumday % (ll) 20;
			sumday /= (ll) 20;
			b1 = sumday % (ll) 13;
			printf("%lld.%lld.%lld.%lld.%lld\n", b1, ka1, t1, w1, ki1);
		} else {
			int b = 0, ka = 0, t = 0, w = 0, ki = 0;
			cou = 0;
			for (int i = 0; i < (int) S.length(); i++) {
				if (S[i] == '.') {
					cou++;
					continue;
				}
				if (cou == 0) {
					b *= 10;
					b += S[i] - '0';
				} else if (cou == 1) {
					ka *= 10;
					ka += S[i] - '0';
				} else if (cou == 2) {
					t *= 10;
					t += S[i] - '0';
				} else if (cou == 3) {
					w *= 10;
					w += S[i] - '0';
				} else {
					ki *= 10;
					ki += S[i] - '0';
				}
			}
			int y = 2012;
			int m = 12;
			int d = 21;
			d += b * (20 * 20 * 18 * 20) + ka * (20 * 18 * 20) + t * (18 * 20)
					+ w * 20 + ki;
			while (d > days[m - 1]) {
				d -= days[m - 1];
				m++;
				if (m == 13) {
					y++;
					m = 1;
					if (y % 400 == 0)
						days[1] = 29;
					else if (y % 100 == 0)
						days[1] = 28;
					else if (y % 4 == 0)
						days[1] = 29;
					else
						days[1] = 28;
				}
			}
			days[1] = 28;
			printf("%d.%d.%d\n", y, m, d);
		}
	}
	return 0;
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i)
	{
		cin >> A[i];
		--A[i];
	}

	vector<bool> visited(N, false);
	ll t = 0;
	while (true)
	{
		if (visited[t])
		{
			break;
		}
		visited[t] = true;
		t = A[t];
	}

	// cerr << "t: " << t << endl;

	ll c0 = 0;
	ll tmp = 0;
	while (tmp != t)
	{
		tmp = A[tmp];
		++c0;
	}

	// cerr << "c0: " << c0 << endl;

	ll c = 0;
	tmp = t;
	do
	{
		if (tmp != A[tmp])	++c;
		tmp = A[tmp];
	} while (tmp != t);

	// cerr << "c: " << c << endl;

	if (K < c0)
	{
		ll n = K;
		ll a = 0;
		for (ll i = 0; i < n; ++i)
		{
			a = A[a];
		}
		cout << a + 1 << endl;
	}
	else if (c == 0)
	{
		cout << A[t] + 1 << endl;
	}
	else
	{
		ll n = (K - c0) % c + c0;
		ll a = 0;
		for (ll i = 0; i < n; ++i)
		{
			a = A[a];
		}
		cout << a + 1 << endl;
	}

	/*
	vector<vector<bool>> adj(N, vector<bool>(N, false));
	for (ll i = 0; i < N; ++i)
	{
		adj[i][A[i]] = true;
	}
	vector<ll> deg(N, 0);
	for (ll i = 0; i < N; ++i)
	{
	}
	*/

	/*
	ll t = 0;
	ll c = 0;
	do
	{
		cerr << t << " ";
		t = A[t];
		++c;
	} while (t != 0);
	cerr << endl;

	cout << A[K % c] + 1 << endl;
	*/

	return 0;
}


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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int H, int W, vector<vector<bool>>& walls) {
    vector<ll> previousRow(W+1, 0), currentRow(W+1, 0);
    previousRow[1] = 1;

    REP(i,1,H+1) {
        REP(j,1,W+1) {
            if (walls[i][j]) {
                currentRow[j] = 0;
                continue;
            }
            currentRow[j] = (previousRow[j] + currentRow[j-1]) % MOD;
        }
        previousRow = currentRow;
    }
    ll answer = currentRow.back();

	stringstream ss;
    ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int H, W;
    cin >> H >> W;

    vector<vector<bool>> walls(H+1, vector<bool>(W+1, false));
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            char c;
            cin >> c;
            if (c == '#') walls[i][j] = true;
        }
    }

    solve(H, W, walls);
    
    return 0;
}



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

typedef long long ll;
#define endl "\n"

const int M = (int) 1e9+7;
int n,k;
ll ans=1;
vector<ll> pos, neg;
int pcnt=0, ncnt=0;

ll solve(){
    cin>>n>>k;
    for (int i=0; i<n; ++i){
        ll foo; cin>>foo;
        if (foo>0) pos.push_back(foo);
        else neg.push_back(abs(foo));
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int P=pos.size(), N=neg.size();
    if (k==n ? N%2==0 : P || k%2==0){
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        for ( ; k; --k){
            if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[ncnt])){
                ans=ans*pos[pcnt]%M; ++pcnt;
            }
            else{
                ans=ans*neg[ncnt]%M; ++ncnt;
            }
        }
        if (ncnt&1){
            ans=1;
            if (pcnt<P && ncnt>=1 && (ncnt>=N || pcnt<1 || pos[pcnt]*pos[pcnt-1]>neg[ncnt]*neg[ncnt-1])){
                for (int tt=0; tt<pcnt+1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt-1; ++tt)
                    ans=ans*neg[tt]%M;
            }
            else{
                for (int tt=0; tt<pcnt-1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt+1; ++tt)
                    ans=ans*neg[tt]%M;
            }
        }
        return ans%M;
    }
    for(; k; --k) {
        if(pcnt<pos.size()&&(ncnt>=neg.size()||pos[pcnt]<neg[ncnt])) {
            ans=ans*pos[pcnt]%M;
            ++pcnt;
        } else {
            ans=ans*neg[ncnt]%M;
            ++ncnt;
        }
    }
    return (M-ans)%M;
}

int main(){
    // INT VS LL
    // freopen("input.txt", "r", stdin);
    //    INT VS LL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<solve();
    return 0;
}


Measured memory_bytes: 5684
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] >= k) {
                count++;
            }
        }
        System.out.println(count);
    }

}



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

using namespace std;

int main () {
	long long x, y;
	cin >> x >> y;
	if (x == 0) {
		if (y < 0) {
			cout << -y + 1;
		}
		else cout << y;
		return 0;
	}
	if (y == 0) {
		if (x < 0) {
			cout << -x;
		}
		else cout << 1 + x;
		return 0;
	}
	if (x >= 0) {
		if (y >= 0) {
			if (y >= x) {
				cout << y - x;
			}
			else cout << 2 + x - y;
		}
		else {
			if (-y >= x) {
				cout << -y - x + 1;
			}
			else cout << 1 + x + y;
		}
	}
	else {
		if (y >= 0) {
			if (y >= -x) {
				cout << 1 + y + x;
			}
			else cout << 1 - y - x;
		}
		else {
			if (-y >= -x) {
				cout << 2 + x - y;
			}
			else cout << y - x;	
		}
	}
	return 0;
}

Measured memory_bytes: 256
n, x = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
if a[0] > x:
    cnt += a[0] - x
    a[0] = x

for i in range(1, n):
    if a[i] + a[i-1] > x:
        cnt += a[i] - (x - a[i-1])
        a[i] = x - a[i-1]
print(cnt)

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

map<int,int>mp;

long long gcd(long long x, long long y)
{

  long long r;
  
  // ユーグリッドの互除法
  while((r = x % y) != 0) // yで割り切れるまでループ
    {
      x = y;
      y = r;
    }
  return y;
}

long long lcm(long long x, long long y)
{

  return (x * y / gcd(x, y));
}
int main(){

  int N,M;

  cin>>N>>M;

  string s,t;

  cin>>s>>t;

  long long  ans=lcm(N,M);

  
  for(int i=1;i<N;i++){
      
    mp.insert(make_pair((i*(ans/N))+1,i));
      
  }
    
  if(t[0]!=s[0]){
    cout<<-1<<endl;
    return 0;
  }
    
  for(int i=1;i<M;i++){
      
    if(mp.count((i*(ans/M))+1)==1){
	
      if(t[i]!=s[mp[(i*(ans/M))+1]]){
	cout<<-1<<endl;
	return 0;
      }
    }
  }
    
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 4736
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  long long xyz[n][3];
  for(int i=0;i<n;i++){
    cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
  }
  pair<long long,int> value[n];
  long long ans = 0;
  for(int s=0;s < (1 << 3);s++){
    long long x,y,z;
    x = 1;
    y = 1;
    z = 1;
    if(s & (1 << 0)) x = -1;
    if(s & (1 << 1)) y = -1;
    if(s & (1 << 2)) z = -1;
    for(int i=0;i<n;i++){
      value[i] = make_pair(x*xyz[i][0]+y*xyz[i][1]+z*xyz[i][2],i);
    }
    sort(value,value+n);
    //reverse(value,value+n);
    x = 0;
    y = 0;
    z = 0;
    for(int i=0;i<m;i++){
      x += xyz[value[i].second][0];
      y += xyz[value[i].second][1];
      z += xyz[value[i].second][2];
    }
    ans = max(ans,abs(x)+abs(y)+abs(z));
  }
  cout << ans << endl;


  return 0;
}


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

#define DEBUG(X) if(X)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int main()
{
  FASTIO;
  string str;
  cin >> str;
  int q;
  cin >> q;
  list<char> ls;
  bool reversed = false;
  for(int i = 0, end = str.size(); i < end; i++)
    ls.push_back(str[i]);
  while(q--)
  {
    int op;
    cin >> op;
    if(op == 1)
      reversed = !reversed;
    else
    {
      int x;
      char c;
      cin >> x >> c;
      if(x == 1)
      {
        if(!reversed) 
          ls.push_front(c);
        else  
          ls.push_back(c);
      }
      else
      {
        if(!reversed)
          ls.push_back(c);
        else  
          ls.push_front(c);
      }
    }
  }

  if(reversed)
    reverse(ls.begin(), ls.end());

  for(auto itr : ls) 
      cout << itr; 
  cout << endl;
  return 0;
}
// coloco a , n -= a, 
/*
  12 3 4
  bbbrrrrbbbrr
*/


Measured memory_bytes: 10064
import java.math.BigDecimal;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		//a,bを入力し、商、余り、浮動小数点を出力する
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int syou=a/b;
		int amari=a%b;
		double syosu=(double)a/(double)b;
		BigDecimal bd=new BigDecimal(syosu);
		BigDecimal syosu2=bd.setScale(6,BigDecimal.ROUND_DOWN);
		System.out.println(syou+" "+amari+" "+syosu2);
	}

}



Measured memory_bytes: 26612
from math import sqrt


def dist2(aa, bb):
    return sum((a - b) ** 2 for a, b in zip(aa, bb))


def main():
    n, d = map(int, raw_input().split())
    xx = []
    for _ in xrange(n):
        xx.append(map(int, raw_input().split()))
    count = 0
    for i in xrange(n - 1):
        for j in xrange(i + 1, n):
            d = dist2(xx[i], xx[j])
            if d == int(sqrt(d)) ** 2:
                count += 1
    print count


if __name__ == '__main__':
    main()


Measured memory_bytes: 28012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

template <typename T>
struct BIT {
    vector<T> bit;
    // 単位元
    const T neutral = 0;
    // 要素数
    int n;
    BIT(int n_ = 1e5) { init(n_); }
    void init(int sz) { 
        n=1; while(n < sz) n*=2;
        bit.assign(n+1, neutral); 
    }
    void update(int i, T w) {
        for(int x=i+1; x<bit.size(); x += x&-x) bit[x] += w;
    }
    // [0,i]
    T query(int i) {
        T ret = neutral;
        for(int x=i+1; x>0; x -= x&-x) ret += bit[x];
        return ret;
    }
    // 合計がw以上の最小の位置
    int lower_bound(T w) {
        int x = 0;
        for(int k=n; k>0; k>>=1) {
            if(x+k <= n && bit[x+k] < w) {
                w -= bit[x+k];
                x += k;
            }
        }
        return x;
    }
};

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n) cin >> a[i], a[i]--;
    REP(i, n) cin >> b[i], b[i]--;

    ll ret = INF;
    REP(i, 1LL<<n) {
        vector<ll> v;
        vector<PII> need(50), v0, v1;
        REP(j, n) {
            if(i&1LL<<j) {
                v.push_back(a[j]);
                if(j%2==0) {
                    need[a[j]].first++;
                    v0.push_back({a[j], j});
                }
                else {
                    need[a[j]].second++;
                    v1.push_back({a[j], j});
                }
            }
            else {
                v.push_back(b[j]);
                if(j%2==0) {
                    need[b[j]].second++;
                    v1.push_back({b[j], j});
                }
                else {
                    need[b[j]].first++;
                    v0.push_back({b[j], j});
                }
            }
        }
        sort(ALL(v));
        vector<PII> vp(50);
        REP(j, n) {
            if(j%2==0) vp[v[j]].first++;
            else vp[v[j]].second++;
        }
        if(need != vp) continue;

        // 何手かかるか？
        sort(ALL(v0));
        sort(ALL(v1));
        vector<ll> sorted;
        REP(i, max(v0.size(), v1.size())) {
            if(i < v0.size()) sorted.push_back(v0[i].second);
            if(i < v1.size()) sorted.push_back(v1[i].second);
        }
        dump(bitset<3>(i));
        dump(sorted);

        ll tmp = 0;
        vector<ll> num(n);
        REP(j, n) {
            FOR(k, sorted[j], n) {
                tmp += num[k];
            }
            num[sorted[j]]++;
        }
        chmin(ret, tmp);
    }

    if(ret == INF) cout << -1 << endl;
    else cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	
	int meiji[44];
	int taisho[14];
	int showa[63];
	int heisei[28];
	int a,b,ans;
	int i,j;
	
	scanf("%d %d",&a,&b);
	
	if(a==0){
		if(b<=1911){    //??????
			ans=b-1868+1;
			printf("M%d\n",ans);
			
		}else if(b<=1925){   //??§??£
			ans=b-1912+1;
			printf("T%d\n",ans);
			
		}else if(b<=1988){   //??????
			ans=b-1926+1;
			printf("S%d\n",ans);
			
		}else if(b<=2016){   //??????
			ans=b-1989+1;
			printf("H%d\n",ans);
		}
	}
	if(a==1){
		ans=1868+b-1;
		printf("%d\n",ans);
	}
	if(a==2){
		ans=1912+b-1;
		printf("%d\n",ans);
	}
	if(a==3){
		ans=1926+b-1;
		printf("%d\n",ans);
		
	}
	if(a==4){
		ans=1989+b-1;
		
		printf("%d\n",ans);
	}
		
	return 0;
}
	

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

int main(){
	int n,x;cin>>n>>x;
	vector<int>v(n);
	int sum=0,cnt=n;
	for(auto&& u:v){cin>>u;sum+=u;}
	sort(begin(v),end(v));
	int rem=x-sum,mn=v.front();
	cnt+=rem/mn;
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MAX_N = 50;

int main()
{
	int n;
	pair<int, int> xy[MAX_N];
	map<pair<int, int>, int> pqs;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> xy[i].first >> xy[i].second;
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i != j)
			{
				int dx = xy[i].first - xy[j].first;
				int dy = xy[i].second - xy[j].second;
				++pqs[make_pair(dx, dy)];
			}
		}
	}
	int count = 0;
	for (auto &pq : pqs)
	{
		count = max(count, pq.second);
	}
	cout << n - count << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;
typedef long long li;
typedef pair <li, li> pi;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

const li mod = 1e9 + 7;

int main() {
    string s, t;
    cin >> s >> t;
    const int n = s.size(), m = t.size();

    vector<int> sas(1), tas(1);
    for (char c : s) {
        sas.push_back(sas.back() + (c == 'A' ? 1 : 2));
    }
    for (char c : t) {
        tas.push_back(tas.back() + (c == 'A' ? 1 : 2));
    }

    int q;
    cin >> q;
    rep(i, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int ssc = (sas[b] - sas[a - 1]) % 3;
        int tsc = (tas[d] - tas[c - 1]) % 3;

        cout << (ssc == tsc ? "YES" : "NO") << endl;
    }

    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001

	

int main(){
	int N,K;

	cin>>K>>N;
	
	vector ok(K+1,vector<int>(N+1,0));
	ok[0][0] = 1;

	vector ng = ok;
	
	for(int i=1;i<=K;i++){
		for(int j=0;j<=N;j++){
			ok[i][j] = ok[i-1][j];
			if(j!=0)ok[i][j] = mod(ok[i][j] + ok[i][j-1]);
			
			ng[i][j] = mod(2*ng[i-1][j]);
			if(j!=0)ng[i][j] = mod(ng[i][j] + ng[i][j-1]);
		}
		for(int j=0;j<=N;j++){
			ng[i][j] = mod(ng[i][j] - ng[i-1][j]);
		}
	}
	
	for(int i=2;i<=2*K;i++){
		int OK = 0,NG = 0;
		for(int j=1;j<=K;j++){
			int x = j;
			int y = i-x;
			if(y<=0||y>K){
				OK++;
			}
			else{
				if(x<y){
					NG++;
				}
			}
		}
		
		int ans = 0;
		for(int j=0;j<=N;j++){
			ans = mod(ans + mod(ok[OK][j] * ng[NG][N-j]));
		}
		if(i%2==0){
			for(int j=0;j<=N-1;j++){
				ans = mod(ans + mod(ok[OK][j] * ng[NG][N-1-j]));
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 34952