akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iterator>
using namespace std;

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

//素数判定
bool isPrime(int n)
{
  if(n<=1) return false;
  for(int i=2;i<=sqrt(double(n));++i)
  {
    if(!(n%i)) return false;
  }
  return true;
}

signed main() 
{
  int a,d,n;
  vi ans;
  while(cin>>a>>d>>n, a||d||n)
  {
    int cnt=0;
    while(1)
    {
      if(isPrime(a))
      {
        ++cnt;
        if(cnt==n) break;
      }
      a+=d;
    }
    ans.pb(a);
  }
  EACH(e,ans) print(e); 

  return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

vector<int> G[100010];
int UD[100010], VD[100010];

void dfs(int c, int p, int d, bool u) {
	if (u)UD[c] = d;
	else VD[c] = d;
	for (int i : G[c]) {
		if (i == p)continue;
		dfs(i, c, d + 1, u);
	}
}

int main() {
	int N, u, v, a, b;
	cin >> N >> u >> v;

	for (int i = 1;i < N;i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(u, 0, 0, 1);
	dfs(v, 0, 0, 0);

	int mx = 0, cost;

	for (int i = 1;i <= N;i++) {
		if (VD[i] >= UD[i]) {
			mx = max(VD[i] - 1, mx);
		}
	}
	cout << mx << endl;
}

Measured memory_bytes: 11648
#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    proconio::input! {
        W: usize,
        H: usize,
        M: usize,
        B: [(usize, usize); M],
    }

    let mut xmax = 0;
    let mut ymax = 0;
    let mut xs = vec![0; W + 1];
    let mut ys = vec![0; H + 1];

    for &(x, y) in &B {
        xs[x] += 1;
        ys[y] += 1;
        xmax = std::cmp::max(xmax, xs[x]);
        ymax = std::cmp::max(ymax, ys[y]);
    }

    let xn = xs.iter().filter(|&&n| n == xmax).count();
    let yn = ys.iter().filter(|&&n| n == ymax).count();
    let bn = B.iter().filter(|(x, y)| xs[*x] == xmax && ys[*y] == ymax).count();

    let ans = xmax + ymax - (if xn * yn == bn { 1 } else { 0 });
    println!("{}", ans);
}

Measured memory_bytes: 13008
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+15
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b+c<22){
		cout<<"win"<<endl;
	}
	else{
		cout<<"bust"<<endl;
	}
	return 0;
}

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

#define ANSMAX 1000000000
unsigned long long int n , k , *arr;

unsigned long long int Serach(unsigned long long int pc){
	unsigned long long int ktmp =0 ,pt = pc , i=0;
	while (1){
		if(arr[i] > pt ){ break;}
		else if(pc >= arr[i]){
			pc -= arr[i];
			i++;
			if(i == n ){
				break;
			}
		}
		else {
			ktmp++;
			if(ktmp == k ){break;} 
			pc = pt ;
		} 
	}
	return i;
}
int main(){
	scanf("%llu %llu",&n,&k);
	arr = (unsigned long long int *)malloc(n * sizeof(unsigned long long int ));
	for(int i =0 ; i < n ; i++){
		scanf("%llu",&arr[i]);
	}
	unsigned long long int l = 0, r = ANSMAX ,res;
	while (1){
		if( l + 1 >=  r){break;}
		unsigned long long int m = (l + r)/2;
		res = Serach(m);
		if(res <  n){l = m;	
		}
		else {r = m;	
		}

	}
	
	printf("%llu\n",r);
	
	return 0;
}



Measured memory_bytes: 2628
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    int H,W;
    cin >> H >> W;
    
    char a[H+2][W+2];
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> a[i][j];
            a[0][j] = '#';
            a[H+1][j] = '#';
        }
        a[i][0] = '#';
        a[i][W+1] = '#';
    }
    
    a[0][0] = '#';
    a[0][W+1] = '#';
    a[H+1][0] = '#';
    a[H+1][W+1] = '#';
    
    for(int i=0;i<=H+1;i++){
        for(int j=0;j<=W+1;j++){
            cout << a[i][j];
        }
        cout << "" << endl;
     }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		
		int aa = a % 10;
		int bb = b % 10;
		int cc = c % 10;
		int dd = d % 10;
		int ee = e % 10;
      
      if(aa == 0){
        aa += 10;
      } if(bb == 0){
        bb += 10;
      }if(cc == 0){
        cc += 10;
      } if(dd == 0){
        dd += 10;
      } if(ee == 0){
        ee += 10;
      }
		int min = 10;
		if(min > aa){
		    min = aa;
		}if(min > bb){
		    min = bb;
		}if(min > cc){
		    min = cc;
		}if(min > dd){
		    min = dd;
		}if(min > ee){
		    min = ee;
		}
      int aaa = 0;
      int bbb = 0;
      int ccc = 0;
      int ddd = 0;
      int eee = 0;
      
      	if(a%10 != 0){
		 aaa =(int)Math.round((a+5) / 10.0)*10;
        }else{
         aaa = a;
        }
      if(b%10 != 0){
		bbb = (int)Math.round((b+5) / 10.0)*10;
        }else{
         bbb = b;
        }
      if(c%10 != 0){
		 ccc = (int)Math.round((c+5) / 10.0)*10;
        }else{
         ccc = c;
        }
      if(d%10 != 0){
		 ddd = (int)Math.round((d+5) / 10.0)*10;
        }else{
         ddd = d;
        }
      if(e%10 != 0){
		 eee = (int)Math.round((e+5) / 10.0)*10;
        }else{
         eee = e;
        }
		int zzz = aaa + bbb + ccc + ddd + eee - 10 + min;
		System.out.println(zzz);
	}
}


