akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	
	static int[][] map;
	
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		
		while(true){
			map = new int[12][];
			for(int i = 0; i < 12; i++)
				map[i] = app.toIntegerArrays(reader.readLine().toCharArray(), 0);
			
			int count = 0;
			for(int i = 0; i < 12; i++){
				for(int j = 0; j < 12; j++){
					if(map[i][j] == 1){
						app.check(i, j);
						count++;
					}
				}
			}
			System.out.println(count);
			
			if(reader.readLine() == null) break;
		}
		isr.close();
		reader.close();
	}
	
	public void check(int x, int y){
		if(x > 11 || y > 11 || x < 0 || y < 0 || map[x][y] == 0) return;
		map[x][y] = 0;
		check(x + 1, y);
		check(x - 1, y);
		check(x, y + 1);
		check(x, y - 1);
	}
	public int[] toIntegerArrays(char[] array, int i){
		int[] result = new int[12];
		for(int var : array) result[i++] = (int)var - (int)'0';
		return result;
	}
	
}

Measured memory_bytes: 24156
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n;cin>>n;
	vector<int> p(n);
	rep(i,n)cin>>p[i];
	int ans=0;
	for(int i=1;i<n-1;i++){
		if(p[i]>p[i-1]&&p[i]<p[i+1]||p[i]>p[i+1]&&p[i]<p[i-1])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	long long int ans=0;
	scanf("%d",&n);
	char s[n+10];
	scanf("%s",s);
	long long int countr=0;
	long long int countg=0;
	long long int countb=0;
	for(int i=0; i<n; i++){
		if(s[i]=='R'){
			countr++;
		}
		if(s[i]=='G'){
			countg++;
		}
		if(s[i]=='B'){
			countb++;
		}
	}
	ans=countr*countg*countb;
	long long int i=0;
	long long int j=1;
	long long int k=2;
	while(i<=n-3){
		if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]){
			ans--;
		}
		j++;
		k+=2;
		if(k>n-1){
			i++;
			j=i+1;
			k=i+2;
		}
	}

	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1704
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>b)
        printf("a > b\n");
    else if(a<b)
        printf("a < b\n");
    else
        printf("a == b\n");
    return 0;
}



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

