akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(void)
{
    int r,c,i,j,xy[101][101];
 
    scanf("%d %d",&r,&c);
    for(i=0;i<r+1;i++)
    {
        for(j=0;j<c+1;j++)
        {
            xy[i][j] = 0;
        }
    }
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            scanf("%d",&xy[i][j]);
        }
    }
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            xy[i][c] += xy[i][j];
        }
    }
    for(i=0;i<r;i++)
    {
        for(j=0;j<c+1;j++)
        {
            xy[r][j] += xy[i][j];
        }
    }
    for(i=0;i<r+1;i++)
    {
        for(j=0;j<c+1;j++)
        {
            printf("%d",xy[i][j]);
            if(j!=c)
            {
                printf(" ");
            }
        }
            printf("\n");
    }
    return 0;
}


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

int n;
vector<int> A(50);

int solve(int i, int m){
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(void){
    int q, M;
    cin >> n;
    for (int i = 0; i < n; i++)  cin >> A[i];
    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> M;
        if (solve(0, M))    cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> par(mx);

int find(int x){
  if(par[x]==x){ return x; } else { return par[x]=find(par[x]); }
}

void unite(int x, int y){
  x=find(x);
  y=find(y);
  par[y]=x;
}

int main(){
  int n,m,ans=0; 
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n){ cin >> a[i]; a[i]--; }
  rep(i,n){ par[i] = i; }
  rep(i,m){ 
  	int x, y;
  	cin >> x >> y;
  	unite(x-1,y-1);
  }
  rep(i,n){if(find(i)==find(a[i])){ ans++; }}
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 44
int F[MAX]={};
int fibonacci(int);

int main()
{
  int n,memo;

  scanf("%d",&n);

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

  return 0;
}

int fibonacci(int n){
  if(n==0||n==1) return F[n]=1;
  if(F[n]!=0) return F[n];
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

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

typedef long long LL;
typedef long double LD;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    LL a, b, c, k;
    cin >> a >> b >> c >> k;
    LL ans = 0;
    if(a >= k){
        ans = k;
    }else if(a + b >= k){
        ans = a;
    }else{
        ans = a - (k - a - b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

const ll modd=1e9+7;
const ll inf=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*    
         -> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         -> cout<<"Case #"<<casee<<": "<<ans<<endl; // for google kickstart

*/

/*-----------------------------------------------------------------------------------------------*/

int main(){
   fastt;
   
   ll m,k;
   cin>>m>>k;

   if(k>=(1LL<<m)){
      cout<<-1<<endl;
      return 0;
   }

   if(m==1 && k==0){
      cout<<0<<" "<<0<<" "<<1<<" "<<1;
      cout<<endl;
      return 0;
   }

   if(m==1 && k==1){
      cout<<-1<<endl;
      return 0;
   }

   for(ll i=0;i<(1LL<<m);i++){
      if(i==k) continue;
      cout<<i<<" ";
   }

   cout<<k<<" ";

   for(ll i=(1LL<<m)-1;i>=0;i--){
      if(i==k) continue;
      cout<<i<<" ";
   }

   cout<<k<<" ";

   cout<<endl;

   return 0;
}


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

int main(){

  while(1){
    int n,m;
    cin >> n;
    if(n==0) break;
    int map[25][25]={},ans=0;

    for(int i=0;i<n;++i){
      int x ,y;
      cin >> x >> y;
      map[y][x]=1;
    }
    cin >> m;
    int nx=10,ny=10;
    for(int i=0;i<m;++i){
      string s;
      int d,dx,dy;
      cin >> s >> d;
      if(s=="N"){
	dy=1;dx=0;
      }
      else if(s=="S"){
	dy=-1;dx=0;
      }
      else if(s=="E"){
	dy=0;dx=1;
      }
      else if(s=="W"){
	dy=0;dx=-1;
      }

      for(int j=0;j<d;j++){
	nx=nx+dx; ny=ny+dy;
	if(map[ny][nx] == 1){
	  ans++;
	  map[ny][nx] = 0;
	}
      }
    }
    if(ans == n)cout << "Yes" <<endl;
    else cout << "No" <<endl;


  }
  return 0;
}

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

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t unsigned long long

using namespace std;

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

  //sort(td.begin(), td.end(), [](auto& x, auto& y){return x[0] > y[0];});
  int n,a,b;
  std::cin >> n >> a >> b;

  int ma;

  ma = min(a,b);

  if(a + b - n > 0){
    std::cout << ma << " " << a + b - n << '\n';
  }else{
    std::cout << ma << " " << 0 << '\n';
  }


  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 n=sc.nextInt();
    int count=0;

    for (int i=1;i<=9;i++) {
      for (int j=1;j<=9;j++) {
         if (i*j==n) {
           count++;
         }
      }
    }

    if(count>0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

  }
}


Measured memory_bytes: 21844
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

V min_factor, prime;

void init(int n) {
  min_factor.resize(n + 1, 0);
  rrep(i, 2, n + 1) {
    if (min_factor[i] == 0) {
      min_factor[i] = i;
      prime.push_back(i);
    }
    for (int x : prime) {
      if (x * i > n || x > i) break;
      min_factor[x * i] = x;
    }
  }
}

vector<P> prime_factor(ll n) {
  vector<P> ret;
  while (n > 1) {
    if (ret.empty() || ret.rbegin()->fi != min_factor[n]) {
      ret.emplace_back(min_factor[n], 1);
    } else
      ++ret.rbegin()->se;
    n /= min_factor[n];
  }
  return ret;
}

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
U_MAP mp;

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

  init(ohara);
  cin >> n;
  rep(i, n) cin >> a[i];
  bool ju1 = true;
  rep(i, n) {
    auto v = prime_factor(a[i]);
    for (auto [x, t] : v) {
      mp[x]++;
      if (mp[x] >= 2) ju1 = false;
    }
  }
  if (ju1) {
    Cout("pairwise coprime");
    return 0;
  }
  ans = a[0];
  rrep(i, 1, n) ans = __gcd(ans, a[i]);
  if (ans == 1)
    Cout("setwise coprime");
  else
    Cout("not coprime");
  return 0;
}

Measured memory_bytes: 22836
d = int(input())
y = d % 7
if y == 0:
  print ('thu')
elif y == 1:
  print('fri')
elif y == 2:
  print('sat')  
elif y == 3:
  print('sun')
elif y == 4:
  print('mon')
elif y == 5:
  print('tue')
elif y == 6:
  print('wed')



Measured memory_bytes: 5592
import java.util.*

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val g = Array<MutableList<Int>>(n) { _ -> mutableListOf() }
    (1..m).forEach { _ ->
        val (x, y) = readLine()!!.split(' ').map { it.toInt() - 1 }
        g[x].add(y)
        g[y].add(x)
    }
    println("Yes")
    bfs(g, 0).forEach { println(it+1) }
}

fun bfs(g: Array<MutableList<Int>>, s: Int): Array<Int> {
    var ans = Array(g.size - 1) { _ -> 0 }
    var used = Array(g.size) { _ -> false }
    val que = ArrayDeque<Int>()
    que.add(s)
    used[s] = true
    while (que.isNotEmpty()) {
        val v = que.pop()
        g[v].forEach { to ->
            if (!used[to]) {
                used[to] = true
                ans[to - 1] = v
                que.add(to)
            }
        }
    }
    return ans
}


Measured memory_bytes: 88912
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010

int main(){
	lint n;cin>>n;
	string s;cin>>s;
	string t;cin>>t;
	lint ans=2*n;
	rep(i,n){
		bool ok=1;
		rep(j,n-i){
			if(s[i+j]!=t[j]){ ok=0;break; }
		}if(ok){ cout<<n+i<<endl;return 0; }
	}cout<<ans<<endl;
}

//sub-EOF


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

int N;
string S;
int CNT[100000][13];
const int MOD = 1e9 + 7;

int solve(int n, int d) {
    if(n == 0) {
        if(S[n] == '?') CNT[n][d] = (d < 10);
        else CNT[n][d] = (S[n] - '0') == d;
        return CNT[n][d];
    }
    if(CNT[n][d] != -1) return CNT[n][d];
    CNT[n][d] = 0;
    if(S[n] == '?') {
        for(int x = 0; x < 10; ++x) {
            CNT[n][d] = (CNT[n][d] + solve(n - 1, 4 * (d - x + 13) % 13)) % MOD;
        }
    } else {
        CNT[n][d] = (CNT[n][d] + solve(n - 1, 4 * (d - S[n] + '0' + 13) % 13)) % MOD;
    }
    return CNT[n][d];
}

int main() {
    cin >> S;
    N = S.size();
    memset(CNT, -1, sizeof(CNT));
    cout << solve(N - 1, 5) << "\n";
}

Measured memory_bytes: 11776
N = int(input())
a = list(map(int, input().split()))
A_total = 0
B_total = 0
A_current = 0
B_current = 0
count = 0
while not len(a) == 0:
  if count%2 == 0:
    A_current = max(a)
    a.remove(A_current)
    A_total += A_current
    count += 1
  else:
    B_current = max(a)
    a.remove(B_current)
    B_total += B_current
    count += 1

print(A_total - B_total)

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int h,w,list[16][16],cnt;
void bfs(int x,int y){
	int dx[] = {0,1},dy[] = {1,0},tx,ty;
	if(y == (h-1) && x == (w-1)){
		++cnt;
		return;
	}
	for(int i = 0;i < 2;++i){
		tx = x + dx[i];
		ty = y + dy[i];
		if(tx < w && ty < h){
			if(!list[ty][tx]) bfs(tx,ty);
		}
	}
	return;
}
int main(){
	int n,x,y;
	while(cin >> w >> h,w){
		cin >> n;
		cnt = 0;
		memset(list,0,sizeof(list));
		for(int i = 0;i < n;++i){
			cin >> x >> y;
			--x;
			--y;
			++(list[y][x]);
		}
		bfs(0,0);
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    H = int(input())

    depth = 0
    while H > 0:
        H //= 2
        depth += 1

    ans = 2 ** depth - 1
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9936
#include<bits/stdc++.h>
#define ll long long
#define re register
#define cs const

using std::cerr;
using std::cout;

int mod=998244353;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int dec(int a,int b){return a-b<0?a-b+mod:a-b;}
inline int mul(int a,int b){ll r=(ll)a*b;return r>=mod?r%mod:r;}
inline void Inc(int &a,int b){a+=b-mod;a+=a>>31&mod;}
inline void Dec(int &a,int b){a-=b;a+=a>>31&mod;}
inline void Mul(int &a,int b){a=mul(a,b);}

cs int N=6e3+7;

int n;
int f[N][N+N];

void Main(){
	scanf("%d%d",&n,&mod);
	f[0][N]=1;int ans=0;
	for(int re i=1;i<=3*n;++i){
		int l=N-i+1,r=N+i-1;
		for(int re j=l;j<=r;++j){
			if(i>0)Inc(f[i][j+1],f[i-1][j]);
			if(i>1)Inc(f[i][j-1],mul(f[i-2][j],i-1));
			if(i>2)Inc(f[i][j],mul(f[i-3][j],(i-1)*(i-2)));
		}
	}for(int re i=N;i<=N+3*n;++i)
		Inc(ans,f[3*n][i]);
	cout<<ans<<"\n";
}

inline void file(){
#ifdef zxyoi
	freopen("D.in","r",stdin);
#endif
}signed main(){file();Main();return 0;}

Measured memory_bytes: 280064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll N,M;
  cin >> N >> M;
  ll h[N];
  for(ll i=0;i<N;i++){
    cin >> h[i];
  }
  vector<vector<int> >G(N);
  for(ll i=0;i<M;i++){
    ll a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans = 0;
  for(ll k=0;k<N;k++){
    bool ok=true;
    for(auto n:G[k]){
      if(h[k]<=h[n]) ok=false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

ll solve(vector<ll>& as, vector<ii>& cs)
{
    sort(as.begin(), as.end());
    sort(cs.begin(), cs.end(), greater<ii>());

 //   cout << "as = ";
  //  for (auto a : as)
   //     cout << a << ' ';
    //cout << endl;

    int L = 0;

    for (auto c : cs)
    {
        auto x = c.first, m = c.second;
        int pos = lower_bound(as.begin() + L, as.end(), x) - as.begin();

//cout << "x = " << x << ", pos = " << pos << ", m = " << m << ", L = " << L << endl;
        while (m-- and L < pos)
            as[L++] = x; 

    //cout << "as = ";
    //for (auto a : as)
     //   cout << a << ' ';
    //cout << endl;
    }

    ll ans = 0;

    for (auto a : as)
        ans += a;

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ll> as(N);

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

    vector<ii> cs(M);

    for (int i = 0; i < M; ++i)
        cin >> cs[i].second >> cs[i].first;

    auto ans = solve(as, cs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2560
def solve():
    N, W = map(int, input().split())
    w, v = [0] * N, [0] * N
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    
    dp = [0] * (W + 1)
    for i in range(N):
        for j in range(W - w[i], -1, -1):
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i])
    print(dp[W])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39792
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		
		Set<Character> set = new HashSet<>();
		for(int i = 0;i < s.length();++i)
			set.add(s.charAt(i));
		
		if(set.size() == 26)
			System.out.println("None");
		else
			for(int i = 0;i < 26;++i)
				if(!set.contains((char)('a' + i))) {
					System.out.println((char)('a' + i));
					break;
				}
	}
}


Measured memory_bytes: 27112
#include<iostream>
#include<stdio.h>
#include<math.h>

int main(){
  while(true){
    int n;
    std::cin >> n;
    if(n == 0) break;

    int s[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
      std::cin >> s[i];
      sum += s[i];
    }
    double m = (double)sum / n;
    double v = 0;
    for(int i = 0; i < n; i++){
      v += (m - s[i]) * (m - s[i]);
    }
    double sd = sqrt(v / n);
    printf("%f\n", sd);
  }

  return 0;
}



Measured memory_bytes: 3192
/*
 * Author: Utkal Sinha
 * Created on: 2020-08-29, Sat, 17:47
 * Problem:
 * Platfrom: General
 * */
#if USE_BOOST2
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
namespace bst = boost::multiprecision;
typedef bst::int1024_t vll; //int512_t or //int128_t
typedef bst::cpp_bin_float_100 vdouble;
#endif

#include <bits/stdc++.h>
using namespace std;
#define GETTIME std::chrono::system_clock::now()
#define DURATION std::chrono::duration<double>
#ifdef MY_DEV_ENV2
#define LOCALDEV
#endif
typedef long long ll;
typedef std::chrono::system_clock::time_point TPT;
static TPT starttime, endtime, timelimit;
static double problem_tle = 1.5;
static inline void calc_problem_end_time() {timelimit = starttime + std::chrono::milliseconds(int (problem_tle * 1000));}
// template end



void love() {
    long double d, t, s;
    cin >> d >> t >> s;
    long double t1 = d/s;
    if(t1 <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    srand(time(0));
#ifdef LOCALDEV
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
#ifdef LOCALDEV
    starttime = GETTIME;
    calc_problem_end_time();
#endif
    while(t--) love();
#ifdef LOCALDEV
    endtime = GETTIME;
    DURATION elapsed_seconds = endtime - starttime;
    DURATION time_limit_seconds = timelimit - starttime;
    clog << "Elapsed time: " << elapsed_seconds.count() << "s\n";
    clog << "Time limit: " << time_limit_seconds.count() << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    ll N, K;
    cin >> N >> K;
    ll ret = 0;
    if (K%2 == 0 && K/2 <= N) {
        ll Khalf = K/2;
        ll n = (N - Khalf)/K + 1LL;
        ret += n*n*n;
    }
    ll n = N/K;
    ret += n*n*n;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long inv[1000000] = {};
map<pair<long long,long long>, long long> stock;
long long combination(long long n, long long r) {
	if (stock[make_pair(n, r)]) return stock[make_pair(n, r)];
	if (r == 0) return stock[make_pair(n, r)] = 1;
	long long hoge = combination(n, r - 1);
	hoge *= (n - r+1);
	hoge %= MAX_MOD;
	hoge *= inv[r];
	hoge %= MAX_MOD;
	return stock[make_pair(n, r)] = hoge;
}
int main() {
#define int long long
	inv[1] = 1;
	for (int i = 2; i <= 300000; ++i){
		inv[i] = inv[MAX_MOD % i] * (MAX_MOD - MAX_MOD / i) % MAX_MOD;
	}
	int n;
	cin >> n;
	vector<int> hoge;
	REP(i, n+1) {
		int tmp;
		cin >> tmp;
		hoge.push_back(tmp);
	}
	int appeared = 0;
	int gekogeko = 0;
	map<int, int> already;
	for (int i = 0;i <= n;++i) {
		if (already[hoge[i]]) {
			appeared = i;
			gekogeko = already[hoge[i]] - 1;
			break;
		}
		already[hoge[i]] = i+1;
	}
	for (int i = 1;i <= n;++i) {
		long long ans = combination(n, i);
		ans += combination(n, i - 1);
		if (gekogeko+n-appeared >= i-1){
			ans -= combination(gekogeko+n-appeared, i - 1);
		}
		ans %= MAX_MOD;
		ans += MAX_MOD;
		ans %= MAX_MOD;
		cout << ans << endl;
	}
	cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 19572
#include <stdio.h>
char str[55];
int N,K; 
int main(){
  scanf("%d %d",&N,&K);
  scanf("%s",str);
  if(str[K-1]=='A'){
    str[K-1]='a';
  }
  else if(str[K-1]=='B'){
    str[K-1]='b';
  }
  else {
    (str[K-1]='c');   
  }
  printf("%s",str);
  return 0;
}


Measured memory_bytes: 1680
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}



Measured memory_bytes: 2576
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e6 + 10, M = 5e5 + 10, S = 2e6 + 10;
const int mod = 998244353;

ll fact[S], finv[S];

ll choose(int n, int k);
ll pwr(ll x, ll e);

int main() {
	fast_cin();
	fact[0] = finv[0] = 1;
	for (int i = 1; i < S; ++i) {
		fact[i] = (i * fact[i - 1]) % mod;
		finv[i] = pwr(fact[i], mod - 2);
	}
	int n, m;
	cin >> n >> m;
	ll ans = 0;
	for (int i = 0; i <= min(n, m); ++i) {
		if ((3 * m - i) % 2) {
			continue;
		}
		ll sum = (3 * m - i) / 2;
		ll cur = choose(sum + n - 1, n - 1);
		if (sum > m) {
			ll temp = n * choose(sum - (m + 1) + n - 1, n - 1);
			temp %= mod;
			cur -= temp;
			cur += mod;
			cur %= mod;
		}
		cur *= choose(n, i);
		cur %= mod;
		ll temp = (n * choose(n - 1, i - 1)) % mod;
		temp *= choose((m - i) / 2 + n - 2, n - 2);
		temp %= mod;
		ans += cur;
		ans -= temp;
		ans += mod;
		ans %= mod;
		// cout << i << ' ' << cur << endl;
	}
	cout << ans << endl;
}

ll choose(int n, int k) {
	if (n < k or k < 0) {
		return 0;
	} else {
		ll ans = (fact[n] * finv[k]) % mod;
		ans = (ans * finv[n - k]) % mod;
		return ans;
	}
}

ll pwr(ll x, ll e) {
	ll res = 1;
	while (e) {
		if (e % 2) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		e /= 2;
	}
	return res;
}

Measured memory_bytes: 31616
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX_N 150000
#define INF 1355135500
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
int d[MAX_N], col[MAX_N];
vector<pair<int, int>>x[MAX_N];
void dijkstra(int s) {
	for (int i = 0; i<MAX_N; i++) {
		d[i] = INF;
		col[i] = WHITE;
	}
	d[s] = 0;
	col[s] = GRAY;
	Q.push(make_pair(0, s));
	while (!Q.empty()) {
		pair<int, int>p = Q.top();
		col[p.second] = BLACK;
		Q.pop();
		for (int i = 0; i<x[p.second].size(); i++) {
			int a = x[p.second][i].first;
			int b = x[p.second][i].second;
			if (d[a]>d[p.second] + b && col[a] != BLACK) {
				d[a] = d[p.second] + b;
				col[a] = GRAY;
				Q.push(make_pair(d[a], a));
			}
		}
	}
}

int main() {
	int n, m, s, a, b, c;
	cin >> n >> m >> s;
	for (int i = 0; i<m; i++) {
		cin >> a >> b >> c;
		x[a].push_back(make_pair(b, c));
	}
	dijkstra(s);
	for (int i = 0; i<n; i++) {
		if (d[i] == INF) { cout << "INF" << endl; }
		else { cout << d[i] << endl; }
	}
	return 0;
}

Measured memory_bytes: 14940
#include <iostream>

int main()
{
    int r, c;
    int x[101][101];
    int sum_r[101] = {0}, sum_l[101] = {0}, sum = 0;
    //r=縦,l=横

    std::cin >> r >> c;
    for (int i = 1; i < r + 1; i++)
    {
        for (int j = 1; j < c + 1; j++)
        {
            std::cin >> x[i][j];
            sum_r[j] += x[i][j];
            sum_l[i] += x[i][j];
            sum += x[i][j];
        }
    }

    for (int i = 1; i < r + 2; i++)
    {
        for (int j = 1; j < c + 2; j++)
        {
            if (i == r + 1) //最終行の処理
            {
                if (j == c + 1)
                {
                    std::cout << sum << std::endl;
                }
                else
                {
                    std::cout << sum_r[j] << ' ';
                }
            }
            else //それ以外の処理
            {
                if (j == c + 1)
                {
                    std::cout << sum_l[i] << std::endl;
                }
                else
                {
                    std::cout << x[i][j] << ' ';
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var l = cin.nextInt();
            var ss = new string[n];
            for (int i = 0; i < n; i++)
            {
                var s = cin.next();
                ss[i] = s;
            }

            Array.Sort(ss, StringComparer.OrdinalIgnoreCase);
            foreach (var item in ss)
            {
                Console.Write(item);
            }

        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int main(int argc, char const *argv[])
{
	int n, k;
	cin >> n >> k;
	
	vector<int> coins(n + 1);
	for (int i = 0; i < n; ++i) cin >> coins[i + 1];

	vector<int> dp(k + 1, false);
	for (int i = 1; i <= k; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (coins[j] > i) continue;
			if (!(dp[i-coins[j]])) {
				dp[i] = true;
				break;
			}
		}
	}
	if (dp[k])
		printf("First\n");
	else
		printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int f(int n,int x){
    if(n==-1) return 0;
    return n/x+1;
}

signed main()
{
    int a,b,x;
    cin>>a>>b>>x;
        
    cout<<f(b,x)-f(a-1,x)<<endl;
}


Measured memory_bytes: 256
N = int(input())
open = []
for _ in range(N):
    open.append(list(map(int,input().split())))
sales = []
for _ in range(N):
    sales.append(list(map(int,input().split())))

ans = -float("inf")
for i in range(1 , 1024):
    sum_val = 0
    mapping = []
    for k in range(N):
        cnt = 0
        for j in range(10):
            if i >> j & 1 and open[k][j] == 1:
                cnt += 1
        mapping.append(cnt)
    for k in range(N):
        sum_val += sales[k][mapping[k]]
    if sum_val > ans:
        ans = sum_val
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
int MOD = 1000000007;
class dynamic_bitset {
private:
    long long bit;
    string sbit                = "";
    unsigned long long bitsize = 0;
    
public:
    dynamic_bitset(int _bit) : bit{_bit} {
        for (int t = 1, mask = 2; bitsize == 0; t++, mask *= 2) {
            if (mask - 1 >= bit) bitsize = t;
        }
        for (int i = 0; i < bitsize; i++) {
            sbit = ((bit >> i & 1) == 1 ? "1" : "0") + sbit;
        }
    }
    dynamic_bitset(int _bit, int bitrange) : bit{_bit}, sbit{} {
        for (int t = 1, mask = 2; bitsize == 0; t++, mask *= 2) {
            if (mask - 1 >= bit) bitsize = t;
        }
        for (int i = 0; i < bitrange; i++) {
            sbit = (i < bitsize and ((bit >> i & 1) == 1) ? "1" : "0") + sbit;
        }
    }
    auto test(int _idx) {
        assert(_idx < sbit.size() && "index  out of range");
        return sbit[_idx] == '1';
    }
    void set(int _idx) {
        assert(_idx < sbit.size() && "findex out of range");
        sbit[_idx] = '1';
    }
    auto size() { return sbit.size(); }
    bool isAll() {
        return accumulate(sbit.begin(), sbit.end(), true,
                          [](bool r, char c) { return r && c == '1'; });
    }
    bool none() {
        return accumulate(sbit.begin(), sbit.end(), true,
                          [](bool r, char c) { return r && c == '0'; });
    }
    auto to_string() { return sbit; }
};
signed main(){
    int h,w,k;
    cin >> h >> w >> k;
    auto dp = vectors(300, 300,0LL);
    dp[1][1] = 1;
    for(int j = 1; j <= h; j++){
        for(int i = 1; i <= w; i++){
            for(int bit = 0; bit < (1 << (w - 1));bit++){
                auto db = dynamic_bitset(bit,w-1);
                bool isValid = true;
                rep(i,(int)db.size() - 1){
                    if(db.test(i) and db.test(i+1))
                        isValid = false;
                }
                if(!isValid)continue;
                if(i+1 <= w and db.test(i-1)){
                    dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD;
                } else if(i-1 >= 1 and db.test(i-2)){
                    dp[i-1][j+1] = (dp[i-1][j+1] + dp[i][j]) % MOD;
                } else {
                    dp[i][j+1]   = (dp[i][j+1]   + dp[i][j]) % MOD;
                }
            }
        }
    }
    cout << dp[k][h+1] << endl;
}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int cnt[2][123456];
vector<P> v[2];

bool comp(P a, P b){
	return a.first < b.first;
}

int main(void){
	int n,i,k,vi,ans,m[2][2];
	fill(cnt[0],cnt[2],0);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> vi;
		++cnt[i%2][vi];
	}
	for(k=0; k<2; ++k){
		for(i=1; i<=100000; ++i){
			v[k].push_back(P((n/2-cnt[k][i]),i));
		}
		sort(v[k].begin(),v[k].end());
	}
	if(v[0][0].second == v[1][0].second){
		ans = min(v[0][0].first+v[1][1].first,v[0][1].first+v[1][0].first);
	}else{
		ans = v[0][0].first+v[1][0].first;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

int main() {
  int N, M;
  ll Map[100010], L[100010];

  cin >> N >> M;
  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 0; i < M; ++i) {
    cin >> Map[i];
  }
  sort(Map, Map+M);

  for (int i = 1; i <= M-1; ++i) {
    L[i-1] = Map[i] - Map[i-1];
  }
  sort(L, L+M-1, greater<ll>());

  int ans = 0;
  for (int i = N - 1; i < M-1; ++i) {
    ans += L[i];
  }

  cout << ans << endl;

  return 0;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

struct Piece {
    int d, w;
};

class Solver {
  public:
    pair<Piece, Piece> split(const Piece &p, int s) {
        s = s % ( p.d + p.w);
        if(s < p.d) {
            return make_pair(Piece{s, p.w}, Piece{p.d - s, p.w});
        } else if(s < p.d + p.w) {
            s -= p.d;
            return make_pair(Piece{p.d, s}, Piece{p.d, p.w - s});
        }
        assert(0);
    }
    int S(const Piece & p) {
        return p.d * p.w;
    }
    bool solve() {
        int N, W, D; cin >> N >> W >> D;
        if(N == 0 and W == 0 and D == 0) return 0;
        vector<Piece> pieces;
        pieces.push_back(Piece{W, D});
        rep(i, N) {
            int p, s; cin >> p >> s;
            p--;
            auto pp = split(pieces[p], s);
            pieces.erase(pieces.begin() + p);
            if(S(pp.first) <= S(pp.second)) {
                pieces.push_back(pp.first);
                pieces.push_back(pp.second);
            } else {                
                pieces.push_back(pp.second);
                pieces.push_back(pp.first);
            }
        }
        sort(all(pieces), [&](const Piece &a, const Piece &b) {
                return S(a) <= S(b);
            });
        rep(i, pieces.size()) {
            cout << S(pieces[i]) << (i == pieces.size() - 1 ? "\n" : " ");
        }
        return 1;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(Solver().solve());
    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;
typedef int int32;
#define int ll

using namespace std;

typedef long long ll;

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

int32 main() {
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();	
	}
	return 0;
}


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

 
 
int main(){
   int N,X,T;

   cin >> N >> X >> T;

   if (N%X==0){
       cout << T*N/X << endl;
   }
   else{
       cout << (N/X)*T + T << endl;
   }
 
    return 0;
}

Measured memory_bytes: 3604
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    ll A,B,C,K; cin>>A>>B>>C>>K;
    ll ans = 0;
    if(K<=A){
        ans = K;
    }else if(K<=A+B){
        ans = A;
    }else{
        ans = A;
        ans -= K-(A+B);
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>
//#include <boost/multiprecision/cpp_int.hpp>

//namespace mp = boost::multiprecision;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
//using Bint = mp::cpp_int;


int H,W;
vector<string>M;


int dfs(int sh,int sw)
{
	vector<vector<int>>cost;
	for(int i=0;i<H;i++)
	{
		cost.push_back(vector<int>(W,10000));
	}
	cost[sh][sw]=0;
	queue<P>q;
	q.push(make_pair(sh,sw));
	while(!q.empty())
	{
		P tp=q.front();q.pop();
		int mv[]={0,-1,0,1,0};
		for(int i=0;i<4;i++)
		{
			int nh=tp.first+mv[i];
			int nw=tp.second+mv[i+1];
			if((0<=nh&&nh<H)&&(0<=nw&&nw<W)&&M[nh][nw]!='#')
			{
				if(cost[nh][nw]>cost[tp.first][tp.second]+1)
				{
					cost[nh][nw]=cost[tp.first][tp.second]+1;
					q.push(make_pair(nh,nw));
				}
			}
		}
	}
	int res=0;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
		{
			if(cost[i][j]!=10000)res=max(res,cost[i][j]);
		}
	return res;
}

int main()
{
	cin>>H>>W;
	for(int i=0;i<H;i++)
	{
		string s;
		cin>>s;
		M.push_back(s);
	}
	int res=0;
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			if(M[i][j]=='.')
			{
				int c=dfs(i,j);
				res=max(c,res);
			}
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3656
import java.util.*;
class Main{
    Main(){
	Scanner sc =new Scanner(System.in);
	int a=sc.nextInt();
	int y;
	for(int i=0;i<a;i++){
	    int b=sc.nextInt();
	    int c=sc.nextInt();
	    y=b%c;
	    if(y==0)y=c;
	    System.out.println(y);
	}
    }
    public static void main (String[]arg){
	new Main();
    }
}

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

int arr[200005];
int main(){
  int N;
  cin >> N;
  for (int i=0; i<N; i++){
  	scanf("%d", &arr[i]);
  }
  sort(arr, arr+N);
  for (int i=1; i<N; i++){
  	if (arr[i] == arr[i-1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N;
int sum;
vector<int> as;
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        as.push_back(A);
        sum += A;
    }
    sort(as.rbegin(), as.rend());

    sum -= 2* as[N - 1];
    for(int i = N - 2; i > 0; i--){
        if(as[i] < 0) sum -= 2 * as[i];
    }

    cout << sum << endl;

    int idx = 1;
    int Y = as[N - 1];
    for(;idx < N - 1; idx++){
        if(as[idx] < 0) break;
        cout << Y << " " << as[idx] << endl;
        Y -= as[idx];
    }

    int X = as[0];
    for(;idx < N - 1; idx++){
        cout << X << " " << as[idx] << endl;
        X -= as[idx]; 
    }
    cout << X << " " << Y << endl;
    return 0;
}

Measured memory_bytes: 2424
a,b,c,d = map(int,input().split())







def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
# print(gcd(a,b))

#最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

cd = lcm(c,d)










n = b-a+1   # ここから，cまたはdで割り切れるものの個数を引く．
# cで割り切れる個数+dで割り切れる個数-c*dで割り切れる個数


if a%c==0:
    c1 = a//c   # 範囲に入っているのは，c*c1から
else:
    c1 = a//c + 1

c2 = b//c       #               c*c2まで．


if a%d==0:
    d1 = a//d
else:
    d1 = a//d + 1

d2 = b//d


if a%(cd)==0:
    cd1 = a//(cd)
else:
    cd1 = a//(cd) + 1

cd2 = b//(cd)



if c1<=c2:
    nc = c2-c1+1
else:
    nc = 0

    
if d1<=d2:
    nd = d2-d1+1
else:
    nd = 0
    

if cd1<=cd2:
    ncd = cd2-cd1+1
else:
    ncd = 0

# print(n,nc,nd,ncd)
print(n-nc-nd+ncd)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
a=I()
b=I()
h=I()
ans=int((a+b)*h/2)
print(ans)
    

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

int main()
{
    string s;
    int n,h=0;
    cin>>n;
    cin>>s;
    if(n>=3)
    {
        for(int i=0; i<n-2; i++)
        {
            if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
                h++;
        }
    }
    cout<<h;
}


Measured memory_bytes: 256
//test
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;
const int N=55;
struct each{
    long long v,w,id;
    bool operator < (each k){
        return 1LL*w*k.v>v*k.w;
    }
}a[N];
long long ans,f[M];
int n,m,d,mw,li,now,v[N],nex[N],head[N];
void addedges(int x,int y){
    nex[++now]=head[x];
    head[x]=now,v[now]=y;
}
void dfs(int x){
    for(int i=head[x];i;i=nex[i]){
        dfs(v[i]),a[x].v+=a[v[i]].v;
        a[x].w+=a[v[i]].w;
    }
}
void insert(long long w,long long v){
    for(int i=mw;i>=w;i--)
        f[i]=min(f[i],f[i-w]+v);
}
void move(each k){
    int x=li;
    for(int i=0;(1<<i)<=x;i++){
        insert(k.w*(1<<i),k.v*(1<<i));
        x-=1<<i;
    }
    if(x)   insert(k.w*x,k.v*x);
}
int main(){
    //freopen("1.out","w",stdout);
    //freopen("1.in","r",stdin);
    scanf("%d%d%d",&n,&m,&d);
    scanf("%lld",&a[1].v);
    a[1].w=1,a[1].id=1;
    for(int i=2,x;i<=n;i++){
        scanf("%lld%d",&a[i].v,&x);
        addedges(x,i),a[i].w=1;
    }
    dfs(1),li=min(n,d),mw=n*n*n;
    memset(f,23,sizeof(f)),f[0]=0;
    for(int i=1;i<=n;i++)   move(a[i]);

    sort(a+1,a+n+1);
    while(a[n].id!=1)   --n;
    for(int i=0;i<=mw;i++){
        if(f[i]>m)  continue;
        int v=f[i],w=i;
        for(int j=1;j<n;j++){
            int k=min(1LL*d-li,(m-v)/a[j].v);
            w+=k*a[j].w,v+=k*a[j].v;
        }
        int k=(m-v)/a[n].v;
        ans=max(ans,w+k*a[n].w);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

//データ数 < 2^(log2n)
constexpr ll log2n = 20;
constexpr ll sizeofn = 1 << log2n+1;
ll SegmentTree[sizeofn];
ll STconvert(ll i,ll j){
  return (1<<log2n)/(j-i+1) + i/(j-i+1);
}

ll STmerge(ll i,ll j){
  return min(i,j);
}

ll STquery(ll i,ll j){
  if(i > j)swap(i,j);
  REP(rep,0,log2n+1){
    ll p = 1 << rep;
    if(i%p == 0 && i+p-1 < j){
      return STmerge(STquery(i+p,j),SegmentTree[STconvert(i,i+p-1)]);
    }
    else if(i%p == 0 && i+p-1 <= j){
      return SegmentTree[STconvert(i,j)];
    }
  }
}

void STchange(ll i,ll j){
  SegmentTree[STconvert(i,i)] = j;
  FOR(rep,1,log2n+1){
    ll p = 1 << rep;
    SegmentTree[STconvert(i/p*p,i/p*p+p-1)] = STmerge(SegmentTree[STconvert(i/p*p,i/p*p+p/2-1)],SegmentTree[STconvert(i/p*p+p/2,i/p*p+p-1)]);
  }
}

signed main(){
  int n,m,s,t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<pair<ll,ll>>> sunuke(n),yen(n);
  int u,v,a,b;
  FOR(i,0,m){
    cin >> u >> v >> a >> b;
    u--;
    v--;
    yen[u].pb(make_pair(v,a));
    yen[v].pb(make_pair(u,a));
    sunuke[u].pb(make_pair(v,b));
    sunuke[v].pb(make_pair(u,b));
  }
  ll dminy[n],dmins[n];
  FOR(i,0,n){
    dminy[i] = -1;
    dmins[i] = -1;
  }
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pque;
  pque.push(make_pair(0,s));
  while(pque.size()){
    pair<ll,ll> p = pque.top();
    pque.pop();
    if(dminy[p.second] == -1){
      dminy[p.second] = p.first;
      for(auto x:yen[p.second]){
        if(dminy[x.first] == -1)pque.push(make_pair(dminy[p.second]+x.second,x.first));
      }
    }
  }
  pque.push(make_pair(0,t));
  while(pque.size()){
    pair<ll,ll> p = pque.top();
    pque.pop();
    if(dmins[p.second] == -1){
      dmins[p.second] = p.first;
      for(auto x:sunuke[p.second]){
        if(dmins[x.first] == -1)pque.push(make_pair(dmins[p.second]+x.second,x.first));
      }
    }
  }
  fill(SegmentTree,SegmentTree+sizeofn,LINF);
  FOR(i,0,n){
    STchange(i,dminy[i]+dmins[i]);
  }
  FOR(i,0,n){
    cout << (ll)1e15-STquery(i,n) << endl;
  }
}

Measured memory_bytes: 35328
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c].append([e,d]);E[d].append([e,c])
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6308
#include <stdio.h>

/***Σ(゜Д゜; ナゼダッ***/

int main(void)
{
	int n, i;
	double rec;
	
	scanf("%d", &n);
	
	rec = 1;
	for (i = n; i > 0; i--){
		rec *= i;
	}
	
	printf("%.lf\n", rec);
	
	return (0);
}

Measured memory_bytes: 628