akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
using namespace std;


int dist[10][10];
int h,w,a,res;
int main() {
    cin >> h >> w;
    rep(i,0,10){
        rep(j,0,10){
            cin >> dist[i][j];
        }
    }
    rep(k, 0, 10) {
        rep(i, 0, 10) {
            rep(j, 0, 10) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    rep(i, 0, h) {
        rep(j, 0, w) {
            cin >> a;
            if (a >= 0) res += dist[a][1];
        }
    }
    cout << res << endl;
}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, K, i;
  cin >> N >> K;
  vi P(N), C(N);
  REP(0, N, i) {
    cin >> P[i];
    P[i]--;
  }
  REP(0, N, i) {
    cin >> C[i];
  }

  auto solve = [&](i64 start) {
    i64 cur = P[start];
    vi PC;
    PC.pb(C[cur]);
    while(cur != start) {
      cur = P[cur];
      PC.pb(PC.back() + C[cur]);
    }
    
    i64 M = sz(PC);
    i64 KK = K;
    i64 ans = 0;
    if(PC.back() > 0) {
      i64 X = K / M;
      if (K % M == 0) {
	X --;
      }
      ans = PC.back() * X;
      KK -= X * M;
    }
    else {
      KK = min(KK, M);
    }

    if(KK > 0) {
      ans += *max_element(PC.begin(), PC.begin()+KK);
    }
    return ans;
  };

  i64 ans;
  REP(0, N, i) {
    if(i == 0) {
      ans = solve(i);
    }
    else {
      ans = max(ans, solve(i));
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main(void){
  int N;
  double T, A;
  cin >> N >> T >> A;
  double H[N];
  for(int i = 0; i < N; i++) cin >> H[i];
  double t;
  double num = fabs(T - H[0] * 0.006 - A);
  int ans = 1;
  for(int i = 1; i < N; i++){
    t = T - H[i] * 0.006;
    t = fabs(t - A);
    if(t < num) {
      ans = i + 1;
      num = t;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {

  int n;
  cin >> n;
  
  vector<int> t(n);
  rep(i,n) cin >> t[i];
  
  sort(t.begin(), t.end());
  
  int sum = 0;
  rep(i,n-1) sum += t[i];
  
  if(t[n-1] < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);
  s.pop_back();

  while (sz(s)) {
    int n = sz(s) / 2;
    if (s.substr(0, n) == s.substr(n)) {
      cout << sz(s) << endl;
      return 0;
    }
    s.pop_back();
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(String.format("%d %d", a*b, (a*2)+(b*2)));
    }
}

Measured memory_bytes: 26088
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	long long int n, k;
	cin >> n >> k;
	cout << min(n % k, k - n % k) << endl;
}


Measured memory_bytes: 3684
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define endl "\n"



void solve(){
   ll n,k;
   cin>>n>>k;
   
   vector<ll>v;
   
   for(ll i=0;i<n;i++){
       ll temp;cin>>temp;
       v.push_back(temp);
   }
   
   ll i=0;
   ll j=k;
   while(j<v.size()){
       if(v[j]>v[i]){cout<<"Yes"<<endl;}
       else{cout<<"No"<<endl;}
       j++;i++;
   }
  
}


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

   solve();
}


Measured memory_bytes: 5328
#include <stdio.h> 
 
 int main(){ 
     char number[1001]; 
     int i, sum; 
     while(1){ 
         scanf("%s", number); 
         if(number[0]=='0')break; 
         sum=0; 
         for(i=0;number[i]!='\0';i++){ 
             sum+=number[i]-'0'; 
         } 
         printf("%d\n", sum); 
     } 
 
 
     return 0; 
 } 



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

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {

        FastReader scanner = new FastReader();
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        char[][] M = new char[H][W];
        for (int i = 0; i < H; i++) {
            String s = scanner.nextLine();
            for (int j = 0; j < W; j++) {
                M[i][j] = s.charAt(j);
            }
        }

        int[][] DP = new int[H][W];

        int i = 0;
        while (i < W) {
            if (M[0][i] == '.') {
                DP[0][i] = 1;
            } else {
                break;
            }
            i++;
        }

        i = 0;
        while (i < H) {
            if (M[i][0] == '.') {
                DP[i][0] = 1;
            } else {
                break;
            }
            i++;
        }

        int mod = 1000000007;
        for (int j = 1; j < H; j++) {
            for (int k = 1; k < W; k++) {
                if (M[j][k] == '.') {
                    if (DP[j - 1][k] == 0 && DP[j][k - 1] != 0) {
                        DP[j][k] = DP[j][k - 1] % mod;
                    } else if (DP[j - 1][k] != 0 && DP[j][k - 1] == 0) {
                        DP[j][k] = DP[j - 1][k] % mod;
                    }
                    DP[j][k] = (DP[j - 1][k] + DP[j][k - 1]) % mod;
                }
            }
        }
        System.out.println(DP[H - 1][W - 1]);
    }

}

Measured memory_bytes: 31876
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int N = 1e5 + 5;
const ll inf = 1e15;
ll dp[N];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	ll n,e,t;
	cin >> n >> e >> t;	
	vector<ll> pos(n+1);
	rep(i,0,n)cin >> pos[i];
	pos[n] = pos[n-1];
	ll best = inf;
	int jp = n - 1;
	for(int i = n - 1;i >= 0; --i){
		if(pos[n-1] - pos[i] <= t/2){
			dp[i] = t + pos[n-1] - pos[i];
		}
		else{
			if(i < n-1)best += 3 * (pos[i+1] - pos[i]);
			while(jp >= 0 && pos[jp] - pos[i] >= (t+1)/2){
				gmin(best, 3 * (pos[jp] - pos[i]) + pos[jp+1] - pos[jp] + dp[jp+1]);
				--jp;
			}
			dp[i] = best;
			gmin(dp[i], t + pos[jp+1] - pos[i] + dp[jp+1]);
		}
	}
	cout << dp[0] + pos[0] + e - pos[n-1] << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, a;
  cin >> n >> a;
  if(n%500 <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

char getGrade(int m, int f, int r){ //文字の中にイント型
    int sum = m+f;
    char grade;
    
    if(m==-1||f==-1){
        grade='F';
    } else if(80<=sum) {
        grade='A';
    } else if(65<=sum&&sum<80) {
        grade='B';
    } else if(50<=sum&&sum<65) {
        grade='C';
    } else if(30<=sum&&sum<50) {
        if(50<=r) grade='C';
        else grade='D';
    } else if(sum<30) {
        grade='F';
    }
    
    return grade;
}

int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1) break;
        
        cout<<getGrade(m,f,r)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3072
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int main ()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if (a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)
		printf("Possible\n");
		else printf("Impossible\n");


}

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

using namespace std;
#define ll long long

int main(){
    
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

        cout<< max( ((h2 * 60 + m2) - (h1*60 + m1) - k), 0);
    return 0;
}


Measured memory_bytes: 3592
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        long o = 0;
        int a[] = new int[s.length()];
        for(int i = 0; i < s.length(); i++){
            a[i] = Character.getNumericValue(s.charAt(i));
        }
        for(int i = 0; i < s.length(); i++){
            if (a[i] == 1) {
                o++;
            }else{
                break;
            }
        }
        if (o >= k) {
            System.out.println(1);
        }else{
            System.out.println(s.charAt((int)o));
        }
    }
}

Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] n = new int[100001];
    int ans = 0;
    Arrays.fill(n,0);
    
    for(int i = 0; i<N;i++){
    	int input = sc.nextInt();
    	n[input]++;
    }
    for(int i = 1; i<100000;i++){
    	int sum = n[i-1]+n[i]+n[i+1];
    	if(sum>ans){
    		ans = sum;
    	}
    }
    System.out.println(ans);
   
  }
}

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

