akhauriyash/Code-Regression huggingface dataset:
package main

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

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

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}

	scanner.Scan()
	M, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}

	var day int

	for i := 0; i < M; i++ {
		scanner.Scan()
		day, err = strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
		N -= day
	}
	if N >= 0 {
		fmt.Println(N)
	} else {
		fmt.Println("-1")
	}
}


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

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

  // ここにプログラムを追記
  
  // 桁数を求める
  int count;
  int nCount = N;
  while (nCount > 0) {
  	nCount /= 10;
    count++;
  }
  
  // 合計を求める
  int sum;
  int nSum = N;
  for (int i = 0; i < count; i++) {
    sum += nSum % 10;
    nSum /= 10;
  }
  
  // ハーシャッド数か確認し出力
  if (N % sum == 0) {
    cout << "Yes" <<endl;
  } else {
    cout << "No" <<endl;
  }
  
}



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

using namespace std;
const int INF=1e9+5;
const int MOD=1e9+7;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	string s;
	unordered_set<string> us;
	for(int i=0;i<n;i++){
		cin>>s;
		us.insert(s);
	}
	cout<<us.size()<<endl;
}


Measured memory_bytes: 17704
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

void solve(ll N, ll Q, vll a, vll x){
    vll sum(N+1,0);
    rep(i, N){
        sum[i+1] = sum[i]+a[i];
    }
    rep(q, Q){
        ll cnt = 0, tmp;
        rep(i, N){
            tmp = upper_bound(sum.begin()+i, sum.end(), x[q]+sum[i])-(sum.begin()+i);
            cnt += tmp-1;
        }
        cout << cnt << endl;
    }
}

void solve2(ll N, ll Q, vll a, vll x){
    rep(i, Q){
        ll s=0, t=0, sum=0;
        ll cnt = 0;
        while(1){
            while(t < N && sum+a[t]<= x[i]){
                sum += a[t]; t++;
            }
            cnt += t-s;
            if(s == N)
                break;
            if(t > s){
                sum -= a[s]; s++;
            }
            else{//* t==s
                s++; t++;
            }
        }
        cout << cnt << endl;
    }
    
}


int main(){
    ll N, Q;
    cin >> N >> Q;
    vll a(N), x(Q);
    rep(i, N){
        scanf("%lld", &a[i]);
    }
    rep(i, Q){
        scanf("%lld", &x[i]);
    }
    //* solve(N, Q, move(a), move(x));
    solve2(N, Q, move(a), move(x));

    return 0;
}


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

int main(void){
 char num[3];
   
  scanf("%s",num);
  if(num[0] == '7' || num[1] == '7' || num[2] == '7'){
  	printf("Yes");
  }else{
  	printf("No");
  }
  
  return 0;
}


Measured memory_bytes: 1736
#include<stdio.h>

#define Max 100000

typedef struct{
  char c;
  int a;
  int b;
} Card;

Card A[100001];


int partition(int,int);
void quicksort(int, int);


int main(){

  int i,n,q,flag = 0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&A[i].c,&A[i].a);
    A[i].b=i;
  }

  quicksort(0,n-1);
  
  for(i=0;i<n-1;i++){
    if(A[i].a==A[i+1].a){
      if(A[i].b>A[i+1].b)flag = 1;
    }
  }
  
  if(flag == 1)printf("Not stable\n");
  else printf("Stable\n");
  
  for(i=0;i<n-1;i++){
    printf("%c %d\n",A[i].c,A[i].a);
  }
  printf("%c %d\n",A[i].c,A[i].a);

  return 0;
  
}


int partition(int p,int r){
  int x;
  int i,j;
  int s,u;
  char y,t;
  
  x=A[r].a;
  i=p-1;
  for(j=p; j < r; j++){
    if(A[j].a<= x){
      i++;
      s=A[i].a;
      t=A[i].c;
      u=A[i].b;
      A[i].a=A[j].a;
      A[i].c=A[j].c;
      A[i].b=A[j].b;
      A[j].a=s;
      A[j].c=t;
      A[j].b=u;
    }
  }
  s=A[i+1].a;
  t=A[i+1].c;
  u=A[i+1].b;
  A[i+1].a=A[r].a;
  A[i+1].c=A[r].c;
  A[i+1].b=A[r].b;
  A[r].a=s;
  A[r].c=t;
  A[r].b=u;
  
  return i+1;
}

void quicksort(int p, int r){
  int q;
  if(p<r){
    q = partition(p,r);
    quicksort(p,q-1);
    quicksort(q+1,r);
  }
}

Measured memory_bytes: 1780
#include<stdio.h>

int main(void){
    int n,i,a,s;
    while(scanf("%d",&n) , n != 0){
        s = 0;
        for(i = 1;i <= n * (n - 1) / 2;i++){
            scanf("%d",&a);
            s+=a;
        }
        printf("%d\n" , s / (n - 1));
    }
    return 0;
}

