akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define INF (1 <<29)
//const int INF = int(100 * 200 * (1e5 + 1));
int N, M, R;
int d[201][201];
int r[8];
int min_cost = INF;
//int min_cost = INF;

void dfs(int from_idx, int dist, int used) {

    if (used == (1 << R) - 1) {
        min_cost = min(min_cost, dist);
        return;
    }

    for (int to_idx = 0; to_idx < R; ++to_idx) if (!(used >> to_idx & 1)) {
        if (dist == -1) {
            dfs(to_idx, 0, used | 1 << to_idx);
        } else {
            dfs(to_idx, dist + d[r[from_idx]][r[to_idx]], used | 1 << to_idx);
        }
    }
}


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

    cin >> N >> M >> R;

    for (int i = 1; i <= N; ++i) {
        fill(d[i] + 1, d[i] + N + 1, min_cost);
        d[i][i] = 0;
    }
    for (int i = 0; i < R; ++i) {
        cin >> r[i];
    }
    int a, b, c;
    for (int i = 0; i < M; ++i) {
        cin >> a >> b >> c;
        if (d[a][b] > c) d[a][b] = d[b][a] = c;
    }
    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    dfs(0, -1, 0);

    cout << min_cost << '\n';

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 5100
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

struct data{
    ll p; ll q; ll r;
};

vector<vpl> G(MAX);
bool visit[MAX];
vl dest(105,INF);
ll n,m;

ll dijkstra(ll start, ll goal){
    priority_queue<P> pq;
    rep(i,n) dest[i] = INF;
    rep(i,n) visit[i] = false;
    dest[start] = 0;
    pq.emplace(0,start);
    while(!pq.empty()){
        P p = pq.top(); pq.pop();
        ll u = p.second;
        visit[u] = true;
        if(dest[u] < p.first * (-1)) continue;
        for(auto i : G[u]){
            ll v = i.first;
            if(visit[v]) continue;
            if(dest[v] > dest[u] + i.second){
                dest[v] = dest[u] + i.second;
                pq.emplace(dest[v] * (-1), v);
            }
        }
    }
    return dest[goal];
}

