akhauriyash/Code-Regression huggingface dataset:
#n == 1でバグるけど2が返ってくるのでヨシ！
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n = int(input())
X = [[int(i) for i in input().split()] for j in range(n-1)]
p = 10 ** 9 + 7

V = [[] for i in range(n+1)]
for x, y in X:
    V[x].append(y)
    V[y].append(x)

root = 0
for i, v in enumerate(V):
    if len(v) == 1:
        root = i
        break

w = 0
b = 1
DP = [[0] *  2 for i in range(n+1)]

def dfs(i):
    if DP[i] != [0, 0]:
        return 0
    DP[i][w] = 1
    DP[i][b] = 1
    for v in V[i]:
        if dfs(v) == 0:
            continue
        DP[i][w] *= DP[v][w] + DP[v][b]
        DP[i][b] *= DP[v][w]
        DP[i][w] %= p
        DP[i][b] %= p

dfs(root)
print(sum(DP[root]) % p)        

Measured memory_bytes: 131744
#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second

using namespace std;

/*int gcd(int a,int b){
	if(b == 0)
		return a;
	return gcd(b,a%b);
}*/

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

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

    int n;
    cin>>n;

    int d[n];

    for(int i =0;i<n;i++)
    	cin>>d[i];

    sort(d,d+n);

    int a = d[n/2 - 1];
    int b = d[n/2];
    int ans;
    if(a == b){
    	ans = 0;
    }
    else{
    	ans = b- a;
    }
    cout<<ans;
}

Measured memory_bytes: 640
n=int(input())
s=input()
ans=0