int main(){
  int A, B;
  int counter = 0;
  cin >> A >> B;
  for(int i = A;i < B + 1;i++){
    int a = i / 10000;
    int b = i % 10;
    int c = i / 1000 % 10;
    int d = i / 10 % 10;
    if(a == b && c == d){
      counter += 1;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
   int n,i,max,min;
   int *p;

   scanf("%d",&n);

   p=(int*)malloc(sizeof(int)*n);

   for(i=0;i<n;i++)
   scanf("%d",p+i);

   max=min=*p;

   for(i=1;i<n;i++){
      if     (*(p+i)>max)   max=*(p+i);
      else if(*(p+i)<min)   min=*(p+i);
   }

   printf("%d\n",max-min);

   free(p);

   return 0;
}


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

ll A,B;

const ll INF=1e18;

int main(){
  cin>>A>>B;
  ll ans=INF;
  for(ll i=1;i<A;i++){
    ll x=B*i;
    ll r=A-x%A;
    r%=A;
    ll z=x+r;

    if(i+r>z/A) ans=min(ans,z);
  }

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

  return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<fstream>
#include<stdio.h>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define PI  3.141592
//----------------------------------------

ll d = pow(10,9)+7;


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




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

	int a;
	a = s.size();

	string x = "";

	rep(i, a) x += "x";

	cout << x << endl;

	
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
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(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

vector<int> z_algorithm(vector<int> &s){
    vector<int> v(s.size(), 0);
    int c = 0;
    For(i, 1, s.size()){
        if(i + v[i-c] < c + v[c]) v[i] = v[i-c];
        else{
            int j = max(0, c + v[c] - i);
            while(i + j < s.size() && s[j] == s[i+j]) ++j;
            v[i] = j;
            c = i;
        }
    }
    v[0] = s.size();
    return v;
}

int main(){
    int n;
    scanf("%d", &n);
    int a[n], b[n];
    rep(i, n) scanf("%d", &a[i]);
    rep(i, n) scanf("%d", &b[i]);

    vector<int> ad(n), bd(n), d(3*n);
    rep(i, n){
        ad[i]=a[i]^a[(i+1)%n];
        bd[i]=b[i]^b[(i+1)%n];
    }
    rep(i, n){
        d[i]=bd[i];
        d[i+n]=d[i+2*n]=ad[i];
    }
    vector<int> v=z_algorithm(d);
    For(i, n, n*2)if(v[i]>=n){
        printf("%d %d\n", i-n, a[i-n]^b[0]);
    }
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int a, b, k;
    cin >> k >> a >> b;
    bool ok = false;
    int v = (a % k);
    int fst;
    if(v == 0) fst = a;
    else fst = (a + (k - v));
    if(fst >= a && fst <= b) ok = true;
    if(ok) cout << "OK\n";
    else cout << "NG\n";
    return 0;
}



Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
ll P[55];
ll L[55];
ll dfs(ll x,ll n) {
	if (n == 0)return 1;
	if (x == 1)return 0;
	else if (x <= 1 + L[n - 1])return dfs(x - 1, n-1);
	else if (x == 2 + L[n - 1])return P[n - 1] + 1;
	else if (x <= 2 + 2 * L[n - 1])return 1 + P[n - 1] + dfs(x - 2 - L[n - 1],n-1);
	else return 2 * P[n - 1] + 1;
}
int main() {
	ll N, X;
	cin >> N >> X;
	P[0] = 1;
	L[0] = 1;
	for (int i = 0; i < N; ++i) {
		P[i + 1] = 2 * P[i] + 1;
		L[i + 1] = 2 * L[i] + 3;
	}
	cout << dfs(X, N) << endl;
	return 0;
}


Measured memory_bytes: 256
fn main() {
    let n: u64 = read();
    let r: u64 = read();

    if n >= 10 {
        println!("{}", r);
        return;
    }
    println!("{}", r + 1000 - 100 * n);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .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")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    if (n<2 || n&1){
        cout<<0<<endl;
        return 0;
    }
    ll k = 10;
    ll ans = 0;
    while(1){
        ll x = n/k;
        if (x==0)break;
        ans += x;
        k = k*5;
    }
    // k=50;
    // while(1){
    //     ll x = n/k;
    //     if (x==0)break;
    //     ans += x;
    //     k = k*50;
    // }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
def main():
    """
    Range:
        (x,y)
        X: x-K+1 〜 x+K-1
        Y: y-K+1 〜 y+K-1

    rangeをすべて試す: 無理
        1つの希望を満たすように範囲指定:
            模様は確定する
                (0,0)-(K,K) * 2(W or B)
                K^2 * N -> 10^3^2 * 10^5
            他の希望は満たされるか判定
    """
    N, K = map(int, input().split())
    xy = []
    for _ in range(N):
        x, y, c = input().split()
        a = K if c == "B" else 0
        xy.append((int(x), int(y) + a))

    AC(K, xy)
    # TLE(K, xy)


def fix(x, K2):
    return min(max(0, x), K2)


def boundary(x, y, K):
    K2 = K * 2
    s = set()
    for i in range(-2, 2):
        for j in range(-2, 2):
            if (i + j) % 2 == 1:
                continue

            x1 = fix(x + i * K, K2)
            y1 = fix(y + j * K, K2)
            x2 = fix(x + (i + 1) * K, K2)
            y2 = fix(y + (j + 1) * K, K2)

            if x1 == x2 or y1 == y2:
                continue

            s.add(((x1, y1), (x2, y2)))

    return s

def AC(K, xy):
    K2 = K * 2
    w = [
        [0] * (K2 + 1)
        for _ in range(K2 + 1)
    ]

    for x, y in xy:
        x = x % K2
        y = y % K2
        for (x1, y1), (x2, y2) in boundary(x, y, K):
            w[y1][x1] += 1
            w[y1][x2] -= 1
            w[y2][x1] -= 1
            w[y2][x2] += 1

    ans = max_cumsum(w)
    print(ans)


def max_cumsum(w):
    # error in atcoder pypy3
    #import numpy as np
    #return np.array(w).cumsum(axis=1).cumsum(axis=0).max()

    import copy
    w = copy.deepcopy(w)
    l = len(w)
    for i in range(1, l):
        for j in range(l):
            w[j][i] += w[j][i-1]

    for i in range(l):
        for j in range(1, l):
            w[j][i] += w[j-1][i]

    return max(map(max, w))


def TLE(K, xy):
    ans = 0
    for i in range(2 * K):
        for j in range(2 * K):
            tmp_ans = 0
            for x, y in xy:
                x = (x + i) % (2 * K)
                y = (y + j) % (2 * K)

                w1 = x < K and y < K
                w2 = x >= K and y >= K
                if w1 or w2:
                    tmp_ans += 1

            ans = max(ans, tmp_ans)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 121688
#include	<iostream>
#include	<deque>
#include	<algorithm>
#include	<unordered_set>

using namespace std;

int main()
{
	int		n;
	cin >> n;
	deque<int>			dq;

	for (int i = 0; i < n; ++i)
	{
		int		temp;
		cin >> temp;
		dq.push_back(temp);
	}

	sort(begin(dq), end(dq));
	auto unq = unique(begin(dq), end(dq));
	dq.erase(unq, end(dq));

	int		q;
	cin >> q;
	unordered_set<int>		us;

	for (int i = 0; i < n; ++i)
	{
		int	temp;
		cin >> temp;
		us.insert(temp);
	}

	int		Cnt = 0;

	for (auto it : dq)
	{
		if (us.find(it) != us.end())
		{
			++Cnt;
		}
	}

	cout << Cnt << endl;

	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}

int main()
{
	//fopen();
	fastio;
	ll n,m;
	cin>>n>>m;
	ll a[n];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	ll i=0,j=10000000010;
	//cout<<j;
	while(j-i>1)
	{
		ll mid=(j+i)/2;
		ll cunt=0;
		rep(i,n){ 
			ll t=lower_bound(a,a+n,mid-a[i])-a;
			cunt+=n-t;
			//cout<<t;
		}
		//cout<<endl;
		if(cunt>=m)i=mid;
		else j=mid;
	}
	ll r[n];
	//cout<<i<<endl;
	rep(j,n) r[j]=a[j]+(j?r[j-1]:0);
	//cout<<r[1]<<endl;
	ll ans=0;
	ll cnt=0;
	rep(j,n){
		ll k=lower_bound(a,a+n,i-a[j])-a;
		ans+=r[n-1]-(k?r[k-1]:0);
		ans+=a[j]*(n-k);
		cnt+=(n-k);
	}
	//cout<<ans<<endl;
	if(cnt>=m)ans-=(cnt-m)*i;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
from collections import Counter
S=list(input())
abc=['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']
for i in abc:
    if i not in S:
        print(i)
        exit()
print("None")


Measured memory_bytes: 4340
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

int readInt(){
  return readln.chomp.to!int;
}

int[] readInts(){
  return readln.chomp.split.to!(int[]);
}

void main(){
  string s = readln.chomp;
  int nf = s[0 .. 2].to!int;
  int nl = s[2 .. 4].to!int;

  bool YYMM = false, MMYY = false;

  if((nf == 0 || nf > 12) && (nl == 0 || nl > 12)) {
    writeln("NA");
    return;
  }
  if(1 <= nf && nf <= 12) MMYY = true;
  if(1 <= nl && nl <= 12) YYMM = true;
  if(YYMM && MMYY){
    writeln("AMBIGUOUS");
  } else if(YYMM){
    writeln("YYMM");
  } else if(MMYY){
    writeln("MMYY");
  }
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];


    int ok = 0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]) ok++;
        else ok = 0;

        if(ok==3) break;
    }
    if(ok==3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>ostream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    string s;
    cin>>s;
    int cnt[2]={};
    REPA(i,s){
        cnt[s[i]-'0']++;
    }
    cout<<min(cnt[0],cnt[1])*2<<endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace B_Iroha_Loves_Strings
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToArray();
            var n = inputs[0];
            var words = new string[n];
            for (int i = 0; i < words.Length; i++)
            {
                words[i] = Console.ReadLine();
            }

            for (int i = 0; i < words.Length - 1; i++)
            {
                for (int j = words.Length - 1; j > i; j--)
                {
                    if (string.Compare(words[j], words[j - 1]) < 0)
                    {
                        var temp = words[j];
                        words[j] = words[j - 1];
                        words[j - 1] = temp;
                    }
                }
            }

            Console.WriteLine(string.Join("",words));
        }
    }
}