int main(){
    cin >> n >> m;
    ll a,b,c;
    struct data d[m];
    rep(i,m){
        cin >> a >> b >> c; a--; b--;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
        d[i].p = a;
        d[i].q = b;
        d[i].r = c;
    }
    ll ans = 0;
    rep(i,m){
        if(d[i].r > dijkstra(d[i].p, d[i].q)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
from math import sqrt
def readinput():
    n=int(input())
    return n

def main(n):
    m=int(sqrt(n))+1
    count=0
    for a in range(1,m+1):
        if a*a < n:
            count+=1
        else:
            break
    
    for a in range(1,m+1):
        for b in range(a+1,n+1):
            if a*b < n:
                count+=2
            else:
                break
    return count

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define N 10
#define M 30
using namespace std;
int h,w,sy,sx,sd,ocnt;
string s[N],ans;
char c[M];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
char itoc[4]={'U','R','D','L'};

void dfs(int y,int x,int d,int cnt){
  if(cnt==ocnt){
    for(int i=0;i<cnt;i++)ans+=c[i];
    return;
  }
  for(int i=-1;i<=1;i++){
    int nd=(d+i+4)%4;
    int ny=y+dy[nd],nx=x+dx[nd];
    while(1){
      if(ny<0||nx<0||h<=ny||w<=nx)break;
      if(s[ny][nx]=='o'){
	s[ny][nx]='.';
	c[cnt]=itoc[nd];
	dfs(ny,nx,nd,cnt+1);
	s[ny][nx]='o';
	break;
      }
      ny+=dy[nd];
      nx+=dx[nd];
    }
  }
}

int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++){
    cin>>s[i];
    for(int j=0;j<w;j++){
      if(s[i][j]=='o')ocnt++;
      else if(s[i][j]!='.'){
	sy=i,sx=j;
	if(s[i][j]=='U')sd=0;
	if(s[i][j]=='R')sd=1;
	if(s[i][j]=='D')sd=2;
	if(s[i][j]=='L')sd=3;
      }
    }
  }
  dfs(sy,sx,sd,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3216
#include <stdio.h>

int main(void){
	int t,a;
	
	while(1){
	
	scanf("%d",&a);
		if(a==0){
			return 0;
		}
	
	for(t=0;a!=1;t++){
		if(a%2==0){
			a=a/2;
		}
		else if(a%2==1){
			a=a*3+1;
		}
	}
	
		printf("%d\n",t);
	}
	
		
	return 0;
}

Measured memory_bytes: 600
K,X = map(int, input().split())

if(X-K+1 < -1000000):
    ans = range(-1000000, X+K)
elif(X+K-1 > 1000000):
    ans=range(X-K+1,1000000+1)
else:
    ans=range(X-K+1,X+K)

b = list(ans)
print(' '.join(map(str, b)))

Measured memory_bytes: 3060
n, q = list(map(int, input().split()))
s = input()
cnt_list = [0] * n
tmp = ""
cnt = 0
for i in range(1, len(s)):
    if s[i-1]=="A" and s[i]=="C":
        cnt += 1
    cnt_list[i] = cnt
for _ in range(q):
    l, r = list(map(int, input().split()))
    print(cnt_list[r-1]-cnt_list[l-1])

Measured memory_bytes: 6084
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N, L[209];
	cin >> N;

	for (int i = 0; i < 2*N; i++) {
		cin >> L[i];
	}
	sort(L, L+2*N);
	int sum = 0;
	for (int i = 0; i < 2*N; i+= 2) {
		sum += L[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair



using namespace std;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef set<int> si;

const int N = 1e5+5;
int arr[N];
double ans[N];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	for(int i=0;i<a;i++){
		cin >> arr[i];
	}
	int f;
	double g = 1000000000.0;
	for(int i=0;i<a;i++){ 
		ans[i] = b - (arr[i] * 0.006);
		if(fabs(ans[i] - c) < g){
			f = i + 1;			
			g = fabs(ans[i] - c);
		}
	}
	cout << f << endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
Ds = []
for i in range(1, M+1):
  if i*i > M:
    break
  if M%i == 0:
    j = M//i
    Ds.append(i)
    Ds.append(j)
#print(Ds)
r = max(filter(lambda i: M//i >= N, Ds))
print(r)


Measured memory_bytes: 3060
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Graph Start
struct edge {
    int from, to;
    long long cost;
};
/// Graph End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N,M);
    vector<int> out(M),in(M),result(N,0);

    rep(i,M){
        cin >> out[i] >> in[i];
        out[i]--; in[i]--;
        result[out[i]]++;
        result[in[i]]++;
    }
    rep(i,N){
        cout << result[i] << nn;
    }

    return 0;
}

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

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

int N;
int a[3001];
// 手番－相手番
int dp[3001][3001];

int solve(int l, int r){
	if (dp[l][r] != 0) return dp[l][r];

	if (r - l == 1) return dp[l][r] = a[l];

	return dp[l][r]=max(-solve(l + 1,r) + a[l], -solve(l,r - 1) + a[r - 1]);
}

signed main(){

	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}

	cout << solve(0, N) << endl;

	return 0;
}


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

int main() {
  string S;
  cin >> S;
  int x =0;
  for(int i=0;i<3;i++){
    if(S.at(i)=='o'){
      x++;
    }
  }
  cout << 700+100*x << endl;
}

Measured memory_bytes: 3580
#include <cstring>
#include <iomanip>
#include <iostream>
using namespace std;
int n, b1, b2, b3, dr[4] = { -3, -1, 1, 3 }; char c1, c2, c3; double dp[19][9];
int main() {
	while (cin >> n, n) {
		cin >> c1 >> c2 >> c3;
		b1 = c1 - 65, b2 = c2 - 65, b3 = c3 - 65;
		memset(dp, 0, sizeof(dp));
		dp[0][b1] = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < 9; j++) {
				int r[4] = { 0 };
				for (int k = 0; k < 4; k++) {
					int u = j + dr[k];
					if (u < 0 || u > 8 || abs(j % 3 - u % 3) == 2 || u == b3) continue;
					r[k] = 1;
				}
				for (int k = 0; k < 4; k++) {
					if (r[k]) dp[i][j + dr[k]] += dp[i - 1][j] / 4;
					else dp[i][j] += dp[i - 1][j] / 4;
				}
			}
		}
		cout << fixed << setprecision(15) << dp[n][b2] << endl;
	}
}

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

int main()
{
    int x;
    cin>>x;
    if(x>=400&&x<=599)
        cout<<8<<endl;
    else if(x>=600&&x<=799)
        cout<<7<<endl;
    else if(x>=800&&x<=999)
        cout<<6<<endl;
    else if(x>=1000&&x<=1199)
        cout<<5<<endl;
    else if(x>=1200&&x<=1399)
        cout<<4<<endl;
    else if(x>=1400&&x<=1599)
        cout<<3<<endl;
    else if(x>=1600&&x<=1799)
        cout<<2<<endl;
    else if(x>=1800&&x<=1999)
        cout<<1<<endl;
}


Measured memory_bytes: 3632
function Main(input) {

	input = input.split("\n");
	//tmp[0]にX, tmp[1]にN
	tmp = input[0].split(" ");

	//tmp2にP
	tmp2 = input[1].split(" ");
  
	var x = parseInt(tmp[0], 10);
	var n = parseInt(tmp[1], 10);


    for( let t = 0 ; t < (x+1) ; t++ ){
        let a = x + (-1) * t;
        let count = tmp2.filter(function(x){return x===String(a)}).length;
		if( count == 0 ) {
            console.log( '%d', a );
            break
        }
      
        a = x + 1 * t;
        count = tmp2.filter(function(x){return x===String(a)}).length;
		if( count == 0 ) {
            console.log( '%d', a );
            break
        }
    }
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int calcGreatestCommonDivisor(int x, int y);

int main(void)
{
	int x, y;
	cin >> x >> y;
	
	int gcd;
	if (x >= y) gcd = calcGreatestCommonDivisor(x, y);
	else gcd = calcGreatestCommonDivisor(y, x);
	
	cout << gcd << endl;
	
	return 0;
}

int calcGreatestCommonDivisor(int x, int y)
{
	if (x % y == 0) return y;
	return calcGreatestCommonDivisor(y, x % y);
}

Measured memory_bytes: 3100
// C - Cat Snuke and a Voyage

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

bool to_I[200000];
bool to_N[200000];

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

	int a, b;
	for (int i=0; i<M; i++) {
		cin >> a >> b;
		if (a == 1) to_I[b] = true;
		if (b == 1) to_I[a] = true;
		if (a == N) to_N[b] = true;
		if (b == N) to_N[a] = true;
	}

	string ans = "IMPOSSIBLE";
	for (int i=2; i<N; i++) {
		if (to_I[i] && to_N[i]) ans = "POSSIBLE";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int A[100000];
int n;

int bsearch(int x){
  int max=n,min=0,mid;
  mid=max/2;
  while(max>min){
    if(A[mid]==x) return 1;
    else if(x>A[mid]) min=mid+1;
    else max=mid;
    mid=(max+min)/2;
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  /* code */
  int i,n2,x,sum=0;

  scanf("%d\n",&n);
  for (i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d\n",&n2);
  for (i=0;i<n2;i++){
    scanf("%d",&x);
    if(bsearch(x)) sum++;
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 988
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
#define MOD 998244353
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    bool b[4];
    int x;
    for(int i = 0; i  <4; i++)
        b[i]=true;
    for(int i = 0; i < 2; i++)
    {
        cin >> x;
        b[x]=false;
    }
    for(int i = 1; i < 4; i++)
        if(b[i])
            cout << i << '\n';
}

Measured memory_bytes: 256
n = int(input())
t, a = list(map(int, input().split()))
ans = t + a
for i in range(n-1):
    new_t, new_a = list(map(int, input().split()))
    bairitsu = max((t - 1) // new_t + 1, (a - 1) // new_a + 1)
    new_t, new_a = bairitsu * new_t, bairitsu * new_a
    ans = new_t + new_a
    t, a = new_t, new_a
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct Node
{
	int key;
	Node *p, *l, *r;
} *root = NULL;

void insert(Node *z){
	Node *x, *y;
	y = NULL;
	x = root;
	while(x!=NULL){
		y = x;
		if(z->key < x->key) x = x->l;
		else x = x->r;
	}
	z->p = y;
	if(y==NULL) root = z;
	else if(z->key < y->key) y->l = z;
	else y->r = z;
}
void preP(Node *x){
	if(x==NULL) return;
	printf(" %d",x->key);
	preP(x->l);
	preP(x->r);
}
void inP(Node *x){
	if(x==NULL) return;
	inP(x->l);
	printf(" %d",x->key);
	inP(x->r);
}
bool find(int k){
	Node *x = root;
	while(x!=NULL && k!=x->key)
		if(k < x->key) x = x->l;
		else x = x->r;
	return x;
}
int main()  
{
	char cmd[10];
	int n,t; cin>>n;
	while(n--){
		scanf("%s",cmd);
		if(cmd[0]=='i'){
			Node *z = new Node;
			scanf("%d",&(z->key));
			z->l = z->r = NULL;
			insert(z);
		}
		else if(cmd[0]=='p'){
			inP(root);
			putchar('\n');
			preP(root);
			putchar('\n');
		}
		else{
			scanf("%d",&t);
			puts(find(t)?"yes":"no");
		}
	}
	return 0;
}




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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
	int n; cin >> n;
	switch(n){
		case 25:
			cout << "Christmas" << endl;
			break;
		case 24:
			cout << "Christmas Eve" << endl;
			break;
		case 23:	
			cout << "Christmas Eve Eve" << endl;
			break;
		case 22:
			cout << "Christmas Eve Eve Eve" << endl;
			break;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)
using namespace std;

int n;
string board[1010];
int dp[1010][1010];

int main(void){
	while(cin >> n,n){
		rep(i,n) cin >> board[i];
		rep(j,n) dp[0][j]=(board[0][j]=='.');
		range(i,1,n)rep(j,n){
			if(j==0){
				dp[i][j]=(board[i][j]=='.');
			}else{
				int next=min({dp[i-1][j-1],dp[i-1][j],dp[i][j-1]});
				if(board[i][j]=='.')
					dp[i][j]=next+1;
				else
					dp[i][j]=0;
			}
		}
		int ans=0;
		rep(i,n)rep(j,n) ans=max(ans,dp[i][j]);
		cout << ans << endl;
	}
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;

#define int long long
#pragma GCC optimize ("O3")
#define ll long long
#define vec vector <int>
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define repD(i,a,b) for (ll i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define maa 1000000007
#define Eps 1e-9
#define PI 3.14159265359

typedef tree<pii,null_type,less <pii >,rb_tree_tag,tree_order_statistics_node_update>ind_set;
typedef gp_hash_table<int, int, hash<int> > ht1;   /// if clear is required
typedef cc_hash_table<int, int, hash<int> > ht2;

///*X.find_by_order("index")
///X.order_of_key("key")

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

int n,k;
int arr[100005];
int DP[100005];
void solve()
{
    cin>>n>>k;
    rep(i,0,n)cin>>arr[i];

    DP[1]=abs(arr[1]-arr[0]);DP[0]=0;
    rep(i,2,n)
    {
        DP[i]=maa;
        rep(j,0,k)
        {
            if (j>i-1)break;
            DP[i]=min(DP[i],abs(arr[i]-arr[i-j-1])+DP[i-j-1]);
        }
    }
    cout<<DP[n-1]<<"\n";

}
signed main()
{

    srand(time(NULL));

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

///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);

    int t=1;
///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case "<<a+1<<": ";
        solve();
    }
}


Measured memory_bytes: 1792
def solve(n, x):
    if x == 1:
        if n == 0:
            return 1
        else:
            return 0
    elif 1 < x < layer[n] // 2 + 1:
        return solve(n-1, x-1)
    elif x == layer[n] // 2 + 1:
        return patty[n-1] + 1
    elif layer[n] // 2 + 1 < x < layer[n]:
        return solve(n-1, x-layer[n-1]-2) + patty[n-1] + 1
    else:
        return patty[n]


N, X = map(int, input().split())

layer, patty = [1], [1]
for _ in range(N):
    layer.append(layer[-1] * 2 + 3)
    patty.append(patty[-1] * 2 + 1)

print(solve(N, X))

Measured memory_bytes: 61828
n = int(input())
s = [input() for _ in range(n)]
a = 0
b = 0
ab = 0
ans = 0
for i in range(n):
    ans += s[i].count('AB')
    if s[i][-1]=='A' and s[i][0]=='B':
        ab += 1
        continue
    if s[i][-1]=='A':
        a += 1
    if s[i][0]=='B':
        b += 1
if ab==0:
    ans += min(a,b)
elif a+b>0:
    ans += ab+min(a,b)
else:
    ans += ab-1
print(ans)

Measured memory_bytes: 44376
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <algorithm>


typedef std::vector<int> liste;

bool solve(int i,int m,liste& list) {
    if(m==0) {
        return true;
    }
    if(i>=list.size()||m<0) {
        return false;
    }
    bool res = (solve(i+1,m,list)||solve(i+1,m-list[i],list));
    return res;
} 
    
int main(void){
        
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int value;
    liste list;
    int n;
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        list.push_back(value);
    } 
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        std::cout << (solve(0,value,list) ? "yes" : "no") << std::endl;
    } 
    
    return 0;
}

Measured memory_bytes: 1216
MOD = 10**9+7
N, M = map(int, input().split())
S = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]

dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
    dp[i+1][0] = 1
for j in range(M):
    dp[0][j+1] = 1

for i, s in enumerate(S):
    for j, t in enumerate(T):
        if s == t:
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % MOD
        else:
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j] + MOD) % MOD
print(dp[-1][-1])


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

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

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

int main(){

    int64_t H, W;
    cin >> H >> W;

    int64_t ans = 1e12;
    for(int x = 1; x <= W - 1; x++){

        int64_t s1, s2, s3;

        s1 = x * H;
        s2 = (W - x) * (H / 2);
        s3 = H * W - s1 - s2;
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));

        s1 = x * H;
        s2 = (W - x) / 2 * H;
        s3 = H * W - s1 - s2;
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));
    }

    for(int y = 1; y <= H - 1; y++){

        int64_t s1, s2, s3;

        s1 = y * W;
        s2 = (H - y) * (W / 2);
        s3 = H * W - s1 - s2;
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));

        s1 = y * W;
        s2 = (H - y) / 2 * W;
        s3 = H * W - s1 - s2;
        ans = min(ans, max({s1, s2, s3}) - min({s1, s2, s3}));
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		System.out.println(n/3);
	}
}

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