Measured memory_bytes: 35548
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n, m, l;
	cin >> n >> m >> l;

	vector< vector<int> > a(n, vector<int>(m, 0));
	vector< vector<int> > b(m, vector<int>(l, 0));
	vector< vector<long long> > c(n, vector<long long>(l, 0));

	//??\???
	for (vector<int>::size_type i = 0; i < n; i++) {
		for (vector<int>::size_type j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (vector<int>::size_type i = 0; i < m; i++) {
		for (vector<int>::size_type j = 0; j < l; j++) {
			cin >> b[i][j];
		}
	}

	//?¨????
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	//??????
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			cout << c[i][j];
			if (j != l - 1)
				cout << " ";
		}
		cout << "\n";
	}

}

Measured memory_bytes: 1372
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
A = ri()
print('Yes' if N % 500 <= A else 'No')

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

const int K = 18, N = 1<<K, M = 1e9+7;
int prod[N][K];
int a[N];

deque<pair<int, int>> vp[N];

void add(int x, int z, int mul) {
    assert(vp[x].empty() || vp[x].back().first <= z);
    if (vp[x].empty() || vp[x].back().first < z)      vp[x].push_back({z, mul});
    else {
        vp[x].back().second += mul;
        if (vp[x].back().second >= M) vp[x].back().second -= M;
    }
}

int rgt[N];

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

    int k;
    cin>>k;

    int L = 1<<(k-1), R = 2*L-1;

    for (int i=L; i<=R; i++) {
        prod[i][0] = i;
        for (int j=1; j<k; j++) {
            prod[i][j] = (1LL*prod[i][j-1]*(i>>j))%M;
        }
    }


    for (int i=L; i<2*L; i++) {
        int x;
        cin>>x;
        a[i] = x+L-1;
    }

     for (int k1=k-1; k1>=0; k1--) {
        for (int k2=k-1; k2>=0; k2--) {
            for (int i=L; i<2*L; i++) {
                int x = a[i];
                int pr = (1LL*prod[i][k1]*prod[x][k2])%M;

                int a1 = (i>>k1), a2 = (x>>k2);
                add(a2, a1, pr);
            }
        }
    }

    long long ans = 0;
    for (int i=1; i<=L; i++) {
        int ll = 2*i, rr = 2*i+1;

        for (auto pr: vp[rr])       rgt[pr.first] = pr.second;

        for (auto pr: vp[ll]) {
            int x = pr.first;
            if (x == 1) continue;
            unsigned long long con = (1LL*pr.second*rgt[x^1])%M;
            con = (con*i*(x>>1))%M;
            ans += con;
        }

        for (auto pr: vp[rr])       rgt[pr.first] = 0;
    }
    cout<<ans%M<<endl;
}


Measured memory_bytes: 325088
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