Measured memory_bytes: 600
t = [int(input()) for i in range(5)]
t1 = 0
t2 = []
for a in t:
  if a % 10 == 0:
    t1 += a
  else:  
    t1 += (a//10 + 1)*10
    t2.append(a % 10)
if t2 == []:
  print(t1)
else:
  print(t1 + min(t2) - 10)

Measured memory_bytes: 3060
using System;
using System.IO;

class kadai01
{
    public static void Main()
    {
//        Console.WriteLine("入力した単語の先頭の文字をつなげ、大文字にした文字列を出力");
//        Console.WriteLine("");
//        Console.WriteLine("文字を入力してください");
        string[] moji = Console.ReadLine().Split(' ');          //入力文字を入れる変数
        string S1 = moji[0];                                    //入力文字を入れる変数
        string S2 = moji[1];                                    //入力文字を入れる変数
        string S3 = moji[2];                                    //入力文字を入れる変数

        string s1_1 = S1.Substring(0, 1);                       //先頭文字を入れる変数＆先頭文字の抽出
        string s2_1 = S2.Substring(0, 1);                       //先頭文字を入れる変数＆先頭文字の抽出
        string s3_1 = S3.Substring(0, 1);                       //先頭文字を入れる変数＆先頭文字の抽出

//        Console.Write("出力結果は・・・・・");
        Console.WriteLine((s1_1.ToUpperInvariant())+ (s2_1.ToUpperInvariant())+ (s3_1.ToUpperInvariant()));

        //3つの先頭文字を大文字に変換して表示

//        Console.ReadLine();
    }
}

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

using namespace std;

int main() {
    int k;
    cin >> k;
    long long sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += __gcd(a, __gcd(b, c));
            }
        }
    }
    cout << sum << endl;
}


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

