akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N, W = map(int, input().split())
    weight, value = [0] * N, [0] * N
    for i in range(N):
        weight[i], value[i] = map(int, input().split())

    # 添字を付け加える系DP．ナップサックとかはこの一種
    # https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E9%A1%9E%E9%A1%8C-3

    INF = 10**20  # INF+INFを計算してもオーバーフローしない範囲で大きく

    I = N
    # dpテーブル dp[i][j]:=i番目以下で価値j以上の時の，重さの最小値
    J = sum(value)
    dp = [[INF]*(J+1) for _ in range(I+1)]
    # 初期条件
    dp[0][0] = 0
    # ループ
    for i in range(1,I+1):
        for j in range(J+1):
            if j-value[i-1] >= 0:
                dp[i][j] = min(dp[i][j], dp[i-1][j-value[i-1]]+weight[i-1])
            dp[i][j] = min(dp[i][j], dp[i-1][j])
    ans = 0
    for j in range(J+1):
        if dp[I][j] <= W:
            ans = j
    print(ans)

resolve()

Measured memory_bytes: 131080
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){
  char W[10],T[1000];
  int count=0,i;
  scanf("%s",W);
  while(1){
    scanf(" %s",T);
    if(strcmp(T,"END_OF_TEXT")==0){
      break;
    }
    for(i=0;W[i]!='\0';i++){
      T[i]=tolower(T[i]);
    }
    if(strcmp(T,W)==0){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++)
	{
	if(s[i]>'Z') s[i]-=26;
	s[i]+=n;
	if(s[i]>'Z') s[i]-=26;
	cout<<s[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int v[105],n, m, sum = 0, cnt = 0;
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        sum += v[i];
    }
    for (int i = 0; i < n; ++i) {
        if (v[i] * m * 4 >= sum) {
            cnt++;
            if (cnt == m) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

struct data
{
    int x,v;
    data(){};
    data(int x, int v):x(x),v(v){};
    bool operator<(const data &r)const{
        return v<r.v;
    }
};

data tree[1000005];
int n;
typedef long long LL;

data min(data a, data b)
{
    if(a<b)return a;
    return b;
}
void update(int n, int s, int e, int si, int ei, data v)
{
    if(e<si|s>ei)return;
    if(si<=s&&e<=ei){
        tree[n]=v;
        return;
    }
    int m=(s+e)/2,lch=2*n,rch=lch+1;
    update(lch,s,m,si,ei,v);
    update(rch,m+1,e,si,ei,v);
    tree[n]=min(tree[lch],tree[rch]);
}

data query(int n, int s, int e, int si, int ei)
{
    if(e<si|s>ei)return data(0,1e9);
    if(si<=s&&e<=ei){
        return tree[n];
    }
    int m=(s+e)/2,lch=2*n,rch=lch+1;
    data v1,v2;
    v1=query(lch,s,m,si,ei);
    v2=query(rch,m+1,e,si,ei);
    return min(v1,v2);
}

LL g(int X, int Y)
{
    return (LL)X*(X+1)/2-(LL)Y*(Y+1)/2-(LL)(X-Y-1)*(X-Y)/2;
}

LL f(int s, int e)
{
    if(s>e)return 0;
    data t=query(1,1,n,s,e);
    int X=e-s+1,Y=t.x-s;
    return g(X,Y)*t.v+f(s,t.x-1)+f(t.x+1,e);
}

int main()
{
    LL res=0;
    int i,x;
    scanf("%d", &n);
    for(i=1;i<=n;i++){
        scanf("%d", &x);
        update(1,1,n,i,i,data(i,x));
    }
    printf("%lld", f(1,n));
    return 0;
}


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

#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf=(1LL<<60);
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r,l;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >>s;
  int g,p;
  g=p=0;
  lol ans=0;
  for(int i=0;i<s.size();i++){
    if(g>p){
      ans+=(s[i]=='g');
      p++;
    }else{
      ans-=(s[i]=='p');
      g++;
    }
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int a,b;
    cin >> a >> b;
    string ans="Yay!";
    if(a>8||b>8) ans = ":(";
    cout << ans << endl;
}

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


Measured memory_bytes: 256
n = int(input())
s = input().strip()

wcs, bcs = [0], [0]
wc, bc = 0, 0
if s[0] == '#':
  bc = 1
for prevs, _s in zip(s, s[1:]):
  if prevs != _s:
    bcs.append(bc + bcs[-1])
    if _s == '#':
      bc = 1
    else:
      bc = 0
  else:
    if _s == '#':
      bc += 1
bcs.append(bc + bcs[-1])

wc, bc = 0, 0
if s[-1] == '.':
  wc = 1
for prevs, _s in zip(s[::-1], s[::-1][1:]):
  if prevs != _s:
    wcs.append(wc + wcs[-1])
    if _s == '.':
      wc = 1
    else:
      wc = 0
  else:
    if _s == '.':
      wc += 1
wcs.append(wc + wcs[-1])

minbw = pow(10, 6)
for bc, wc in zip(bcs, wcs[::-1]):
  if bc + wc < minbw:
    minbw = bc + wc
print(minbw)


Measured memory_bytes: 20856
#include<stdio.h>

int main(void) {
	int n;
	int i;
	int k = 0;
	int max = 0;
	int max_youso = 0;

	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		int cnt = 0;
		k = i;
		while (k > 0) {
			if (k % 2 == 0) {
				cnt++;
				k = k / 2;
			}
			else {
				break;
			}
		}
		//printf("%d\t%d\n", i, cnt);
		if (max <= cnt) {
			max = cnt;
			max_youso = i;
		}
	}

	printf("%d\n", max_youso);


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    REP(i, n) cin >> x[i];

    int ans = 0;
    REP(i, n){
        ans += min(x[i], k - x[i]) * 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
public class Main {
	
	
	 
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
 
        for(int i =a;i<=b;i++){
            String s = String.valueOf(i);
            if(s.charAt(0)==s.charAt(4) && s.charAt(1)==s.charAt(3)){
                ans++;
            }
        }
        System.out.println(ans);
	}
}

Measured memory_bytes: 25428
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int result = (n/500)*1000;
		n %= 500;
		result += (n/5)*5;
		System.out.println(result);
	}
}

Measured memory_bytes: 22736
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
    int n, A[4][3][10];
    int b,f,r,v;
    cin >> n;
    for (int i = 0;i<4;i++) {
        for (int j = 0;j<3;j++) {
            for (int k = 0;k<10;k++) {
                A[i][j][k] = 0;
            }
        }
    }
    for (int i = 0;i < n;i++) {
        cin >> b>>f >> r>> v;
        A[b-1][f-1][r-1] +=v ;
    }
    for (int i = 0;i < 4;i++) {
        for (int j = 0;j < 3;j++) {
            for (int k = 0;k < 10;k++) {
                cout << " " << A[i][j][k];
            }
            cout << endl;
        }
        if (i!=3) {
            for (int x=0;x<20;x++) {
                cout <<"#";
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
from itertools import permutations
INFTY = 10**8
N,M,R = map(int,input().split())
A = list(map(int,input().split()))
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b,c = map(int,input().split())
    G[a].append((b,c))
    G[b].append((a,c))
d = {i:[INFTY for _ in range(N+1)] for i in range(N+1)}
for i in G:
    d[i][i] = 0
    for x in G[i]:
        d[i][x[0]] = x[1] 
for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            d[i][j] = min(d[i][j],d[i][k]+d[k][j])
dmin = INFTY
for x in permutations(range(R),R):
    cnt = 0
    for i in range(R-1):
        cnt += d[A[x[i]]][A[x[i+1]]]
    dmin = min(dmin,cnt)
print(dmin)

Measured memory_bytes: 49496
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  ll n;
  cin >> n;

  ll ans = n - 1;
  for(ll i = 2; i * i <= n; i++) {
    if(n % i != 0)
      continue;
    ans = min(ans, (i + n / i - 2));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> ii;
typedef std::pair<int, ii> iii;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ii> vii;
typedef std::vector<iii> viii;
const int INF=10000000;
#define pb(a) push_back(a)
#define m0(x) memset(x,-1,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define all(x) (x).begin(), (x).end()
const ll mod=1e9+7;
int N,mingroup,maxgroup,minsize,maxsize;
ll factorial[1005];
ll rfactorial[1005];

ll pow(ll base, ll exp) {
  if(exp==0) return 1;
  if(exp&1) return (base*pow(base,exp-1))%mod;
  else return pow((base*base)%mod,exp/2);
}

void start(){
  factorial[0]=1;
  for (int i=1; i<=1000; i++){
    factorial[i]=(factorial[i-1]*i)%mod;
  }
}




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

ll memo[1001][1001];


ll DP(ll remaining, ll current){
  //cerr<<remaining<<" "<<current<<endl;
  if (remaining==0) return 1;
  else if (remaining<0 or current>maxgroup) return 0;
  else {
    if (memo[remaining][current]==-1){
      ll ans=DP(remaining,current+1);
      
      for (ll i=minsize; i<=maxsize and i*current<=remaining; i++){
          
          ll num=factorial[remaining];
          ll denom=(pow(factorial[current],i)*factorial[remaining-i*current])%mod;
          denom=(denom*factorial[i])%mod;
          denom=inverse(denom);

          ll temp=DP(remaining-i*current,current+1);
          temp=(temp*num)%mod;
          temp=(temp*denom)%mod;

          ans=(ans+temp+mod)%mod;
          //ans=(ans+DP(remaining-i*current,current+1))%mod;
        
      }
      memo[remaining][current]=ans;

    }
    return memo[remaining][current];
  }





}




int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  start();
  m0(memo);
  cin >> N >> mingroup >> maxgroup >> minsize >> maxsize;
  cout<<DP(N,mingroup)<<endl;

  

  



}


Measured memory_bytes: 8192
#include <stdio.h>

static int List[1001];

static int prime(int num);

int main(int argc, char *argv[])
{
	long long c = 1;
	int i, N;
	scanf("%d", &N);

	if ( N == 1 ){
		printf("1\n");
		return 0;
	}

	for ( i = 2; i <= N; i++ ){
		prime(i);
	}

	for ( i = 2; i <= N; i++ ){
		if ( List[i] > 0 ){
			c *= List[i] + 1;
			c %= 1000000007;
		}
	}

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

static int prime(int num)
{
	int i, mod;

	for ( i = 2, mod = num; mod != 1; i++ ){
		while( mod % i == 0 ){
			mod /= i;
			List[i]++;
		}
	}
	return 0;
}


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    string a;

    cin >> a;

    if(a[2]==a[3] and a[4]==a[5]) {

        cout << "Yes" <<'\n';

    } else {

        cout << "No" <<'\n';

    }

    return 0;

}



Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( (ll)( 1e9 + 7 ) )


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

	vector<tuple<string, ll, ll>> v( N );
	rep( i, N )
	{
		string S;
		ll P;
		cin >> S >> P;
		v[i] = mt( S, P, i + 1 );
	}

	sort( ALL( v ), []( tuple<string, ll, ll> a, tuple<string, ll, ll> b ) {
			return ( get<1>( a ) > get<1>( b ) );
		} );

	stable_sort( ALL( v ), []( tuple<string, ll, ll> a, tuple<string, ll, ll> b ) {
			return ( get<0>( a ) < get<0>( b ) );
		} );

	rep( i, N )
	{
		cout << get<2>( v[i] ) << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 888
fun main() {
    val n = readLine()?.toLong() ?: return
    val m = (1e9 + 7).toLong()
    if (n == 1L) {
        println("0")
        return
    }
    var a = 1L
    var o = 1L
    var t = 1L
    repeat(n.toInt()) {
        a = a * 10L % m
        o = o * 9L % m
        t = t * 8L % m
    }
    a = (a - o - o + t) % m
    if (a < 0) {
        a += m
    }
    println(a.toString())
}


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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m;
    cin >> n >> m;
    yukari<int> g(n);
    akari<int> e(n);
    while (m--)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        e[v]++;
    }
    queue<int> q;
    for (int s = 0; s < n; s++)
    {
        if (!e[s])
        {
            q.push(s);
        }
    }

    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int nv : g[v])
        {
            e[nv]--;
            if (!e[nv])
            {
                q.push(nv);
            }
        }
        cout << v << '\n';
    }
}

int main()
{
    solve();
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        while(true){
            if (a%2==0) {
                ans++;
                a /= 2;
            }
            else
            {
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 入力
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Vector2d> p = new ArrayList<>();
		for (int i=0; i<n; i++) {
			double x = sc.nextDouble();
			double y = sc.nextDouble();
			p.add(new Vector2d(x, y));
		}
		sc.close();
		System.out.println(String.format("%1$.1f", solve(p)));
	}

	static class Vector2d {
		Vector2d(Double x, Double y){
			this.x = x;
			this.y = y;
		}
		Double x;
		Double y;
		public String toString() {
			return String.format("%1$.10f %2$.10f", x, y);
		}
	}

	public static Vector2d sub(Vector2d v1, Vector2d v2){
		return new Vector2d(v2.x - v1.x, v2.y - v1.y);
	}

	public static Double solve(List<Vector2d> p) {
		Double v2times = 0.0;
		int s = p.size();
		for (int i=0; i<s; i++) {
			v2times += (p.get(i).x * p.get((i+1)%s).y - p.get(i).y * p.get((i+1)%s).x);
		}
		return v2times / 2;
	}
}



Measured memory_bytes: 28876
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

int main() {

    int a,b,c;
    cin >>a >>b>>c;
    if(a+b>=c && a<=c)
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = "CODEFESTIVAL2016";
    int cnt = 0;
    for(int i = 0;i < s.length();i++){
      if(s.charAt(i)!=t.charAt(i))cnt++;
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int curr=0,max=INT_MIN;
    for(int i=1;i<n;i++)
    {
        if(h[i]>h[i-1])
            curr=0;
        else
            curr++;
        if(curr>max)
            max=curr;
    }
    if(max==INT_MIN)
        max=0;
    cout<<max<<endl;
}

Measured memory_bytes: 640
program ABC145C
    implicit none
    integer(8)::N,i,j
    real(8)::dim=0
    real(8)::p=1
    real(8),allocatable,dimension(:)::X,Y

    read(5,*)N
    allocate(X(N))
    allocate(Y(N))

    do i=1,N
        read(5,*)X(i),Y(i)
    end do

    do i=1,N-1
        do j=i+1,N
            dim=dim+sqrt((X(i)-X(j))**2+(Y(i)-Y(j))**2)
        end do
    end do

    print'(f0.10)',2*dim/N
end program ABC145C

Measured memory_bytes: 768
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int N;
    cin>>N;

    if(N==1){
        cout<<"Hello World"<<endl;
        return 0;
    }
    else{
        int A,B;
        cin>>A>>B;
        cout<<A+B<<endl;
        return 0;
    }

}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;

    vector<i64> A(N);
    rep(i,0,N) cin >> A[i];

    vector<i64> p(N),q(N),r(N),s(N);
    vector<i64> L(N),R(N);
   {
        p[1]=A[0];
        q[1]=A[1];
        L[1]=0;
        i64 x=A[0],y=A[1];
        rep(i,2,N){
            y+=A[i];
            L[i]=L[i-1];
            while(L[i]+1<i and abs(x-y)>abs((x+A[L[i]+1])-(y-A[L[i]+1]))){
                x+=A[L[i]+1];
                y-=A[L[i]+1];
                ++L[i];
            }
            p[i]=x;
            q[i]=y;
        }
    }
    {
        r[N-2]=A[N-2];
        s[N-2]=A[N-1];
        R[N-2]=N-2;
        i64 x=A[N-2],y=A[N-1];
        for(int i=N-3; i>=0; --i){
            x+=A[i];
            R[i]=R[i+1];
            while(R[i]>i and abs(x-y)>abs((x-A[R[i]])-(y+A[R[i]]))){
                x-=A[R[i]];
                y+=A[R[i]];
                --R[i];
            }
            r[i]=x;
            s[i]=y;
        }
    }

    i64 ans=inf64;
    rep(i,1,N-2){
        i64 p_=p[i],q_=q[i],r_=r[i+1],s_=s[i+1];
        print(i);
        print(p_);
        print(q_);
        print(r_);
        print(s_);
        ans=min(ans,max({p_,q_,r_,s_})-min({p_,q_,r_,s_}));
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  string s,t;
  cin >> s >> t;
  int cnt = 0;
  rep(i,3){
    if(s[i]==t[i]) cnt ++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
//#define ll __int64
//#define int ll
typedef  long long ll;
typedef unsigned long long ull;
const int MAXN=1e5+10;
const int MOD=1e9+7;
const double eps=1e-6;
const double finf=1e10;
using namespace std;
template<class T>inline void read(T &res)
{
    char c;T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
//-------------------------------------------//
int l[10],vis[10];
int main()
{
    int n,a,b,c,use,ans=INF;
    cin>>n>>a>>b>>c;
    for(int i=0;i<n;++i)scanf("%d",&l[i]);
    for(int i=1;i<(1<<n);++i)
    {
        int cnt=0,sum=0,c1=0;
        for(int x=0;x<n;++x)
            if((i>>x)&1)cnt++,sum+=l[x];
        c1=(cnt-1)*10+abs(sum-a);
        for(int j=0;j<(1<<n);++j)
        {
            if(i&j||j==0)continue;
            int cnt=0,sum=0,c2=0;
            for(int x=0;x<n;++x)
                if((j>>x)&1)cnt++,sum+=l[x];
            c2=(cnt-1)*10+abs(sum-b);
            for(int k=0;k<(1<<n);++k)
            {
                if(i&k||j&k||k==0)continue;
                use|=k;
                int cnt=0,sum=0,c3=0;
                for(int x=0;x<n;++x)
                    if((k>>x)&1)cnt++,sum+=l[x];
                c3=(cnt-1)*10+abs(sum-c);
                ans=min(ans,c1+c2+c3);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3764
#include<stdio.h>
#include<string.h>
int main()
{
    int a[2][105],i,n,ans,s=0,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[0][i]);
    for(i=0;i<n;i++)
        scanf("%d",&a[1][i]);
    for(i=0;i<n;i++)
    {
        ans=0;
        for(j=0;j<n;j++)
        {
            if(j<i)
                ans+=a[0][j];
            else ans+=a[1][j];

        }
        if(ans+a[0][i]>s) s=ans+a[0][i];
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#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(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;
    int K = S.size();
    int R = 15 - K;

    for(char c : S) {
        if(c == 'o') R++;
    }

    cout << (R >= 8 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> is(26);
  rep(i, n)
    is[s[i] - 'a'].insert(i);
  rep(qi, q)
  {
    int ty;
    cin >> ty;
    if (ty == 1)
    {
      int i; char c;
      cin >> i >> c;
      i--;
      is[s[i] - 'a'].erase(i);
      s[i] = c;
      is[s[i] - 'a'].insert(i);
    }
    else
    {
      int l, r;
      cin >> l >> r;
      l--;
      int count = 0;
      rep(i, 26)
      {
        auto it = is[i].lower_bound(l);
        if (it != is[i].end() && *it < r)
          count++;
      }
      printf("%d\n", count);
    }
  }
}

Measured memory_bytes: 24196
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#define ll long long
#include<bits/stdc++.h>

using namespace std;
int main() {
	int n,A=0,B=0;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(rbegin(a),rend(a));
    rep(i,n){
        if(i%2==0)
            A+=a[i];
        else
            B+=a[i];
    }
    cout<<A-B<<endl;
}



Measured memory_bytes: 256
/*
	Name: None
	Copyright: zhangjingcanËùÓÐ£¬Î´¾­ÔÊÐí²»µÃ×ªÔØ
	Author: zhangjingcan
	Date:25/02/20 18:46
	Description: C++ÎÄ¼þ
*/
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main(int argc, char** argv) {
	ios::sync_with_stdio(false);
	cin>>a>>b;
	if(a%2&&b%2)cout<<"Odd\n";
	else cout<<"Even\n";
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
fn main() {
    let scan = stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let A: i64 = vec[0].parse().unwrap();
    let B: i64 = vec[1].parse().unwrap();
    let mut ans: i32 = 0;
    let mut x: i64 = A;
    while x <= B {
        x *= 2;
        ans += 1;
    }
    println!("{}", ans)

}


Measured memory_bytes: 4352
n = int(input())
XA ,BA ,BX = 0 ,0 ,0
AB = 0
for i in range(n):
    s = str(input())
    AB += s.count("AB")
    if s[0] == "B":
        if s[-1] == "A":
            BA += 1
        else:
            BX += 1
    else:
        if s[-1] == "A":
            XA += 1

if BA > 1:
    AB += (BA-1)
    BA = 1
if XA:
    if BA:
        AB += 1
        XA -= 1
if BX:
    if BA:
        AB += 1
        BX -= 1
AB += min(XA,BX)
print(AB)

Measured memory_bytes: 3064
x1, y1, x2, y2 = map(int, input().split())
dx = x2-x1
dy = y2-y1
x3, y3 = x2 - dy, y2 + dx
x4, y4 = x3 - dx, y3 - dy 
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

template<typename T>
T gcd(T u, T v) {
    T r;
    while (v) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    REP(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    reverse(all(b));
    vector<int> sa(n);
    vector<int> sb(n);
    sa[0] = a[0];
    sb[0] = b[0];
    REP(i,n-1){
        sa[i+1] = gcd(a[i+1],sa[i]);
    }
    REP(i,n-1){
        sb[i+1] = gcd(b[i+1],sb[i]);
    }
    int res = 0;
    REP(i,n){
        if(i==0){
            chmax(res,sb[n-2]);
        }else if(i==n-1){
            chmax(res,sa[n-2]);
        }else{
            chmax(res,gcd(sa[i-1],sb[n-2-i]));
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin>>s;

  string ans = s.substr(0, 3);
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 3656
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iomanip>
#define PI 3.14159265358979

using namespace std;
typedef unsigned long long ull;

int main() {
	double a, b, x_;
	cin >> a >> b >> x_;
	double x = x_ / a;
	double y = x * 2 / b;
	double ans;
	if (y <= a) {
		ans = atan2(b, y) / PI * 180.0;
	}
	else {
		y = (x * 2.0 / a )- b;
		ans = atan2(b - y, a) / PI * 180.0;
	}
	cout <<setprecision(11)<< ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n, l; cin >> n >> l;
  vector<string> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  string ans = "";
  for(int i = 0; i < n; i++){
    ans += v[i];
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

L=gets.to_f
puts (L/3.0)**3.0

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

class Node{
public:
	int location;
	int p,l,r;
	Node(){}
};

class Point{
public:
	int id,x,y;
	Point(){}
	Point(int id,int x,int y):id(id),x(x),y(y){}
	bool operator <(const Point &p)const{
		return id<p.id;
	}

	void print(){
		printf("%d\n",id);
	}
};

static const int MAX=1000000;
static const int NIL=-1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,const Point &p2){
	return p1.x<p2.x;
}

bool lessY(const Point &p1,const Point &p2){
	return p1.y<p2.y;
}

int makeKDTree(int l,int r,int depth){
	if(!(l<r) )return NIL;
	int mid=(l+r)/2;
	int t=np++;
	if(depth%2==0){
		sort(P+l,P+r,lessX);
	}else{
		sort(P+l,P+r,lessY);
	}
	T[t].location=mid;
	T[t].l=makeKDTree(l,mid,depth+1);
	T[t].r=makeKDTree(mid+1,r,depth+1);
	return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
	int x=P[T[v].location].x;
	int y=P[T[v].location].y;
	if(sx<=x && x<=tx && sy<=y && y<=ty){
		ans.push_back(P[T[v].location]);
	}
	if(depth%2==0){
		if(T[v].l!=NIL){
			if(sx<=x)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
		}
		if(T[v].r!=NIL){
			if(x<=tx)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
		}
	}else{
		if(T[v].l!=NIL){
			if(sy<=y)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
		}
		if(T[v].r!=NIL){
			if(y<=ty)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
		}
	}
}

int main(void){
	int x,y;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d %d",&x,&y);
		P[i]=Point(i,x,y);
		T[i].l=T[i].r=T[i].p=NIL;
	}
	np=0;
	int root=makeKDTree(0,N,0);

	int q;
	scanf("%d",&q);
	int sx,tx,sy,ty;
	vector<Point> ans;
	for(int i=0;i<q;i++){
		scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
		ans.clear();
		find(root,sx,tx,sy,ty,0,ans);
		sort(ans.begin(),ans.end());
		for(int j=0;j<ans.size();j++){
			ans[j].print();
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 16468
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

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

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

using namespace std;

int main() {
  string s;
  cin >> s;
  while (true) {
    s = s.substr(0, s.length() - 1);
    int length = s.length();
    if (length % 2 == 1) {
      continue;
    }
    string s1 = s.substr(0, length / 2);
    string s2 = s.substr(length / 2, length / 2);
    if (s1 == s2) {
      cout << s.length() << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int valid;
Int idx;
string s;

void check(){
  if(s[idx] == 'm'){
    idx++;

    check();

    valid &= s[idx++] == 'e';

    check();

    valid &= s[idx++] == 'w';
  }
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  idx = 0;
  valid = 1;
  cin>>s;
  s += '!';
  check();
  valid &= s[idx] == '!';
  cout<<(valid? "Cat":"Rabbit")<<endl;
  return 0;
}



Measured memory_bytes: 3212
def bit_count(n)
  ret=0
  until n==0
    n=n&(n-1)
    ret+=1
  end
  ret
end

n=gets.to_i

stores=n.times.map{
  f=gets.split.map(&:to_i)
  ret=0
  f.each_with_index{|open,i|ret+=(1<<i) if open==1}
  ret
}

profits=n.times.map{gets.split.map(&:to_i)}

max=(1..2**10-1).map{|i|
  stores.each_with_index.map{|j,idx|profits[idx][bit_count(i&j)]}.inject(:+)
}.max

puts max

Measured memory_bytes: 2556
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<long> > pattern(8);

  for (int i = 0; i < 8; i++) {
    pattern[i] = vector<long>(n);
  }

  for (int i = 0; i < n; i++) {
    long x, y, z;
    cin >> x >> y >> z;
    long xi = -x, yi = -y, zi = -z;

    pattern[0][i] = x + y +z;
    pattern[1][i] = xi + y + z;
    pattern[2][i] = x + yi + z;
    pattern[3][i] = x + y + zi;
    pattern[4][i] = xi + yi + z;
    pattern[5][i] = x + yi + zi;
    pattern[6][i] = xi + y + zi;
    pattern[7][i] = xi + yi + zi;
  }

  long max = 0;
  for(int p = 0; p < 8; p++)
  {
    sort(pattern[p].begin(), pattern[p].end(), std::greater<long>());
    long sum = 0;
    for(int i = 0; i < m; i++)
    {
      sum += pattern[p][i];
    }
    if (sum > max) {
      max = sum;
    }

  }

  cout << max << endl;

}


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

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

	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		if (i < 10) {
			cnt++;
		}
		else if (i < 100) {
		}
		else if (i < 1000) {
			cnt++;
		}
		else if (i < 10000) {
		}
		else if (i < 100000) {
			cnt++;
		}
		else if (i < 1000000) {
		}
		else if (i < 10000000) {
			cnt++;
		}
	}

	cout << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl
#define all(vec) vec.begin(), vec.end()

int main() {
   stack<int> Q;
   string c;
   while (cin >> c) {
       char cc = c.at(0);
       if (cc != '+' && cc != '-' && cc != '*') Q.push(stoi(c));
       else {
           int a, b;
           a = Q.top();
           Q.pop();
           b = Q.top();
           Q.pop();
           if (cc == '+') Q.push(a+b);
           if (cc == '-') Q.push(b-a);
           if (cc == '*') Q.push(a*b);
       }
   }
   ct(Q.top());
}


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

int main(){
  int N;
  cin >> N;
  int a,b;
  a = N/100;
  N %= 100;
  b = N/10;
  N %= 10;
  if(a==7||b==7||N==7){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX = 100100;

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev){
    // ノードcurrentを訪問した直後の処理
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;
    int next;
    for(auto next: G[current]){
        if(!visited[next]){
            // ノードcurrentからノードnextへ訪問する直前の処理
            parent[next] = current;
            dfs(next, current);
            // ノードnextの探索が終了した直後の処理
            lowest[current] = min(lowest[current], lowest[next]);   // 条件3
        }else if(next != prev){
            // エッジ current --> next がBack-edgeの場合の処理
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

void art_points(){
    rep(i,N) visited[i] = false;
    timer = 1;
    // lowestの計算
    dfs(0,-1);  // 0 == root

    set<int> ap;
    int np = 0;
    for(int i=1; i<N; i++){
        int p = parent[i];
        if(p == 0) np++;
        else if(prenum[p] <= lowest[i]) ap.insert(p);
    }
    if(np > 1) ap.insert(0);
    for(auto itr = ap.begin(); itr!=ap.end(); itr++){
        cout << *itr << endl;
    }
}

int main()
{
    int m;
    cin >> N >> m;
    rep(_,m){
        int s, t; cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);  // Gは隣接リスト
    }
    art_points();

    return 0;
}



Measured memory_bytes: 6844
from collections import defaultdict
import functools
import itertools

N = int(input())
P = [tuple(map(int, input().split())) for i in range(N)]

D = defaultdict(list)
for p1, p2 in itertools.combinations(P, 2):
    d = (p1[0] - p2[0], p1[1] - p2[1])
    if d[0] == 0 and d[1] == 0:
        continue
    elif d[0] == 0:
        d = (0, abs(d[1]))
    elif d[0] < 0:
        d = (-d[0], -d[1])
    for S in D[d]:
        if p1 in S:
            S.add(p2)
            break
        elif p2 in S:
            S.add(p1)
            break
    else:
        D[d].append({p1, p2})

ans = 50
for L in D.values():
    ans = min(ans, len(L) + N - functools.reduce(lambda x, S: x + len(S), L, 0))
print(ans if N >= 2 else 1)


Measured memory_bytes: 4076
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 500000

struct Info{
	int left,right;
};

int N;
ll depth[NUM];
ll dp1[NUM]; //自分でセーブを行い、自分の子孫ではセーブを行わない場合の、自分以下の部分木を踏破する最小コスト
ll dp2[NUM]; //自分の子で適宜セーブを行う際の、自分以下の部分木を踏破する最小コスト
ll num_leaf[NUM];
Info info[NUM];

void calcDepth(int node_id,int value){

	depth[node_id] = value;
	if(node_id == N-1)return;
	calcDepth(info[node_id].left,value+1);
	calcDepth(info[node_id].right,value+1);
}

int main(){

	scanf("%d",&N);

	//木構造を取得
	for(int i = 0; i < N-1; i++){
		scanf("%d %d",&info[i].left,&info[i].right);
		info[i].left--;
		info[i].right--;
	}

	calcDepth(0,0);

	for(int i = 0; i < N; i++){
		dp1[i] = 0;
		dp2[i] = 0;
	}

	num_leaf[N-1] = 1; //エンディングは葉

	for(int i = N-2; i >= 0; i--){

		num_leaf[i] = num_leaf[info[i].left]+num_leaf[info[i].right];

		/*たとえばiから見て左の部分木(L)は、iにセーブポイントがあれば、必ずinfo[i].leftからスタートできる(i→info[i].leftへ下るコストは都度計上)
		 よって、Lを踏破するコストは、事実上、info[i].leftにセーブポイントがある場合のコストと同じ(常にスタートがinfo[i].leftになるから)。
		 右の部分木も同様。そして、左右の子へと下る回数の合計は、iより下の葉の数に等しいので、num_leaf[i]を計上する
		 * */
		dp1[i] = dp1[info[i].left]+dp1[info[i].right]+num_leaf[i];

		/*
		 * 左の部分木は、iにセーブポイントを作って踏破する。
		 * 右の部分木は、右の部分木内にセーブポイントを作って踏破する。
		 * +1は、左の部分木を踏破し終わった後、info[i].rightに下る時のコスト
		 *
		 */
		dp2[i] = dp1[info[i].left]+num_leaf[info[i].left]+1+dp2[info[i].right];
		/*上の行の逆*/
		dp2[i] = min(dp2[i],dp1[info[i].right]+num_leaf[info[i].right]+1+dp2[info[i].left]);
		/*
		 * i→info[i].leftに下る
		 * →左部分木内で適宜セーブポイントを作り、左部分木を踏破
		 * ★★★★木は有向!!遡れない★★★★
		 * ため、rootからiへ下る→info[i].rightに下る
		 * →右部分木内で適宜セーブポイントを作り、右部分木を踏破
		 * */
		dp2[i] = min(dp2[i],1+dp2[info[i].left]+depth[i]+1+dp2[info[i].right]);
	}

	printf("%lld\n",dp2[0]);

	return 0;
}



Measured memory_bytes: 30436
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

int W,H,ans;
char MAP[101][101];
bool flag[101][101];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void dfs(int  y,int x,char c){
	flag[y][x]=true;
	for(int i=0; i<4; ++i){
		int nx = x+dx[i];
		int ny = y+dy[i];
		if(1<=nx&&nx<=W&&1<=ny&&ny<=H&&MAP[ny][nx]==c&&!flag[ny][nx]){
			dfs(ny,nx,c);
		}
	}
}

int main(){
	while(cin>>H>>W&&H&&W){
		ans=0;
		for(int i=1; i<=H; ++i){
			for(int j=1; j<=W; ++j){
				cin >> MAP[i][j];
				flag[i][j]=false;
			}
		}
		for(int i=1; i<=H; ++i){
			for(int j=1; j<=W; ++j){
				if(!flag[i][j]){
					++ans;
					dfs(i,j,MAP[i][j]);
				}
			}
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 1648
import math
def main1():
    input_num = int(input())
    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num
    for i in range(num_sqrt+1,0,-1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i -2
            if minimam > distance:
                minimam = distance
    print(minimam)
main1()

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
const int NICO = 1000000 + 10;
int n, x;
int main()
{
    cin >> n;int cnt = 0;
    for(int i=1;i<=n;i++)
    {
        cin >> x;
        if(x%2==1) cnt ++;
    }
    cout << ((cnt%2==0)?"YES":"NO") << endl;
}

Measured memory_bytes: 256