struct Edge{
	Edge(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to,cost;
};

struct Info{
	Info(int arg_node_id,int arg_sum_cost){
		node_id = arg_node_id;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct Info &arg) const{

		return sum_cost > arg.sum_cost; //総コストの昇順(PQ)
	}
	int node_id,sum_cost;
};

int K;
int min_dist[NUM];
vector<Edge> G[NUM];


int main(){

	scanf("%d",&K);

	for(int i = 0; i <= K-1; i++){

		G[i].push_back(Edge((i+1)%K,1)); //コスト1の辺
		G[i].push_back(Edge((10*i)%K,0)); //コスト0の辺
	}

	for(int i = 0; i < K; i++){

		min_dist[i] = BIG_NUM;
	}

	min_dist[1] = 0;

	priority_queue<Info> Q;
	Q.push(Info(1,0));

	int next_node,next_cost;

	while(!Q.empty()){

		if(Q.top().sum_cost > min_dist[Q.top().node_id]){

			Q.pop();
		}else if(Q.top().node_id == 0){

			printf("%d\n",Q.top().sum_cost+1);
			return 0;

		}else{

			for(int i = 0; i < G[Q.top().node_id].size(); i++){

				next_node = G[Q.top().node_id][i].to;
				next_cost = Q.top().sum_cost+G[Q.top().node_id][i].cost;

				if(min_dist[next_node] > next_cost){

					min_dist[next_node] = next_cost;
					Q.push(Info(next_node,next_cost));
				}
			}

			Q.pop();
		}
	}

	return 0;
}


Measured memory_bytes: 6780
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    string ans = (a + b >= x && x >= a)? "YES" : "NO";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=2019;
string s;
int ans,g[200001],a[2019],ls;
signed main()
{
	int x,y=0;
	g[0]=1;
	for(int i=1;i<=200000;i++)
	g[i]=g[i-1]*10%mod;
	cin>>s;
	ls=s.size();
	a[0]=1;
	for(int i=ls-1;i>=0;i--)
	{
		x=(s[i]-'0')*g[ls-i-1]%mod;
		ans+=a[(x+y)%mod];
		a[(x+y)%mod]++;
		y=(x+y)%mod;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#define INF 1000000000
using namespace std;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;

	int A[N];
	for (int i = 0; i < N; ++i) cin >> A[i];

	sort(A, A + N);

	vector<int> kinds;
	int prev = -114514, chain = 0;
	for (int i = 0; i <= N; ++i) {
		if (i == N) {
			kinds.push_back(chain);
			continue;
		}

		if (prev == A[i]) {
			chain++;
		}
		else {
			if (chain)
				kinds.push_back(chain);
			chain = 1;
		}
		prev = A[i];
	}

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

	int ans = 0;
	while (kinds.size() > K) {
		ans += kinds[kinds.size() - 1];
		kinds.erase(kinds.end() - 1);
	}

	cout << ans << endl;
}

Measured memory_bytes: 2168
N, M = list(map(int,input().split()))
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = list(map(int,input().split()))
    s[i] -= 1

err = False

digit = [0]*N
digit_bool = [False]*N

for i in range(M):
    if digit_bool[s[i]]:
        if digit[s[i]] != c[i]:
            err = True
    else:
        digit[s[i]] = c[i]
        digit_bool[s[i]] = True

if digit[0] == 0:
    if digit_bool[0]:
        if N != 1:
            err = True
    elif N == 1:
        digit[0] = 0
    else:
        digit[0] = 1

if err:
    print('-1')
else:
    print(''.join(list(map(str,digit))))

Measured memory_bytes: 9188
N = int(input())
(*A,) = map(int, input().split())
maxA = max(A)

C = {a: 0 for a in A}
for a in A:
    C[a] += 1

D = {a: 0 for a in A}
for a in A:
    if C[a] > 0:
        t = 2
        while a * t <= maxA:
            D[a * t] = 1
            t += 1

ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)


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

using namespace std;

class Point {
public:
	int id, x, y;
	Point(int id, int x, int y) :
			id(id), x(x), y(y) {
	}
	Point() {
	}
	bool operator <(const Point& p) const {
		return id < p.id;
	}
	void print() {
		printf("%d\n", id);
	}
};
class Node {
public:
	int location, l, r;
};

bool lessX(const Point& p1, const Point& p2) {
	return p1.x < p2.x;
}
bool lessY(const Point& p1, const Point& p2) {
	return p1.y < p2.y;
}

const int NIL = -1;
const int MAX = 500000;
Point P[MAX];
Node T[MAX];
int np = 0;

int makeKdTree(int l, int r, int depth) {
	if (!(l < r))
		return NIL;

	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	} else {
		sort(P + l, P + r, lessY);
	}

	int t = np++;
	int mid = (l + r) / 2;
	T[t].location = mid;
	T[t].l = makeKdTree(l, mid, depth + 1);
	T[t].r = makeKdTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;
	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		ans.push_back(P[T[v].location]);
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL && sx <= x)
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		if (T[v].r != NIL && x <= tx)
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
	} else {
		if (T[v].l != NIL && sy <= y)
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		if (T[v].r != NIL && y <= ty)
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
	}
}