int main(){
    int M,D;
    cin>>M>>D;
    ll ans=0;
    if(D>20){
        for(int i=21;i<=D;i++){
            int x=i/10, y=i%10;
            if(1<=x*y && x*y<=M && y>=2) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    ans = 0

    for i in range(1, N+1):
        if i % 2 != 0:
            ans += 1

    print(ans/float(N))

    # for i in range(N):
    #     A = list(map(int, input().split()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;
int main() {
	string s;
	cin >> s;
	bool tf = true;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == 'L') {
			tf = false;
		}
		if (i % 2 == 1 && s[i] == 'R') {
			tf = false;
		}
	}
	if (tf)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for _ in range(m)]

price = min(A)+min(B)
for x,y,c in xyc:
    k = A[x-1] + B[y-1] - c 
    if k < price:
        price = k
        
print(price)

Measured memory_bytes: 38560
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P; 
typedef tuple<ll,ll,ll> T;
const ll INF = 1e8;

int main(){
	string s;
	cin >> s;
	set<char> st;
	for(auto i : s){
		st.insert(i);
	}
	if(s.size()==st.size())
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    vi32 l(10);
    char c;
    rep(i, 10) if (!(cin >> l[i] >> c)) return;
    int v1, v2;
    cin >> v1 >> c >> v2;
    int L = accumulate(all(l), 0);
    f80 t = (f80) L / (v1 + v2);
    f80 x = t * v1;
    int sum = 0;
    rep(i, 10) {
      if (x <= sum + l[i]) {
        cout << i + 1 << '\n';
        break;
      }
      sum += l[i];
    }
  }
}



Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<long long>  X;
    X.resize(N);
    for(int i = 0 ; i < N ; i++) cin >> X[i];

    vector<long long> orgX = X;
    sort(X.begin() , X.end());


    int t = N/2;
    long long a = X[t-1];
    long long b = X[t];

    for(int i = 0 ; i < N ; i++){
        if(a < orgX[i]){
            cout << a << endl;
        }
        else cout << b << endl;
    }

    return 0;
}


Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();

    UnionFind uf = new UnionFind(N);

    for (int i = 0; i < M; i++) {
      int left = scanner.nextInt() - 1;
      int right = scanner.nextInt() - 1;
      int dist = scanner.nextInt();

      Result lr = uf.find(left);
      Result rr = uf.find(right);

      if (lr.root == rr.root) {
        if (rr.dist - lr.dist != dist) {
          System.out.println("No");
          return;
        }
      } else {
        uf.union(left, right, dist);
      }
    }

    System.out.println("Yes");
  }

  static class UnionFind {
    private final int[] table;
    private final int[] delta;
    private final int[] ranks;

    UnionFind(int size) {
      this.table = new int[size];
      this.delta = new int[size];
      this.ranks = new int[size];
      for (int i = 0; i < size; i++) {
        table[i] = i;
      }
    }

    Result find(int x) {
      if (table[x] != x) {
        Result res = find(table[x]);
        table[x] = res.root;
        delta[x] += res.dist;
      }
      return new Result(table[x], delta[x]);
    }

    void union(int x, int y, int dist) {
      Result xRoot = find(x);
      Result yRoot = find(y);
      if (xRoot.root == yRoot.root) return;

      if (ranks[xRoot.root] < ranks[yRoot.root]) {
        Result tmp = xRoot;
        xRoot = yRoot;
        yRoot = tmp;
        dist = -dist;
      }

      table[yRoot.root] = xRoot.root;
      delta[yRoot.root] = xRoot.dist + dist - yRoot.dist;
      if (ranks[xRoot.root] == ranks[yRoot.root]) ranks[xRoot.root]++;
    }
  }
  
  static class Result {
    public final int root;
    public final int dist;

    Result(int root, int dist) {
      this.root = root;
      this.dist = dist;
    }
  }
}


Measured memory_bytes: 153248
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    int x;
    cin >>  x;
    if (x == 7 || x == 5 || x == 3) cout << "YES" << endl;
    else cout << "NO" << endl;    
    return 0;
}



Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1)+(x&1);
}
int main(){
    fast_io

    string s;
    cin>>s;

    string s0,s1;
    int ans=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            if(s[i+1]=='0') {
                s[i+1]='1';
            }
            else {
                s[i+1]='0';
            }
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
  string S;
  i64 Q;
  cin >> S >> Q;
  list<char> ans;
  for (char i : S)
    ans.push_back(i);
  bool t = true;
  for (i64 _ = 0; _ < Q; _++)
  {
    i64 T;
    cin >> T;
    if (T == 1)
      t = !t;
    else
    {
      i64 F;
      char C;
      cin >> F >> C;
      if (t)
      {
        if (F == 1)
          ans.push_front(C);
        else
          ans.push_back(C);
      }
      else
      {
        if (F == 1)
          ans.push_back(C);
        else
          ans.push_front(C);
      }
    }
  }
  if (!t)
    reverse(ans.begin(), ans.end());
  for (char i : ans)
    cout << i;
  cout << endl;
  return 0;
}


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

using namespace std;

#define int long long
#define tie() ios_base :: sync_with_stdio(0); cin.tie(0) ; cout.tie(0)
#define err(x) cerr << #x << " is : " << x << endl
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()

const int N = 1e5 + 20;
const int mod = 1e9 + 7;