Measured memory_bytes: 13532
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$N = $sc->nextInt();
$d = [];
for ($i = 0; $i < $N; $i++) {
    $d[] = $sc->nextInt();
}
rsort($d);
$d = array_unique($d);
echo count($d);

Measured memory_bytes: 4984
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n, m, a, b;
    cin >> n >> m;
    int h[n];
    for(int i = 0; i < n; i++) cin >> h[i];
    vector<int> adj[n];
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int r = 0;
    for(int i = 0; i < n; i++){
        bool g = 1;
        for(auto& x : adj[i]){
            if(h[x] >= h[i]){
                g = 0;
                break;
            }
        }
        r += g;
    }
    cout << r << '\n';
}


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

#pragma GCC optimize("O3")

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

int main() {
    vector<vector<int>> grid(3);
    int n;
    for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			int value;
			cin >> value;
			grid[i].emplace_back(value);
		}
	}
    cin >> n;
    vector<int> numbers(n);
    for(int i = 0; i < n; ++i) {
		cin >> numbers[i];
	}
	
	for(auto x: numbers) {
		for(int i = 0; i < 3; ++i) {
			for(int j = 0; j < 3; ++j) {
				if(grid[i][j] == x) grid[i][j] = -1;
			}
		}
	}
	
	bool bingo = 0;
    
    for(int i = 0; i < 3; ++i) {
		if(grid[i][0] == -1 && grid[i][1] == -1 &&  grid[i][2] == -1) 
			bingo = 1;
	}
	
	for(int i = 0; i < 3; ++i) {
		if(grid[0][i] == -1 && grid[1][i] == -1 && grid[2][i] == -1) 
			bingo = 1;
	}
	
	if(grid[0][0] == -1 && grid[1][1] == -1 && grid[2][2] == -1)
		bingo = 1;
		
	if(grid[0][2] == -1 && grid[1][1] == -1 && grid[2][0] == -1)
		bingo = 1;
	
	if(bingo) cout << "Yes";
	else cout << "No";
	
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long int a,b,c,d=0;
    cin>>a>>b>>c;
    int A[a][b];
    int B[b][c];
    long int C[a][c];
        for(int i=0;i<a;i++){
        for(int o=0;o<c;o++){
         C[i][o]=0;   
        }
        }
    for(int i=0;i<a;i++){
        for(int o=0;o<b;o++){
            cin>>A[i][o];
        }
    }
        for(int i=0;i<b;i++){
        for(int o=0;o<c;o++){
            cin>>B[i][o];
        }
    }
    for ( int i = 0;i<a;i++){
    for ( int j = 0;j<c;j++){
        for ( int k = 0;k<b;k++){
            C[i][j] +=A[i][k]*B[k][j]; 
        }
    }
}
    for(int i=0;i<a;i++){
        for(int o=0;o<c;o++){
            if(o==c-1){
                cout<<C[i][o];
                break;
            }
            cout<<C[i][o]<<" ";
        }
        cout<<endl;
    }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n),b(n);
	REP(i,0,n)cin>>a[i];
	REP(i,0,n)cin>>b[i];

	sort(b.begin(),b.end());

	lli res=0;
	/*aiに対してai+biのk桁目のビットが立つ数を数え上げる*/
	for(lli digit = 29;digit>=0;digit--){
		lli bekihigh = 1<<(digit+1),bekilow = 1<<digit;
		REP(i,0,n){
			a[i] %= bekihigh;
			b[i] %= bekihigh;
		}
		sort(b.begin(),b.end());
		lli num = 0;
		REP(i,0,n){
			lli add = 0;
			if(bekilow - a[i]>=0){
				add += lower_bound(b.begin(),b.end(),bekihigh-a[i])-
						lower_bound(b.begin(),b.end(),bekilow-a[i]);
			}
			else{
				add += lower_bound(b.begin(),b.end(),bekihigh-a[i])-b.begin();
				add += lower_bound(b.begin(),b.end(),bekihigh)
						-lower_bound(b.begin(),b.end(),bekihigh+bekilow-a[i]);
			}
			num+=add;
		}
		if(num&1)res+=bekilow;
	}
	cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int adj[][] = new int[N][N];
		for(int i = 0 ; i < N ; ++i){
			String S = sc.next();
			for(int j = 0 ; j < N ; ++j){
				adj[i][j] = S.charAt(j) - '0';
			}
		}
		int color[] = new int[N];
		Arrays.fill(color, -1);
		Queue<Integer> q = new LinkedList<Integer>();
		// 与えられたグラフを2色に塗る
		q.add(0);
		color[0] = 0;
		boolean f = true;
		l: while(!q.isEmpty()){
			int cur = q.poll();
			int c = color[cur];
			for(int i = 0 ; i < N ; ++i){
				if(adj[cur][i] == 0){
					continue;
				}
				if(color[i] == -1){
					color[i] = 1 - c;
					q.add(i);
				}else if(color[i] == c){
					f = false;
					break l;
				}
			}
		}
		if(!f){
			System.out.println(-1);
			return ;
		}
		int dist[][] = new int[N][N];
		for(int i = 0 ; i < N ; ++i){
			for(int j = 0 ; j < N ; ++j){
				if(adj[i][j] == 1){
					dist[i][j] = 1;
				}else{
					dist[i][j] = -1;
				}
				if(i == j){
					dist[i][j] = 0;
				}
			}
		}
		for(int k = 0 ; k < N ; ++k){
			for(int i = 0 ; i < N ; ++i){
				for(int j = 0 ; j < N ; ++j){
					if(dist[i][k] > 0 && dist[k][j] > 0){
						int d = dist[i][k] + dist[k][j];
						if(dist[i][j] < 0){
							dist[i][j] = d;
						}else{
							dist[i][j] = Math.min(dist[i][j], d);
						}
					}
				}
			}
		}
		int m = 0;
		for(int i = 0 ; i < N ; ++i){
			for(int j = 0 ; j < N ; ++j){
				m = Math.max(dist[i][j], m);
			}
		}