int main(){
    string s; cin >> s;
    if(s[0] != s[1] || s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <climits>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <climits>
#include <numeric>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef long long int lli;

int memo[1000010] = {0,0,1};
double PI = 3.14159265359;
const lli MOD = pow(10,9)+7;



int main(void){
    
    lli N,A,B;
    cin >> N >> A >> B;
    vi a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    
    lli res = 0;
    for(int i = 0; i < N -1; i++){
        
        if(A*(a[i+1] - a[i]) >= B){
            res += B;
        }else{
            res += A*(a[i+1] - a[i]);
        }
        
        
    }
    
    cout << res << endl;
    
    
}


Measured memory_bytes: 640
#include <stdio.h>

int main (void)
{
    int n, m, k;
    int row, col;

    scanf("%d %d %d", &n, &m, &k);

    for (col = 0; col <= m; col++) {
        for ( row = 0; row <= n; row++) {
            if (n * col + (m - col) * row - col * row == k) {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    string s[100020];
    for (int i = 0; i < N; i++) cin >> s[i];

    unordered_map<string, int> mp;

    lint res = 0;

    for (int i = 0; i < N; i++) {
        sort(s[i].begin(), s[i].end());
        res += mp[s[i]];
        mp[s[i]]++;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 17700
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

class Z_algorithm {
public:
	void process(const char* str, int n) {
		v.resize(n);
		v[0] = n;
		int i = 1, j = 0;
		while (i < n) {
			while (i + j < n && str[j] == str[i + j]) ++j;
			v[i] = j;
			if (j == 0) { ++i; continue; }
			int k = 1;
			while (i + k < n && k + v[k] < j) v[i + k] = v[k], ++k;
			i += k; j -= k;
		}
	}
	void process(string S) {
		process(S.c_str(), S.length());
	}
	vector<int> v;
};

class Rolling_Hash {
public:
	Rolling_Hash() {
		v.clear();
	}
	void process(const char* str, int n, int width) {
		if (width > n) { return; }
		v.resize(n - width + 1);
		ll p1 = 0, p2 = 0;
		ll t1 = 1, t2 = 1;
		{
			ll k = width;
			ll d1 = digit1;
			ll d2 = digit2;
			while (k > 0) {
				if (k & 1) {
					t1 *= d1;
					t1 %= mod1;
					t2 *= d2;
					t2 %= mod2;
				}
				k /= 2;
				d1 = (d1 * d1) % mod1;
				d2 = (d2 * d2) % mod2;
			}
		}
		for (int i = 0; i < width; i++) {
			p1 *= digit1; p1 += str[i]; p1 %= mod1;
			p2 *= digit2; p2 += str[i]; p2 %= mod2;
		}
		int j = 0;
		v[j] = (p1 << 30) + p2; j++;
		for (int i = width; i < n; i++, j++) {
			p1 *= digit1; p1 += str[i] - str[i - width] * t1; p1 %= mod1;
			p2 *= digit2; p2 += str[i] - str[i - width] * t2; p2 %= mod2;
			if (p1 < 0) { p1 += mod1; }
			if (p2 < 0) { p2 += mod2; }
			v[j] = (p1 << 30) + p2;
		}
	}
	void process(string S, int width) {
		process(S.c_str(), S.length(), width);
	}

private:
	const ll digit1 = 10007LL;
	const ll digit2 = 10009LL;
	const ll mod1 = 1000000007LL;
	const ll mod2 = 1000000009LL;

public:
	vector<ll> v;
};

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

	Rolling_Hash R;
	int a = 0, b = N / 2 + 1;
	while (b - a > 1) {
		int c = (a + b) / 2;
		R.process(S, c);
		multiset<ll> mset;
		for (int i = c; i < R.v.size(); i++) {
			mset.insert(R.v[i]);
		}
		bool f = false;
		for (int i = 0; i + c < R.v.size(); i++) {
			if (mset.find(R.v[i]) != mset.end()) {
				f = true; break;
			}
			mset.erase(mset.find(R.v[i + c]));
		}
		if (f == true) { a = c; }
		else { b = c; }
	}
	cout << a << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 500
using namespace std;
int n,m,iomap[maxn][maxn],res=0;
vector<pair<int,int> > s,e;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>iomap[i][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<m-1;j++)
		{
			if(iomap[i][j]%2==0)
				continue;
			--iomap[i][j];
			++iomap[i][j+1];
			s.push_back(make_pair(i+1,j+1));
			e.push_back(make_pair(i+1,j+2));
			++res;
		}
	int j=m-1;
	for(int i=0;i<n-1;i++)
	{
		if(iomap[i][j]%2==0)
			continue;
		--iomap[i][j];
		++iomap[i+1][j];
		s.push_back(make_pair(i+1,j+1));
		e.push_back(make_pair(i+2,j+1));
		++res;
	}
	cout<<res<<endl;
	for(int i=0;i<s.size();i++)
		cout<<s[i].first<<' '<<s[i].second<<' '<<e[i].first<<' '<<e[i].second<<endl;
	return 0;
}

Measured memory_bytes: 5228
#include <iostream>
using namespace std;
long n, a[100010];
int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];

  long L = 2, R = 2;
  for(int i = n-1; i >= 0; --i) {
    L = (L + a[i] - 1) / a[i] * a[i];
    R = R / a[i] * a[i] + a[i] - 1;
  }
  if(L >= R) cout << -1;
  else cout << L << " " << R;
  return 0;
}

Measured memory_bytes: 1024
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap.Strict as IntMap
import Control.Monad
import Control.Monad.ST
import Data.STRef

type Weight = Int
type Tree = IntMap.IntMap (U.Vector (Int,Weight))

data GrowableVector s a = GV {-# UNPACK #-} !Int !(U.MVector s a)

buildTree :: U.Vector (Int,Int,Weight) -> IntMap.IntMap (U.Vector (Int,Weight))
buildTree edges = runST $ do
  let insert' key val m = do
        case IntMap.lookup key m of
          Nothing -> do
            vec <- UM.new 1
            UM.write vec 0 val
            ref <- newSTRef (GV 1 vec)
            return $ IntMap.insert key ref m
          Just ref -> do
            GV len vec <- readSTRef ref
            vec' <- if len < UM.length vec then return vec else UM.grow vec len
            UM.write vec' len val
            writeSTRef ref $ GV (len+1) vec'
            return m
      adjust ref = do
        GV len mvec <- readSTRef ref
        vec <- U.unsafeFreeze mvec
        return (U.take len vec)
  m <- U.foldM' (\m (u,v,w) -> insert' v (u,w) m >>= insert' u (v,w)) IntMap.empty edges
  mapM adjust m

main = do
  n <- readLn
  edges <- U.replicateM (n-1) $ do
    [u,v,w] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (u-1, v-1, w)
  let tree :: Tree
      tree = buildTree edges
  let result = U.create $ do
        vec <- UM.replicate n (-1)
        -- white: 0, black: 1
        let dfs !i !color = do
              x <- UM.read vec i
              when (x == -1) $ do
                UM.write vec i color
                let Just t = IntMap.lookup i tree
                U.forM_ t $ \(j,w) -> do
                  dfs j ((color + w) `rem` 2)
        dfs 0 0
        return vec
  U.mapM_ print result


Measured memory_bytes: 87548
#include <iostream>
#include <algorithm>

using namespace std;
int main(void){
    // Your code here!
    int N, W;
    cin >> N >> W;
    int dp[N+1][W+1];
    int v[N], w[N];
    
    
    
    for(int i = 0; i < N; i++){
        cin >> v[i] >> w[i];
    }
    
    dp[0][0] = 0;
    for(int i = 0; i <= W; i++) dp[0][i] = 0;
    for(int i = 1; i <= N; i++) dp[i][0] = 0;
    
    for(int i = 0; i < N; i++){
        for(int j = 1; j <= W; j++){
            if(j- w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i+1][j - w[i]] + v[i]);
            } else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    
    cout << dp[N][W] << endl;
}



Measured memory_bytes: 7040
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextInt()
    val a1 = a / 1000
    val a2 = (a-1000*a1) / 100
    val a3 = (a-1000*a1-100*a2) / 10
    val a4 = (a-1000*a1-100*a2-10*a3)
    if(a1 === a2 || a2 === a3 || a3 === a4) println("Bad")
    else println("Good")
}

Measured memory_bytes: 31268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b < c + d) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
}	

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll Q,H,S,D,N;
	ll ans;
	scan(Q);scan(H);scan(S);scan(D);scan(N);
	ll onemin=min(S,min(H*2,Q*4));
	if(N%2){
		if(D<=2*onemin){
			ans=N/2*D+onemin;
		}
		else{
			ans=N*onemin;
		}
	}
	else{
		ans=N/2*min(D,onemin*2);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l[10010],ans;
char s[10010][15];
int a,b,c;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		l[i]=strlen(s[i]+1);
		for(int j=1;j<l[i];j++){
			if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
		}
		if(s[i][1]=='B'){
			if(s[i][l[i]]=='A') a++;
			else b++;
		} 
		else{
			if(s[i][l[i]]=='A') c++;
		}
	}
	if(a==0) ans+=min(b,c);
	else if(b==0&&c==0) ans+=a-1;
	else if(b==0||c==0) ans+=a;
	else ans+=a+1+min(b,c)-1; 
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;
  
  long A[N+1] = {0};
  long C[N+1] = {0};
  long sum = 0;
  for(long i=2; i<N+1; i++){
    cin >> A[i];
    C[A[i]]++;
  }
  for(long i=1; i<N+1; i++){
    cout << C[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 6760
import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        sc.nextInt();
        String S1 = sc.next();
        String S2 = sc.next();

        System.out.println(solve(S1, S2));

        sc.close();
    }

    static int solve(String S1, String S2) {
        int result = 1;
        int index = 0;
        int prevLength = 0;
        while (index != S1.length()) {
            int factor;
            if (index + 1 != S1.length() && S1.charAt(index) == S1.charAt(index + 1)) {
                if (prevLength == 0) {
                    factor = 6;
                } else if (prevLength == 1) {
                    factor = 2;
                } else {
                    factor = 3;
                }

                prevLength = 2;
            } else {
                if (prevLength == 0) {
                    factor = 3;
                } else if (prevLength == 1) {
                    factor = 2;
                } else {
                    factor = 1;
                }

                prevLength = 1;
            }

            result = multiplyMod(result, factor);
            index += prevLength;
        }

        return result;
    }

    static int multiplyMod(int x, int y) {
        return (int) ((long) x * y % MODULUS);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=200050;
const int M=2*N;
const ll inf=9e18;
struct SegmentTree
{
	ll mn[M];
	void init(){ for(int i=0;i<M;i++) mn[i]=inf;}
	SegmentTree(){ init();}
	void Set(int i, ll f){ i+=N;for(;i;i>>=1) mn[i]=min(mn[i],f);}
	ll Get(int l, int r)
	{
		ll ans=inf;
		for(l+=N,r+=N;l<=r;l>>=1,r>>=1)
		{
			if(l%2==1) ans=min(ans,mn[l++]);
			if(r%2==0) ans=min(ans,mn[r--]);
		}
		return ans;
	}
} L,R;
int a[N];
ll dp[N],tmp[N];
ll Solve(int n, int D)
{
	set<int> st;
	vector<pair<int,int> > work;
	for(int i=1;i<=n;i++) work.pb(mp(a[i],i));
	sort(work.begin(),work.end());
    ll ans=0;
    for(int j=0;j<n;j++)
	{
		int i=work[j].second;
		if(j!=0)
		{
			bool lf=0,rf=0;
			ll l=L.Get(1,i-1);
			if(l!=inf) lf=1;
			l+=a[i]+(ll)i*D;
			ll r=R.Get(i+1,n);
			if(r!=inf) rf=1;
			r+=a[i]-(ll)i*D;
			ll add=min(l,r);
			if(lf && rf) add=min(add,(ll)a[i]*2);
			//printf("%i %lld l:%lld %lld r:%lld\n",i,add,l,L.Get(1,i-1),r);
			ans+=add;
		}
		L.Set(i,a[i]-(ll)i*D);
		R.Set(i,a[i]+(ll)i*D);
		//printf("Ins:%lld %lld\n",a[i]-(ll)i*D,a[i]+(ll)i*D);
	}
	return ans;
}
int main()
{
	int n,i,D;
	scanf("%i %i",&n,&D);
	for(i=1;i<=n;i++) scanf("%i",&a[i]);
	if(n==1) return 0*printf("0\n");
	printf("%lld\n",Solve(n,D));
	/*ll ans=0;
	for(i=2;i<n;i++) ans+=a[i]*2;
	ans+=a[1]+a[n];
	ll sum;
	ans+=(ll)D*(n-1);
	sum=ans;
	int id=1;
	for(i=2;i<=n;i++) if(a[i]<a[id]) id=i;
	dp[id]=0;
	ll mn=a[id]-(ll)id*D;
	for(i=id+1;i<=n;i++)
	{
		dp[i]=mn+a[i]+(ll)i*D+dp[i-1];
		mn=min(mn,a[i]-(ll)i*D);
	}
	tmp[id]=0;
	mn=a[id]+(ll)id*D;
	for(i=id-1;i>=1;i--)
	{
		tmp[i]=mn+a[i]-(ll)i*D+tmp[i+1];
		mn=min(mn,a[i]+(ll)i*D);
	}
	//for(i=1;i<=n;i++) ans=min(ans,dp[i]+tmp[i]);
	//for(i=1;i<=n;i++) printf("i:%i dp:%lld tmp:%lld\n",i,dp[i],tmp[i]);
	ans=min(ans,dp[n]+tmp[1]);
	printf("%lld\n",ans);*/
	/*for(i=1;i<=n;i++)
	{
		tmp[i]=a[i]-(ll)i*D;
		if(i>1) tmp[i]=min(tmp[i],tmp[i-1]);
	}
	ll ret=0;
	mn=a[n]+(ll)n*D;
	for(i=n-1;i>=1;i--)
	{
		ret+=tmp[i]+mn;
		mn=min(mn,a[i]+(ll)i*D);
	}
	printf("%lld\n",ret);*/
	return 0;
}

Measured memory_bytes: 10484
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    string n;
    cin>>n;
    ll nLL=stoll(n);
    queue<string> strq;
    strq.push("7");
    strq.push("5");
    strq.push("3");
    vector<string> pre;
    while(!strq.empty()){
        string tempstr=strq.front();strq.pop();
        ll tempLL=stoll(tempstr);
        if(tempLL<=nLL){
            pre.push_back(tempstr);
            strq.push(tempstr+'7');
            strq.push(tempstr+'5');
            strq.push(tempstr+'3');
        }        
    }
    int ans=0;
    for(int i=0;i<pre.size();i++){
        bool find3=(pre[i].end()!=find(pre[i].begin(),pre[i].end(),'3'));
        bool find5=(pre[i].end()!=find(pre[i].begin(),pre[i].end(),'5'));
        bool find7=(pre[i].end()!=find(pre[i].begin(),pre[i].end(),'7'));
        if(find3&find5&find7){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5372
my_rate = input()
rate_kyu = [2000, 1800, 1600, 1400, 1200, 1000, 800, 600, 400]

for i,rate in enumerate(rate_kyu):
  if i == 0:
    continue
  if int(rate_kyu[i]) <= int(my_rate) < int(rate_kyu[i-1]):
    print(i)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9+7;

int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
	freopen("output.txt","w", stdout);
	freopen("error.txt","w", stderr);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, k;
	cin>>n>>k;

    ll ans = 0;
    ll minsum, maxsum;
    for(ll i = k; i <= n + 1; i++) {
        minsum = i * (i - 1) / 2;
        maxsum = n * i - minsum;
        ans += maxsum - minsum + 1;
    }
    ans = ans % mod;
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string c0,c1,c2,c3;
    c0 = "AC";
    c1 = "WA";
    c2 = "TLE";
    c3 = "RE";
    int nc0,nc1,nc2,nc3;
    nc0 = 0;nc1 = 0;nc2 = 0;nc3 = 0;
    int N;
    string S;
    cin >> N;
    rep(i, N){
        cin >> S;
        if(S == c0){
            nc0++;
        }else if(S == c1){
            nc1++;
        }else if(S == c2){
            nc2++;
        }else{
            nc3++;
        }
    }
    cout << "AC x " << nc0 << endl;
    cout << "WA x " << nc1 << endl;
    cout << "TLE x " << nc2 << endl;
    cout << "RE x " << nc3 << endl;

}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int[] count = {0,0,0,0};
		for(int i=0; i<n; i++) {
			String s = in.next();
			switch(s) {
				case "AC":
					count[0]++;
					break;
				case "WA":
					count[1]++;
					break;
				case "TLE":
					count[2]++;
					break;
				case "RE":
					count[3]++;
					break;
				default:
					break;
			}
		}
		
		System.out.println("AC x " + count[0]);
		System.out.println("WA x " + count[1]);
		System.out.println("TLE x " + count[2]);
		System.out.println("RE x " + count[3]);
		
		
		in.close();
	}
}


Measured memory_bytes: 58268
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2019)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = int(degit) * pow(10, idx, 2019)
    m = (m + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)


Measured memory_bytes: 10788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

const ll MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

struct Info{
    Info(ll arg_to,ll arg_cost){
        to = arg_to;
        cost = arg_cost;
    }
    bool operator<(const struct Info &arg) const{
            return cost > arg.cost;
    };
    ll to,cost;
};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x,y,cou=0;
    cin>>x>>y;
    while(x<=y){
        x*=2;
        cou++;
    }
    cout<<cou<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int x;
    cin>>x;
    if(x>=30)print("Yes")
    else print("No")
    
    
    
    
    return 0;
}


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

int main() {
	string S, a = {}, b = {}; cin >> S;
	int Q; cin >> Q;
	bool x = 0;
	for (int i = 0; i < Q; i++) {
		int t,f;
		string c;
		cin >> t; t--;
		if (!t) {
			x = !x; continue;
		}
		cin>>f >> c; f--;
		if ((bool)f^x)a = a + c;
		else b = c + b;
	}
	S = b + S + a;
	for (int i = 0; i < S.size(); i++) {
		if (x)cout << S[S.size() - 1 - i];
		else cout << S[i];
	}
}

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

using namespace std;

int main(){
  int N, T;
  cin >> N >> T;
  
  vector<pair<int, int>> AB(N);
  for(int i = 0; i < N; i++){
    int A, B;
    cin >> A >> B;
    AB[i] = make_pair(A, B);
  }
  
  sort(AB.begin(), AB.end());
  
  int dp[3001][6100];
  for(int i = 0; i < 3001; i++){
    for(int j = 0; j < 6100; j++){
      dp[i][j] = 0;
    }
  }
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < T; j++){
      dp[i + 1][j + AB[i].first] = max(dp[i][j] + AB[i].second, dp[i + 1][j + AB[i].first]);
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }
    for(int j = T; j < 6100; j++){
      dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
    }
  }
  
  int d = 0;
  for(int j = 0; j < 6100; j++){
    d = max(dp[N][j], d);
  }
  
  cout << d <<endl;
  
  return 0;
}