int32_t main()
{
      tie();
      int t = 1;
      //cin >> t;
      while(t--)
      {
            int n , k;
            cin >> n >> k;
            int mn = LLONG_MAX;
            map <int , int> vis;
            n = n % k;
            while(true)
            {
                  if(vis[n])
                        break;
                  vis[n] = true;
                  n = abs(n - k);
                  mn = min(mn , n);
            }
            cout << mn << endl;
      }
      return 0;
}


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

bool stringPalindrome(string s, long long int start, long long int end){

    while (start<end)
    {
        if(s[start]!=s[end-1]) return false;
        start++;
        end--;
    }
    return true;
}

int main(){

    string s;
    cin >> s;
    int N;
    N=s.length();
    if(stringPalindrome(s,0,N) && stringPalindrome(s,0,N/2) && stringPalindrome(s,(N/2)+1,N)) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
from collections import*
z,v,a=input,range,print
h,w,k=map(int,z().split());r,s,t,u=map(lambda x:int(x)-1,z().split())
b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0
d=deque([(r,s)])
while d:
  x,y=d.popleft()
  if(x==t)&(y==u):exit(a(l[x][y]))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=l[x][y]:break
      if l[p][q]<0:d+=[(p,q)];l[p][q]=l[x][y]+1
a(-1)

Measured memory_bytes: 93860
from collections import defaultdict
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

N,M = map(int, input().split())
S = list(input())
T = list(input())

"""
存在するならば長さは必ずLである。
Lで存在しない場合、n * Lでも存在しない
"""
L = lcm(N, M)

X = defaultdict(str)

for p,s in enumerate(S):
    X[p * L // N] = s

flag = True
for q,t in enumerate(T):
    if X[q * L // M] and X[q * L // M] != t:
        flag = False
    else:
        X[q * L // M] = t

ans = L if flag else -1
print(ans)

Measured memory_bytes: 18652
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto s = sread();
    if (s.solve())
        writeln("YES");
    else
        writeln("NO");
}

bool solve(string s)
{
    auto key = "keyence";
    if (s[0 .. key.length] == key)
        return true;
    if (s[$ - key.length .. $] == key)
        return true;

    long iter;
    while (s[iter] == key[iter])
        iter++;

    // s[$ - (key.length - iter) .. $].writeln();
    // key[iter .. $].writeln();
    return (s[$ - (key.length - iter) .. $] == key[iter .. $]);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2656
#include<iostream>
using namespace std;
int main()
{
  int n;
  string s;
  
  cin >> n;
  cin >> s;
  
  int cnt = 0;
  for(int i = 2; i < n; i++)
  {
    if(s[i - 2] == 'A' &&
       s[i - 1] == 'B' &&
       s[i] == 'C')
    {
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 384
N,M=map(int,input().split())
X=list(map(int,input().split()))

X=sorted(X)
between=[0]*(M-1)
answer=0

for i in range(1,M):
    between[i-1]=X[i]-X[i-1]
bet=sorted(between)
for i in range(M-N):
    answer+=bet[i]

print(answer)

Measured memory_bytes: 13968
#include<algorithm>
#include<string.h>
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	long long cnt=1;
	char c=s[0];
	for(int i=1; i<n; i++){
		if(c!=s[i]){
			c=s[i];
			cnt++;
		}
	}
	
	cout<<cnt<<endl;
	
	return 0;
}

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

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

    int n, a, b, p;
    cin >> n >> a >> b;
    int q[3] = {};
    for (int i = 0; i < n; ++i) {
        cin >> p;
        q[0] += p <= a;
        q[1] += a < p && p <= b;
        q[2] += b < p;
    }

    cout << min(q[0], min(q[1], q[2])) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d = 0, e = 0, count = 0;
	cin >> a>>b>>c>>d;
	if (std::abs(c - a) <= d) {
		cout << "Yes" << endl;
	}
	else if (std::abs(b - a) <= d && std::abs(c - b) <= d) {
		cout << "Yes" << endl;
	}
	else { cout << "No" << endl; }
	return 0;
}

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

int N;
struct Point {
  int x, y;
};

vector<Point> r, b;

const int INF = 1e9;
const int MAX_V = 202;

struct edge { int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

void addEdge(int from, int to, int cap){
  G[from].push_back((edge) {to, cap, static_cast<int>(G[to].size())});
  G[to].push_back((edge) {from, 0, static_cast<int>(G[from].size()) - 1});
}

int dfs(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t) {
  int flow = 0;
  while(true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if( f == 0 ) return flow;
    flow += f;
  }
}

int main () {
  cin >> N;
  r.resize(N), b.resize(N);
  rep(i,N) {
    cin >> r[i].x >> r[i].y;
    addEdge(0, i+1, 1);
  }
  rep(i,N) {
    cin >> b[i].x >> b[i].y;
    addEdge(N+1+i, 2*N + 1, 1);
  }

  rep(i,N) {
    rep(j,N) {
      if(r[i].x < b[j].x && r[i].y < b[j].y) {
        addEdge(i+1, j+N+1, INF);
      }
    }
  }

  cout << maxFlow(0, 2*N + 1) << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
int main()
{
    string s ;
    cin>>s ;
    if(s.empty())
    {
        cout<< "ABC "<<endl ;
    }else{

    if(s[s.size()-2]=='B')
        cout<<"ARC"<<endl ;
    else
    cout<<"ABC"<<endl ;
    }

}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K <= A)
    cout << K << endl;
  else if (K <= A + B)
    cout << A << endl;
  else
    cout << 2*A + B - K << endl;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n,k,s;

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return s*t;
}

int main(void){
	n=read();
	k=read();
	s=read();
	for(int i=1;i<=k;i++)
	printf("%d ",s);
	if(s!=1e9){
		for(int i=k+1;i<=n;i++)
		printf("%d ",s+1);
	}
	else{
		for(int i=k+1;i<=n;i++)
		printf("1 ");
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

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

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

    int total = 0;
    rep(i, n) total += p[i];

    cout << total << endl;

    return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	long long sum = 0;

	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		sum += i;
	}

	cout << sum;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<int, ll> PIL;
typedef pair<ll, int> PLI;
const ll INF = 1e+18;

vector<PIL> e[100001];

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

  for(int i = 0; i < n-1; i++){
    int a, b, c;
    cin >> a >> b >> c;
    e[a].push_back(make_pair(b, c));
    e[b].push_back(make_pair(a, c));
  }

  int q, k;
  cin >> q >> k;

  ll dist[100001];
  for(int i = 1; i <= n; i++) dist[i] = INF;
  dist[k] = 0;
  priority_queue<PLI, vector<PLI>, greater<PLI> > que;
  que.push(PLI(0, k));

  while(!que.empty()){
    PLI p = que.top();
    que.pop();

    int v = p.second;
    if(dist[v] < p.first) continue;
    for(auto itr = e[v].begin(); itr != e[v].end(); itr++){
      if(dist[itr->first] > dist[v] + itr->second){
        dist[itr->first] = dist[v] + itr->second;
        que.push(PLI(dist[itr->first], itr->first));
      }
    }
  }

  int x[100000], y[100000];
  for(int i = 0; i < q; i++){
    cin >> x[i] >> y[i];
  }

  for(int i = 0; i < q; i++){
    cout << dist[x[i]] + dist[y[i]] << endl;
  }


  return 0;
}

Measured memory_bytes: 11632
#include<bits/stdc++.h>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int n,s=0;cin>>n;
    int a[n];
    for(auto& x:a) cin>>x,s+=x;
    int m;cin>>m;
    while(m--)
    {
    	int v,b;cin>>v>>b;
    	cout<<s-a[v-1]+b<<endl;
    }
    return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, M;
set<PII> P[100010];
string ans[100010];


void solve(){
	repe(i, 1, N){
		int x = 1;
		for(auto it = P[i].begin();it != P[i].end();it++, x++){
			string u;
			rep(j, 0, 6-((int)log10(i)+1)) u += '0';
			u += to_string(i);
			string d;
			rep(j, 0, 6-((int)log10(x)+1)) d += '0';
			d += to_string(x);
			ans[it->se] = u+d;
		}
	}
	repe(i, 1, M) cout << ans[i] << endl;
}


signed main(){
	cin >> N >> M;
	repe(i, 1, M){
		int p, y;
		cin >> p >> y, p;
		P[p].insert({ y, i });
	}

	solve();

	return 0;
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long X;
  cin >> X;
  int ans = 0;
  long long cur = 100;
  for (; cur < X; ans++) {
    cur = (__int128_t)cur * 101 / 100;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	int Ndays;
	scanf("%d", &Ndays);
	int a, b, c;
	int A = 0, B = 0, C = 0;
	while (Ndays--) {
		scanf("%d %d %d", &a, &b, &c);
		int AA = max(B, C) + a;
		int BB = max(A, C) + b;
		int CC = max(A, B) + c;
		A = AA, B = BB, C = CC;
	}
	printf("%d", max(max(A, B), C));
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
int main()
{
int used[1000000];
int num;
int i,j,left,right;
scanf("%d",&num);
for(i=0;i<100005;i++)
    used[i] = 0;
for(i=0;i<num;i++)
{
scanf("%d",&left);
scanf("%d",&right);
for(j=left;j<=right;j++)
    used[j]++;
}
j=0;
for(i=0;i<100005;i++)
    if(used[i]!=0)
        j++;
printf("%d",j);
return 0;
}

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

int main(){
  int D[7],C;
  string S;
  for(int i=1;i<=6;i++){
    cin>>D[i];
  }
   cin>>S;
  for(int i=0;i<S.length();i++){
    if(S[i]=='S'){
      C=D[1],D[1]=D[5],D[5]=D[6],D[6]=D[2],D[2]=C;
    }else if(S[i]=='W'){
      C=D[1],D[1]=D[3],D[3]=D[6],D[6]=D[4],D[4]=C;
    }else if(S[i]=='E'){
      C=D[1],D[1]=D[4],D[4]=D[6],D[6]=D[3],D[3]=C;
    }else if(S[i]=='N'){
      C=D[1],D[1]=D[2],D[2]=D[6],D[6]=D[5],D[5]=C;
    }
  }
  cout <<D[1]<<endl;
}

Measured memory_bytes: 3152
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, K;
int main()
{
  cin >> N >> K;
  ll res = 0;
  if (K % 2 != 0)
  {
    ll a = N / K;
    res = a * a * a;
    cout << res << endl;
    return 0;
  }
  else
  {
    ll a = N / K;
    ll b = K / 2;
    res = a * a * a;
    if (N >= b)
    {
      ll c = (N - b) / K + 1;
      res += c * c * c;
    }

    cout << res << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
string  MAX(string x,string y){
    if(x.size()>y.size()) return x;
    if(x.size()<y.size()) return y;
    return max(x,y);
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    rep(i,m) cin>>a.at(i);
    vector<int> nums={-1,2,5,5,4,5,6,3,7,6};
    
    vector<string> dp(20000,""); //dp[i]->i本のhマッチを使って作れる最大の整数
    rep(i,n){
        if(i!=0&&dp.at(i)=="") continue;
        rep(j,m){
            int A=a.at(j);
            int N=nums.at(A);
            dp.at(i+N)=MAX(dp.at(i+N),dp.at(i)+to_string(A));
        }
    }
    
    cout<<dp.at(n)<<endl;
}



Measured memory_bytes: 33152
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
    }

    int len = INF;
    vector<int> res;
    for (int s = 0; s < n; s++)
    {
        vector<int> d(n, INF);
        vector<int> prev(n, -1);
        queue<int> que;
        que.push(s);
        d[s] = 0;
        while (que.size())
        {
            int now = que.front();
            que.pop();
            for (auto next : g[now])
            {
                if (d[next] == INF)
                {
                    d[next] = d[now] + 1;
                    prev[next] = now;
                    que.push(next);
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (s == i || d[i] == INF)
            {
                continue;
            }
            for (auto next : g[i])
            {
                if (next != s)
                {
                    continue;
                }
                vector<int> tmp;
                tmp.push_back(s);
                int rec = i;
                while (rec != s)
                {
                    tmp.push_back(rec);
                    rec = prev[rec];
                }
                if (len > tmp.size())
                {
                    len = tmp.size();
                    res = tmp;
                }
            }
        }
    }
    if (len == INF)
    {
        cout << "-1" << endl;
    }
    else
    {
        cout << res.size() << endl;
        for (auto ans : res)
        {
            cout << ans + 1 << endl;
        }
    }
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main() {

	//N人の子供
	int N;
	//キャンディカウント用
	int count_candy = 0;

	//子供の人数を入力
	cin >> N;

	//必要なキャンディの個数を求める
	for (int i = 0; i < N; i++) {
		count_candy = count_candy + (i + 1);
	}

	//出力
	cout << count_candy << endl;

}

Measured memory_bytes: 256
M = int(input())
A=list(map(int,input().split()))
A.sort()
ma=A[-1]
is_prime = [True] * (ma + 1)
for i in A:
    if not is_prime[i]:
        continue
    for j in range(i * 2, ma + 1, i):
        is_prime[j] = False
k=[i for i in range(ma + 1) if is_prime[i]]
N=[]
if len(A)==1:
    print(1)
else:
    if A[0] !=A[1]:
        N.append(A[0])
    for i in range(1,len(A)-1):
        if A[i-1]!=A[i] and A[i]!=A[i+1]:
            N.append(A[i])
    if A[len(A)-2] != A[len(A)-1]:
        N.append(A[len(A)-1])
    s=set(k) & set(N)
    print(len(s))

Measured memory_bytes: 122200
def is_prime(x):
    # Perform prime number discrimination for odd numbers of 3 or more.
    return pow(2, x - 1, x) == 1

def solve():
    n = int(input())
    print("{}: ".format(n), end='')
    if is_prime(n):
        print(n)
    else:
        ans = []
        while n % 2 == 0:
            n //= 2
            ans.append(2)
        d = 3
        while d <= n ** 0.5:
            if is_prime(d):
                while n % d == 0:
                    n //= d
                    ans.append(d)
            d += 2
        if is_prime(n):
            ans.append(n)
        print(*ans)

solve()

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

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll ans;
  if(k % 2 == 1){
    ans = b-a;
  }
  else ans = a-b;
  if(abs(ans) > 1000000000000000000){
    puts("Unfair");
  }
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);


	if(a==b+c || b==c+a || c==a+b){
		printf("Yes\n");
	}else{
		printf("No\n");
	}





	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(string& s, int K) {
        int n = s.length();
        vector<int> A;
        for (int i = 0; i < n; ++i) {
            int cnt = 1;
            while (i + 1 < n && s[i] == s[i + 1]) {
                ++i;
                ++cnt;
            }
            A.push_back(cnt);
        }

        int res = n - A.size();
        n = A.size();
    
        for (int i = 1; i < n && K > 0; i += 2, --K) {
            if (i + 1 < n) {
                res += 2;
            } else {
                res += 1;
            }
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int K;
    cin >> K;
    string s;
    cin >> s;
    Solution sol;
    cout << sol.solve(s, K) << "\n";

    return 0;
}

Measured memory_bytes: 972
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

ll dp[105][100005];
vll wt,val;

ll cal(ll idx,ll weight)
{
	if(idx==-1)
		return 0;
	if(dp[idx][weight]!=-1)
	{
		return dp[idx][weight];
	}
	else
	{
		if(weight>=wt[idx])
			dp[idx][weight]=max(cal(idx-1,weight-wt[idx])+val[idx],cal(idx-1,weight));
		else dp[idx][weight]=cal(idx-1,weight);
		return dp[idx][weight];
	}
}

int main()
{
	fastIO
	//inp_out();
	ll n,W;
	cin>>n>>W;
	memset(dp,-1,sizeof(dp));
	wt.resize(n);
	val.resize(n);
	for(ll i=0;i<n;++i)
	{
		cin>>wt[i]>>val[i];
	}
	cout<<cal(n-1,W);
	return 0;
}



Measured memory_bytes: 82304
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
  ll n,a,b,ans;
  
  cin >> n >> a >> b;
  
  ans=n/(a+b)*a+min(a,n%(a+b));
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in(){int x;std::cin>>x;return x;}

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  int N;
  vi t;
  cin>>N;
  vi x,y;
  int a,b,c;
  x.pb(0);
  y.pb(0);
  t.pb(0);
  rep(i,N){
    cin>>a>>b>>c;
    t.pb(a);
    x.pb(b);
    y.pb(c);
  }

  rep1(i,N+1){
    int difx = abs(x[i]-x[i-1]);
    int dify = abs(y[i]-y[i-1]);
    int dift = abs(t[i]-t[i-1]);
    if(dify + difx > dift){
      print("No");
      return 0;
    }else{
      int tmp = dift - dify - difx ;
      if(tmp % 2 == 1){
        print("No");
        return 0;
      }    
    }
    
  }
  print("Yes");
  return 0;
}


Measured memory_bytes: 1644
#include<bits/stdc++.h>
using namespace std;
bool first_C=true;
bool first_F=true;
int C_POS=-1;
int rp;
char command[10000];
int main()
{
	gets(command);
	for(int i=0;i<strlen(command);i++)
	{
		if(command[i]=='C' && first_C)
		{
			rp++;
			first_C=!first_C;
			C_POS=i;
		}
		if(command[i]=='F' && first_F && i>C_POS && C_POS!=-1)
		{
			rp++;
			first_F=!first_F;
		}
		if(rp==2)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    vector<ll> x(n-1), y(n-1);
    deque<ll> neg, pos;
    rep(i, n) {
        if (a[i] < 0) neg.push_back(a[i]);
        else pos.push_back(a[i]);
    }

    int cnt = 0;
    if (pos.size() == 0) {
        x[0] = neg[n-1]; neg.pop_back();
        y[0] = neg[n-2]; neg.pop_back();
        pos.push_back(x[0] - y[0]);
        cnt++;
    } else if (neg.size() == 0) {
        x[0] = pos[0]; pos.pop_front();
        y[0] = pos[1]; pos.pop_front();
        neg.push_back(x[0] - y[0]);
        cnt++;
    }

    while (neg.size() > 1) {
        x[cnt] = pos[0]; pos.pop_front();
        y[cnt] = neg[0]; neg.pop_front();
        pos.push_back(x[cnt] - y[cnt]);
        cnt++;
    }
    while (pos.size() > 1) {
        x[cnt] = neg[0]; neg.pop_front();
        y[cnt] = pos[0]; pos.pop_front();
        neg.push_back(x[cnt] - y[cnt]);
        cnt++;
    }
    ll ans = pos[0] - neg[0];
    x[n-2] = pos[0];
    y[n-2] = neg[0];
    cout << ans << endl;
    rep(i, n-1) {
        cout << x[i] << " " << y[i] << endl;
    }
}



Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int h,w;
  cin >> h >> w;
  char c[h][w];
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
    }
  }
  int x[8]={1,1,0,-1,-1,-1,0,1};
  int y[8]={0,1,1,1,0,-1,-1,-1};
  rep(i,h){
    rep(j,w){
      if(c[i][j]!='#'){
        char sum='0';
        rep(k,8){
          int xx=x[k]+j;
          int yy=y[k]+i;
          if(xx>=w||xx<0||yy>=h||yy<0){
            continue;
          }
          if(c[yy][xx]=='#'){
            sum++;
          }
        }
        c[i][j]=sum;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << c[i][j];
    }
    cout << endl;
  }
}

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

int main() {
  int n,d;
  
  cin >> n >> d;
  
  int p;
  
  if(n%(2*d+1) == 0)
    p = n/(2*d+1);
  
  else
    p = n/(2*d+1)+1;
  
  cout << p << endl;
}

Measured memory_bytes: 256
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

int main(){
    cpp();
    ll x, n;
    cin>>x>>n;
    set<ll> s;
    for(ll i=-150; i<=150; i++){
        s.insert(i);
    }
    for(ll i=0; i<n; i++){
        ll temp;
        cin>>temp;
        s.erase(temp);
    }
    ll ans;
    ll minDiff=INT_MAX;
    for(auto ele: s){
        if(llabs(x-ele)<minDiff){
            minDiff = llabs(x-ele);
            ans = ele;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3672
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int mod=998244353;
inline int ad(int x){return x>=mod?x-mod:x;}
int f[3010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
   	int n=read(),m=read(),ans=0;
   	for(int i=1;i<=n;i++)
   	{
   		int d=read();
		if(d<m)ans=ad(ans+1LL*f[m-d]*(n-i+1)%mod);
		if(d==m)ans=ad(ans+1LL*i*(n-i+1)%mod);
   		for(int j=m;j>d;j--)f[j]=ad(f[j]+f[j-d]);
   		f[d]=ad(f[d]+i);
   	}pr2(ans);
    return 0;
}

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

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

string input, ss;
int a[3], it, cnt;

int Not(int x) {
    return 2-x;
}

int And(int x, int y) {
    if (x*y == 0) return 0;
    if (x == 2 && y == 2) return 2;
    return 1;
}

int Or(int x, int y) {
    if (x == 2 || y == 2) return 2;
    if (x == 1 || y == 1) return 1;
    return 0;
}

int parse() {
    char c = ss[it++];
    if ('0' <= c && c <= '2') return c-'0';
    if (c == '-') return Not(parse());

    int x = parse();
    c = ss[it++];
    int y = parse();
    ++it;
    return c == '*' ? And(x, y) : Or(x, y);
}

void dfs(int i) {
    if (i == 3) {
        ss = input;
        for (char& c : ss) {
            if (c == 'P') c = a[0]+'0';
            if (c == 'Q') c = a[1]+'0';
            if (c == 'R') c = a[2]+'0';
        }
        it = 0;
        if (parse() == 2) cnt++;
        return ;
    }

    rep (j,3) {
        a[i] = j;
        dfs(i+1);
    }
}

int main() {
    while (cin >> input && input != ".") {
        rep (i,3) a[i] = i;
        cnt = 0;
        dfs(0);
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int mod = 1e6;

vector<vii> adjlist;

main(){
    int n,m;
    cin>>n>>m;
    int a,b;
    adjlist.assign(n+1,vii());
    while(m--){
        cin>>a>>b;
        adjlist[a].push_back(ii(b,1));
        adjlist[b].push_back(ii(a,1));
    }
    queue<int>q; q.push(1);
    vector<int> ans(n+1,mod);
    while(!q.empty()){
        int u = q.front();q.pop();
        for(int i=0;i<adjlist[u].size();i++){
            ii v = adjlist[u][i];
            if(ans[v.first] == mod){
                ans[v.first] = u;
                q.push(v.first);
            }
        }
    }
    cout<<"Yes"<<"\n";
    for(int i=2;i<=n;i++) cout<<ans[i]<<'\n';
}

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

int main(){
    int n,l;
    cin>>n>>l;
    vector<string>s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3608