//		System.out.println(Arrays.deepToString(dist));
		System.out.println(m + 1);
	}
}


Measured memory_bytes: 25508
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int INF = (int)10e9;

int main(){
  int n, m;
  while(scanf("%d%d", &n, &m) && (n|m)){
    vector<int> C(m);
    for(int i=0; i<m; i++) scanf("%d", &C[i]);
    
    vector<int> dp(256, INF);
    vector<int> next(256);
    dp[128] = 0;
    while(n--) {
      fill(next.begin(), next.end(), INF);
      int in; scanf("%d", &in);
      for(int i=0; i<256; i++){
	if(dp[i] == INF) continue;
	for(int j=0; j<m; j++){
	  int conv = i + C[j];
	  conv = min(max(conv, 0), 255);
	  int diff = (in - conv) * (in - conv);
	  next[conv] = min(next[conv], dp[i] + diff);
	}
      }
      dp = next;
    }
    
    printf("%d\n", *min_element(dp.begin(), dp.end()));
  }
  return 0;
}

Measured memory_bytes: 1048
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
//#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const int big=1e9+10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
int main(void){
	int i,j,n,m,q,w,ans=0;cin>>n>>m;
	vector<bool>a(n+1);
	vector<bool>b(n+1);
	for(i=0;i<m;i++){
		cin>>q>>w;
		if(q>w){swap(q,w);}
		if(q==1){b[w]=true;}
		if(w==n){a[q]=true;}
	}
	for(i=2;i<n;i++){
		if(a[i]&&b[i]){cout<<"POSSIBLE"<<endl;return 0;}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n, ans = 0;
	cin >> n;
	int a[114514], b[114514];
	rep(i, n + 1) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		if (a[i] >= b[i]) {
			ans += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
		else {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
			if (b[i] <= a[i + 1]) {
				ans += b[i];
				a[i + 1] -= b[i];
				b[i] = 0;
			}
			else {
				ans += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(s=="keyence") cout <<"YES" <<endl;
    else{
        rep(i,n){
            for(int j = 1;j<=n;++j){
                string t = s.substr(i,j);
                string x = s.substr(0,i);
                if(i+j>=n)continue;
                if(n-i-j<0)continue;
                string y = s.substr(i+j,n-i-j);
                if(x+y=="keyence"){
                    cout <<"YES" <<endl;
                    return 0;
                }
            }
        }
        cout << "NO" <<endl;
    }

}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e3+1;
const LL Inf=1e17;
int N,M;
LL X[MAX_N][3];

/*
LL dp[MAX_N][MAX_N][3][8];
LL score(LL x, LL y, LL z) {
  if(x==Inf) return -Inf;
  return abs(x)+abs(y)+abs(z);
}

LL f(int mask) {
  REPE(i,N)REPE(j,N) REP(k,3) {
    LL a=(mask>>k)&1?-Inf:Inf;
    dp[i][j][k][mask]=a;
  }
  REP(k,3)dp[0][0][k][mask]=0;
  REPE(i,N)REPE(j,M) {
    int X[3];
    REP(k,3) X[k]=dp[i][j][k][mask];
    if(abs(X[0])==Inf) continue;
    REP(k,3) X[k]+=X[i][k]
    if(i+1<=N&&j+1<=M) {
      
      tie(xx,yy,zz)=dp[i+1][j+1];
      if(score(xx,yy,zz)<score(x2,y2,z2)) {
        dp[i+1][j+1]={x2,y2,z2};
      }
    }
    if(i+1<=N) {
      LL xx,yy,zz; tie(xx,yy,zz)=dp[i+1][j];
      if(score(xx,yy,zz)<score(x,y,z)) {
        dp[i+1][j]={x,y,z};
      }
    }
  }
  
  LL x,y,z; tie(x,y,z)=dp[N][M];
  cout<<score(x,y,z)<<endl;
}
void solve() {
  LL res=0;
  REP(mask,8) {
    SMAX(res,f(mask));
  }
  cout<<res<<endl;
}*/

void solve() {
  LL res=0;
  REP(mask,8) {
    vector<LL> A(N);
    REP(i,N) {
      LL a=0;
      REP(k,3) {
        LL x=X[i][k];
        if(mask&(1<<k)) x=-x;
        a+=x;
      }
      A[i]=a;
    }
    sort(A.rbegin(),A.rend());
    SMAX(res,accumulate(A.begin(),A.begin()+M,0LL));
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>M;
  REP(i,N) cin>>X[i][0]>>X[i][1]>>X[i][2];
  solve();
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] v = new int[5000];
	    for(int i = 0;i < 5000;i++){
	    	v[i] = 1;
	    }
	    int p = 3;
	    while(true){
	        if(p*p > 10000){
	            break;
	        }else{
	            if(v[(p-1)/2] == 0){
	                p += 2;
	            }else{
	                int t = p*p;
	                while(t < 10000){
	                    v[(t-1)/2] = 0;
	                    t += 2*p;
	                }
	                p += 2;
	            }
	        }
	    }
	    v[0] = 0;
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 1 || n == 2){
				System.out.println(0);
				continue;
			}else if(n == 3){
				System.out.println(1);
				continue;
			}else if(n == 4){
				System.out.println(2);
				continue;
			}
			int m = n+1;
			int count = 0;
			if((m-2)%2 != 0){
				if(v[(m-3)/2] == 1){
					count+=2;
				}
			}
			for(int i = 3;i <= (n+1)/2;i+=2){
				if((m-i)%2 == 0 || v[(i-1)/2] != 1){
					continue;
				}
				if(v[(m-i-1)/2] == 1){
					count += (i == m-i)?1:2;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 24100
class UnionFind:
    def __init__(self, node):
        self.parent = [-1 for _ in range(node)]

    def find(self, target):
        if self.parent[target] < 0:
            return target
        else:
            self.parent[target] = self.find(self.parent[target])
            return self.parent[target]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return
        if self.parent[root_x] > self.parent[root_y]:
            root_x, root_y = root_y, root_x
        self.parent[root_x] += self.parent[root_y]
        self.parent[root_y] = root_x

    def get_size(self, x):
        return -self.parent[self.find(x)]


def main():
    n, m = map(int, input().split())
    bridge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
    answer = [n * (n - 1) // 2 for _ in range(m)]
    uf = UnionFind(n)
    is_same_before = False
    size_a = 0
    size_b = 0
    for i in range(-1, -m - 1, -1):
        a, b = bridge[i]
        if i < -1:
            answer[i] = answer[i + 1]
            if not is_same_before:
                answer[i] -= size_a * size_b
        is_same_before = uf.is_same(a, b)
        if not is_same_before:
            size_a = uf.get_size(a)
            size_b = uf.get_size(b)
        uf.union(a, b)
    for a in answer:
        print(a)


if __name__ == '__main__':
    main()



Measured memory_bytes: 33568
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::pair<std::pair<int, int>, bool>> point(2*n);
    for (int i = 0; i < 2*n; i++) {
        std::cin >> point[i].first.first >> point[i].first.second;
        point[i].second = i < n;
    }
    std::sort(point.begin(), point.end());
    std::multiset<int> s;
    int ans = 0;
    for (auto p : point) {
        int y = p.first.second;
        if (p.second) s.insert(y);
        else {
            auto iter = s.upper_bound(y);
            if (iter == s.begin()) continue;
            ans++;
            iter--;
            s.erase(iter);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

signed main(){
    
    int n;
    cin >> n;


    int ans = 0;

    if(n >= 3*5*7)ans++;
    if(n >= 3*5*11)ans++;
    if(n >= 3*5*13)ans++;
    if(n >= 27*7)ans++;
    if(n >= 27*5)ans++;
    

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


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> W(N+1);
  W.at(0)=0;
  for(int i=0;i<N;i++){
    W.at(i+1)=W.at(i);
    if(S.at(i)=='W'){
      W.at(i+1)++;
    }
  }
  int min_ans=1000000000;
  for(int i=1;i<N+1;i++){
    int ans=W.at(i-1)+W.at(i)-W.at(N)+N-i;
    min_ans=min(min_ans,ans);
  }
  cout << min_ans << endl;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(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; }
typedef long long ll;
using namespace std;
int main(void){
    int a,b,c;cin>>a>>b>>c;
    rep1(i,b){
        int na=a*i;
        if(na%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int count=0;
		for(int i=1;i<=n;i++) {
			a[sc.nextInt()-1]=i;
		}
		for(int i=0;i<n;i++) {
			System.out.print(a[i]+" ");
		}
	}
}



Measured memory_bytes: 62872