Measured memory_bytes: 71808
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func getFloat() float64 {
	sc.Scan()
	n, _ := strconv.ParseFloat(sc.Text(), 64)
	return n
}

func sum(n []int) int {
	a := 0
	for _, v := range n {
		a += v
	}
	return a
}

func partseFloat(s string) (n float64) {
	n, _ = strconv.ParseFloat(s, 64)
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := getInt(), getInt()

	a := make([]int, m)

	for i := 0; i < m; i++ {
		a[i] = getInt()
	}

	x := make([]bool, n+1)

	j := 0
	for i := 0; i <= n; i++ {
		if j < m && i == a[j] {
			x[i] = false
			j++
		} else {
			x[i] = true
		}
	}

	dp := make([]uint64, n+1)
	dp[0] = 1
	if x[1] {
		dp[1] = 1
	} else {
		dp[1] = 0
	}

	for i := 2; i <= n; i++ {
		if x[i] {
			dp[i] = dp[i-1] + dp[i-2]
			dp[i] %= 1000000007
		} else {
			dp[i] = 0
		}
	}
	//fmt.Println(dp)
	fmt.Println(dp[n])
}


Measured memory_bytes: 2816
#coding:utf-8
len = list(map(int,input().split()))

def return_min(x,y):
  if x > y:
    return y
  else:
    return x

