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

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            var A = new long[N];
            var B = new long[N];

            long Median(long[] items)
            {
                Array.Sort(items);
                var m = items.Length / 2;
                return items.Length % 2 == 1 ? items[m] : items[m] + items[m - 1];
            }

            for (var i = 0; i < N; i++) (A[i], B[i]) = Scanner.Scan<int, int>();

            var answer = Median(B) - Median(A) + 1;

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 50264
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

vector<pii>gr[MAXN];
set<int>cols[MAXN];
int color[MAXN];

void dfs( int node, int par, int done )
{
    int col = 1;
    set<int>cols;
    cols.insert(done);
    for( auto nx : gr[node] )
    {
        int next = nx.F, edge = nx.S;
        if( next == par )
            continue;

        if( cols.count(col) )
            col++;

        color[edge] = col;
        if( next != par )
            dfs(next, node, col);

        cols.insert(col);
        col++;
    }
}

int main() 
{
    fastio();

    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        u--,v--;
        gr[u].pb({v,i});
        gr[v].pb({u,i});
    }

    dfs(0, -1, -1);
    int ans = 0;
    for(int i=0;i<n-1;i++)
    {
        ans = max(ans, color[i]);
    }
    cout<<ans,nl;
    for(int i=0;i<n-1;i++)
    {
        cout<<color[i],nl;
    }

    return 0;
}

Measured memory_bytes: 19456
import sys
input = sys.stdin.readline
n=int(input())
T=[]
append=T.append
for i in range(n):
  a,b=map(int,input().split())
  append([a,b])
T.sort(key=lambda x:x[1])
chk=True
t=0
for i in range(n):
  a,b=T[i]
  t+=a
  if t>b:
    chk=False
print("Yes" if chk==True else "No")

Measured memory_bytes: 38928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define MAX_SIZE (100000)
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> A;
  int a;
  for (size_t i = 0; i < N; i++) {
    cin >> a;
    A.push_back(a);
  }

  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    B[i] = i;
  }

  auto comparator = [&A](int a, int b){ return A[a] < A[b]; };
  sort(B.begin(), B.end(), comparator);

  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += abs(B[i] - i) % 2;
  }

  cout << sum / 2 << endl;

  return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s;
ll res = 0;

// < ----------- func eh ---------------- ? //


// <------------- Start of main() -------------------> //

void MAIN() {
	ll x,y,q;
	cin>>x>>y>>q;
	ll d= q-x-y;
	if(d>=0 && 4*x*y < d*d) cout<<"Yes\n";
	else cout<<"No\n";
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


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

int main() {
    int N, M;
    map<string, int> m;
    map<string, int>::iterator ite;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (m.find(s) == m.end()) {
            m.insert(make_pair(s, 1));
        } else {
            ite = m.find(s);
            ite->second += 1;
        }
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        string s;
        cin >> s;
        if (m.find(s) == m.end()) {
            m.insert(make_pair(s, -1));
        } else {
            ite = m.find(s);
            ite->second -= 1;
        }
    }

    int maxval = 0;             // ないカードを言うのはあり
    for (ite = m.begin(); ite != m.end(); ite++) {
        maxval = max(maxval, ite->second);
    }
    cout << maxval << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <list>
using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, K; cin >> N >> K;
	vector<int> a(N), b(N);
	for (int& x: a) cin >> x;
	for (int& x: b) cin >> x;
	vector<int> dp(K + 1);
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		vector<int> c(401, 1), C(K + 1);
		for (int dk = 0; dk <= K; dk++) {
			for (int z = a[i]; z <= b[i]; z++) C[dk] = (C[dk] + c[z]) % MOD;
			for (int z = 0; z <= 400; z++) c[z] = (ll)c[z] * z % MOD;
		}
		vector<int> _dp(K + 1);
		for (int k = 0; k <= K; k++)
			for (int dk = 0; k + dk <= K; dk++)
				_dp[k + dk] = (_dp[k + dk] + (ll)dp[k] * C[dk]) % MOD;
		dp = _dp;
	}
	cout << dp[K] << endl;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
