akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  REP(i,100){
    int c = n - i*4;
    if(c>=0 && c%7==0){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;


int main() {
    long double l;
    
    cin>>l;
    
    cout<<setprecision(12)<<(l/3)*(l/3)*(l/3)<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N,M,i,a,b;
  int A[50]={0};
  scanf("%d %d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d %d",&a,&b);
    A[a-1]++;
    A[b-1]++;
  }
  for(i=0;i<N;i++){
    printf("%d\n",A[i]);
  }
  return 0;
}

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

int main()
{
    string S;
    cin >> S;
    if(S.length() % 2){ printf("No\n"); return 0; }
    string X = "";
    for(int i=1; i<=(S.length() / 2); ++i) X += "hi";
    if(X == S){ printf("Yes\n"); }
    else printf("No\n");
}

Measured memory_bytes: 256
loop do
  m , f , r = gets.split.map{|v|
    v.to_i
  }
  if m == -1 && f == -1 && r == -1
    break
  end
  if m == -1 || f == -1
    print "F", "\n"
  elsif m + f >= 80
    print "A", "\n"
  elsif m + f >= 65 && m + f < 80
    print "B", "\n"
  elsif m + f >= 50 && m + f < 65
    print "C", "\n"
  elsif m + f >= 30 && m + f < 50 && r >= 50
    print "C", "\n"
  elsif m + f >= 30 && m + f < 50
    print "D", "\n"
  elsif m + f < 30
    print "F", "\n"
  end
end


Measured memory_bytes: 6868
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define debug(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define OUT2(n1,n2) cout << n1 << " " << n2 << endl
#define OUT3(n1,n2,n3) cout << n1 << " " << n2 << " " << n3 << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(n);
  vector<deque<ll> > a(n, deque<ll>(n-1));
  FOR(i,0,n) {
    VIN(a[i]);
  }

  unordered_set<ll> yesterday;
  FOR(i,0,n) yesterday.insert(i);
  while (true) {
    bool updated = false;
    unordered_set<ll> done;
    for(auto itr = yesterday.begin(); itr != yesterday.end(); ++itr) {
    //FOR(i,0,n) {
      ll i = *itr;
      if (a[i].empty()) continue;
      if (done.find(i) != done.end()) continue;
      ll aite = a[i].front() - 1;
      if (done.find(aite) != done.end()) continue;

      if (a[aite].front() == i + 1) {
        a[i].pop_front();
        a[aite].pop_front();
        done.insert(i);
        done.insert(aite);
        updated = true;
      }
    }

    //VOUT2(a);
    yesterday = done;
    ans++;
    if (!updated) break;
  }
  bool flg = true;
  FOR(i,0,n) {
    if (!a[i].empty()) {
      flg = false;
      break;
    }
  }
  if (flg) OUT(ans-1);
  else OUT(-1);

}


Measured memory_bytes: 8832
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
struct UF{
    vector<int> par;
    UF(int N){
        par.resize(N);
        REP(i, N) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx==ry) return;
        par[ry] = rx;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int N, M;
    cin>>N>>M;
    UF uf(N);
    vector<int> A(N);
    REP(i, N) {
        cin>>A[i];
        A[i]--;
    } 
    vector<P> B(M);
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        B[i] = P(--x, --y);
        uf.unite(x, y);
    }
    int res = 0;
    REP(i, N){
        if(uf.same(i, A[i])) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

const ll MOD = 998244353;
const ll mod2 = 998244353;
 
ll fac[201100], finv[201100], inv[201100];
 
void init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<201100;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll power(ll a,ll b){return b?power(a*a%mod2,b/2)*(b%2?a:1)%mod2:1;}

ll C(ll n,ll k)
{
  ll x=1,y=1;
  for(int i=1;i<=k;i++)
  {
    x=x*(n-i+1)%mod2;
    y=y*i%mod2;
  }
  return x * power(y,mod2-2) % mod2;
}

int main(){FIN

    ll n,m,k;cin>>n>>m>>k;
    ll ans =0;
    init();
    REP(i,k+1){
        ans+=(((m*fac[n-1])%MOD*finv[i])%MOD*finv[n-1-i])%MOD*power(m-1,n-1-i);
        ans %= MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8388
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#define INF 10000
using namespace std;
struct edge{int from,to,cost;};
edge es[1000];
int d[10];
void shortestpath(int s){
  for(int i=0;i<10;i++) d[i]=INF;
  d[s]=0;
  while(1){
    bool update=false;
    for(int i=0;i<100;i++){
      edge e=es[i];
      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }
    if(!update) break;
  }
}
int main(){
  int H,W,A;
  int ans=0,k;
  scanf("%d %d",&H,&W);
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      scanf(" %d",&k);
      if(k==0) continue;
      es[10*i+j].cost=k;
      es[10*i+j].from=i;
      es[10*i+j].to=j;
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      scanf(" %d",&A);
      if(A==-1||A==1) continue;
      shortestpath(A);
      ans+=d[1];
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, D;
    cin >> H >> W >> D;

    map<int, pair<int, int>> A;
    FOR(y, 0, H) {
        FOR(x, 0, W) {
            int a;
            cin >> a;
            A[a] = make_pair(y, x);
        }
    }

    vector<int> cost(H * W + 1, -1);
    FOR(i, 1, D + 1) {
        auto now = A[i];
        cost[i] = 0;
        for (int j = i + D; j <= H * W; j += D) {
            auto p = A[j];
            cost[j] = cost[j - D] + abs(now.first - p.first) + abs(now.second - p.second);
            now = p;
        }
    }

    int Q;
    cin >> Q;
    FOR(_, 0, Q) {
        int L, R;
        cin >> L >> R;
        print(cost[R] - cost[L]);
    }

    return 0;
}

Measured memory_bytes: 8704
n = int(input())
a = input()
b = input()
c = input()
result = []
for i in range(n):
    tmp = []
    tmp.append(a[i])
    tmp.append(b[i])
    tmp.append(c[i])
    tmp = list(set(tmp))
    result.append(len(tmp))
print(sum(result)-n)

Measured memory_bytes: 3064
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))


sa = rls()[::-1]
sb = rls()[::-1]
sc = rls()[::-1]
card = sa.pop()
while(1):
    try:
        if(card == "a"):
            card = sa.pop()
        elif(card == "b"):
            card = sb.pop()
        else:
            card = sc.pop()
    except IndexError:
        break
print(card.upper())

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

int main(){
  int N , K;
  cin >> N >> K;
  
  int S = 1;
  for(int i=0; i<N; i++){
    if(S*2 <= S+K){
      S = S*2;
    }
    else{
      S += K;
    }
  }
  cout << S <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
static const int max_value = numeric_limits<int>::min();
static const int min_value = numeric_limits<int>::max();
static const int arr_len = 200000;

int main(){
    int R[arr_len], n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> R[i];
    }
    int maxv = max_value, minv = min_value;
    for(int i = 0; i < n; i++){
        maxv = max(maxv, R[i]-minv);
        minv = min(minv, R[i]);
    }
    cout << maxv << '\n';
    return 0;

}

Measured memory_bytes: 1940
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
void read(long long &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=110;
long long a,b,x,y,l,r,ans,ll,rr;
int aa[maxn],bb[maxn],lena,lenb,len,k;
int main(){
	read(a),read(b);x=a,y=b;
    while(a)aa[++lena]=a&1,a>>=1;
	while(b)bb[++lenb]=b&1,b>>=1;
	for(rg int i=max(lena,lenb);i;i--){
		if(aa[i]!=bb[i]){len=i;break;}
		x-=1ll*aa[i]<<(i-1);
		y-=1ll*bb[i]<<(i-1);
	}
	for(rg int i=len-1;i;i--)if(bb[i]){k=i;break;}
    l=x,r=(1ll<<(len-1))+(1ll<<k)-1;
	ll=(1ll<<(len-1))+x,rr=(1ll<<len)-1;
	if(ll>r)ans=r-l+1+rr-ll+1;
	else ans=rr-l+1;
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

A.append(A[0] + K)

ma = 0

for i in range(N):
    if ma < A[i+1] - A[i]:
        ma = A[i+1] - A[i]

print(int(K-ma))

Measured memory_bytes: 26420
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n,ans;
    cin >> n;
    vector <int> b(n);
    for(int i=0;i<n-1;i++)
    {
        cin >> b[i];
    }
    ans=b[0];
    for(int i=0;i<n;i++)
    {
        ans+=min(b[i],b[i+1]);
    }
    cout << ans+b[n-2] << '\n';
}

Measured memory_bytes: 256
def main() :
	S = input()
	K = int(input())

	is_1 = True
	for i in range(K) :
		if (len(S) < i) :
			break

		# print("S[i] : " + S[i])
		if (S[i] != "1") :
			is_1 = False
			break

	if (is_1) :
		print("1")
		return

	for i in range(len(S)) :
		if (S[i] == "1") :
			continue

		print(S[i])
		break


main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void)
{
	int map[21][21];
	int N, M;
	int x, y;
	char d[10];
	int l;
	int dx, dy;
	int i, j;
	int count;
	
	while (1){
		scanf("%d", &N);
		if (N == 0){
			break;
		}
		
		memset(map, 0, sizeof(map));
		for (i = 0; i < N; i++){
			scanf("%d%d", &x, &y);
			map[y][x] = 1;
		}
		
		x = y = 10;
		count = map[y][x];

		scanf("%d", &M);
		for (i = 0; i < M; i++){
			scanf("%s", d);
			scanf("%d", &l);
			
			switch (d[0]){
			  case 'N':
			    dx = 0;
				dy = 1;
				break;

			  case 'S':
			    dx = 0;
				dy = -1;
				break;

			  case 'E':
			    dx = 1;
				dy = 0;
				break;

			  case 'W':
			    dx = -1;
				dy = 0;
				break;
			}
			
			for (j = 0; j < l; j++){
				x += dx;
				y += dy;
				count += map[y][x];

//if (map[y][x] != 0){
//	printf("[%d %d]", x, y);
//}

				map[y][x] = 0;
			}
		}
		if (count == N){
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	
	return (0);
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> R(100005);
  rep(i, 0, M) {
    int l, r;
    cin >> l >> r;
    l--;
    R[l]++,R[r]--;
  }
  rep(i, 0, R.size() - 1) R[i+1] += R[i];
  int ans = 0;
  rep(i, 0, R.size()) if(R[i] == M) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from collections import Counter
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    return N,


@njit
def f(n):
    """
    約数の個数を求める
    """
    ndivs = np.ones((n+1), dtype=np.int32)
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            ndivs[j] += 1
    return ndivs


@njit
def solve(N):
    fn = f(N)
    ans = 0
    for k in range(1, N+1):
        ans += k * fn[k]
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main(){
  ll N, H;
  cin >> N >> H;
  vector<int> a(N);
  vector<int> b(N);
  for (ll i=0; i<N; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll nagerukatana;
  for (ll i=0; i<N; i++) {
    if (b.at(i) >= a.at(N-1)) {
      nagerukatana = i;
      break;
    }
  }
  ll nagedamage = 0;
  for (ll i=nagerukatana; i<N; i++) nagedamage += b.at(i);
  ll count = 0;
  while (H > 0) {
    if (H <= nagedamage) {
      for (ll i=N-1; i>=nagerukatana; i--) {
        H -= b.at(i);
        count++;
        if (H <= 0) break;
      }
    }
    else {
      H -= a.at(N-1);
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

struct edge {
    int to, cost;
};

vector <edge> edges[100005];
int c[100005];

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

    for (int i = 1; i <= K; i++) {
        edges[i].push_back((edge){(i + 1) % K, 1});
        edges[i].push_back((edge){i * 10 % K, 0});
    }

    deque <int> q;
    fill(c, c+K, 1e9);

    q.push_back(1);
    c[1] = 1;

    while (q.size()) {
        int cur = q.front();
        q.pop_front();

        for (edge e : edges[cur]) {
            if (c[cur] + e.cost >= c[e.to]) continue;
            c[e.to] = c[cur] + e.cost;
            if (e.cost == 0) {
                q.push_front(e.to);
            } else {
                q.push_back(e.to);
            }
        }
    }

    cout << c[0] << "\n";
    return 0;
}

Measured memory_bytes: 6272
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_line(&mut buf);
    let ns = buf
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect::<Vec<isize>>();
    let (a, b) = (ns[0], ns[1]);
    if a < b {
        println!("{}", b * 2 - 1);
    } else if b < a {
        println!("{}", a * 2 - 1);
    } else {
        println!("{}", a * 2);
    }
}


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

int main()
{
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S.at(i) != T.at(i))
        {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3920
// {{{
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<string>
// }}}
/* {{{
#include<cstring>
#include<ctime>
#include<ncurses.h>
#include<tuple>
}}}  */
using namespace std;

inline int toInt(std::string s) {int v; std::istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {std::ostringstream sout;sout<<x;return sout.str();}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << (a + b >= 10? "error": toString<int>(a + b)) << endl;
  return 0;
}


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

int main(void){
	int gameCount, taroScore, hanakoScore;
	int len;
	string taro, hanako;

	gameCount = taroScore = hanakoScore = 0;

	cin >> gameCount;

	for (int i = 0; i < gameCount; i++){
		cin >> taro >> hanako;
		
		if (taro.length() > hanako.length()) len = hanako.length();
		else  len = taro.length();

		for (int j = 0; j < len; j++){
			if (taro[j] == hanako[j]){
				if (j == len - 1){
					if (taro.length() < hanako.length()){
						hanakoScore += 3;
						break;
					}
					else if (taro.length() > hanako.length()){
						taroScore += 3;
						break;
					}
					else{
						taroScore += 1;
						hanakoScore += 1;
						break;
					}
				}
				continue;
			}
			if (taro[j] - hanako[j] < 0){
				hanakoScore += 3;
				break;
			}
			else if (taro[j] - hanako[j] > 0){
				taroScore += 3;
				break;
			}
		}
	}

	cout << taroScore << " " << hanakoScore << "\n";

	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define N first
#define D second
using namespace std;

typedef long long ll;

const int MAXN = 1e5;


int n, zer;
vector<int> pos, neg;
vector<pair<int, int>> moves;
int ans;

void move(int x, int y) {
	moves.push_back({x, y});
	ans = x - y;
}

int main() {
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(!x) 
			zer++;
		else if(x > 0) 
			pos.push_back(x);
		else 
			neg.push_back(x);
	}

	while(zer > 1) {
		moves.push_back({0, 0});
		zer--;
	}

	if(pos.size()) {

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

		if(neg.size() || zer) {
			if(zer) neg.push_back(0);
			ans = neg[0];
			for(int i = 1; i < pos.size(); i++) {
				move(ans, pos[i]);
			}
			move(pos[0], ans);
			for(int i = 1; i < neg.size(); i++) {
				move(ans, neg[i]);
			}
		} else {
			move(pos[0], pos[n-1]);
			for(int i = 2; i < n-1; i++) {
				move(ans, pos[i]);
			}
			if(n > 2) move(pos[1], ans);
		}
	} else {
		if(zer) {
			for(int x : neg) {
				move(ans, x);
			}
		} else {
			sort(neg.begin(), neg.end(), [](int x, int y) { return x > y;});
			ans = neg[0];
			for(int i = 1; i < n; i++) move(ans, neg[i]);
		}
	}

	cout << ans << '\n';
	for(auto p : moves) cout << p.first << ' ' << p.second << '\n';

	return 0;
}

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  string S; cin >> S;
  
  bool flag = true;
  int cnt = 0;

  for (int i = 1; i < S.length(); i++){
    if (flag == true && S[i] == S[i - 1]){
      cnt++;
      flag = false;
      i++;
    }else if(flag == false){
      flag = true;
    }
  }

  cout << S.length() - cnt << endl;
  
  return 0;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a<b&&b<c){
        cout << "Yes" << endl;
    }
    else{
        cout <<"No" << endl;
    }
    return 0;
}


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


int main() {
    int N; cin >> N;
    vector<int> tastes(N); for (int i = 0; i < N; i++) cin >> tastes[i];
    int ans = 0;
    for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) {
        ans =  ans + tastes[i] * tastes[j];
    }

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


Measured memory_bytes: 256
/**
*   @Author : MeGA
*   @InitTime :02/08/20 17:22:31
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0); 
     int n,k;
     cin>>n>>k;
     double ans=0;
     for(int i=1;i<=n;i++){
        if(i<k){
             int score=i;
             int cnt=0;
             while(score<k ){
               score*=2;
               cnt++;
             }
             ans+=((1.0/n)*pow(0.5,cnt));
        }else{
         ans+=((1.0/n));
        }
     }
     cout<<fixed<<setprecision(12)<< ans<<endl;
     

}

Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    A = []
    for i in range(N):
        a, b = NMI()
        A.append([a, b])
    A.sort(key=lambda x: x[1])
    t = 0
    for a in A:
        t += a[0]
        if t > a[1]:
            print("No")
            exit()

    print("Yes")



if __name__ == "__main__":
    main()

Measured memory_bytes: 38428
def simplify(s):
    res = []
    o = 0
    e = 0
    for c in s:
        if c == ")" and res and res[-1] == "(":
            res.pop()
            o -= 1
        else:
            res.append(c)
            if c == "(":
                o += 1
            else:
                e += 1
    return res, o, e


def submit():
    n = int(input())
    slist = []
    for _ in range(n):
        slist.append(simplify(input()))

    open_only = []
    end_only = []
    mix = []
    for s, o, e in slist:
        if o > 0 and e == 0:
            open_only.append((s, o, e))
        elif o == 0 and e > 0:
            end_only.append((s, o, e))
        else:
            mix.append((s, o, e))
    mix.sort(key=lambda x: x[1] - x[2], reverse=True)

    check = 0
    for s, o, e in open_only:
        check += o

    for s, o, e in mix:
        check -= e
        if check < 0:
            print("No")
            return
        check += o

    for s, o, e in end_only:
        check -= e
    
    if check == 0:
        print("Yes")
    else:
        print("No")


submit()

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

long long n, a, b;

int main() {
  cin >> n >> a >> b;
  if (a > b)
    cout << 0 << endl;
  else if (n == 1)
    cout << (a == b) << endl;
  else {
    b -= a;
    cout << (n - 2) * b + 1 << endl;
  }
  return 0;
}


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

int main(void){
    
    ll n, k, d, x;
    
    cin >> n >> k;
    
    ll a[9999]={};
    
    for(ll i=1; i<=k; i++){
        
        cin >> d;
        
        for(ll j=1; j<=d; j++){
            
            cin >> x;
            
            if(a[x]==0){
                
                a[x] = 1;
                n -= 1;
                
            }
            
        }
        
    }
    
    cout << n << endl;
    
    return 0;
    
}

Measured memory_bytes: 3700
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>


#define MIN(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

int cost[10][10];
int d[10];
bool used[10];
int V = 10;

void dijkstra(int s){
	for(int k=0;k<V;k++){
		for(int i=0;i<V;i++){
			for(int j=0;j<V;j++){
				cost[i][j] = MIN(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
}

int main(){
		int h,w;

		scanf("%d %d",&h,&w);

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				scanf("%d",&cost[i][j]);
			}
		}

		int A[h][w];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				scanf("%d",&A[i][j]);
			}
		}

		dijkstra(1);

		int ans = 0;

		//for(int i=0;i<10;i++) printf("%d ",d[i]);
		//printf("\n");

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(A[i][j]!=-1) ans += cost[A[i][j]][1];
			}
		}

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


	return 0;
}


Measured memory_bytes: 256
N = int(input())
L = sorted(map(int, input().split()))
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if len(set([L[i],L[j],L[k]])) != 3:
                continue
            elif L[i]+L[j]>L[k]:
                cnt += 1
            else:
                continue
print(cnt)

Measured memory_bytes: 9220
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private static int upperBound(long[] a, int st, int ed, long k) {
		if (st == ed - 1) {
			if (a[st] <= k) {
				return st + 1;
			} else {
				return st;
			}
		}

		int m = (ed - st) / 2 + st;
		if (a[m] <= k) {
			// 右側
			return upperBound(a, m, ed, k);
		} else {
			// 左側
			return upperBound(a, st, m, k);
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		long[] A = nextLongArray(sc, N);
		long[] B = nextLongArray(sc, N);
		long[] C = nextLongArray(sc, N);

		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);

		sc.close();

		long[] x = new long[N];
		for (int b = 0; b < N; b++) {
			x[b] = N - upperBound(C, 0, N, B[b]);
		}

		for (int b = N - 2; b >= 0; b--) {
			x[b] += x[b + 1];
		}

		long ans = 0;

		for (int a = 0; a < N; a++) {
			int i = upperBound(B, 0, N, A[a]);
			if (i < x.length) {
				ans += x[i];
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}
}


Measured memory_bytes: 94272
//注意到每个上升数可以拆成刚好9个1111...1111，即9个(10^k - 1) / 9，k非负
//设答案为x 
//即N = Sum{(10^Pi - 1) / 9 | 1 <= i <= 9x}
//即9N + 9x = Sum{10^Pi | 1 <= i <= 9x}，即能找到9x个10^Pi使得它们的和为9N + 9x 
//考虑9N + 9x的数位和为S，显然9 | S
//此时我们已经找到了一个让S个10^Pi和为9N + 9x的方案，显然这是这样的方案中用的数最少的
//取任意一位，将其拆成10个它的下一位，即可让用的数 += 9
//故S <= 9x即可
//枚举答案x，每次暴力 + 9
//答案是O(L)级别的，进位次数是均摊O(L)的 

#include <cstdio>
#include <cstring>

using namespace std;

const int Max_L(10000050);

char N[Max_L];
int L, V[Max_L], S;

void init()
{
	scanf("%s", N + 1), L = strlen(N + 1);
	for (int i = 1;i <= L;++i)
		V[L - i + 1] = N[i] - '0';
}

void Mult9()
{
	int x(0);
	for (int i = 1;i <= L;++i)
	{
		V[i] = V[i] * 9 + x;
		x = V[i] / 10;
		V[i] %= 10;
	}
	if (x)
		V[++L] = x;
	for (int i = 1;i <= L;++i)
		S += V[i];
}

void Add9()
{
	int x(9);
	for (int i = 1;i <= L;++i)
	{
		if (x == 0)
			break;
		S -= V[i];
		V[i] += x;
		x = V[i] / 10;
		V[i] %= 10;
		S += V[i];
	}
	if (x)
		S += (V[++L] = x);
}

void work()
{
	for (int x = 1;;++x)
	{
		Add9();
		if (S <= 9 * x)
		{
			printf("%d", x);
			return;
		}
	}
}

int main()
{
	init();
	Mult9();
	work();
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using ipair = pair<int,int>;

int INF = 1e9+7;

using ipair = pair<int,int>;
bool operator>(const ipair a,const ipair b){return a.first > b.first;}

int g[15][15];

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;

  vector<int> ans(N);

  rep(i, N){
    
    queue<ipair> q;
    q.push(make_pair(i, 0));

    vector<bool> visited(N, false);
    visited[i] = true;

    auto push = [&](int v, int d) {
      if(visited[v]) return;
      ans[d]++;
      visited[v] = true;
      q.push(make_pair(v, d));
    };

    while(!q.empty()){
      ipair p = q.front(); q.pop();
      int v = p.first;
      int d = p.second;

      if(v+1 < N) push(v+1, d+1);
      if(v-1 >= 0) push(v-1, d+1);
      if(v==X) push(Y, d+1);
      if(v==Y) push(X, d+1);
    }
  }

  for(int i=1; i<=N-1; i++){
    cout << ans[i] / 2 << endl;
  }
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll  = long long;
using ii  = pair<int, int>;
using vi  = vector<int>;
using vd  = vector<double>;
using vb  = vector<bool>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int n, h;
	cin >> n >> h;

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

	sort(DESC(a));
	sort(DESC(b));

	int mx = a.front();

	int res = 0;
	for (auto v : b) {
		if (h <= 0) break;
		if (v > mx) {
			h -= v;
			res++;
		}
		else break;
	}

	if (h > 0) res += (int)ceil((double)h / mx);
	cout << res << endl;
}


Measured memory_bytes: 1024
#スペース区切りの整数の入力
H, W = map(int, input().split())

ans = 0

if((H==1)or(W==1)):
  print("1")
elif(((H*W)%2 == 0)):
  ans = H*W/2
  print(int(ans))
else:
  ans = int(H*W/2)
  ans = ans + 1
  print(ans)



Measured memory_bytes: 3060
import math

def original_ceil(n):
    return max(0, math.ceil(n))

n, k = [int(i) for i in input().split()]
max_p = original_ceil(math.log2(k))
list_p = [pow(2, i) for i in range(max_p + 1)]
bunbo = n * list_p[-1]
bunshi = sum([list_p[- original_ceil(math.log2((k/(i + 1)))) - 1] for i in range(n)])
print(bunshi / bunbo)

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    ll i,j,k;
    ll sum = 0;
    for(i=0;i<m;i++){
        cin >> a.at(i);
        sum+=a.at(i);
    }
    if(sum>n){
        cout << -1 << endl;
        return 0;
    }
    else{
        cout << n - sum << endl;
        return 0;
    }
    
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
	int l;
    cin >> n >> l;
	vector<string> st(n);
	for(int i=0; i<n; i++){
    	cin >> st.at(i);
    }
	sort(st.begin(), st.end());
	string anser = "";
	for(int i=0; i<n; i++){
    	anser = anser + st.at(i);
    }
    cout << anser << endl;
    return 0;
}

Measured memory_bytes: 256
h, w = gets.strip.split.map(&:to_i)
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

colors = a.map.with_index(1) {|count, color| [color]*count }.flatten

colors = colors.each_slice(w).to_a
colors.map.with_index {|column, index| index.odd? ? column.reverse : column }.each do |column|
  puts column.join(' ')
end


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(){

    ios::sync_with_stdio(false);

    int n,l,x;
    int d=0,cont=1;;

    cin>>n>>x;

    while(n--){
        cin>>l;
        d += l;
        if(d<=x){
            cont++;
        }
        else break;
    }

    cout<<cont<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500000
#define INFTY 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int main(){
  int A[MAX],n,i;
  cnt=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",cnt);

  return 0;
}
void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;

  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];

  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else {
      A[k]=R[j];
      j=j+1;
    }
  }
}
void mergeSort(int *A,int left,int right){
  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);

    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next().replaceAll("\\?",".");
		String b = sc.next();
		for(int i = a.length() - b.length(); i >= 0; i--) {
			String regex = a.substring(i, i+b.length());
			if(b.matches(regex)) {
				System.out.println(a.replaceFirst(a.substring(0,i)+regex,a.substring(0,i)+b).replaceAll("\\.","a"));
				return;
			}
		}
		System.out.println("UNRESTORABLE");
	}
}

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

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

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

int main() {
  int N;
  cin>>N;
  int64_t ans=0;
  for(int i=1;i<N+1;i++){
    if(i%3==0 || i%5==0) continue;
    else ans+=i;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3596
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
      m: usize,
      xyzs: [[i64; 3]; n],
    }
    let mut xyzs = xyzs;
    let coef = [1, -1];
    let mut ans = 0;
    for s1 in coef.iter() {
        for s2 in coef.iter() {
            for s3 in coef.iter() {
                xyzs.sort_by_key(|v| {
                    v[0] * s1 + v[1] * s2 + v[2] * s3
                });
                let mut x = 0;
                let mut y = 0;
                let mut z = 0;
                for i in n-m..n {
                    x += xyzs[i][0];
                    y += xyzs[i][1];
                    z += xyzs[i][2];
                }
                ans = max(ans, x.abs() + y.abs() + z.abs());
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll ans=v[0];
  rep(i,n-1) ans=LCM(ans,v[i+1]);
  cout<<ans<<endl;
}

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

int main()
{
    long long int a, b, c, d;
    long long int hasil;
    cin >> a >> b >> c >> d;
    if (a*c >= a*d)
    {
        if (b*c>=b*d)
        {
            if (a*c > b*c)
            {
                hasil = a*c;
            }
            else
            {
                hasil = b*c;
            }
        }
        else if (b*c<=b*d)
        {
            if (a*c > b*d)
            {
                hasil = a*c;
            }
            else
            {
                hasil = b*d;
            }
        }
    }
    else if (a*c <= a*d)
    {
        if (b*c>=b*d)
        {
            if (a*d > b*c)
            {
                hasil = a*c;
            }
            else
            {
                hasil = b*c;
            }
        }
        else if (b*c<=b*d)
        {
            if (a*d > b*d)
            {
                hasil = a*d;
            }
            else
            {
                hasil = b*d;
            }
        }
    }
    cout << hasil;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }

void func(long long K, long long A, long long B){

    if(B-A<=2){
        cout<<K+1<<endl;
        return;
    }
    //両替する隙がない
    if(K-A<1){
        cout<<K+1<<endl;
        return;
    }

    lli lef = K-A+1;
    LOG(lef);
    lli ans = A + (B-A)*(lef/2);
    if(lef%2==1)ans++;
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(K, A, B);
    return 0;
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll a,v; cin >> a >> v;
    ll b,w; cin >> b >> w;
    ll T; cin >> T;

    if(v>w){
        ll x=abs(a-b);
        ll y=(v-w)*T;
        if(x<=y){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int flags[100005];
    memset(flags, 0, sizeof(flags));
    int cnta = 0;
    int cntw[100005];
    memset(cntw, 0, sizeof(cntw));
    for (int i = 0; i < b; i++)
    {
        int t;
        char cmd[5];
        scanf("%d%s", &t, cmd);
        if (cmd[0] == 'A')
        {
            if (!flags[t]) cnta++;
            flags[t] = 1;
        }
        else
        {
            if (!flags[t]) cntw[t]++;
        }
    }
    int answ = 0;
    for (int i = 1; i <= a; i++)
    {
        if (flags[i]) answ += cntw[i];
    }
    cout << cnta << ' ' << answ << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> num;
  int n;
  for(int i=0; i<5; i++){
    cin >> n;
    num.push_back(n);
  }

  sort(num.begin(), num.end(), greater<int>());

  for(int i=0; i<5; i++){
    if(i == 0)
      cout << num[i];
    else
      cout << " " << num[i];
  }
  cout << endl;
}

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

typedef long long ll;
typedef pair<int,ll> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;
int main() {
	int n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==1)cout<<"Borys";
	if((b-a)%2==0)cout<<"Alice";

	return 0;
}


Measured memory_bytes: 256