min = len[0]
min_index = 0
if min > len[1]:
  min = len[1]
  min_index = 1
if min > len[2]:
  min = len[2]
  min_index = 2
  
if min_index == 0:
  res = min * return_min(len[1],len[2]) /2
elif min_index == 1:
  res = min * return_min(len[0],len[2]) /2
else:
  res = min * return_min(len[0],len[1]) /2

print(int(res))

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

#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int a,b,c,d,e,f;
    cin >>a>>b>>c>>d>>e>>f;
    // water
    map<int, bool> water;
    map<int, bool> sugar;
    int i = 0;
    int j = 0;
    double maxdence = 100.0 * e / (double)(100.0 + e);
    while(true){
        while(true){
            if(100*a*i + 100*b*j <= f){
                water[100*a*i + 100*b*j] = true;
                j++;
            }else{
                break;
            }
        }
        j = 0;
        if(100*a*i + 100*b*j > f){
            break;
        }
        i++;
    }
    i = 0;
    j = 0;
    while(true){
        while(true){
            if(c*i + d*j <= f){
                sugar[c*i + d*j] = true;
                j++;
            }else{
                break;
            }
        }
        j = 0;
        if(c*i + d*j > f){
            break;
        }
        i++;
    }
    int tmpwa = 0;
    int tmpsu = 0;
    double ansdence = 0;
    double tmpdence;
    for(auto wa : water){
        for(auto su : sugar){
            if(wa.first + su.first <= f){
            tmpdence = 100.0 * su.first / (double)(wa.first + su.first);
            if( tmpdence <= maxdence){
                if(tmpdence >= ansdence){
                    ansdence = tmpdence;
                    tmpwa = wa.first;
                    tmpsu = su.first;
                }

            }
            }
        }
    }
    cout << tmpsu + tmpwa << " " << tmpsu << endl;
    return 0;
}

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