#define int ll
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<P> v(n);
  for(int i=0;i<n;++i) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end(), [](P p1, P p2){return (p1.first + p1.second) > (p2.first + p2.second);});
  int taka = 0, ao = 0;
  for(int i=0;i<n;++i) {
    if(i%2 == 0) taka += v[i].first;
    else ao += v[i].second;
  }
  cout << taka - ao << endl;

}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

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

    vector<ll> b(n+1);
    b[0] = 0;
    for (int i = 0; i < n; i++)
    {
        b[i+1] = (a[i]+b[i])%m;
    }

    ll ans = 0;
    map<ll, ll> p;
    for (int i = 0; i <= n; i++)
    {
        ans += p[b[i]];
        p[b[i]]++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;
		int numX = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();
			numX = scanner.nextInt();

			if (numX - numA <= numB && numA <= numX) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numM = 0;
		int numX = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextInt();
			numX = scanner.nextInt();

			Set<Integer> wk = new HashSet<Integer>();

			for (int i = 0; i < numM; i++) {
				wk.add(scanner.nextInt());
			}
			int res1 = 0;
			for (int i = numX; i <= numN; i++) {
				if (wk.contains(i)) {
					res1++;
				}

			}
			int res2 = 0;
			for (int i = 0; i <= numX; i++) {
				if (wk.contains(i)) {
					res2++;
				}

			}

			System.out.println(Math.min(res1, res2));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			long[] wk = new long[numN];
			long[] wk2 = new long[numN];

			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
				wk2[i] = wk[i];
			}

			Arrays.sort(wk2);

			//中央値の準備（１：中央値より大きい値が除外された時の中央値　２：中央値より小さい値が除外された時の中央値）
			long m1 = wk2[(numN / 2) - 1];
			long m2 = wk2[(numN / 2)];

			for (int i = 0; i < wk.length; i++) {
				if (wk[i] > m1) {
					System.out.println(m1);
				} else {
					System.out.println(m2);
				}
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n:usize,
        k:usize,
    }
    let mut a = n % k;
    let mut b = k - a;
    println!("{}", min(a, b));
}


Measured memory_bytes: 4352
public class Main {