int main() {

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].location = T[i].l = T[i].r = NIL;
	}

	int root = makeKdTree(0, n, 0);

	int q;
	scanf("%d", &q);
	int sx, tx, sy, ty;
	vector<Point> ans;
	for (int i = 0; i < q; ++i) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int i = 0; i < ans.size(); ++i) {
			ans[i].print();
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 13936
import bisect

def main():
    num = int(input())
    data = list(map(int, input().split()))
    ans = 10 ** 10
    for i in range(num + 1):
        left = sum(data[:i])
        righ = sum(data[i:])
        kari = abs(left - righ)
        if kari < ans:
            ans = kari

    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
object Main {
  def main (args: Array[String]) {
    for(line <- scala.io.Source.stdin.getLines()){
      val Array(v1,opr,v2) = line.split(" ");
      if (opr == "?")  return
      val val1:Int = v1.toInt
      val val2:Int = v2.toInt
 
      opr match{
        case "+"  =>  println(val1 + val2)
        case "-"  =>  println(val1 - val2)
        case "*"  =>  println(val1 * val2)
        case "/"  =>  println(val1 / val2)
        case _ => println("????");
      }
    }
  }
}

Measured memory_bytes: 43924
# -*- coding: utf-8 -*-
"""
Created on Wed Apr  5 11:19:44 2017

@author: syaga
"""

if __name__ == "__main__":
    A, B = list(map(int, input().split()))
    total = A + B
    if total > 23:
        print(total-24)
    else:
        print(total)


Measured memory_bytes: 2940
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		long N = scan.nextInt();
		long K = scan.nextInt();
		long ans = 0;

		if(K == 0){
			System.out.println(N*N);
		}else{

			for(long b = K+1;b <= N;b++){


				long p = N /b;
				long r = N - p*b;
				ans += p * Math.max(0, b-K);
				ans += Math.max(0, r-K+1);




			}
			System.out.println(ans);


		}
	}






}


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

#define ll              long long int
#define ld              long double
#define f1(i, a, b)     for(ll i = a; i < b; i++)
#define f2(a, b)        for(auto a : b)
#define ar(v, i)        v[i]
#define in_(x)          ll x; cin >> x;
#define ino_(type, x)   type x; cin >> x;
#define pb              push_back

using namespace std;

int main()
{
    ll k, n;
    cin >> k >> n;
    vector<ll> v;
    
    f1(i, 0, n)
    {
        in_(x)
        v.pb(x);
    }
    ll res = 0;
    ll maxdiff = 0;
    
    f1(i, 0, n)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            if(d > maxdiff)
            {
                maxdiff = d;
            }
        }
        else
        {
            ll d = abs(ar(v, i) - k) + ar(v, 0);
            if(d > maxdiff)
            {
                maxdiff = d;
            }
        }
    }
    
    ll ind;
    
    f1(i, 0, n)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            if(d == maxdiff)
            {
                ind = i + 1;
                break;
            }
        }
        else
        {
            ll d = abs(ar(v, i) - k) + ar(v, 0);
            if(d == maxdiff)
            {
                ind = 0;
                break;
            }
        }
    }
    
    // cout << ind << endl;
    
    f1(i, ind, n)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            res += d;
            // cout << res << "#" << endl;
        }
        else
        {
            if(ind != 0)
            {
                ll d = abs(ar(v, i) - k);
                res += d;
                res += v[0];
                // cout<< "THIS" << res << endl;
            }
        }
    }
    
    f1(i, 0, ind - 1)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            res += d;
            // cout << res << "@" << endl;
        }
        else
        {
            ll d = abs(ar(v, i) - ar(v, 0));
            res += d;
            // cout << res << "*" << endl;
        }
    }
    cout << res << endl;
    
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


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







Measured memory_bytes: 256
A,B = map(int, input().split())
if A > B:
    a = B
    b = A
else:
    a = A
    b = B
for i in reversed(range(1,a+1)):
    if b%i == 0 and a%i == 0:  
        print(a*b//i)
        break
else:
    print(a*b)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
using namespace std;
int main()
{
	long long int n;
	cin>>n;
	int k;
	k=n%10;
	if(k==2||k==4||k==5||k==7||k==9)cout<<"hon"<<endl;
	else if(k==0||k==6||k==8||k==1)cout<<"pon"<<endl;
	else cout<<"bon"<<endl;
	return 0;
 } 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){

    int n, m; cin >> n >> m;
    

    vector<pair<bool, int> > red(n, make_pair(false, 1));
    red[0].first = true;

    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        x--;
        y--;
        if(red[x].first == true){
            if(red[x].second == 1){
                red[x].first = false;
            }
            red[x].second--;
            red[y].first = true;
            red[y].second++;
        }else{
            red[x].second--;
            red[y].second++;
        }
    }


    int ans = 0;
    for(int i = 0; i < n; i++){
        //cout << red[i].first << " ";
        if(red[i].first == true) ans++;
    }

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

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


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


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

using namespace std;