using namespace std;


map<int, bool> mp;

int main() {

	ios_base :: sync_with_stdio(0); cin.tie(NULL);
	
	int n;
	cin >> n;

	bool ok = true;

	for(int i = 0, x; i < n; ++i) {
		cin >> x;

		if (mp.count(x)) {
			ok = false;
		}

		mp[x] = true;

	}

	cout << (ok ? "YES" : "NO") << '\n';
	


	return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===



ll dp[110][100100];



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

	int N, W; cin >> N >> W;
	Vl v(N), w(N);
	for (int i = 0; i < N; ++i) {
		cin >> w[i] >> v[i];
	}

	memset(dp, 0, sizeof(dp));

	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= W; ++j) {
			if (j - w[i - 1] >= 0) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}

	cout << dp[N][W] << endl;



	return 0;
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, K, D = 1;
  cin >> N >> K;
    
  for(int i=0; i<N; i++){
    if (D+K<2*D){ 
      D += K;
    }
    else {
      D *= 2;
    }
   }
   cout << D << endl;   
}

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

 	ll mod = 1000000000+7;
 
	int main() {

		#ifndef ONLINE_JUDGE
	        freopen("input.txt","r",stdin);
	        // freopen("output.txt","w",stdout);
	    #endif
	    ios::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);
		string s;
		cin>>s;
		int sum=0;
		for(int i=0;i<s.size();i++){
			sum+=s[i]-'0';
		}
		if(sum%9==0){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	   	
		
	}

	


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin>>n;

   int m = n%10;

   if(m==2||m==4||m==5||m==7||m==9){
       cout<<"hon"<<endl;
   }
   else if(m==0||m==1||m==6||m==8){
       cout<<"pon"<<endl;
   }
   else{
       cout<<"bon"<<endl;
   }
   return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[3001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, T, A[3001], B[3001];
	scanf("%d %d", &N, &T);
	for (i = 1; i <= N; i++) scanf("%d %d", &(A[i]), &(B[i]));
	
	data d[3001];
	for (i = 0; i < N; i++) {
		d[i].key = B[i+1];
		d[i].id = i + 1;
	}
	merge_sort(d, N);
	
	int j, dp[2][3001][2] = {};
	for (i = N - 1; i >= 0; i--) {
		for (j = 0; j < T; j++) dp[i%2][j][1] = (dp[1-i%2][j][1] > dp[1-i%2][j][0] + B[d[i].id])? dp[1-i%2][j][1]: dp[1-i%2][j][0] + B[d[i].id];
		for (j = 0; j < T - A[d[i].id]; j++) {
			dp[i%2][j+A[d[i].id]][0] = dp[1-i%2][j][0] + B[d[i].id];
			if (dp[i%2][j+A[d[i].id]][1] < dp[1-i%2][j][1] + B[d[i].id]) dp[i%2][j+A[d[i].id]][1] = dp[1-i%2][j][1] + B[d[i].id];
		}
	}
	
	printf("%d\n", dp[0][T-1][1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1820
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,0,n){
        cin>>a[i];
        a[i]--;
    }
    int c = 0;
    rep(i,0,n){
        if(i==a[a[i]]){c++;}
    }
    cout<<c/2<<endl;
}

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

if N % 2 == 1:
    print(0)
else:
    res_two = 0
    res_five = 0
    for i in range(1, 100):
        if N // (2 ** i) == 0:
            break
        res_two += N // (2 ** i)
    for i in range(1, 100):
        if N // (5 ** i) == 0:
            break
        res_five += N // (5 ** i) // 2
    print(min(res_two, res_five))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int n,ans=0;
vector<vector<int>> tree(100010);
vector<pair<int,int>> edge(100010);
const ll MOD = 1000000007;
void bfs(int t,map<pair<int,int>,int> &group){//探索開始地点tと色group
    queue<pair<int,int>> q;//探索する点とそこに行くのに使った色
    q.push(make_pair(t,0));
    while(!q.empty()){
        int i=q.front().first;
        //cout<<i<<endl;
        int usedcolor=q.front().second;
        q.pop();
        int color=1;
        For(x,0,tree.at(i).size()){
            int j=tree.at(i).at(x);
            if(color==usedcolor) color++;
            group[make_pair(min(i,j),max(i,j))]=color;
            if(tree.at(j).size()) q.push(make_pair(j,color));
            color++;
        }
    }
    return;
}
void Main(){
    cin>>n;
    For(i,0,n-1){
        int a,b;cin>>a>>b;a--;b--;
        edge.at(i).first=a;
        edge.at(i).second=b;
        tree.at(a).push_back(b);
    }
    map<pair<int,int>,int> color;
    bfs(0,color);
    For(i,0,n-1) ans=max(ans,color[make_pair(edge.at(i).first,edge.at(i).second)]);
    cout<<ans<<endl;
    For(i,0,n-1) cout<<color[make_pair(edge.at(i).first,edge.at(i).second)]<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 11392
from itertools import product
import numpy as np
from operator import itemgetter
N, M = map(int,input().split())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))