  private static void solve() {
    int a = ni();
    int b = ni();
    if (a * b == 15) {
      System.out.println("*");
    } else if (a + b == 15) {
      System.out.println("+");
    } else {
      System.out.println("x");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n, d;
  cin >> n >> d;
  int x[n], y[n];
  rep(i, n) cin >> x[i] >> y[i];

  int ans = 0;
  rep(i, n) {
    ll d2 = (ll)x[i] * x[i] + (ll)y[i] * y[i];
    if (d2 <= (ll)d * d) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5152
using Yorukatsu031.Questions;
using Yorukatsu031.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu031.Questions
{
    /// <summary>
    /// ABC051 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            yield return s.Replace(',', ' ');
        }
    }
}


namespace Yorukatsu031
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu031.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu031.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	string s;
	cin >> s;
	string ans;
	int t;
	int slong = s.size();
	for (t = 0; t < slong; t++) {
		if (s[t] == '0') {
			ans.push_back('0');
		}
		if (s[t] == '1') {
			ans.push_back('1');
		}
		if (s[t] == 'B'&&ans.size()>0) {
			ans.pop_back();
		}
	}

	cout << ans;

	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    lrep(i, k, n+2){
        ans += (((((n)+(n-i+1))%mod)* (i%mod)/2 - ((i-1)%mod)*(i%mod)/2)+1)%mod;
        //cout << ans << endl;
    }
    cout << ans%mod << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    Graphl a(n);
    vector<int> p(m), y(m);
    rep(i, m)
    {
        cin >> p[i] >> y[i]; --p[i];
        a[p[i]].push_back(y[i]);
    }

    for (auto &v : a)
    {
        sort(ALL(v));
    }

    rep(i, m)
    {
        // auto b = find(ALL(a[p[i]]), y[i]);
        //int index = distance(a[p[i]].begin(), b);
        int index = lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin();
        printf("%06d%06d\n", p[i] + 1, index + 1);
    }
}

Measured memory_bytes: 7808
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K



int main(){
    ll n;
    ll a[10000];
    cin >> n;
    ll ans = 0;
    REP(i,n){
        cin >> a[i];
        while(a[i]%2==0 && a[i]!=0){
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		System.out.println(n*n-a);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21716
import java.util.Arrays;
import java.io.*;

public class Main{
    public static void  main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int cards = Integer.parseInt(br.readLine());
        int[] card = new int[cards];
        String  input = br.readLine();

        for(int i = 0; i<cards-1; i++){
            card[i] = Integer.parseInt(input.substring(0,input.indexOf(" ")));
            input = input.substring(input.indexOf(" ")+1);
        }
        card[cards-1] = Integer.parseInt(input);
        Arrays.sort(card);

        int Bob = 0;
        int Alice = 0;
        boolean isAliceTurn = cards%2 == 1;

        for(int a_card : card){
            if(isAliceTurn){
                Alice += a_card;
                isAliceTurn = false;
            }
            else{
                Bob += a_card;
                isAliceTurn = true;
            }
        }
    System.out.println(Alice - Bob);
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n;
  cin >> n;
  int ans = n;
  rep(i, n) {
    int l, r;
    cin >> l >> r;
    ans += r - l;
  }
  out(ans);
}
int main(void) { solve(); }

Measured memory_bytes: 3544
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7

    n, q = list(map(int, readline().split()))
    tmd = collections.defaultdict(list)
    for i in range(n-1):
        tma, tmb = list(map(int, readline().split()))
        tmd[tma-1] += [tmb-1]
        tmd[tmb-1] += [tma-1]
    score = [0] * n
    for i in range(q):
        p, x = list(map(int, readline().split()))
        score[p-1] += x

    ql = [[0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[0]
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    score[tmv] += score[tmp]
                    ql.append([cost + 1, tmv])
                    fq[tmv]
        else:
            break
    print(*score)


if __name__ == '__main__':
    solve()


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul n;
  cin >> n;
  vector< ul > a(n+1), b(n);
  for (ul i=0; i<=n; ++i) cin >> a[i];
  for (ul i=0; i<n; ++i) cin >> b[i];
  ul ans = 0;
  for (ul i=0; i<n; ++i) {
    ans += min(a[i], b[i]);
    b[i] -= min(a[i], b[i]);
    ans += min(a[i+1], b[i]);
    a[i+1] -= min(a[i+1], b[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n=gets.to_i
arr=Array.new(n+1,100000)
arr2=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049].reverse
arr[0]=0
arr[1]=1
i=2
(n-1).times{
    
    k=0
    12.times{
        if   i>=arr2[k]
        
          arr[i]=[arr[i-arr2[k]]+1,arr[i]].min
        end
        
        k+=1
    }
    
    
i+=1
    
    
    
}



p arr[n]

Measured memory_bytes: 3836
import sys

input = sys.stdin.readline

def main():
    a,b = map(int, input().split())
    
    A = []
    for i in range(a):
        s = list(map(int, input().split()))
        A.append(s)
    
    B = []
    for i in range(b):
        s = int(input())
        B.append(s)
    
    for i in range(a):
        c = 0
        for k in range(b):
            c += A[i][k] * B[k]
        print(c)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 5996
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println((((A + N - 1) / N) * N <= B)?"OK":"NG");
		sc.close();
	}
}

Measured memory_bytes: 35836
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> ws(n);
  for(Int i=0;i<n;i++) cin>>ws[i];

  Int sum=0;
  for(Int i=0;i<n;i++) sum+=ws[i];

  Int ans=sum,res=0;
  for(Int i=0;i<n;i++){
    res+=ws[i];
    chmin(ans,abs(res-(sum-res)));
  }

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


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

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

void solve(ll testnum)
{
    string s;
    cin >> s;
    if(s[s.size()-1] != 's') {
    	cout << s + "s" << "\n";
    } else {
    	cout << s + "es" << "\n";
    }
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <math.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

int main(){
    string n1;
    cin >> n1;

    ll l = n1.length();

    ll index = 0;
    rep(i, l){
        ll k = l - 1 - i;
        if(k <= i)
        {
            break;
        }

        if(n1.at(i) != n1.at(k))
        {
            index++;
        }
    }

    cout << index << endl;
    return 0;
}

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

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

void insertionsort(int A[] , int N){
  int j, i , v;
  for (i = 1; i < N; i++){
    v = A[i];
    j = i-1;
    while (j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A,N);
  }
}

int main() {
  int N,i,j;
  int A[100];

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

  trace(A,N);
  insertionsort(A,N);

  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
using namespace std;
int m, n, k;
char f[1005][1005];
int sum[3][1005][1005] = { 0 };
int main() {
	cin >> m >> n >> k;
	for (int i = 0; i < m; i++)
		for (int j = 0; j < n; j++) cin >> f[i][j];
	for (int u = 0; u < 3; u++) {
		char c;
		int cnt = 0;
		if (u == 0) c = 'J';
		if (u == 1) c = 'O';
		if (u == 2) c = 'I';
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (f[i][j] == c) sum[u][i][j] = 1;
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				sum[u][i][j + 1] += sum[u][i][j];
			}
		}
		for (int j = 0; j < n; j++) {
			for (int i = 0; i < m; i++) {
				sum[u][i + 1][j] += sum[u][i][j];
			}
		}
	}
	for (int q = 0; q < k; q++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--; c--; d--;
		for (int u = 0; u < 3; u++) {
			int res = 0;
			res += sum[u][c][d];
			if (a - 1 >= 0 && b - 1 >= 0) res += sum[u][a - 1][b - 1];
			if (a - 1 >= 0) res -= sum[u][a - 1][d];
			if (b - 1 >= 0) res -= sum[u][c][b - 1];
			if(u!=2) cout << res << " ";
			else cout << res << endl;
		}
	}
	return 0;
}


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

int main() {
  vector<int> si(6);
  for (int i = 0; i < 6; i++) cin >> si.at(i);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    char c = s.at(i);
    int tmp;
    switch (c) {
    case 'N':
      tmp = si[4];
      si[4] = si[0];
      si[0] = si[1];
      si[1] = si[5];
      si[5] = tmp;
      break;
    case 'S':
      tmp = si[1];
      si[1] = si[0];
      si[0] = si[4];
      si[4] = si[5];
      si[5] = tmp;
      break;
    case 'E':
      tmp = si[3];
      si[3] = si[5];
      si[5] = si[2];
      si[2] = si[0];
      si[0] = tmp;
      break;
    case 'W':
      tmp = si[2];
      si[2] = si[5];
      si[5] = si[3];
      si[3] = si[0];
      si[0] = tmp;
      break;
    }
  }
  cout << si.at(0) << endl;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;

    int x = floor(N / 1.08);
    if(floor(x * 1.08) == N){
        cout << N / 1.08 << endl;
        return 0;
    }

    x += 1;
    if(floor(x * 1.08) == N){
        cout << x << endl;
        return 0;
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ll long long


#define fi first
#define se second


#define alli(a, n, k) (a+k),(a+n+k)
#define rep(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)


#define endl '\n'


typedef vector<int> vii;

typedef pair<int, int> pii;


class Solution {
public:
    const int static MAX = 1e5 + 5;
    int a;
    pii p[MAX];
    void solve(std::istream& in, std::ostream& out) {
		int n, m;
        priority_queue<int, vii, greater<int>> pq;
        in >> n >> m;
        rep(i, 0, n, 1) {
            in >> a;
            pq.push(a);
        }
        rep(i, 0, m, 1) {
            in >> p[i].se >> p[i].fi;
        }
        sort(alli(p, m, 0), greater<pii>());
        rep(i, 0, m, 1) {
            while(p[i].se > 0 and pq.top() < p[i].fi) {
                pq.pop();
                pq.push(p[i].fi);
                p[i].se--;
            }
        }
        ll ans = 0;
        while (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
        out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 1660
N, X, Y = map(int, input().split())

ans_list = [0] * N
for i in range(N):
    for j in range(i+1,N):
        curr = min(j-i, abs(X-i-1) + 1 + abs(Y-j-1))
        ans_list[curr] += 1

for i in range(1,N):
    print(ans_list[i])

Measured memory_bytes: 3444
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;

typedef map<int,vector<int> > Graph;

bool visit(Graph &g, int v, vector<int> &order, map<int,int> &color) {
  color[v] = 1;
  FOR(e, g[v]) {
    if (color[*e/*->dst*/] == 2) continue;
    if (color[*e/*->dst*/] == 1) return false;
    if (!visit(g, *e/*->dst*/, order, color)) return false;
  }
  order.push_back(v); color[v] = 2;
  return true;
}
bool topologicalSort(Graph &g, vector<int> &order) {
  //int n = g.size();
  map<int,int> color;//(n);
  FOR(u, g) if (!color[u->first] && !visit(g, u->first, order, color))
    return false;
  reverse(ALL(order));
  return true;
}

int main(){
	int i,V,E,s,t;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d",&V,&E);
		Graph g;//(V);
		set<int>orphan;
		for(int i=0;i<V;i++)orphan.insert(i);
		for(;E--;)scanf("%d%d",&s,&t),g[s].push_back(t),orphan.erase(s),orphan.erase(t);
		//for(;!g.empty();){
			vector<int> order;
			topologicalSort(g,order);
			for(i=0;i<order.size();i++){
				printf("%d\n",order[i]);
				g.erase(order[i]);
			}
		//}
		FOR(u,orphan)printf("%d\n",*u); //孤立した頂点が存在するデータがあるので注意
	//}
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;

int main(){
    
    int N;cin>>N;
    vector<int> S(N);//iがS[i]番目にある
    for(int i=0;i<N;i++){
        int a;cin>>a;
        a--;
        S[a]=i;
    }
    int ans=0,now=S[0],cnt=1;
    for(int i=1;i<N;i++){
        if(S[i]>now) cnt++;
        else cnt=1;
        ans=max(ans,cnt);
        now=S[i];
    }
    if(N!=1) cout<<N-ans<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {   
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if(k < a) cout << k << ln;
    else if(k <= a+b) cout << a << ln;
    else cout << a - (k-a-b) << ln;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>

using namespace std;

int main(){
  char ch;
  int i=0;
  while(1){
    scanf("%c",&ch);
    if(ch=='\n'){
      cout<<endl;
      break;
    }
    // if(i==0)cout<<endl;
    if(ch>='A'&&ch<='z'){
      if(ch>='A'&&ch<='Z'){
        ch+=32;
      }else{
        ch-=32;
      }
    }
    printf("%c",ch);
    i++;
  }
  return 0;
}



Measured memory_bytes: 3148
// Date: 2020-02-24

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n;
LL a[N];
int main() {
    scanf("%d", &n);
    LL sum = 0;
    rep(i, 1, n) scanf("%lld", &a[i]), a[i] -= i;
    sort(a+1, a+1+n);
    LL ans = 0;
    int l = 1, r = n;
    while(l + 1 < r) {
        ans += a[r]-a[l];
        ++l, --r;
    }
    if(l < r) ans += a[r]-a[l];

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


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
static const int MAX_V = 100000;

//Graph Element
struct E {
	E(int t, int f) {
		to = t;
		from = f;
	}
	E(int t, int f, int c) {
		to = t;
		from = f;
		cost = c;
	}
	int to;
	int from;
	int cost;
	bool visited;
	bool use;
};
struct V {
	vector<E*> edge;
	bool visited;
};
V G[MAX_V];
/////////////////////////////////////////////

//dfs
int ans = 0;
int VS, ES;
void dfs(int n) {
	rep(i, 0, G[n].edge.size()) {
		if (G[n].edge[i]->use && !G[G[n].edge[i]->to].visited) {
			G[G[n].edge[i]->to].visited = true;
			dfs(G[n].edge[i]->to);
		}
	}
}

void dfs_stack_lib(int n) {
	rep(i, 0, G[n].edge.size()) {
		if (G[n].edge[i]->use && !G[G[n].edge[i]->to].visited) {
			G[G[n].edge[i]->to].visited = true;
			dfs(G[n].edge[i]->to);
		}
	}
}

void dfs_stack_array(int n) {
	rep(i, 0, G[n].edge.size()) {
		if (G[n].edge[i]->use && !G[G[n].edge[i]->to].visited) {
			G[G[n].edge[i]->to].visited = true;
			dfs(G[n].edge[i]->to);
		}
	}
}
//BFS by array
//void bfs_queue_array(int n) {
//	int q[1000] = {};
//	int s = 0, e = 0;
//	q[e++] = n;
//	int c = 0;
//
//	while (s < e) {
//		c = q[s++];
//		G[c].visited = true;
//
//		rep(i, 0, G[c].edge.size()) {
//			if (G[c].edge[i]->use && !G[G[c].edge[i]->to].visited) {
//				q[e++] = G[c].edge[i]->to;
//			}
//		}
//	}
//}

//BFS by queue
void bfs_queue_lib(int n) {
	int q[1000] = {};
	int s = 0, e = 0;
	q[e++] = n;
	int c = 0;

	while (s < e) {
		c = q[s++];
		G[c].visited = true;

		rep(i, 0, G[c].edge.size()) {
			if (G[c].edge[i]->use && !G[G[c].edge[i]->to].visited) {
				q[e++] = G[c].edge[i]->to;
			}
		}
	}
}
int main() {
	cin >> VS >> ES;

	rep(i, 0, ES)
	{
		int s, t; cin >> s >> t;
		G[s].edge.push_back(new E(t, s));
		G[t].edge.push_back(new E(s, t));
	}

	///////////////////////////////////////////////////////////
	//DFS
	//Edge all false
	repe(i, 1, VS) rep(j, 0, G[i].edge.size()) {
		//Edge all visited false;
		repe(k, 1, VS) rep(l, 0, G[k].edge.size()) G[k].edge[l]->use = true;
		repe(k, 1, VS) G[k].visited = false;

		G[i].edge[j]->use = false;

		//DFS
		G[1].visited = true;
		//dfs(1);
		bfs_queue_lib(1);

		bool ok = true;
		repe(k, 1, VS)  ok &= G[k].visited;
		if (!ok)ans++;
	}

	cout << ans << endl;

	return 0;
}

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

K, S = map(int, input().split())
res = 0
for X in range(K+1):
    for Y in range(K+1):
        Z = S - X - Y
        if 0 <= Z and Z <= K: res += 1

print(res)

Measured memory_bytes: 5192
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int cnt = 0;
    for (int i = 0; i < n; ++ i) {
        for (int j = i + 1; j < n; ++ j) {
            int x = a[i], y = a[j];
            cnt += lower_bound(a.begin() + j + 1, a.end(), x + y) - upper_bound(a.begin() + j + 1, a.end(), y - x);
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            long N = long.Parse(NK[0]);
            long K = long.Parse(NK[1]);

            long amari = N % K;
            long amari2 = K - amari;

            long ans = Math.Min(amari, amari2);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int a[500009],t[500009],r=0;
void mergesort(int lo,int hi){
if(lo==hi) return;
int mid =(lo+hi)/2;
    mergesort(lo,mid);
    mergesort(mid+1,hi);

    int i,j,k;
    i=lo;
    j=mid+1;
    for(k=lo;k<=hi;k++){

        if(i==mid+1) t[k]=a[j++];
        else if(j==hi+1)  t[k]=a[i++];
        else if(a[i]<a[j]) t[k]=a[i++];
        else t[k]=a[j++];
        r++;
    }

     for(k=lo;k<=hi;k++){
     a[k]=t[k];
    }
}
int main()
{

  int m,n,i,j,s=0,t=0,te;
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];

mergesort(0,n-1);
for(i=0;i<n-1;i++) cout<<a[i]<<" ";
cout<<a[n-1]<<endl;
            cout<<r;
        cout<<endl;

    return 0;
}

Measured memory_bytes: 6904
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[3 * N];
        for (int i = 0; i < 3 * N; i++) {
            A[i] = scan.nextLong();
        }
        PriorityQueue<Long> red_queue = new PriorityQueue<>(Comparator.naturalOrder());
        long red_sum = 0;
        for (int i = 0; i < N; i++) {
            red_sum += A[i];
            red_queue.add(A[i]);
        }
        PriorityQueue<Long> blue_queue = new PriorityQueue<>(Comparator.reverseOrder());
        long blue_sum = 0;
        for (int i = 2 * N; i < 3 * N; i++) {
            blue_sum += A[i];
            blue_queue.add(A[i]);
        }
        long[] red_holder = new long[N+1];
        long[] blue_holder = new long[N+1];
        red_holder[0] = red_sum;
        for (int i = 1; i <= N; i++) {
            red_queue.add(A[N + i - 1]);
            red_sum += A[N + i - 1];
            red_sum -= red_queue.poll();
            red_holder[i] = red_sum;
        }
        blue_holder[0] = blue_sum;
        for (int i = 1; i <= N; i++) {
            blue_queue.add(A[N + N - i]);
            blue_sum += A[N + N - i];
            blue_sum -= blue_queue.poll();
            blue_holder[i] = blue_sum;
        }
        long ans = Long.MIN_VALUE;
        for (int i = 0; i <= N; i++) {
            ans = Math.max(ans, red_holder[i]-blue_holder[N-i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 100100