int main() {
    cout.tie(0)->sync_with_stdio(0);
    using P = complex<double>;
    int N, D;
    cin >> N >> D;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        double X, Y;
        cin >> X >> Y;
        P Q = {X, Y};
        res += (abs(Q) <= D);
    }
    cout << res << '\n';
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,n) for(int i=s;i<n;i++)
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    vector<int> dp(n,999999999);
    dp[0]=0;
    reps(i,1,n){
        int tmp=999999999;
        reps(j,1,min(k+1,i+1)){
            tmp=min(tmp,dp[i-j]+abs(h[i]-h[i-j]));
        }
        dp[i]=tmp;
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<functional>

using namespace std;

int main() {
	int n[3];
	for (int i = 0; i < 3; i++) { cin >> n[i]; }
	sort(n, n + 3);
	if (n[0] == 5 && n[1] == 5 && n[2] == 7) {
		cout << "YES" << endl;
	}
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; typedef long long  ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
const ll M = ll(1e9 + 7);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{os << "("; os << v.first << ", " << v.second << ")"; return os;}
/***********************************************************************/
vector<vector<ll>> a;
ll n, w, x, y;
ll dp[105][100005];
ll solve(ll idx, ll wt)
{
    if (dp[idx][wt] != -1)
        return dp[idx][wt];

    if (idx >= n or wt <= 0)
        return dp[idx][wt] = 0;

    if (wt >= a[idx][0])
    {
        return dp[idx][wt] = max(a[idx][1] + solve(idx + 1, wt - a[idx][0]), solve(idx + 1, wt));
    }
    return dp[idx][wt] = solve(idx + 1, wt);
}
int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    for (ll i = 0; i < 105; i++)
        for (ll j = 0; j < 100005; j++)
            dp[i][j] = -1;

    cin >> n >> w;
    for (ll i = 1; i <= n; i++)
    {
        cin >> x >> y;
        a.push_back({x, y});
    }
    cout << solve(0, w);
}

Measured memory_bytes: 82304
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// floor(x): truncate

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    int n, a = 0, b = 0, ab = 0, cnt = 0;
    cin >> n;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s[0] == 'B' && s[s.length() - 1] == 'A')
        {
            ab++;
        }
        else if (s[0] == 'B')
        {
            b++;
        }
        else if (s[s.length() - 1] == 'A')
        {
            a++;
        }
        if (s.find("AB") != -1)
        {
            for (int j = 0; j < s.length() - 1; j++)
            {
                string x, y;
                x = s[j];
                y = s[j + 1];
                if (x + y == "AB")
                {
                    cnt++;
                }
            }
        }
    }
    //cout << "cnt:" << cnt << " a:" << a << " b:" << b << endl;
    if (ab >= 2)
    {
        cnt += ab - 1;
    }
    if (ab > 0 && a > 0)
    {
        a--;
        cnt++;
    }
    if (ab > 0 && b > 0)
    {
        b--;
        cnt++;
    }
    cnt += min(a, b);
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int a = std.nextInt();
        String s = std.next();
        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