int main()
{
    int a, b, c, d;

    scanf("%d %d %d %d", &a, &b, &c, &d);

    printf("%s\n", abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  sort(ALL(a));
  sort(ALL(b));

  if (n % 2 == 1) {
    lint r = b[n / 2];
    lint l = a[n / 2];
    cout << r - l + 1 << endl;
  } else {
    lint r = b[n / 2 - 1] + b[n / 2];
    lint l = a[n / 2 - 1] + a[n / 2];
    cout << r - l + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 6424
# -*- coding: utf-8 -*-

R, G, B, N = [int(i) for i in input().split()]

cnt = 0
for i in range(N // R + 1):
    r = i * R
    for j in range((N - r) // G + 1):
        g = j * G

        b = N - r - g

        if b % B == 0:
            cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

struct edge{
    int to;
    ll cost;
};

//V:=頂点数、E:=辺数
const int MAX_V = 1e5;
vector<edge> es[MAX_V];
ll d[MAX_V], d2[MAX_V];

//グラフに負の辺がない場合に、O(E*log(V))でsから全ての点への最短距離をそれぞれ求める
void dijkstra(int s, ll *d){
    priority_queue<pli, vector<pli>, greater<pli> > que;
    fill(d, d+MAX_V, INF);
    d[s] = 0;
    que.push(pli(0, s));
    while(!que.empty()){
        pli p = que.top();
        que.pop();
        int v = p.second;
        //d[v]が確定している
        if(d[v] < p.first) continue;
        for(auto &e: es[v]){
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                que.push(pli(d[e.to], e.to));
            }
        }
    }
}

//num[i]:=sからtへの最短路の途中でiによる場合の数
ll num[MAX_V], num2[MAX_V];
priority_queue<pli> q;
bool used[MAX_V];

void dfs(int now, ll *d, ll *num){
    used[now] = true;
    for(auto &e: es[now]){
        if(d[now] == d[e.to]+e.cost){
            num[e.to] += num[now];
            num[e.to] %= MOD;
            q.push(pli(d[e.to], e.to));
        }
    }
}

void calc(int s, int t, ll *d, ll* num){
    fill(num, num+MAX_V, 0);
    fill(used, used+MAX_V, false);
    dijkstra(t, d);
    num[s] = 1;
    q.push(pli(d[s], s));
    while(!q.empty()){
        pli p = q.top();
        q.pop();
        if(!used[p.second]) dfs(p.second, d, num);
    }
}

int main(){
    int N, M, s, t;
    cin >> N >> M >> s >> t;
    s--, t--;
    rep(i, M){
        int u, v;
        ll r;
        cin >> u >> v >> r;
        u--, v--;
        edge e1 = {v, r}, e2 = {u, r};
        es[u].pb(e1), es[v].pb(e2);
    }
    calc(s, t, d, num);
    calc(t, s, d2, num2);
    ll D = d[s];
    vector<pii> check;
    rep(i, N){
        if(d[i]*2 == D && d2[i]*2 == D) check.pb(pii(i, i));
    }
    //d[i]:=tからiの最短距離、d2[i]:=sからiの最短距離
    rep(i, N){
        for(auto &e: es[i]){
            if(d2[i]+e.cost+d[e.to] == D){
                if(d2[i]*2 < D && d[e.to]*2 < D){
                    check.pb(pii(i, e.to));
                }
            }
        }
    }
    ll ans = num[t]*num2[s]%MOD;
    for(auto &e: check){
        //cout << e.first << ' ' << e.second << endl;
        ll tmp = num[e.first]*num2[e.second]%MOD;
        tmp *= tmp, tmp %= MOD;
        ans += MOD-tmp, ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18900
#include<stdio.h>
#define N 100

int cmp(void *a,void *b){
    return *(int*)a-*(int*)b;
}

int main(){
    int a,b,c,d,i,n;
    int flag,j,cnt;
    int s[N]={0};
    int p[N]={0};
    int t[N]={0};

    scanf("%d",&n);

    for(i=0;i<n*(n-1)/2;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if(c<d){
            s[b]+=3;
        }else if(c>d){
            s[a]+=3;
        }else{
            s[a]++;
            s[b]++;
        }
    }

    for(i=1;i<=n;i++)t[i]=s[i];
    qsort(t,n+1,sizeof(int),cmp);
    for(i=n,cnt=0;flag=0,i>=0;i--){
        for(j=1;j<=n;j++){
            if(p[j]==0&&t[i]==s[j]){
                flag++;
                p[j]=cnt+1;
            }
        }
        if(flag)cnt+=flag;
    }

    for(i=1;i<=n;i++)printf("%d\n",p[i]);
    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int A, B, X; cin >> A >> B >> X;
    if (A > X) cout << "NO";
    else if (A + B > X) cout << "YES";
    else cout << "NO";
    cout << endl;
}

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

using ll = long long;

int main() {
    int N;  cin >> N;
    vector<ll> x(N), y(N);
    vector<pair<ll, int>> v1(N), v2(N);
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i];
        v1[i] = make_pair(x[i] + y[i], i);
        v2[i] = make_pair(y[i] - x[i], i);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    auto d = [&](int i, int j) {
        return abs(x[i] - x[j]) + abs(y[i] - y[j]);
    };
    ll ans = max(d(v1[0].second, v1[N - 1].second), d(v2[0].second, v2[N - 1].second));
    cout << ans << endl;
}


Measured memory_bytes: 12760
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int abs(int x)
{
    return x>0 ? x : -x;
}
int main()
{
    int N;
    scanf("%d",&N);
    vector<long long int> partsum(N);
    for(int i=0;i<N;i++)
    {
        int num;
        scanf("%d",&num);
        partsum[i]=i==0?num:partsum[i-1]+num;
    }
    long long int mn=92233720368547758,su=partsum[N-1];
    for(int i=0;i<N-1;i++)
    {
        mn=min(mn,abs(2*partsum[i]-su));
    }
    printf("%lld\n",mn);
    return 0;
}


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

int main() {

  int N, K, X, Y;
  cin >> N >> K >> X >> Y;

  int answer = 0;

  if (N <= K) {
    answer = N * X;
  } else {
    answer = K * X + (N - K) * Y;
  }
  
  cout << answer << endl;

}

Measured memory_bytes: 256
n, x, m = map(int, input().split())

period = 0


UNDEF = -1
last_idx = [UNDEF] * (m + 1)


ans = 0


def get_start_and_loop(n, x, m):
    first = x
    cur = first
    i = 0
    vals = []
    for i in range(n):
        if last_idx[cur] != UNDEF:
            return last_idx[cur], sum(vals[: last_idx[cur]]), i - last_idx[cur], sum(vals[last_idx[cur]: ]), cur
        last_idx[cur] = i
        vals.append(cur)
        cur = (cur * cur) % m
        i += 1
    return n, sum(vals), 1, 0, 0

start, start_sum, period, period_sum, cur = get_start_and_loop(n, x, m)

ans = start_sum
n -= start
ans += n // period * period_sum
n %= period

for i in range(n):
    ans += cur
    cur = (cur * cur) % m

print(ans)











Measured memory_bytes: 69616
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    count = 0
    ans = 0
    mi = float("inf")

    for a in A:
        ans += abs(a)
        mi = min(mi, abs(a))
        if a <= 0:
            count += 1

    if count & 1:
        print(ans - mi * 2)
    else:
        print(ans)

    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 14412
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
	/* your cord */
  for ( i = 0; i <= VMAX; i++ ) {
  	C[i] = 0;
	}
	
  for ( j = 0; j < n; j++ ){
    scanf("%hd", &A[j+1]);
    C[A[j+1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) {
  		C[i] = C[i] + C[i-1];
	}
	
  for ( j = n; j >= 1; j-- ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 9636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] s = new int[m];
        int[] c = new int[m];
        int[][] a = new int[n+1][10];
        boolean no = false;
        for(int i = 0; i < m; i++){
            s[i] = Integer.parseInt(sc.next());
            c[i] = Integer.parseInt(sc.next());
            a[s[i]][c[i]]++;
            if(n >= 2 && s[i] == 1 && c[i] == 0){
                no = true;
            }
        }
        
        for(int i = 1; i <= n; i++){
            int b = 0;
            for(int j = 0; j < 10; j++){
                if(a[i][j] > 0){
                    b++;
                }
            }
            if(b >= 2){
                no = true;
            }
        }
        
        if(no){
            System.out.println(-1);
        }else{
            int[] ans = new int[n+1];
            for(int i = 0; i < m; i++){
                ans[s[i]] = c[i];
            }
            if(n >= 2 && ans[1] == 0){
                ans[1] = 1;
            }
            for(int i = 1; i <= n; i++){
                System.out.print(ans[i]);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 21844
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
# define x first
# define y second
using namespace std;
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; }

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll stack = 0, money = 1000;
  rep(i, n-1){
    if(a[i]==a[i+1]) continue;
    if(a[i]>a[i+1]){
      money = stack * a[i] + money;
      stack = 0;
    } else if(stack == 0 && a[i]<a[i+1]){
      stack = money / a[i];
      money %= a[i];
    }
  }
  money = stack * a[n-1] + money;

  cout << money << endl;
}


Measured memory_bytes: 3632
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc =new Scanner(System.in);
        int[] counter = new int[26];
        while (sc.hasNextLine()) {
            String str = sc.nextLine();
            int[] array = new int[str.length()];
            // System.out.println("str.length = " + str.length());
            for (int i = 0; i < str.length(); i++) {
                    array[i] = str.charAt(i) - 'a';
                    // System.out.println("array[" + i + "] = " + array[i]);
            }
            for (int j = 0; j < array.length; j++) {
                int value = array[j];
                // System.out.println("value = " + value);
                if ((value >= 0) && (value <= 25)) {
                    counter[value]++;
                    // System.out.println("counter[" + value + "] = " + counter[value]);
                } else if ((value >= -32) && (value <= -7)) {
                    counter[value + 32]++;
                    // System.out.println("counter[" + (value + 32) + "] = " + counter[value + 32]);
                }
            }
        }
        for (char ch = 'a'; ch <= 'z'; ch++) {
            // System.out.println("ch - 'a' = " + (ch - 'a'));
            System.out.println(ch + " : " + counter[ch - 'a']);
        }
    }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; ++i) {
        stringstream ss;
        ss<<i;
        string s;
        ss>>s;
        string r = s;
        reverse(all(r));
        if(s==r) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << a*b << "\n";
    return 0;
}


Measured memory_bytes: 3632
#include<cstdio>

int x,y,s,sum2=0;
int main()
{
    while(1)
    {
         scanf("%d %d %d\n",&x,&y,&s);
         if(x==0&&y==0&&s==0){
             break;
         }
        for(int a = 1; a < s-1; a++)
        {
            for(int b =1; b <=s-1; b++)
            { 
                int sum1=a*(100+x)/100+b*(100+x)/100;
                if (sum1==s) {
                    int i=a*(100+y)/100+b*(100+y)/100;
                    if (i>sum2) {     
                        sum2=i;
                    }
                
                }
                
            }
        }
        printf("%d\n",sum2);
        sum2=0;
    }
    return 0;
}



Measured memory_bytes: 2684
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdio>
        using namespace std;
        int main(){
          std::string m;
          int d = 0;
          cin >> m;
          if(m[0] == '1') d += 1;
          if(m[1] == '1') d += 1;
          if(m[2] == '1') d += 1;
          cout << d << endl;
          return 0;
        }

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

int main(){

  int n, cnt[6];
  double h, low;

  cin >> n;

  low = 165.0;
  fill(cnt, cnt+6, 0);
  for(int i=0; i<n; i++){
    cin >> h;
    for(int j=0; j<6; j++){
      if(j != 5){
        if(h < low + 5.0 * j){
          cnt[j]++;
          break;
        }
      }
      else{
        cnt[5]++;
      }
    }
  }

  for(int i=0; i<6; i++){
    cout << i+1 << ":";
    for(int j=0; j<cnt[i]; j++){
      cout << "*";
    }
    cout << endl;
  }

  return 0;

}

Measured memory_bytes: 1232
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] l = new int[n];
    for(int i = 0; i < n; i++) {
      l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    long ans = 0;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        int t = l[i] + l[j];
        int left = 0;
        int right = n;
        int k = 0;
        while(left < right) {
          int med = (left + right) / 2;
          if(l[med] < t) {
            k = med;
            left = med + 1;
          } else {
            right = med;
          }
        }
        ans += ((long)Math.max(0, k - j));
      }
    }
    System.out.println(ans);
  }
}


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


int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  int ans=0;
  rep(i,n){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int ch=1;
  rep(i,n-1){
    if(a.at(i)==a.at(i+1)){
      ch++;
    }
    else{
      ans+=ch%2;
      ch=1;
    }
  }
  ans+=ch%2;
  cout<<ans<<endl;
  
}




Measured memory_bytes: 640
fun main(args: Array<String>) {
    val ab = readLine()!!.split(" ").map { it.toInt() }
    
    var result = ""
    
    val small = if (ab[0] < ab[1]) ab[0] else ab[1]
    val big = if (ab[0] < ab[1]) ab[1] else ab[0]
    
    for (i in 1..big) {
        result += small.toString()
    }
    
    print(result)
}

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

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

int main() {

    ll n, m; cin >> n >> m;

    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> z(n);
    for (ll i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> z[i];
    }

    ll ans = 0;
    //全パターンをbit全探索
    for (ll bit = 0; bit < (1 << 3); ++bit) {
        vector<ll> pm(3);
        for (ll i = 0; i < 3; ++i) {
            if (bit & (1 << i)) {
                pm[i] = -1;
            } else {
                pm[i] = 1;
            }
        }

        vector<ll> s(n);
        for (ll i = 0; i < n; ++i) {
            s[i] = x[i] * pm[0] + y[i] * pm[1] + z[i] * pm[2];
        }

        sort(s.rbegin(), s.rend());

        ll sum = 0;
        for (ll i = 0; i < m; ++i) {
            sum += s[i];
        }

        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
 
    const lines = input.split('\n')
    const N = lines[0] - 0
    const h = lines[1].split(' ').map(Number)

    let c = h[0]

    for (let i = 0; i < N - 1; i++) {
        if (h[i] < h[i + 1]) {
            c += h[i + 1] - h[i]
        }
    }

    console.log(c)

})(input)


Measured memory_bytes: 29596
int main(){
    int H, W;
    scanf("%d %d", &H, &W);
    
    while (H != 0 || W != 0){
        int i,j;
        for (i = 1; i <= H ; i++) {
            for (j = 1; j <= W; j++) {
                if (i % 2 == 0) {
                    if (j % 2 == 0)
                        printf("#");
                    else
                        printf(".");
                }
                else {
                    if (j % 2 == 0)
                        printf(".");
                    else
                        printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &H, &W);
    }
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<string> split_naive(const string &s, char delim) {
	vector<string> elems;
	string item;
	for (char ch: s) {
		if (ch == delim) {
			if (!item.empty())
				elems.push_back(item);
			item.clear();
		}
		else {
			item += ch;
		}
	}
	if (!item.empty())
		elems.push_back(item);
	return elems;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	char line[100];
	while(cin.getline(line,sizeof(line))){
		string S(line);
		auto T=split_naive(S,' ');
		int offset = 0;
		for(auto& x:T){
			int N=x.size();
			if(N==3){
				int a = x[0]-'a';
				int b = x[1]-'a';
				int c = x[2]-'a';
				if(c>=0 && c<=25 && ((a-b+26)%26)==12 && ((a-c+26)%26)==15){
					offset = a-('t'-'a');
					break;
				}
			}
			else if(N==4){
				int a = x[0]-'a';
				int b = x[1]-'a';
				int c = x[2]-'a';
				int d = x[3]-'a';
				if(d>=0 && d<=25 && ((a-b+26)%26)==12 && ((a-c+26)%26)==19 && ((a-d+26)%26)==0){
					offset = a-('t'-'a');
					break;
				}
				else if(d>=0 && d<=25 && ((a-b+26)%26)==12 && ((a-c+26)%26)==11 && ((a-d+26)%26)==1){
					offset = a-('t'-'a');
					break;
				}
			}
			else if(N==5){
				int a = x[0]-'a';
				int b = x[1]-'a';
				int c = x[2]-'a';
				int d = x[3]-'a';
				if(d>=0 && d<=25 && ((a-b+26)%26)==12 && ((a-c+26)%26)==19 && ((a-d+26)%26)==0){
					offset = a-('t'-'a');
					break;
				}
				else if(d>=0 && d<=25 && ((a-b+26)%26)==12 && ((a-c+26)%26)==11 && ((a-d+26)%26)==1){
					offset = a-('t'-'a');
					break;
				}
			}
		}
		for(int j=0;j<100;j++){
			if(line[j]>='a' && line[j]<='z'){
				int c=line[j]-'a';
				c=(c+26-offset)%26;
				line[j] = c+'a';
			}
		}
		out(line);
	}
	return 0;
}


Measured memory_bytes: 3032
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <cctype>

using namespace std;

const int64_t INF=10000000000000000;
int main(){
    int64_t r,d,x;
    cin>>r>>d>>x;
    for(int i=0;i<10;i++){
        x=x*r-d;
        cout<<x<<endl;
    }
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	string::size_type orig_sz = s.size();
	int answer = 0;
	for (int i = 0; i < orig_sz; i++) {
		s = s.substr(0, s.size() - 1);
		if (s.size() % 2 != 0) {
			continue;
		}
		
		string first = s.substr(0, s.size() / 2);
		string second = s.substr(s.size() / 2);
		if (first == second) {
			answer = s.size();
			break;
		}
	}

	cout << answer << endl;
	return 0;
}


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

int main()
{
	long long n,s=0;
	cin>>n;
	long long a[n+1],f[n+1],ans=0LL;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
		f[i]=s;
	}
	for(int i=1;i<n;i++)
	{
		ans+=((a[i]%1000000007)*\
		((s-f[i])%1000000007))%1000000007;
		ans%=1000000007;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int n;
ll dp[100010][3];

int main() {

	cin >> n;
	vector<int> a(n), b(n),c(n);
	rep(i,n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for(int i=1; i<n; i++) {
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
  return 0;
}


Measured memory_bytes: 3712
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

H, W = [int(x) for x in input().split()]
grid = []
for _ in range(H):
    grid.append(input())

dp = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if grid[i][j] != '.':
            continue
        if i == 0 and j == 0:
            dp[i][j] = 1
        elif i == 0:
            dp[i][j] = dp[i][j - 1]
        elif j == 0:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD

print(dp[i][j])


Measured memory_bytes: 43616