akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace Contest
{
    class ABC
    {
        static void Main()
        {
            Solve();
        }

        private static void Solve()
        {
            int N = int.Parse(Console.ReadLine());
            string INPUT = Console.ReadLine();
            int res = 1;
            for(int i = 0; i < N - 1; i++)
            {
                if(INPUT[i] != INPUT[i + 1])
                {
                    res++;
                }
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11232
from fractions import gcd

def count_multiples(a,b,m):
    a = ((a-1)//m + 1)
    b = b//m
    return b-a+1

a,b,c,d = map(int,input().split())
print(b-a+1 - count_multiples(a,b,c) 
    - count_multiples(a,b,d) 
    + count_multiples(a,b,(c*d)//gcd(c,d)))

Measured memory_bytes: 5564
import java.util.*;
public class Main {
		
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int p[] = new int[N];
		for(int i=0;i<N;i++)p[i]=sc.nextInt()-1;

		UnionFind uf = new UnionFind(N);
		
		for(int i=0;i<M;i++) {
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			
			uf.unite(x, y);
		
		}
		sc.close();
		
		int cnt = 0;
		for(int i=0;i<N;i++) {
			if(uf.same(i, p[i]))cnt++;
		}
		System.out.println(cnt);
		
	}
}

class UnionFind{
	
	int parent[];
	
	UnionFind(int N){
		parent = new int[N];
		Arrays.fill(parent, -1);
	}
	
	boolean same(int x, int y){
		return root(x)==root(y);
	}
	
	int root(int x) {
		if(parent[x]<0)return x;
		return parent[x] = root(parent[x]);
	}
	
	int size(int x) {
		return -parent[root(x)];
	}
	
	void unite(int x, int y) {
		if(size(x)<size(y)) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		int rx = root(x);
		int ry = root(y);
		
		if(rx==ry)return;
		
		parent[rx] += parent[ry];
		parent[ry] = rx;
		
	}
	
}

Measured memory_bytes: 89220
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N, T;
  cin >> N >> T;
  ll t[N];
  REP(i, N) { cin >> t[i]; }
  ll ans = 0;
  FOR(i, 1, N) {
    ll diff = t[i] - t[i - 1];
    if (diff > T) {
      ans += T;
    } else {
      ans += diff;
    }
  }
  ans += T;
  cout << ans;
  return 0;
}


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

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    if ((N==1&&A!=B)||A>B){
        cout << 0 << endl;
    }
    else if (N==1||N==2){
        cout << 1 << endl;
    }
    else {
        ll ans=(B-A)*(N-2)+1;
        cout << ans << endl;
    }
}

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

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

    int X[N], s = 0;
    for(size_t i = 0; i < N; ++i) {
        cin >> X[i];
        s += X[i];
    }

    int P1 = s / N, P2 = s / N + 1;

    int ans1 = 0, ans2 = 0;
    for(size_t i = 0; i < N; ++i) {
        ans1 += (X[i] - P1)*(X[i] - P1);
        ans2 += (X[i] - P2)*(X[i] - P2);
    }

    cout << min(ans1, ans2) << endl;
    
    return 0;
}

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

long long min4(long long &w,long long &x,long long &y,long long &z) {
	return min(w,min(x,min(y,z)));
}

long long max4(long long &w, long long &x, long long &y, long long &z) {
	return max(w, max(x, max(y, z)));
}

int main() {
	int N;
	cin >> N;
	vector<long long>A(N);
	vector<long long>Sum(N + 1);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		Sum[i + 1] = Sum[i] + A[i];
	}
	int l = 0;
	int r = 2;
	long long ans = 1e18;
	for (int c = 1; c <= N - 3; ++c) {
		{
			long long absl = 1e18;
			for (int i = l; i < c; ++i) {
				long long x = Sum[i + 1] - Sum[0];
				long long y = Sum[c + 1] - Sum[i + 1];
				if (absl >  abs(x-y)) {
					absl = abs(x-y);
					l = i;
				}
				else {
					break;
				}
			}
		}
		{
			long long absr = 1e18;
			for (int j=r; j < N-1; ++j) {
				long long x = Sum[j + 1] - Sum[c + 1];
				long long y = Sum[N] - Sum[j + 1];
				if (absr > abs(x - y)) {
					absr = abs(x - y);
					r = j;
				}
				else {
					break;
				}
			}
		}
		long long ll = Sum[l + 1] - Sum[0];
		long long lr = Sum[c + 1] - Sum[l + 1];
		long long rl = Sum[r + 1] - Sum[c + 1];
		long long rr = Sum[N] - Sum[r + 1];
		//cout << l << "_" << c << "_" << r << endl;
		//cout << ll<<"_"<<lr<<"_"<<rl<<"_"<<rr<< endl;
		ans = min(ans,max4(ll,lr,rl,rr)-min4(ll,lr,rl,rr));
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 6412
//        VIVEK UPADHYAY
//        MANIT, BHOPAL(M.P)


//                         JAB-TAK TODEGA NHI,
//                         TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<endl
#define ok cout<<"ok\n" ;
typedef long long ll;
const int MAXN = 1e5 + 10 ;
const int MAX = 1e7 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18+ 10 ;
string toNegativeBase(ll n, int negBase)
{
   
    if (n == 0)
        return "0";
    
    string converted = "";
    while (n != 0)
    {
   
        int remainder = n % negBase;
        n /= negBase;
      
        if (remainder < 0)
        {
            remainder += (-negBase);
            n += 1;
        }
        
      
        converted = (char)(remainder + '0') + converted;
    }
    
    return converted;
}
int main() {
    
    ll N ;
    cin >> N ;
    cout<<toNegativeBase(N,-2) ;
    return 0 ;
}


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

abc = []
edge = [[] for _ in range(n)]
rev_edge = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    abc.append((a - 1, b - 1, p - c))
    edge[a - 1].append(b - 1)
    rev_edge[b - 1].append(a - 1)


def dfs(e, s):
    v_set = {s}
    stack = [s]
    while stack:
        v = stack.pop()
        for next_v in e[v]:
            if next_v in v_set:
                continue
            v_set.add(next_v)
            stack.append(next_v)
    return v_set


def bellman_ford(sub_abc, n):
    inf = float("inf")
    dist = [inf] * n
    dist[0] = 0

    for _ in range(n):
        updated = False
        for u, v, d in sub_abc:
            if dist[u] + d < dist[v]:
                dist[v] = dist[u] + d
                updated = True
        if not updated:
            break
    else:
        return -1

    return max(-dist[n - 1], 0)


use = dfs(edge, 0) & dfs(rev_edge, n - 1)
print(bellman_ford([(a, b, c)
                    for (a, b, c) in abc if a in use and b in use], n))


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

i32 n,m,i,j;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

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

    vl csum(n+1); rep(i,n) csum[i+1] += csum[i] + a[i];

    /**
     * 解説見た
     * ある区間の累積和がmの倍数なら
     *    累積和 csum[r+1] - csum[r] に対して
     *    csum[r+1]%m == csum[l]%m
     *    が言える。
     *    例えば、
     *    csum[r+1] = p*m + q;
     *    csum[l] = r*m + s;
     *    と考えると、自明に
     *    csum[r+1] - csum[l] = (p-r) * m
     *    より累積和がmの倍数になっている
     *
     *    ... 思いつかねーーーーーーーーーーー!!!
     */

    map<i32, i32> modM;
    for(auto num : csum) ++modM[num%m];

    i64 answer = 0;
    for(auto p : modM) answer += (p.second-1)*p.second/2;

    cout << answer << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
using namespace std;

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

void Main()
{
	int N;
	cin >> N;
	vector<int> a(N);

	rep(i, N)
	{
		cin >> a[i];
	}

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

	int A = 0;
	int B = 0;
	rep(i, N)
	{
		if (i % 2 == 0) A += a[i];
		else B += a[i];
	}

	cout << A - B << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vec(type) vector<type>

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

	int ans = 0;
	for (int a = 1; a <= k; a++) {
		int bsum = 0;
		for (int b = 1; b <= k; b++) {
			int csum = 0;
			for (int c = 1; c <= k; c++) {
				csum += gcd(gcd(a,b),c);
			}
			bsum += csum;
		}
		ans += bsum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
public class Main{
  public static void main(String[] args)
  {
	for(int i = 1; i < 10; i++)
        {
            for(int j = 1; j < 10; j++)
            {
            	System.out.println(i + "x" + j + "=" + i*j);
            }
        }
  }   
}


Measured memory_bytes: 24184
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N ;
    string S;
    ll K ;
    cin >> N >> S >> K ;

    rep(i, S.size()){
        if(S[i] == S[K-1]) cout << S[i];
        else cout << "*" ;
    }

    cout << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//専用ライブラリ
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e9
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n+1);
    vector<int>ans;
    rep(i,1,n+1)
        cin>>a[i];
    int b[200001];
    memset(b,0,sizeof(b));
    if(a[n]==0)
        b[n]=0;
    else
    {b[n]=1;
        ans.push_back(n);}
    
    for(int i=n-1;i>=1;i--)
    {
        int sum=0;
        bool abc=0;
        for(int j=2;j*i<=n;j++)
        {
                sum+=b[i*j];
        }
        if(sum%2==0&&a[i]==0)
            b[i]=0;
        else if(sum%2==0&a[i]==1)
        {
            b[i]=1;
            abc=1;
        }
        else if(sum%2==1&a[i]==1)
            b[i]=0;
        else if(sum%2==1&a[i]==0)
        {
            b[i]=1;
            abc=1;
        }
        if(abc==1)
        ans.push_back(i);
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3192
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set, TreeSet}
import scala.util.Random
import java.util.Date

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D = in.next().toInt
  val c = new Array[Long](26+1)
  val s = Array.ofDim[Long](D+1, 26+1)

  for (i <- 1 to 26) {
    c(i) = in.next().toInt
  }
  for (d <- 1 to D) {
    for (i <- 1 to 26) {
      s(d)(i) = in.next().toInt
    }
  }

  // optional
  val t = new Array[Int](D+1)
  for (i <- 1 to D) {
    t(i) = in.next().toInt
  }

  class Board(val t: Array[Int]) {

    // 各コンテストの開催日をセットで保持する
    private val eventDays = Array.fill(26+1)(TreeSet[Int]())

    var score: Long = {
      var res = 0L

      val last = new Array[Int](26+1)
      for (day <- 1 to D) {
        val now = t(day)

        last(now) = day
        eventDays(now) += day

        res += s(day)(now)
        for (contest <- 1 to 26) {
          res -= c(contest) * (day - last(contest))
        }
      }

      res
    }

    // ${day}日の開催コンテストを, ${contest}に変更する
    def update(day: Int, contest: Int): Unit = {
      def tousa(l: Int): Int = ((1 + l) * l) / 2

      score -= s(day)(t(day))
      score += s(day)(contest)

      val delSet = eventDays(t(day))
      delSet -= day
      var start = delSet.maxBefore(day).getOrElse(0)
      var end = delSet.minAfter(day).map(_ - 1).getOrElse(D)
      score += c(t(day)) * tousa((day-1) - start)
      score += c(t(day)) * tousa(end - day)
      score -= c(t(day)) * tousa(end - start)

      val addSet = eventDays(contest)
      start = addSet.maxBefore(day).getOrElse(0)
      end = addSet.minAfter(day).map(_ - 1).getOrElse(D)
      score -= c(contest) * tousa((day-1) - start)
      score -= c(contest) * tousa(end - day)
      score += c(contest) * tousa(end - start)
      addSet += day

      t(day) = contest
    }
  }

  val board = new Board(t)

  val M = in.next().toInt
  for (_ <- 1 to M) {
    val d, q = in.next().toInt

    board.update(d, q)
    val ans = board.score

    pw.println(ans)
  }

  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 58264
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

mod = 1000000007

"""
# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))
    L2 = [L[i] - (i + 1) for i in range(N)]
    L2.sort()
    if N % 2 == 0:
        b = L2[(N // 2) - 1]
    else:
        b = L2[(N // 2)]

    print(sum(abs(l - b) for l in L2))

Measured memory_bytes: 114896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()

	x := make([]int, n)
	y := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = scanInt()
		y[i] = scanInt()
	}

	cnt := make(map[point]int,n*n)
	ma := 0

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}

			p := x[i] - x[j]
			q := y[i] - y[j]
			cnt[point{p,q}]++
			ma = max(ma, cnt[point{p,q}])
		}
	}

	fmt.Fprintln(wr, n-ma)
	// fmt.Fprintln(wr, cnt)

}

type point struct {
	x,y int
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
    int x;
    scanf("%d",&x);
    int tmp1=x/500;
    int ans=tmp1*1000;
    int tmp2=x%500;
    int tmp3=tmp2/5;
    ans+=tmp3*5;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,t,m,n,a)vector<vector<t> > name(m,vector<t> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	for(;;){
		int m,r,f;
		std::cin >> m>>f>>r;
		if(m==-1&&f==-1&&r==-1)exit(0);
		if(m==-1||f==-1)std::cout << "F" << std::endl;
		else{
			if(m+f>=80)std::cout << "A" << std::endl;
			else if(m+f>=65) std::cout << "B" << std::endl;
			else if(m+f>=50)std::cout << "C" << std::endl;
			else if(m+f>=30){
				if(r>=50)std::cout << "C" << std::endl;
				else std::cout << "D" << std::endl;
			}
			else std::cout << "F" << std::endl;
		}
		
	}
}


Measured memory_bytes: 3076
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

int main(){
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%lf\n",d);
    return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <math.h>

int t = 0,L[250002],R[250002];

void marge(int A[],int left,int mid,int right)
{
  int i,j,k,n1,n2;

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

  for(i = 0;i < n1;i++) L[i] = A[left + i];
  for(i = 0;i < n2;i++) R[i] = A[mid + i];
  L[n1] = 2000000000;
  R[n2] = 2000000000;
  
  i = 0;
  j = 0;
  for(k = left;k < right;k++)
  {
    if(L[i] <= R[j])
    {
      A[k] = L[i++];
      t++;
    }
    else
    {
      A[k] = R[j++];
      t++;
    }
  }
}

void margesort(int A[],int left,int right)
{
  int mid;

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

int main()
{
  int A[500000],n,i;

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

  margesort(A,0,n);

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

  return 0;
}



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

int main(){
  int Cflag=0;
  string S;
  cin>>S;
  
  if(S.at(0)!='A'){
    cout<<"WA"<<endl;
    return 0;
  }
  else if(S.at(1)>='A'&&S.at(1)<='Z'){
    cout<<"WA"<<endl;
    return 0;
  }
  else if(S.at(S.size()-1)>='A'&&S.at(S.size()-1)<='Z'){
    cout<<"WA"<<endl;
    return 0;
  }
  for(int i=2;i<S.size()-1;i++){
    if(S.at(i)=='C'&&Cflag==0)
      Cflag=1;
    else if(S.at(i)>='A'&&S.at(i)<='Z'){
      cout<<"WA"<<endl;
      return 0;
    }
  }
  if(Cflag==1)
    cout<<"AC"<<endl;
  else
    cout<<"WA"<<endl;
}
  

Measured memory_bytes: 256
n = gets.chomp.to_i

xy_array = n.times.inject([]) do |acc, i|
  acc[i] = []
  gets.chomp.to_i.times do
    x, y = gets.split.map(&:to_i)
    acc[i] << [x - 1, y == 1]
  end
  acc
end

[true, false].repeated_permutation(n) do |combination|
  result = combination.each_with_index.all? {|c, i| 
    next true unless c

    xy_array[i].all? do |xy|
      combination[xy[0]] == xy[1]
    end
  }
  if result
    puts combination.count(true)
    exit
  end
end


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  if(n>k) n %=k;
  while(1){
    if(n > abs(n-k)) n = abs(n-k);
    else break;
  }
  cout << n << endl;
  
}


Measured memory_bytes: 256
import sys
n=int(input())
w=[]
for i in range(n):
  w.append(input())

if len(w)!=len(set(w)):
  print('No')
  sys.exit()

for i in range(n-1):
  p=list(w[i])
  q=list(w[i+1])
  if p[-1]!=q[0]:
    print('No')
    sys.exit()
  
print('Yes')

Measured memory_bytes: 9192
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		var k, t int
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			fmt.Scan(&t)
			m[t]++
		}
	}
	count := 0
	for _, v := range m {
		if v == N {
			count++
		}
	}
	fmt.Println(count)
}


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

int main (){
    string weather;
    string weather_next;
    vector<string> weather_list = {"Sunny", "Cloudy", "Rainy", "Sunny"};
    cin >> weather;
    int i;
    for(i = 0; i < weather_list.size(); i++){
        if(weather == weather_list[i]){
            cout << weather_list[i + 1];
            return 0;
        }
    }
    return 0;
}

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

int main()
{
    int N, F;

    map < pair < string , string >, int > mp;
    vector < pair < string , string > > ans;
    cin >> N >> F;

    for ( int i = 0; i < N; i++ ) {
        int M;
        string S[10];
        cin >> M;
        for ( int j = 0; j < M; j++ ) {
            cin >> S[j];
        }
        for ( int j = 0; j < M; j++ ) {
            for ( int k = j + 1; k < M; k++ ) {
                string s = S[j], t = S[k];
                if ( s > t ) swap(s, t);
                auto d = make_pair(s, t);
                if ( mp.find(d) == mp.end() ) {
                    mp[d] = 1;
                } else {
                    mp[d]++;
                }
                if ( mp[d] == F ) {
                    ans.push_back(d);
                }
            }
        }
    }

    sort(begin(ans), end(ans));

    cout << ans.size() << endl;

    for ( auto &d : ans ) {
        cout << d.first << " " << d.second << endl;
    }

    return ( 0 );
}



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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	ll X, D, N;

	cin >> N >> X >> D;

	if (D == 0) {
		cout << (X ? N + 1 : 1) << '\n';
		return 0;
	}

	if (D < 0)
		D = -D, X = -X;

//	X += D * (abs(X) / D);
//
//	while (X < 0)
//		X += D;


	map<ll, V<pair<ll, ll>>> M;

	for (int nx = 0; nx <= N; ++nx) {
		ll V = (nx - 1) * 1LL * nx / 2;
		ll U = nx * 1LL * N - (nx + 1) * 1LL * nx / 2;
		assert(V <= U);
		ll sh = (X * 1LL * nx) / D;
		ll md = (X * 1LL * nx) % D;
		assert(sh * D + md == X * nx);
		while (md < 0)
			md += D, --sh;
		assert(sh * D + md == X * nx);
		assert(md < D);
		M[md].pb(mp(V + sh, U + sh));
	}

	ll ans = 0;

	for (auto& pr : M) {

		db(pr);

		V<pair<ll, ll>>& v = pr.sc;
		sort(v.begin(), v.end());
		ll l = v[0].fs, r = v[0].sc;
		for (int i = 0; i < sz(v); ++i) {
			if (i + 1 < sz(v) && v[i + 1].fs <= r) {
				r = max(r, v[i + 1].sc);
				continue;
			} else {
				ans += (r - l + 1);
				if (i + 1 < sz(v))
					l = v[i + 1].fs, r = v[i + 1].sc;
			}
		}
	}


	cout << ans << '\n';


	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 22144
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = input().split()
    f.append(a)

p = [list(map(int, input().split())) for i in range(n)]

for i in range(1, 2**10):
    ref = 0
    i = str(bin(i))[2:].zfill(10)
    for j in range(n):
        cnt = 0
        for k in range(10):
            if i[k] == f[j][k] == "1":
                cnt += 1
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int A, B, C, D;
int main()
{
    cin >> A >> B >> C >> D;

    int t = C/B + (C%B>0);
    int s = A/D + (A%D>0);
    if(t<=s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    //cout << s << " " << t << endl;
    return 0;
}


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

using namespace std;

int main() {
    int N, M;

    cin >> N >> M;

    int l_max = 0;
    int r_min = 100001;
    for (int i = 0; i < M; ++i) {
        int l, r;
        scanf("%d%d", &l, &r);
        l_max = max(l, l_max);
        r_min = min(r, r_min);
    }
    cout << max(0, r_min - l_max + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int a[100010];
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }
    int cnt=0;
    if(N==2)
    {
        if(a[0]==2&&a[1]==1)
        {
            cout <<0<<endl;
        }
        else
        {
            cout <<1<<endl;
        }
    }
    else
    {
        int cnt=0;
        for(int i=0;i<N-2;i++)
        {
            if(a[i]==i+1)
            {
                swap(a[i],a[i+1]);
                cnt++;
            }
        }
        if(a[N-2]==N-1)
        {
            cnt++;
        }
        else if(a[N-1]==N)
        {
            cnt++;
        }
        cout << cnt <<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

int main(){

	int x, y;

	in(x), in(y);


	out(x + y / 2);

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
using namespace std;
const int N=2011,mod=1e9+7;
int fac[N*N],ifac[N*N];
int n,m;
inline int C(int n,int m){
	if(n<0||m<0||n<m)return 0;
	return 1ll*fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
int f[N][N];
inline int fp(int a,int b){
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)
			res=1ll*res*a%mod;
	return res;
}
int main(){
	scanf("%d%d",&n,&m);
	if(m==1){
		puts("1");
		return 0;
	}
	fac[0]=1;
	rep(i,1,4000000)
		fac[i]=1ll*i*fac[i-1]%mod;
	ifac[4000000]=fp(fac[4000000],mod-2);
	_rep(i,4000000,1)
		ifac[i-1]=1ll*i*ifac[i]%mod;
	f[0][0]=1;
	rep(i,1,n)
		rep(j,0,i){
			f[i][j]=f[i-1][j];
			if(j)f[i][j]=(f[i][j]+1ll*f[i][j-1]*(n-j+1)%mod*C(n-i+(n-j+1)*(m-1)-1,m-2))%mod;
		}
	printf("%d\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 46464
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define debug(x) #x << " = " << (x) << " "
using ll = long long;
using namespace std;
constexpr size_t max_n = 200000;
bool a[max_n+1];
int main() {
    int n, k; scanf("%d%d", &n, &k);
    repeat (i,n) { char c; scanf(" %c", &c); a[i] = (c == 'A'); }
    int m = n;
    a[m+1] = false;
    while (k --) {
        if (a[0]) {
            a[0] = false;
        } else {
            repeat (i,m) a[i] = not a[i+1];
        }
        while (2 <= m and not a[m-2] and a[m-1]) m -= 2;
        if (m == 0) break;
        if (m == 1) k %= 2;
    }
    repeat (i,n) printf("%c", a[i] ? 'A' : 'B');
    printf("\n");
    return 0;
}


Measured memory_bytes: 640
#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>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    int count = 0;
    if(e-a > k){
        count++;
    }
    
    if(count == 0){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }

}

Measured memory_bytes: 3676
N, M, X = map(int, input().split(' '))
price, exp, rst = [], [ []  for i in range(N) ], -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
for i in range(1 << N):
    price_combi, exp_combi, sum_exp, ls_cnt = [], [], [0] * M, []
    for j in range(N):
        if i >> j & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in exp_combi:
        for t in range(M):
            sum_exp[t] += s[t]
    [ ls_cnt.append(x) for x in sum_exp if x >= X ]
    if len(ls_cnt) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

Measured memory_bytes: 9180
#include <iostream>
                 
int main() {     
    int x, y, z, cnt = 0;
                 
    std::cin >> x >> y >> z;
                 
    for(int i = x; i <= y; i++) {
        if((z % i) == 0) cnt++;
    }            
    std::cout << cnt << std::endl;
    return 0;    
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(a+b,min(a+c,b+c))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x;scanf("%lld",&x);
	for(int i=1;i<150;i++)
		for(int j=-150;j<150;j++)
			if(1ll*i*i*i*i*i-1ll*j*j*j*j*j==x)return printf("%d %d",i,j),0;
	return 0;
}

Measured memory_bytes: 3812
import itertools

d = []
for i in range(5):
  d.append(int(input()))

k = int(input())

d2 = [abs(i[0] - i[1]) for i in list(itertools.combinations(d, 2))]

over = [i for i in d2 if i > k]
if len(over) == 0 :
  print("Yay!")
else:
  print(":(")

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 1 | b % 2 == 1 | c % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (a == b && b == c) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        ll next_a = b / 2 + c / 2;
        ll next_b = c / 2 + a / 2;
        ll next_c = a / 2 + b / 2;
        a = next_a;
        b = next_b;
        c = next_c;
        ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=505;
int a[N][N];
int32_t main(){
    int n,m,h,w;
    cin>>n>>m>>h>>w;
    if(h*w==1){
        cout<<"No\n";
    }else{
        int cnt=h*w-1;
        int sm=(1000000000-1)/cnt;
        int bd=sm*cnt+1;
        int s=0;
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                if(i%h==0&&j%w==0)
                    a[i][j]=-bd;
                else
                    a[i][j]=sm;
                s+=a[i][j];
            }
        }
        if(s<=0)cout<<"No\n";
        else{
            cout<<"Yes\n";
            for(int i=1;i<=n;++i){
                for(int j=1;j<=m;++j)cout<<a[i][j]<<' ';
                cout<<'\n';
            }
        }
    }
    return 0;
}

Measured memory_bytes: 5648
/*input
3
1 1 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int a[maxn];
vector<pii> ans;

int main(){
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	sort(a,a+n);

	int pos;

	if(a[0]>=0){
		pos=n-1;
	}
	else if(a[n-1]<=0){
		pos=1;
	}
	else{
		pos=0;
		REP(i,n) if(a[i]>=0) pos++;
	}

	assert(pos>0&&pos<n);

	int neg=n-pos;

	int cur=a[n-1];
	REP(i,neg-1){
		// cur, a[i+1] - > cur-a[i+1]
		ans.pb(MP(cur,a[i+1]));
		cur-=a[i+1];
	}

	int sml=a[0];
	REP(i,pos-1){
		// sml, a[n-2-i] -> 
		ans.pb(MP(sml,a[n-2-i]));
		sml-=a[n-2-i];
	}
	ans.pb(MP(cur,sml));
	cur-=sml;
	cout<<cur<<'\n';
	for(auto i:ans){
		cout<<i.F<<' '<<i.S<<'\n';
	}

	return 0;
}


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

using namespace std;

#define gc c=getchar()
#define r(x) read(x)

#define For(i, a, b) for (i = a; i <= b; i++)
#define Step(i, a, b, x) for (i = a; i <= b; i += x)

template<typename T>
inline void read(T&x){
    x=0;T k=1;char gc;
    while(!isdigit(c)){if(c=='-')k=-1;gc;}
    while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}

const int p=998244353;

map<string,int>F;
map<string,int>G;

int f(string s);

int g(string s){
	if(G[s])return G[s];
	int &ans=G[s],n=s.size();
	if(n==1)return ans=s[0]-'0'+1;
	for(int i=1;i<n;++i){
		if(n%i)continue;
		string t="";
		for(int j=0;j<i;++j){
			int c=1;
			for(int k=j;k<n;k+=i)c&=s[k]-'0';
			t+=char(c+'0');
		}
		ans=(ans+f(t))%p;
	}
	return ans;
}

int f(string s){
	if(F[s])return F[s];
	int &ans=F[s],n=s.size();
	if(!n)return ans=1;
	for(int i=1;i<=n;++i)ans=(ans+(long long)g(s.substr(0,i))*f(s.substr(i,n)))%p;
	return ans;
}

string s;

int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;
	cout<<f(s);
	return 0;
}


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U>
void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U>
void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V>
void Printarray3(T f,U a,V b){
  rep(i,a){
    rep(j,b){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}
template<typename T,typename U>
void Printarray4(T f,U n){
  rep(i,n){
    rep(j,n){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}

void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;cin>>s;
  int a=0,b=0;
  rep(i,s.size()){
    if(s[i]=='A')a++;
    if(s[i]=='B')b++;
  }
  flag2func(!(a==0 || b==0));
}


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            if (s.substr(0, i) + s.substr(j) == "keyence"s) {
                cout << "YES\n";
                return 0;
            }
        }
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

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

  map<string, int> m;
  ll ans = 0;
  rep(i, N) {
    string s; cin >> s;
    all(sort, s);
    ans += m[s];
    ++m[s];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>
  int main(void)
  {
    int a,b,c,i;
    while(1){
        if(scanf("%d%d",&a,&b)==EOF)
                 break;
        c=a+b;
        i=1;
    while(1){
        if((c/10)<1)
                break;
        else{i++;
            c/=10;}
             }
             printf("%d\n",i);
             }
    return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
   int t=0; 
   for(int i=0;i<4;i++) t+=sc.nextInt();
    System.out.println(t/60);
    System.out.println(t%60);
    }
    }

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    while (A >= B) {
        B *= 2;
        K--;
    }
    while (B >= C) {
        C *= 2;
        K--;
    }
    cout << (K < 0 ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 3632
n = int(input())
s = [input()[0] for _ in range(n)]

cnt = [s.count(v) for v in ("M", "A", "R", "C", "H")]
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            ans += cnt[i] * cnt[j] * cnt[k]
            
print(ans)

Measured memory_bytes: 52440
#include <bits/stdc++.h>
#define fol(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;cin>>n;
    int a,b=0,c=0;
    fol(i,n){
        cin>>a;
        a%2?c++:b++;
    }
    if(b>=0&&c%2==0){
        cout << "YES"<<endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int h1,m1,h2,m2,k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int s = 60*h1+m1, e = 60*h2+m2;
    int ans = e-s-k;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 3652
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    print('#'*b)
    for i in range(a-2):
        print("#",end='')
        for j in range(b-2):
            print('.',end='')
        print("#")
    print('#'*b)
    print()


Measured memory_bytes: 6992