typedef pair<ll,pll> ppll;

int main() {
  ll n,m,s;
  cin >> n >> m >> s;
  vector<map<ll,pll>> G(n);
  for(ll i=0;i<m;i++) {
    ll u,v,a,b;
    cin >> u >> v >> a >> b;
    u--,v--;
    G[u][v]={a,b};
    G[v][u]={a,b};
  }
  vec mai(n),mnu(n);
  for(ll i=0;i<n;i++) {
    cin >> mai[i] >> mnu[i];
  }
  mat d(n,vec(50*(n-1)+1,-1));
  vec ans(n,-1);
  vec mins(n,-1);
  priority_queue<ppll,vector<ppll>,greater<ppll>> q;
  s=min(s,50*(n-1));
  q.push({0,{0,s}});
  while(q.size()) {
    ll td=q.top().first;
    ll f=q.top().second.first;
    ll s=q.top().second.second;
    q.pop();
    ll flag=0;
    if(ans[f]<0) ans[f]=td;
    if(d[f][s]>-1) continue;
    d[f][s]=td;
    mins[f]=s;
    for(auto p:G[f]) {
      ll t=p.first;
      ll co=p.second.first;
      ll v=p.second.second;
      if(s-co>=0&&d[t][s-co]==-1) {
        q.push({td+v,{t,s-co}});
      }
    }
    ll ns=min(s+mai[f],50*(n-1));
    ll nd=td+mnu[f];
    if(d[f][ns]==-1) q.push({nd,{f,ns}});
  }
  for(ll i=1;i<n;i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 10332
w=str(input())
x=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
z=[]
for i in range(len(x)):
    if w.count(x[i])%2!=0:
        z.append(11)
    else:
        z.append(3)

if 11 in z:
    print("No")
else:
    print("Yes")


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

using namespace std;

vector<int> solve(int N, int M, const string& S)
{
    vector<int> ans;
    int x = 0;
    while (x < N) {
        int y = -1;
        for (int i = 1; i <= M && x + i <= N; ++i) {
            if (S[x + i] == '0') {
                y = x + i;
            }
        }
        if (y == -1) {
            return {};
        }
        ans.push_back(y - x);
        x = y;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

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

    reverse(S.begin(), S.end());
    auto ans = solve(N, M, S);
    if (ans.empty()) {
        cout << -1 << endl;
        return 0;
    }
    for (auto x : ans) {
        cout << x << " ";
    }
    cout << endl;
}


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

int main() {
  int n, T, c, t, mc = INT_MAX;
  cin >> n >> T;
  REP(i, n) {
    cin >> c >> t;
    if (t <= T) {
      mc = min(c, mc);
    }
  }
  if (mc == INT_MAX) {
    cout << "TLE" << endl;
  } else {
    cout << mc << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	char str;
	int n[3]={},ans=0,x;
	while(cin>>str){
		if(str=='J'&&n[1]==0&&n[2]==0)n[0]++;
		else if(str=='O'&&n[1]<n[0]&&n[2]==0)n[1]++;
		else if(str=='I'&&n[2]<(x=min(n[0],n[1]))){
			n[2]++;
			if(n[2]==x)ans=max(ans,x);
		}
		else{
			for(int i=0;i<3;i++)n[i]=0;
			if(str=='J')n[0]=1;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1140
from collections import deque
N,K = map(int,input().split())
P = list(map(int,input().split()))

upper = [1 for i in range(N)]
for i in range(1, N):
	x = N-i-1
	if P[x] < P[x+1]:
		upper[x] = upper[x+1] + 1

skip = [-1,-1]
flg = False
for i in range(N):
	if upper[N-i-1] >= K:
		skip.append(N-i-1)

skip.pop()
deq_min = deque([P[0]])
deq_max = deque([P[0]])
minlen = 1
maxlen = 1
for i in range(1, K):
	while minlen > 0 and deq_min[-1] > P[i]:
		deq_min.pop()
		minlen -= 1
	deq_min.append(P[i])
	minlen += 1
	while maxlen > 0 and deq_max[-1] < P[i]:
		deq_max.pop()
		maxlen -= 1
	deq_max.append(P[i])
	maxlen += 1

ans = 1
next_skip = skip.pop()
for i in range(1, N-K+1):
	new_i = i+K-1
	min_rem = (deq_min[0] == P[i-1])
	max_add = (deq_max[0] < P[new_i])
	if not (min_rem and max_add):
		if i != next_skip:
			ans += 1
	if i == next_skip:
		next_skip = skip.pop()
	if min_rem:
		deq_min.popleft()
		minlen -= 1
	if deq_max[0] == P[i-1]:
		deq_max.popleft()
		maxlen -= 1
	while minlen > 0 and deq_min[-1] > P[new_i]:
		deq_min.pop()
		minlen -= 1
	deq_min.append(P[new_i])
	minlen += 1
	while maxlen > 0 and deq_max[-1] < P[new_i]:
		deq_max.pop()
		maxlen -= 1
	deq_max.append(P[new_i])
	maxlen += 1
print(ans)

Measured memory_bytes: 27076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll n, d[int(1e7) + 10];

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

    cin >> n;

    ll ans = 1;

    for (ll i = 2; i <= n; ++i) {
	d[i] += 2;
	ans += i * d[i];

	for (ll j = i + i; j <= n; j += i)
	    ++d[j];
    }

    cout << ans << "\n";
}


Measured memory_bytes: 81756
a=gets.chomp
b=gets.chomp
c=gets.chomp
t=[a,b,c]
cur = 0
while 1
  if t[cur].size == 0
    puts [:A,:B,:C][cur]
    exit
  end
  ch = t[cur][0]
  t[cur] = t[cur].slice(1,t[cur].size)
  cur = ch.ord - 97
end


Measured memory_bytes: 1916
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
struct cmp 
{
    bool operator()(const pair<ll, ll>& l, const pair<ll, ll>& r) const {
        return (l.f * r.s - l.s * r.f > 0);
    }
};
int n;
vector<pair<ll, ll>> c;
ld dist(pair<ll, ll> xy)
{
    return sqrt(xy.f * xy.f + xy.s * xy.s);
}
pair<ll, ll> sum(int a, int b)
{
    pair<ll, ll> ans = {0, 0};
    if(b >= n) 
    {
        pair<ll, ll> p1 = sum(a, n - 1);
        pair<ll, ll> p2 = sum(0, b - n);
        ans.f = p1.f + p2.f;
        ans.s = p1.s + p2.s;
    }
    else
    {
        int l = 0, r = 0;
        if(a > 0) l = c[a - 1].f, r = c[a - 1].s;
        ans.f += c[b].f - l;
        ans.s += c[b].s - r;
    }
    return ans;
}
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    F0R(i, n)
    {
        ll x, y; cin >> x >> y;
        c.pb({x, y});
    }
    sort(c.begin(), c.end(), [](auto a, auto b) {
            return atan2(a.f,a.s) < atan2(b.f,b.s);
            });
    FOR(i, 1, n)
    {
        c[i].f += c[i - 1].f;
        c[i].s += c[i - 1].s;
    }
    ld best = 0;
    F0R(i, n)
    {
        F0R(j, n)
        {
            best = max(best, dist(sum(j, j + i)));
        }
    }
    cout << setprecision(25) << fixed << best;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
  int n,i;
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  for(i=1;i<s.size();i++)
    if(s[i]==s[i-1]){
      cout << "no" << endl;
      return 0;
    }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 3632
/*
                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {   if(n % 2 ==1)
        result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
return result % M;
}      
bool isPrime(int n) 
{ 
if (n <= 1) 
    return false; 
if (n <= 3) 
    return true; 
if (n % 2 == 0 || n % 3 == 0) 
    return false; 
for (int i = 5; i * i <= n; i = i + 6) 
    if (n % i == 0 || n % (i + 2) == 0) 
        return false; 
return true; 
} 
signed main()
{   jaldi
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c && a==c)
    cout<<"No";
    else if(a==b || b==c || a==c)
    cout<<"Yes";
    else  
    cout<<"No";
}   


Measured memory_bytes: 256
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)

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

int main()
{
    int x;
    cin >> x;
    
    int num[x];
    for(int i=0; i<x; i++){
        cin >> num[i];
    }
    for(int j=x-1; j>=0; j--){
        cout << num[j];
        if(j != 0)
            cout << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3084
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
b = [x for x in a if "#" in x]
#print(*b)
c = zip(*[y for y in zip(*b) if "#" in y])
#print(list(c))
for d in c:
  print("".join(d))

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>

typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin >> s;

  ll ans = 0;
  std::string::iterator it = s.begin();
  char now = *it;
  for (it = s.begin(); it != s.end(); it++) {
    if (now != *it) {
      ans++;
    }
    now = *it;
  }

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


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(S: str, T: str):
    res = 0
    for s,t in zip(S,T):
        if s == t:
            res += 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


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

using namespace std;

void FAST_IO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

#define REP(_i, _a) for(int _i = 0; _i < (int)_a; ++_i)
#define FOR(_i, _a, _b) for(int _i = (int)_a; _i <= (int)_b; ++_i)
#define FORD(_i, _a, _b) for(int _i = (int)_a; _i >= (int)_b; --_i)
#define RESET(_a, _value) fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define ALL(_a) _a.begin(), _a.end()
#define SIZE(_a) _a.size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define newline '\n';

// DEBUG UTIL
#define DEBUG(args...) { cerr << "> "; \
						 string _s = #args; \
						 replace(_s.begin(), _s.end(), ',', ' '); \
						 stringstream _ss(_s); istream_iterator<string> _it(_ss); \
						 err(_it, args); }

void err(istream_iterator<string> it) { cerr << endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << ": " << a << " ";
	err(++it, args...);
}

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

string format(const string& s, ...) {
    va_list args;
    va_start (args, s);
    size_t len = vsnprintf(NULL, 0, s.c_str(), args);
    va_end (args);
    std::vector<char> vec(len + 1);
    va_start (args, s);
    vsnprintf(&vec[0], len + 1, s.c_str(), args);
    va_end (args);
    return &vec[0];
}

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 2e9;

ll N, M;
vector<ll> x, y, z;


ll dp[1005][1005][8];
bool vis[1005][1005][8];

ll rec(int pos, int ambil, int bitmask) {
	// DEBUG(pos, ambil, bitmask);

	if (pos >= N && ambil != M) {
		return -1e18;
	}
	if (pos >= N && ambil == M) {
		return 0;
	}
	if (vis[pos][ambil][bitmask]) {
		return dp[pos][ambil][bitmask];
	}

	vis[pos][ambil][bitmask] = 1;
	ll& ret = dp[pos][ambil][bitmask];

	ll ans = 0LL;

	if (bitmask & 1) {
		ans += x[pos];
	} else {
		ans -= x[pos];
	}
	

	if (bitmask & 2) {
		ans += y[pos];
	} else {
		ans -= y[pos];
	}

	if (bitmask & 4) {
		ans += z[pos];
	} else {
		ans -= z[pos];
	}

	ret = max(ans + rec(pos+1, ambil+1, bitmask), rec(pos+1, ambil, bitmask));

	return ret; 
}

void read() {
	cin >> N >> M;
	x.resize(N);
	y.resize(N);
	z.resize(N);
	REP(i, N) {
		cin >> x[i] >> y[i] >> z[i];
	}
}

void solve() {
	ll maks = 0LL;
	for (int i = 0; i < 8; ++i) {
		maks = max(maks, rec(0, 0, i));
	}
	cout << maks << endl;
}

int main() {
	FAST_IO();

	int TC = 1;
	// cin >> TC;
	FOR(tc, 1, TC) {
		read();
		solve();
	}

	return 0;
}


Measured memory_bytes: 70400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    vector<int> v(10);
    for(int i = 0; i <10; i++) cin >> v[i];
    sort(v.begin(), v.end(), greater<int>());
    for(int i = 0; i < 3; i++) cout << v[i] <<"\n";
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[50][4][8100];
int x[41];
int t[41];
inline int ABS(int a){return max(a,-a);}
int main(){
	int a;
	while(scanf("%d",&a),a){
		int m=0;
		for(int i=0;i<a;i++){
			scanf("%d%d",x+i,t+i);
			m=max(m,t[i]);
		}
		for(int i=0;i<a+1;i++){
			for(int j=0;j<4;j++){
				for(int k=0;k<200*a+10;k++)
					dp[i][j][k]=99999999;
			}
		}
		dp[0][0][0]=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<4;j++){
				for(int k=0;k<200*a+10;k++){
					if(dp[i][j][k]>9999999)continue;
					int t1=(i?x[i-1]:0)*(j+1)+x[i];
					//printf("1: %d %d %d %d\n",i,j,k,dp[i][j][k]+t1);
					if(dp[i][j][k]+t1<=t[i]){
						dp[i+1][1][k+x[i-1]+x[i]]=min(dp[i+1][1][k+x[i-1]+x[i]],t[i]);
					}
					if(j<3){
						int t2=ABS((i?x[i-1]:0)-x[i])*(j+1);
					//	printf("2: %d %d %d %d\n",i,j,k,dp[i][j][k]+t2);
						if(dp[i][j][k]+t2<=t[i]){
							dp[i+1][j+1][k+ABS((i?x[i-1]:0)-x[i])]=min(dp[i+1][j+1][k+ABS((i?x[i-1]:0)-x[i])],t[i]);
						}
					}
				}
			}
		}
		for(int i=a;i>=0;i--){
			int ret=99999999;
			for(int j=0;j<4;j++){
				for(int k=0;k<200*a+10;k++){
					if(dp[i][j][k]<9999999)ret=min(ret,k+x[a-1]);
				}
			}
			if(ret<999999){
				if(i==a)printf("OK %d\n",ret);
				else printf("NG %d\n",i+1);
				break;
			}
		}
	}
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,x;
  cin >> n >> x;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  ll cnt=0;
  rep(i,n){
    if(i!=n-1){
      if(x>=a[i]){
        cnt++;
        x -=a[i];
      }
    }
    else{
      if(x==a[i]){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

int main(int argc, const char* argv[]) {
  u64 n;
  cin >> n;
  
  double ret = 0.0;
  
  rep(i, n) {
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY") {
      ret += x;
    } else {
      ret += x * 380000.0;
    }
  }
  
  cout << ret << endl;
  
  return 0;
}


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

int main() {
    string N;cin >> N;
    int S = N.size();int X = (int) (N[S - 1] - '0');
    if (X == 3) cout << "bon" << endl;
    else if (X == 0 || X == 1 ||X == 6 || X == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3620
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N; cin >> N;
	
	int B[N-1]; F0R(i, N-1) cin >> B[i];
	
	int A[N]; F0R(i, N-1) A[i] = B[i];
	A[N-1] = MX;
	
	F0R(i, N-1) A[i+1] = min(A[i+1], B[i]);
	
	int sum = 0;
	F0R(i, N) {
		sum += A[i];
	}
	
	cout << sum << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 256
puts readlines[0..-2].map(&:to_i).each_slice(5).map{|a|b=a.uniq.sort;b==[1,2]?a:b==[1,3]?a.map{|i|i==3?1:2}:b==[2,3]?a.map{|i|i==2?1:2}:[3]*5}

Measured memory_bytes: 6104
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  rep(i, 9) {
    rep(j, 9) {
      cout << (i + 1) << "x" << (j + 1)  << "=" << ((i + 1) * (j + 1)) << endl;
    }
  }
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int isprime(int a) //判断素数的函数

{
	if(a==1) return 0;
	if(a==2) return 1;
	for(int i=2;i<sqrt(a)+1;i++){
		if(a%i==0) return 0;
	}
	return 1;
}
int main(){
	int x;
	cin>>x;
	while(!isprime(x)){
		x++;
	}
	cout<<x<<endl;
}


Measured memory_bytes: 256