def my_index(l,x,default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

for i in range(10**3):
    i=str(i).zfill(3)
    if my_index(s,i[0])!=-1:
        s2=s[my_index(s,i[0])+1:]
        if my_index(s2,i[1])!=-1:
            s3=s2[my_index(s2,i[1])+1:]
            if my_index(s3,i[2])!=-1:
                ans+=1
print(ans)



Measured memory_bytes: 9240
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define N 3
#define N1 9

struct P{
    int f[N1];
    int space;
    string path;

    bool operator < (const P &p) const{
        for(int i = 0; i < N1; i++){
            if(f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
    return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};


int isT(P p){
    for(int i = 0; i < N1; i++){
        if(p.f[i] != (i + 1)) return 0;
    }
    return 1;
}

string bfs(P s){
    queue<P> Q;
    map<P, bool> V;
    P u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;

    while(!Q.empty()){
        u = Q.front();
        Q.pop();
        if(isT(u) == 1) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for(int r = 0; r < 4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if(!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main(){
    P in;

    for(int i = 0; i < N1; i++){
        cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N1;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;

    return 0;
}


Measured memory_bytes: 30652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;


int main(void) {

    string s;
    cin>>s;
    if(s=="SUN")fin(7);
    else if(s=="SAT")fin(1);
    else if(s=="FRI")fin(2);
    else if(s=="THU")fin(3);
    else if(s=="WED")fin(4);
    else if(s=="TUE")fin(5);
    else if(s=="MON")fin(6);
    
}


Measured memory_bytes: 256
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N int
  var A []int
  NextInt(&N)
  NextIntSlice(&A)
  S := A[0] + A[1]
  X := 0
  for _, a := range A[2:] { X ^= a }
  if X > S || (S - X) % 2 == 1 { Write(-1); return }
  D := (S - X) / 2
  if D & X > 0 { Write(-1); return }
  B := make([]int, 0)
  for x := X; x > 0; {
    b := x & (-x)
    B = append(B, b)
    x -= b
  }
  for i := len(B) - 1; i >= 0; i-- {
    if D + B[i] <= A[0] { D += B[i] }
  }
  if D == 0 || D > A[0] { Write(-1); return }
  Write(A[0] - D)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 1864
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int INF= 1e9+7;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n;
    cin>>n;

    vector<int>h(n);

    for(int i=0;i<n;i++)
        cin>>h[i];

    vector<int>dp(n,INF);//dp[i] -> minimum cost to reach position i

    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        for(int j : {i+1,i+2})
        {
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }

    cout<<dp[n-1]<<endl;



    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string s;
    cin >> N >> s;
    int x = 0, ma = 0;
    for(int i = 0; i < N; i++){
        if(s[i] == 'I') x++;
        else x--;
        ma = max(ma,x);
    }
    cout << ma << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int h,n; cin>>h>>n;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    int b = 0;
    rep(i,0,n) b+=a[i];
    if(b>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
	// your code goes here
	double r;
	cin>>r;
	double c;
	c=2*3.141592653589*r;
	cout<<fixed<<setprecision(6)<<c<<endl;
	return 0;
}


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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
bool vis[100000]={0};
int par[100000]={-1};
vvi g;int n,m;

void bfs(int i){
	queue<int> q;
	q.push(i);vis[0]=1;
	while(!q.empty()){
		int t=q.front();q.pop();
		
		for(auto z:g[t]) {
			if(vis[z]==false) {
				vis[z]=1;
				par[z]=t;
				q.push(z);
			}
		}
	}
}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	 cin>>n>>m;
	 int a,b;
	 g.resize(n);
	 repi(i,m){
		cin>>a>>b;--a;--b;
		g[a].pb(b);g[b].pb(a); 
	 }
	 bfs(0);
	 bool ch=true;
	 repi(i,n) if(vis[i]==false) {ch=false;break;}
	 if(ch){
	 	cout<<"Yes\n";
	 	rep(i,1,n-1) cout<<par[i]+1<<endl;
	 }
	 else cout<<"No\n";
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	
	
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



Measured memory_bytes: 10364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll,ll> vll;
typedef map<ll,ll> mll;
typedef set<ll> sll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair


ll n,m,ans;
int main() {
	cin>>n>>m;
	if(n<4)
		ans+=(4-n)*100000;
	if(m<4)
		ans+=(4-m)*100000;
	if(n==1 && m==1)
		ans+=400000;
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define mod 1e9 + 7;
const int INF = 1e9 + 5;
#define PQ priority_queue<int>
#define pii pair<int, int>
#define ff first
#define ss second


using namespace std;

	
ll knap(ll n, vi wt , vi val, ll W ){
	ll ** dp = new ll *[n+1];
	for(int i=0; i<=n; i++){
		dp[i] = new ll[W+1];

	}
	for(int i=0; i<=n; i++){
		dp[i][0]=0;
	}
	for(int j=0; j<=W; j++)dp[0][j]=0;
	
	for(int i=1; i<=n; i++){
		for(int w=0; w<=W; w++){
			dp[i][w] = dp[i-1][w];
			if(wt[i-1]<=w){
			dp[i][w] = max(dp[i][w], val[i-1] + dp[i-1][w-wt[i-1]]); }
		}
	}



	ll ans = dp[n][W];
	return ans;
}

int main(){

	ll n, W;
	cin>>n>>W;
	vi w(n), v(n);
	for(int i=0; i<n; i++){
		cin>>w[i]>>v[i];
	}
	
	cout<<knap(n, w, v, W);



	return 0;
}

Measured memory_bytes: 82592
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll k, l, m, n;
const int M = 1e9 + 7;


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

    cin >> n;

    m = (ll)M;

    vl a(n);
    rep(i, n) cin >> a[i];

    vl b(n - 1);
    b[n - 2] = a[n - 1];
    repd(i, n - 2) {
        b[i] = b[i + 1] + a[i + 1];
        if(b[i] > m) b[i] -= m;
    }

    ll sum = 0;
    rep(i, n - 1) {
        sum += a[i] * b[i];
        if(sum > m) sum %= m;
    }

    cout << sum << endl;
}

Measured memory_bytes: 6364
import itertools
while True:
    n, x = list(map(int, input().split()));
    if (n == 0) and (x == 0):
        break;
    N = [];
    for i in range(1,n+1):
        N.append(i)

    a = 0;
    for c  in itertools.combinations(N, 3):
        if sum(c) == x:
            a += 1;
    print(a);
    


Measured memory_bytes: 5636
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long 
#define ld long double
#define MOD 1000000007
#define mod9 1000000009
#define mod 1000003
#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define test ll t;cin>>t;while(t--)
#define bi begin()
#define ei end()
#define fi first 
#define se second  
#define forn(a,b) for(ll i=a;i<b;i++)
#define sz(s) s.size()     
#define pi 3.14159265358979323846
#define sp(x) cout<<fixed<<setprecision(x)
//ld round(ld var) 
//{ 
//    // 37.66666 * 100 =3766.66 
//    // 3766.66 + .5 =3767.16    for rounding off value 
//    // then type cast to int so value is 3767 
//    // then divided by 100 so the value converted into 37.67 
//    ld value = (int)(var * 100 + .5); 
//    return (ld)value / 100; 
//} 
int main()
{
	  string s;
	  cin>>s;
	  if(s=="ABC")
	  cout<<"ARC"<<endl;
	  else
	  cout<<"ABC"<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

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

  vector<int> W(1e5 * 5);
  vector<int> E(1e5 * 5);
  for (int i = 1; i < n; i++) {
    W[i] = W[i - 1];
    if (s[i - 1]  == 'W') {
      ++W[i];
    }
  }
  for (int i = n - 1; i > 0; i--) {
    E[i - 1] = E[i];
    if (s[i]  == 'E') {
      ++E[i - 1];
    }
  }

  //for (int i = 0; i < n; i++) {
  //  cout << W[i];
  //}
  //cout << endl;
  //for (int i = 0; i < n; i++) {
  //  cout << E[i];
  //}
  //cout << endl;

  int ans = 1e6;
  for (int i = 0; i < n; i++) {
    ans = min(ans, (W[i] + E[i]));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7696
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>

using namespace std;

int main() {
    int N;
    string S;

    cin >> N >> S;

    int answer=0;
    for(int i=0; i<N-2; i++){
        string tmp="";
        tmp+=S[i];
        tmp+=S[i+1];
        tmp+=S[i+2];
        if(tmp=="ABC")
            answer++;
    }

    cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int m,f,r;
    while (1){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        else if (m == -1 || f == -1) cout << "F\n";
        else if (m+f >= 80) cout << "A\n";
        else if (m+f < 80 && m+f >= 65) cout << "B\n";
        else if (m+f < 65 && m+f >= 50) cout << "C\n";
        else if (m+f < 50 && m+f >= 30){
            if (r >= 50) cout << "C\n";
            else cout << "D\n";
        }
        else cout << "F\n";
    }
    return 0;
}


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

int main(){
    ll a;
    string b;
    cin >> a >> b;
    if(b.size() == 1) b += ".00";
    else if(b.size() == 3) b += '0';
    ll b100 = 100*(b[0]-'0') + 10*(b[2]-'0') + (b[3]-'0');
    cout << (a*b100)/100 << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main()
{
  ll n = 0;
  ll d = 0;

  cin >> n >> d;

  vector <ll> x(n), y(n);

  for (ll i = 0; i < n; i++) {

    cin >> x[i] >> y[i];

  }

  ll count = 0;

  for (ll i = 0; i < n; i++) {

    double ans = static_cast <double>(sqrt(x[i] * x[i] + y[i] * y[i]));
    if (ans <= d) {

      count++;

    }
  }
  cout << count << endl;
}

Measured memory_bytes: 6460
#include<bits/stdc++.h>
using namespace std;
 
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long   

const ll mod=1e9+7;

int main()
{
    ll n,i;
    sfl(n);
    ll a[n+1];
    ll b[105]={0},cnt=0;
    for(i=1;i<=n;i++)
    {
        sfl(a[i]);
        b[a[i]]++;
    }
    for(i=1;i<=101;i++)
    {
        if(b[i]>0)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    cnt=0;
    return 0;
}

Measured memory_bytes: 256
import re

s = input()[::-1]
while len(s) > 0:
    for ptn in ['dream', 'dreamer', 'erase', 'eraser']:
        if re.match(ptn[::-1], s) is not None:
            s = s[len(ptn):]
            break
    else:
        break
print('YES' if len(s) == 0 else 'NO')

Measured memory_bytes: 3316
a,b=map(int,input().split())

if a<=0<=b:
    #0 in [a,b]
    print("Zero")
elif 0<a:
    #0<a<=b
    print("Positive")
else:
    #a<=b<0
    M=b-a+1
    if M%2:
        print("Negative")
    else:
        print("Positive")


Measured memory_bytes: 61804
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, M = reads()
cakes = []
for _ in range(N):
  cakes.append(reads())

signs = (-1, 1)

ans = 0
for s1, s2, s3 in product(*([signs]*3)):
  xs = [x1 * s1 + x2 * s2 + x3 * s3 for x1, x2, x3 in cakes]
  xs.sort()
  xs.reverse()
  ans = max(ans, sum(xs[:M]))
print(ans)


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

typedef long long LL;

const int N = 15;

int n, m;
string s[15], t[15], Map[15];
bool vis[15];

vector <int> S[15];
int kS;

int loc[15];

bool CheckAll(){
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++){
            int x = n - i - 1;
            int y = m - j  - 1;
            if (Map[i][loc[j]] != Map[x][loc[y]]) return false;
        }
    return true;
}

void DecideCol(int now){
    if (now == m - 1){
        if (CheckAll()) { printf("YES\n"); exit(0); }
        return ;
    }

    if (loc[now] != now) DecideCol(now + 1);
    else {
        for (int i = now + 1; i < m; i++) if (loc[i] == i){
            swap(loc[i], loc[now]);
            DecideCol(now + 1);
            swap(loc[i], loc[now]);
        }
        DecideCol(now + 1);
    }
}

void CheckCol(){
    for (int i = 0; i < m; i++) loc[i] = i;
    DecideCol(0);
}

void DecideRow(int now, int up, int down, int cnt){  // now 第几个集合，up上行，down下行，cnt这个集合已经用了多少个
    if (now > kS) { CheckCol(); return ; }
    if (up == down){                  // 单独处理奇集合
        for (int i = 0; i < S[now].size(); i++) if (!vis[S[now][i]]){
            Map[up] = s[S[now][i]];
            break;
        }
        DecideRow(now + 1, up + 1, down - 1, 0);
        return ;
    }
    for (int i = 0; i < S[now].size() - 1; i++) if (!vis[S[now][i]]){
        vis[S[now][i]] = true;
        Map[up] = s[S[now][i]];
        for (int j = i + 1; j < S[now].size(); j++) if (!vis[S[now][j]]){
            vis[S[now][j]] = true;
            Map[down] = s[S[now][j]];
            if (cnt + 2 == S[now].size()) DecideRow(now + 1, up + 1, down - 1, 0);
            else DecideRow(now, up + 1, down - 1, cnt + 2);
            vis[S[now][j]] = false;
        }
        vis[S[now][i]] = false;
    }
}

int main(){
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++){
        cin >> s[i]; t[i] = s[i];
        sort(t[i].begin(), t[i].end());
    }

    S[++kS].push_back(0);
    for (int i = 1; i < n; i++){
        bool flag = false;
        for (int j = 1; j <= kS; j++)
            if (t[i] == t[S[j][0]]){
                S[j].push_back(i);
                flag = true; break;
            }
        if (!flag) S[++kS].push_back(i);
    }

    int cnt = 0;
    for (int i = 1; i <= kS; i++)
        if (S[i].size() & 1) cnt++;
    
    if ((n & 1) == 0 && cnt > 0) { printf("NO\n"); return 0; }
    if ((n & 1) == 1 && cnt > 1) { printf("NO\n"); return 0; }

    if (n & 1) for (int i = 1; i < kS; i++)
        if (S[i].size() & 1){
            swap(S[i], S[kS]);
            break;
        }

    DecideRow(1, 0, n - 1, 0);

    printf("NO\n");

    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, r;
    while (cin >> n >> r, n) {
        int area = 0, len = 0;
        vector<pair<pair<int, int>, pair<int, int> > > sheets(n + 1);
        vector<int> nextx(10005, -1);
        for (int i = 0; i < n; i++) {
            cin >> sheets[i].first.first >> sheets[i].first.second >>
                sheets[i].second.first >> sheets[i].second.second;
        }
        sheets[n] = make_pair(make_pair(10005,0), make_pair(10005,0));
        sort(sheets.begin(), sheets.end());
        
        int bx = 0;
        for (int i = 0; i <= n; i++) {
            int x = sheets[i].first.first;
            int nx = sheets[i].second.first;
            if (x != bx) {
                for (int j = 0; j <= 10000; j++) {
                    if (nextx[j] < bx) continue;
                    int ulen = (j == 0 ? -1 : nextx[j-1]), blen = nextx[j+1];
                    //cerr << j << " +" << max(0, min(nextx[j], x) - max(bx, ulen)) +
                    //       max(0, min(nextx[j], x) - max(bx, blen)) << endl;
                    len += max(0, min(nextx[j], x) - max(bx, ulen)) +
                           max(0, min(nextx[j], x) - max(bx, blen));
                    if (nextx[j] < x) {
                        len++;
                        //cerr << j << " start" << endl;
                        area += nextx[j] - bx;
                    } else {
                        area += x - bx;
                    }
                }
                //cerr << x << " " << len << endl;
            }
            for (int j = sheets[i].first.second; j < sheets[i].second.second; j++) {
                if (nextx[j] < x) {
                    len++;
                    //cerr << j << " end" << endl;
                }
                nextx[j] = max(nextx[j], nx);
            }
            bx = x;
        }
        
        cout << area << endl;
        if (r == 2) cout << len << endl;
    }
}

Measured memory_bytes: 1404
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, m, x = tin()
	#s = input()
	al = lin()
	pre = sum([1 for v in al if v < x])
	post = len(al)-pre
	return min(pre, post)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62072
#include<bits/stdc++.h>
#define io std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007;
using namespace std;
int main()
{
    io;
    int n,k,c=0;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        if(v[i]>=k)
            c++;
    }
    cout<<c;
}


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

int main()
{
    int n; cin>>n;
    int a2=0, a4=0, x=0;
    for(int i=0; i<n; ++i) {
        int a; cin>>a;
        a%4==0 ? a4++ : a%2==0 ? a2++: x++;
    }
    cout<<(x-(a2==0)>a4 ? "No" : "Yes")<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) { cin >> A[i]; }
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    int cnt = 0;
    int x = 0;
    if (A[0] < A[1]) x = 1;
    if (A[0] > A[1]) x = -1;
    rep(i, 2, N) {
        if (A[i - 1] == A[i]) continue;
        if (A[i - 1] < A[i]) {
            if (x == 0) x = 1;
            if (x < 0) {
                cnt++;
                x = 0;
            }
        }
        if (A[i - 1] > A[i]) {
            if (x == 0) x = -1;
            if (x > 0) {
                cnt++;
                x = 0;
            }
        }
    }
    cout << cnt + 1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {int a,b,m,p,q,syo,x,y,z,c;
             cin>>a>>b>>m;
  vector<int> r(a);
             vector<int> d(b);
  p=0;
  q=0;
  syo=1000000;          
 
 for(int i=0;i<a;i++){cin>>p; r.at(i)=p;}           
  for(int i=0;i<b;i++){cin>>q; d.at(i)=q;}  
  for(int i=0;i<m;i++){cin>>x>>y>>z; 
                      syo=min(syo,(r.at(x-1)+d.at(y-1)-z));}  
        sort(r.begin(), r.end());
      sort(d.begin(), d.end());
            c=r.at(0)+d.at(0);
            cout<<min(c,syo)<<endl;
            
    
 
}


Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#define f first
#define s second
using namespace std;
typedef long long LL;
const int MAXN = 1e6+66;
int main()
{
    LL q,a,b;
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        LL k = sqrt((long double)a*b*1.0);
        if(k*(k+1) < a*b)
        {
            cout<<k-1+k<<endl;
            continue;
        }
        if(k*k == a*b)
        {
            if(a == k) cout<< k-1+k-1<<endl;
            else cout<<k-1+k-2<<endl;
            continue;
        }
        cout<<k-1+k-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
typedef vector<int> VI;

int n;

int main(){
    cin>>n;
    rep(i,1,9) if(n%i==0&&n/i<=9){printf("Yes\n");return 0;}
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))
c = [c1, c2, c3]

d = [[-1, -1, -1] for _ in range(3)]

for a1 in range(c[0][0]+1):
    b1 = c[0][0] - a1
    b2 = c[0][1] - a1
    b3 = c[0][2] - a1

    a2 = c[1][0] - b1
    a3 = c[2][0] - b1

    d[0][0] = a1 + b1
    d[0][1] = a1 + b2
    d[0][2] = a1 + b3
    d[1][0] = a2 + b1
    d[1][1] = a2 + b2
    d[1][2] = a2 + b3
    d[2][0] = a3 + b1
    d[2][1] = a3 + b2
    d[2][2] = a3 + b3

    if c == d:
        print('Yes')
        exit(0)
    else:
        continue

print('No')

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

#define mod 998244353
int a[100050];

int main() {
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);
if(a[0] != 0) {
puts("0");
return 0;
}
	sort(a, a + n);
	int val = 0, pre = 1, res = 1;
	for(int i = 0; i < n; val++) {
		int cnt = 0;
		while(i < n && a[i] == val) i++, cnt++;
		if(!cnt || (val == 0 && cnt != 1)) {
			res = 0;
			break;
		}
		for(int j = 0; j < cnt; j++) res = (long long) res * pre % mod;
		pre = cnt;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 10e9 + 7
     
     
    int main(){
    ll h,a,cnt =0;
      cin >> h >> a;
      while(h>0){
      
      h = h - a;
      cnt++;
      }
    cout << cnt;
     
    return 0;
     
    }



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define modp(x) ((x)%modn)
using namespace std;
const int maxn=100005,INF=1e9+7;
int f[maxn],a[maxn];
int n,k;
int main()
{
	scanf("%d%d",&n,&k);
	rep(i,1,n) scanf("%d",a+i),f[i]=INF;
	f[1]=0;
	rep(i,2,n) rep(j,1,min(k,i-1)) f[i]=min(f[i-j]+abs(a[i]-a[i-j]),f[i]);
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 1024
a,b,c,x,y=map(int,input().split())

cmax=max(x,y)*2
zmin=(a+b)*10**5
for nc in range(0,cmax+1,2):
    na=max(x-nc//2,0)
    nb=max(y-nc//2,0)
    z=a*na+b*nb+c*nc
    zmin=min(zmin,z)
    
print(zmin)


Measured memory_bytes: 3060
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
const int N=2e5 + 5;

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    ll dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    dp[1][1]=1;
    for(int i=2;i<n+1;i++){
        ll pre[n+1]={0};
        forn(i1,n)pre[i1+1]=(pre[i1]+dp[i-1][i1+1])%mod;
        for(int j=1;j<i+1;j++){
            if(s[i-2]=='<')dp[i][j]=(pre[j-1]);
            else{
                ll temp=pre[n]-pre[j-1];
                temp=(temp+mod)%mod;
                dp[i][j]=temp;
            }
        }
    }
    ll ans=0;
    //forn(i,n){forn(j,n)cout<<dp[i+1][j+1];cout<<endl;}
    forn(i,n)ans=(ans+dp[n][i+1])%mod;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 70656
#include <iostream>

using namespace std;

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

    char s[50][50];

    for(int j = 0; j < H; j++){
        for(int i = 0; i < W; i++){
            cin >> s[j][i];
        }
    }


    for(int j = 0; j < H; j++){
        for(int i = 0; i < W; i++){
            if(s[j][i] == '.'){
                continue;
            }
            if(i-1 >= 0 && s[j][i-1] == '#'){
                continue;
            }
            if(i+1 < W && s[j][i+1] == '#'){
                continue;
            }
            if(j-1 >= 0 && s[j-1][i] == '#'){
                continue;
            }
            if(j+1 < H && s[j+1][i] == '#'){
                continue;
            }
            cout << "No" << endl;
            return 0;
        }

    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int count = 0;
    int N;
    int A[200];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    while(1){
        bool flag = true;

        for(int i = 0; i < N; i++){
            if(A[i] % 2 != 0){
                flag = false;
                break;
            }
        }

        if(flag){
            for(int i=0;i<N;i++){
                A[i] /= 2;
            }
            count++;
        }    

        if(flag == false){
            break;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S1,S2,S3;
  cin>>S1>>S2>>S3;
  for(int i=0;i<301;i++){
    char mark;
    if(i==0){
      mark=S1.at(0);
      S1.erase(S1.begin());
    }
    else{
      if(mark=='a'){
        if(S1.size()==0){
          cout<<'A'<<endl;
          break;
        }
        else{
          mark=S1.at(0);
          S1.erase(S1.begin());
        }
      }
      if(mark=='b'){
        if(S2.size()==0){
          cout<<'B'<<endl;
          break;
        }
        else{
          mark=S2.at(0);
          S2.erase(S2.begin());
        }
      }
      if(mark=='c'){
        if(S3.size()==0){
          cout<<'C'<<endl;
          break;
        }
        else{
          mark=S3.at(0);
          S3.erase(S3.begin());
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const double inf=1e8;
int main(){
	int n,k;
	while(cin>>n>>k,n+k){
		vvp in(k-1);
		rep(i,n){
			char c;int a;
			cin>>c>>a;
			in[a-1].pb(pii(c,i));
		}
		int cnt=0;
		int last;
		while(1){
			cnt++;
			vvp tmp(k-1);
			for(int i=k-2;i>=0;i--)rep(j,in[i].size()){
				last=in[i][j].second;
				int t=i;
				if(in[i][j].first=='L')t--;
				else t++;
				if(t==-1||t==k-1)n--;
				else{
					tmp[t].pb(in[i][j]);
					if(tmp[t].size()==2){
						swap(tmp[t][0].first,tmp[t][1].first);
					}
				}
			}
			in=tmp;
			if(!n)break;
		}
		cout<<cnt<<" "<<last+1<<endl;;
	}
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int> w(n,0),e(n,0);
    rep(i,n){
        if(s[i]=='W') w[i]=1;
        else e[i]=1;
    }
    vector<int> cw(n+1,0),ce(n+1,0);
    for(int i=0;i<n;i++){
        cw[i+1]+=cw[i]+w[i];
        ce[i+1]+=ce[i]+e[i];
    }

    //rep(i,n) cout<<cw[i]<<" ";
    //cout<<endl;
    int ans=n;
    rep(i,n){
        int tmp=cw[i];
        tmp+=ce[n]-ce[i+1];
        //cout<<cw[i]<<" "<<ce[n]-ce[i+1]<<endl;
        ans=min(ans,tmp);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 8264
n = gets.to_i
as = gets.split.map(&:to_i).sort!
q = gets.to_i
ms = gets.split.map(&:to_i)

sums = []
1.upto(n) do | i | # iはasから取得する数
  cmbs = as.combination(i).to_a
  cmbs.map{ | ary | sum = 0; ary.each{ | a | sum += a }; sums << sum }
end

ms.each do | m |
  if sums.include? m
    puts 'yes'
  else
    puts 'no'
  end
end


Measured memory_bytes: 102912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef pair<int,int>p;
typedef set<int>s;
#define ll long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define FOR(i,a,b) for(int i=a;i>b;--i)
#define FORE(i,a,b) for(int i=a;i>=b;--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bg begin()
#define en end()
/*note

*/
int main()
{
string s,t,t1="";
cin>>s>>t;
fr(i,0,t.size()-1){t1+=t[i];}
if(t1==s)cout<<"Yes"<<endl;
else cout<<"No"<<endl;



}


Measured memory_bytes: 3596
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut ans: u32 = 0;

    for i in 0..s.len() {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i, n) for(int i = 0; i < int(n); i ++)
#define ff(i, n) for(int i = 1; i < int(n); i ++)

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pi;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl;
typedef vector<pil>vil;
typedef long double ld;

#define INF 1000000000000

ll dp[2010][2010];
ll a[2010];


int main(){
    int N;ll hog,res;
    bool fla;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    if(N==1){
        cout<<a[0]<<endl;
        return 0;
    }
    dp[0][N-1]=a[N-1];
    for(int i=1;i<N;i++){
        dp[i][N-1]=a[i-1];
    }
    fla=false;
    for(int i=N-2;i>=1;i--){
        if(fla){
            dp[0][i]=max(dp[0][i+1]+a[i],dp[N-1][i+1]+a[N-1]);
            for(int j=1;j<N;j++){
                dp[j][i]=max(dp[j][i+1]+a[(j+i)%N],dp[j-1][i+1]+a[j-1]);
            }
        }
        else{
            hog=-INF;
            if(a[0]<a[i]){
                hog=dp[0][i+1];
            }
            if(a[N-1]>a[i-1]){
                hog=max(hog,dp[N-1][i+1]);
            }
            dp[0][i]=hog;
            for(int j=1;j<N;j++){
                hog=-INF;
                if(a[j]<a[(i+j)%N]){
                    hog=dp[j][i+1];
                }
                if(a[j-1]>a[(i+j-1)%N]){
                    hog=max(hog,dp[j-1][i+1]);
                }
                dp[j][i]=hog;
            }
        }
        fla=!fla;
    }
    res=-INF;

    if(fla){
        for(int i=0;i<N;i++){
            res=max(res,dp[i][1]+a[i]);
        }
    }
    else{
        for(int i=0;i<N;i++){
            res=max(res,dp[i][1]);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 32588
#include <bits/stdc++.h>
#include <iterator>
#include <tuple>
using namespace std;
using ll = long long;

int main()
{
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  for (int i = 0; i < d; ++i)
    cin >> p[i] >> c[i];

  int cnt = 1e7;
  for (int i = 0; i < (1 << d); ++i)
  {
    int sum = 0;
    int t = 0;
    for (int j = 0; j < d; ++j)
    {
      if ((1 << j) & i)
      {
        sum += (j + 1) * 100 * p[j] + c[j];
        t += p[j];
      }
    }
    if (sum < g)
    {
      int tmp = 0;
      for (int j = d; j > 0; --j)
      {
        if ((1 << (j - 1)) & i)
          continue;
        tmp = ceil((g - sum) / (j * 100.0));
        if (tmp > p[j - 1])
        {
          tmp = p[j - 1];
        }
        t += tmp;
        sum += tmp * j * 100;
        break;
      }
    }
    if (sum >= g)
    {
      cnt = min(cnt, t);
    }
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
k,n=map(int,input().split())
a=list(map(int,input().split()))

maxer=0
sum=0

for i in range(n-1):
    sa=a[i+1]-a[i]
    maxer=max(maxer,sa)
    sum=sum+sa
sa=(k-a[n-1])+a[0]
maxer=max(maxer,sa)
sum=sum+sa

print(sum-maxer)

Measured memory_bytes: 77388
import java.util.Scanner;

public class Main {
	static class Pair {
		int first;
		int second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}
	}

	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			int n = in.nextInt();
			int w = in.nextInt();
			Pair[] a = new Pair[n];

			for (int i = 0; i < n; i++) {
				int vv = in.nextInt();
				int ww = in.nextInt();

				a[i] = new Pair(vv, ww);
			}

			System.out.printf("%d\n", knapsack(w, a));
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

	private static long knapsack(int w, Pair[] a) {
		int n = a.length;
		long[][] dp = new long[n+1][w+1];

		for (int i = 0; i < n+1; i++) {
			for (int j = 0; j < w+1; j++)
				dp[i][j] = 0;
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= w; j++) {
				dp[i][j] = dp[i-1][j];

				if (a[i-1].second <= j) {
					long v = dp[i-1][j-a[i-1].second] + a[i-1].first;

					if (v > dp[i][j])
						dp[i][j] = v;
				}
			}
		}

		return dp[n][w];
	}
}

Measured memory_bytes: 35348
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

struct edge{
    ll u;
    ll v;
    ll cost;
    edge(){}
    edge(ll u,ll v, ll cost):u(u),v(v),cost(cost){}
};

void dijkstra(ll root,ll n,vector<vector<edge>>&T ,vector<ll>& dist){
    queue<ll> q;
    q.push(root);
    dist[root] = 0;
    while(!q.empty()){
        ll next = q.front(); q.pop();
        for(auto e:T[next]){
            if(dist[e.v] > dist[e.u] + e.cost){
                dist[e.v] = dist[e.u] + e.cost;
                q.push(e.v);
            }
        }
    }
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<vector<edge>> T(n);
    for(int i = 0; i < n - 1;i++){
        ll s,t, w; cin >> s >> t >> w;
        T[s].emplace_back(edge(s,t,w));
        T[t].emplace_back(edge(t,s,w));
    }
    
    
    /*
     ??¨?????´??????????????????????????????????????????????????¢????±???????????¬????????±??????????????????¢????????§?????????????????????????????????????????????????????¢????±???????
             ?±??????????????????¢?????????????????????????????´???
     */
    ll root = 0;
    ll v1,v2;
    ll max_dist;
    vector<ll> dist(n,INF);
    dijkstra(root, n, T, dist);
    v1 = max_element(dist.begin(), dist.end()) - dist.begin();
    
    dist.assign(n,INF);
    dijkstra(v1, n, T, dist);
    v2 = max_element(dist.begin(), dist.end()) - dist.begin();
    
    cout << dist[v2] << endl;
    
    return 0;
}

Measured memory_bytes: 13388
import java.util.*

fun main(args:Array<String>) {
    val scn= Scanner(System.`in`)
    val n=scn.nextInt()
    var h=IntArray(n)
    var cnt=0
    for (i in 0 until n){
        h[i]=scn.nextInt()
        for (j in 0 until i){
            if (h[j]>h[i]) break
            if (j==i-1)cnt++
        }
    }
    println(cnt+1)
}


Measured memory_bytes: 29720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>

using namespace std;

int main()
{
    int x;
    while(~scanf("%d",&x))
    {
        int i,a[100100]= {0},b[100100]= {0},c[100100]= {0};
        long long d[100100]={0};
        for(i=1; i<=x; i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=1; i<=x; i++)
        {
            scanf("%d",&b[i]);
        }
        for(i=1; i<=x; i++)
        {
            scanf("%d",&c[i]);
        }
        sort(a+1,a+1+x);
        sort(b+1,b+x+1);
        sort(c+1,c+x+1);
        for(i=1; i<=x; i++)
        {
            int l=1,r=x,mid;
            while(l<=r)
            {
                mid=l+(r-l)/2;
                if(a[mid]>=b[i])
                {
                    r=mid-1;
                }
                else if(a[mid]<b[i])
                {
                    l=mid+1;
                }
            }
            d[i]=d[i-1]+r;
        }
        long long sum=0;
        for(i=1; i<=x; i++)
        {
            int l=1,r=x,mid;
            while(l<=r)
            {
                mid=l+(r-l)/2;
                if(b[mid]>=c[i])
                {
                    r=mid-1;
                }
                else if(b[mid]<c[i])
                {
                    l=mid+1;
                }
            }
            sum=sum+d[r];
        }
        printf("%lld\n",sum);
    }
    return 0;
}



Measured memory_bytes: 2176
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

N = gif
t = gi
v = gi
repl 1, N-1 do |i|
  t[i] += t[i-1]
end

t.map!{|i| i * 2 }
t << 0

x = [0] * (t[-2] + 1)

rep N do |i|
  if v[i] < x[t[i - 1]]
    x[t[i - 1]] = v[i]
    repl t[i - 1] - 1, t[i - 2], -1 do |j|
      x[j] = [x[j + 1] + 0.5, x[j]].min
    end
  end

  repl t[i - 1] + 1, t[i] do |j|
    x[j]=[x[j-1]+0.5, v[i]].min
  end
end

x[-1]=0
repl t[-2], 1, -1 do |i|
  x[i-1] = [x[i-1], x[i]+0.5].min
end

puts x.each_cons(2).map{|l, r|
  (l + r)*0.5/2.0
}.inject(:+)


Measured memory_bytes: 3252