npa = np.array(a)

ans = -1000000000000
for pat in product([-1,1], repeat=3):
  #print(pat)
  npw = np.zeros(N)
  npw = np.dot(npa, np.array(pat).T)
  sort_reverse = np.sort(npw)[::-1]
  sums = sort_reverse[:M].sum()
  ans = max(ans, sums)
  
print(ans)

Measured memory_bytes: 12520
import math
def judge_prime(n):
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True

n=int(input())
cnt=0
for i in range(n):
    x=int(input())
    if judge_prime(x):
        cnt+=1
print(cnt)


Measured memory_bytes: 5680
#include<stdio.h>

int main(void)
{
  int n,k,i,min=1;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++)
    {
      if(min <= k)
	{
	  min = min * 2;
	}
      else
	{
	  min = min + k;
	}
    }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;
typedef long long ll;

const int MAXN=3005;
const int MOD=998244353;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N,S,A[MAXN],dp[MAXN][MAXN];

ll qmult(ll X, ll Y, ll M) {    
    return X * Y % M;
}

ll qexp(ll A, ll B, ll M) {
    if (B == 0) return 1; 
    ll half = qexp(A, B/2, M); 
    half = qmult(half, half, M);
    half %= M;
    if (B%2==1) half *= A%M;
    return half%M;
}

int tinv;

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>S;
	FOR(i,1,N) cin>>A[i];
	tinv = qexp(2, MOD-2, MOD);
	
	FOR(i,0,N) dp[i][0] = qexp(2, N, MOD);
	FOR(i,1,N) FOR(j,1,S){
		//db(i), db(j);
		dp[i][j] = dp[i-1][j];
		if (j-A[i] >= 0){
			dp[i][j] += dp[i-1][j-A[i]] * tinv;
			dp[i][j] %= MOD;
		}
		//db(dp[i][j]);
	}
	cout<<dp[N][S];
	//cout << dp[0][2];
}


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

using namespace std;

/* 折り返しは 0 or 1 回                   
 * 1.時計回りに全て                   0(1)
 * 2.反時計回りに全て                 0(1)
 * 3.時計回りにある駅まで見て反転     0(M)
 * 4.反時計回りにある駅まで見て反転    0(M)
 * pの初期値が0だと都合がいい
 * di -= p
 * -になったら+N
 */

int N, M, p;
int d[10010];


int main(void)
{
    cin >> N >> M >> p;
    for(int i=0; i<M; i++){
        cin >> d[i];
        // 前処理
        d[i] -= p;
        if(d[i] < 0){
            d[i] += N;
        }
    }

    // 先にdをソートしておく
    // 大量にある0を先頭に来ないように省く
    // dの初めから使用値までソート
    sort(&d[0], &d[M]);

    int ans=0;

    // 1. dの最大値が分かれば 最大値*100 で求まる
    ans = d[M-1]*100;

    // 2. dの最小値が分かれば (N-最小値)*100 で求まる
    // minで1.の結果と比較する
    ans = min(ans, (N-d[0])*100);
    
    // 3. d[i+1]まで見る
    for(int i=0; i<M-1;i++){
        int c1 = 2*(d[i]*100);
        int c2 = (N-d[i+1])*100;
        ans = min(ans, c1+c2);
    }

    // 4. d[i-1]まで見る
    for(int i=M-1; i>0; i--){
        int c1 = 2*((N-d[i])*100);
        int c2 = d[i-1]*100;
        ans = min(ans, c1+c2);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii(), K=ii();
    vector<ll> p;
    REP(i,0,N){
        p.push_back(ii());
    }
    sort(p.begin(), p.end());
    oie(accumulate(p.begin(), p.begin() + K, 0LL));

    return 0;
}

Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll a,b,x; cin>>a>>b>>x;
  if(2*x<=a*a*b) {cout<<fixed<<setprecision(15)<<atan((double)(a*b*b)/(2*x))*180/pi<<endl; return 0;}
  x=a*a*b-x; 
  cout<<fixed<<setprecision(15)<<atan((double)(2*x)/(a*a*a))*180/pi<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
string s;





int main()
{

	cin >>s;
	int flag = 0;
	REP(i,s.length()){
		if(s[i] == 'C' && flag == 0)
			flag = 1;
		if(s[i] == 'F' && flag == 1)
			flag = 2;
	}

	if(flag == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;




}

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

vector<int> z_algorithm(string base_str, int start_index) {
  string s = base_str.substr(start_index, base_str.size()-start_index);
  vector<int> z(s.size());
  z[0] = s.size();
  int i = 1;
  int j = 0;
  while ( i < s.size() ) {
    while ( i+j < s.size() && s[j] == s[i+j] ) { j++; }
    z[i] = j;

    if ( j == 0 ) { i++; continue; }

    int k = 1;
    while ( k < j && k+z[k] < j ) {
      z[i+k] = z[k];
      k++;
    }
    i += k;
    j -= k;
  }
  return z;
}

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;

  int ans = 0;
  for ( int i = 0; i < n; i++ ) {
    vector<int> z = z_algorithm(s, i);
    for ( int j = 1; j < z.size(); j++ ) {
      if ( z[j] > ans && z[j] <= j ) {
        ans = z[j];
      }
    }
  }

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


Measured memory_bytes: 3652
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    std::cin >> n;
    
    vector<ll> cnt(3);
    
    for (int i = 0; i < n; i++) {
        ll a;
        std::cin >> a;
        ll num = 0;
        if(a%2 == 0){
            num = 1;
        }
        
        if(a%4 == 0){
            num = 2;
        }
        cnt[num]++;
    }
    
    if( cnt[0] == cnt[2]+1 && cnt[1] == 0){
        std::cout << "Yes" << std::endl;
        return 0;
    }
    
    if( cnt[0] <= cnt[2] ){
        std::cout << "Yes" << std::endl;
        return 0;
    }
    
    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n;
string s;
void solve(){
	cin>>n>>s;
	cout<<(n>=3200?s:"red");
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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


typedef long long ll;

int main() {
  int n, k, c; cin >> n >> k >> c;
  ++c;
  string s; cin >> s;
  vector<int> l1(n+2*c), l2(n+2*c);
  int o = c;
  for (int i = n-1; i >= 0; --i) {
    if (s[i] == 'o') {
      l1[i+o] = l1[i+o+c]+1;
    }
    else {
      l1[i+o] = l1[i+o+1];
    }
    // cout << i << " " << l1[i+o] << endl;
  }
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'o') {
      l2[i+o] = l2[i+o-c]+1; 
    }
    else {
      l2[i+o] = l2[i+o-1]; 
    }
    // cout << i << " " << l2[i+o] << endl;
  }

  for (int i = 0; i < n; ++i) { 
    if (l1[i+o+1]+l2[i+o-1] < k) { cout << i+1 << endl; }
  }
}


Measured memory_bytes: 3332
N,M = map(int,input().split())
A_list = list(map(int,input().split()))

sum=sum(A_list)
#print(sum)

for i in range(0,N):
    if A_list[int(i)] < sum / (4*M):
        A_list[int(i)]="Noooo"
    else:
        A_list[int(i)]="Yeeees"
#print(A_list)

if A_list.count("Yeeees") >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61960