akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int n,fa[100005],x[100005],y[100005];
pair<int,int> px[100005],py[100005];
vector<pair<int,pair<int,int> > > pe;
int gf(int x){
	if (fa[x]==x) return x; else return fa[x]=gf(fa[x]);
}
int Abs(int x){
	if (x>=0) return x; else return -x;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>px[i].first;
		x[i]=px[i].first;
		px[i].second=i;
		cin>>py[i].first;
		y[i]=py[i].first;
		py[i].second=i;
		fa[i]=i;
	}
	sort(px,px+n);
	sort(py,py+n);
	for (int i=0;i<n-1;i++){
		pe.push_back(mp(min(Abs(px[i+1].first-px[i].first),Abs(y[px[i+1].second]-y[px[i].second])),mp(px[i].second,px[i+1].second)));
		pe.push_back(mp(min(Abs(py[i+1].first-py[i].first),Abs(x[py[i+1].second]-x[py[i].second])),mp(py[i].second,py[i+1].second)));
	}
	sort(pe.begin(),pe.end());
	long long cnt=0;
	for (int i=0;i<pe.size();i++){
		gf(pe[i].second.second);
		gf(pe[i].second.first);
		if (fa[pe[i].second.first]!=fa[pe[i].second.second]){
			fa[gf(pe[i].second.second)]=gf(pe[i].second.first);
			cnt+=pe[i].first;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 7540
from collections import defaultdict
d = defaultdict(int)
N, M = map(int, input().split())
abL = [list(map(int, input().split())) for _ in range(N)]
cdL = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    for j in range(M):
        d[j] = abs(abL[i][0] - cdL[j][0]) + abs(abL[i][1] - cdL[j][1])

    m = min(d.values())
    for k, v in d.items():
        if (v == m):
            print(k + 1)
            break


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vint cntW(N + 1), cntE(N + 1); //cntP[i] := 0<=j<=i-1 のうちでS[j] = Pとなるjの数
                                   //cntP.back()-cntP[i] = i<=j<N のうちでS[j] = Pとなるjの数
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'W')
        {
            cntW[i + 1] = cntW[i] + 1;
            cntE[i + 1] = cntE[i];
        }
        else
        {
            cntW[i + 1] = cntW[i];
            cntE[i + 1] = cntE[i] + 1;
        }
    }
    int ans = INT_MAX;
    for (int i = 0; i < N; i++)
    {
        chmin(ans, cntW[i] + cntE.back() - cntE[i + 1]);
    }
    cout << ans;
    return 0;
}

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

using lint = long long int;
using pii = std::pair<int, int>;

using std::vector;
vector<lint> ve;

int main(void) {
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		lint temp;
		scanf("%lld", &temp);
		ve.push_back(temp);
	}
	sort(ve.begin(), ve.end());

	lint cur = -1, cur_cou = 0;
	lint fi = -1, se = -1;
	for (int i = N - 1; i >= 0; i--) {
		if (cur == ve[i]) {
			cur_cou++;
		}
		else {
			cur = ve[i];
			cur_cou = 1;
		}

		if (cur_cou % 2 == 0) {
			if (fi == -1) {
				fi = cur;
			}
			else {
				printf("%lld", fi * cur);
				return 0;
			}
		}
	}
	printf("0");

	return 0;
}

Measured memory_bytes: 1400
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    su = 0; cnt = 0; i = 0
    for line in readlines():
        a, b = map(int, line.split(","))
        su += a*b
        cnt += b
        i += 1
    x = (cnt // i)
    if (2*x+1)*i <= 2*cnt:
        x += 1
    write("%d\n%d\n" % (su, x))
solve()



Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin >> n >> k;
    cout << min(n%k,(k-n%k)%k) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>

int main()
{
int n, k;
std::cin >> n >> k;
if(n % k == 0){
    std::cout << 0;
} else {
    std::cout << 1;
}
return 0;
}

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

namespace ConsoleApp3
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var numbers = Console.ReadLine().Split(' ');

			var nega = from num in numbers
					   where int.Parse(num) < 0
					   orderby int.Parse(num)
					   select int.Parse(num);

			var other = from num in numbers
						where int.Parse(num) >= 0
						orderby int.Parse(num)
						select int.Parse(num);

			var negativeList = nega.ToList<int>();
			var otherList = other.ToList<int>();

			int min = 0;
			int max = 0;
			// 0以上のみ
			if (negativeList.Count == 0)
			{
				min = otherList.First();
				max = otherList.Last();

				int m = otherList.Sum() - min * 2;				
				Console.WriteLine(m);

				int newNum = min;
				for (int i = 1; i < n - 1; i++)
				{
					Console.WriteLine("{0} {1}", newNum, otherList[i]);
					newNum -= otherList[i];
				}
				Console.WriteLine("{0} {1}", max, newNum);				
				return;
			}
			// 負のみ
			else if (otherList.Count == 0)
			{
				min = negativeList.First();
				max = negativeList.Last();

				int m = negativeList.Sum() - max * 2;
				m *= -1;
				Console.WriteLine(m);

				int newNum = max;
				for (int i = 0; i < n - 1; i++)
				{
					Console.WriteLine("{0} {1}", newNum, negativeList[i]);
					newNum -= negativeList[i];
				}
				return;
			}
			// 混合
			else
			{
				min = negativeList.First();
				max = otherList.Last();

				int m = otherList.Sum() - negativeList.Sum();
				Console.WriteLine(m);

				int newNum = min;
				for (int i = 0; i < otherList.Count - 1; i++)
				{
					Console.WriteLine("{0} {1}", newNum, otherList[i]);
					newNum -= otherList[i];
				}
				negativeList[0] = newNum;
				newNum = max;
				for (int i = 0; i < negativeList.Count; i++)
				{
					Console.WriteLine("{0} {1}", newNum, negativeList[i]);
					newNum -= negativeList[i];
				}
				return;
			}
		}
	}
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

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

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, C, K;
  cin >> N >> C >> K;
  vint T(N);
  rep(i, N) cin >> T[i];
  sort(all(T));
  int sum[N+1];
  int l = 0, r = 0, ans = 0;
  while(1) {
    while(r < N && r-l < C && T[r]-T[l] <= K) r++;
    ans++;
    if(r >= N) break;
    l = r;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll maxi, mini;
    if(N & 1) {
        maxi = B[N/2];
        mini = A[N/2];
    } else {
        maxi = B[N/2] + B[N/2-1];
        mini = A[N/2] + A[N/2-1];
    }
    cout << maxi - mini + 1 << endl;
    return 0;
}


Measured memory_bytes: 6368
#include <vector>
#include <cassert>
#include <iostream>
using namespace std;
const int mod = 1000000007;
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int>> dp(H + 1, vector<int>(W, 0));
    dp[0][0] = 1;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            for (int k = 0; k < 1 << (W - 1); k++) {
                bool ok = true;
                for (int l = 0; l < W - 2; l++) {
                    if (k >> l & 1 && k >> (l + 1) & 1) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    if (w >= 1 && k >> (w - 1) & 1) {
                        dp[h + 1][w - 1] += dp[h][w];
                        dp[h + 1][w - 1] %= mod;
                    }
                    else if (w <= W - 2 && k >> w & 1){
                        dp[h + 1][w + 1] += dp[h][w];
                        dp[h + 1][w + 1] %= mod;
                    }
                    else{
                        dp[h + 1][w] += dp[h][w];
                        dp[h + 1][w] %= mod;
                    }
                }
            }
        }
    }
    cout << dp[H][K - 1];
    return 0;
}

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

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

    vector<int> vec(n);

    for (int i = 0; i<n ; i++) 
    {
        cin >> vec.at(i);
    }

    int result = 0;
    for (int i = 0; i < n; i++) {
        int dec = 2;
        while (vec[i] % dec == 0){
            dec = dec * 2;
            result++;
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 256
function Main(input){
  var arr = input.split('\n');
  arr.pop();
  var b={};
  var r={};
  for(var i=1;i<arr.length;i++){
    if(i<=Number(arr[0])){
      if(isNaN(b[arr[i]])){
        b[arr[i]]=1;
      }else{
        b[arr[i]]+=1;
      }
    }else if(i>Number(arr[0])+1){
      if(isNaN(r[arr[i]])){
        r[arr[i]]=1;
      }else{
        r[arr[i]]+=1;
      }
    }
  }
  for(var i in r){
    if(!isNaN(b[i])){
      b[i]-=r[i];
    }
  }
  var maxv=0;
  for(var i of Object.keys(b)){
    if(b[i]>maxv){
      maxv=b[i];
    }
  }
  console.log(maxv);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
LL of[309],jf[90009], p[309];

int main(){
	int n;
	while(scanf("%d",&n),n){
		int ol=0,jl=0;
		for(int i=0; i<(n+1)*n/2;i++){
			LL x;
			scanf("%lld",&x);
			if(x%2==0)
				of[ol++] = x;
			else
				jf[jl++] = x;
		}
		sort(of,of+ol);
		sort(jf,jf+jl);
		
		LL a0 = int(sqrt((1.0*of[0]/jf[0]*of[1]))+0.001);
		printf("%lld\n%lld",a0,of[0]/a0);
		for(int i=1;i<n;i++)
			printf(" %lld",of[i]/a0);
		printf("\n");
	}
	return 0;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n;
int a[MAXN];
int d[MAXN];
LL cc[MAXN];

void init ();
void input ();
void work ();

void NO ()
{
	cout << "NO" << endl;
	exit ( 0 );
}



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ){
		d[i] = ( a[i%n+1] << 1 ) - a[i] - a[(i+1)%n+1];
		if ( d[i] % n ) NO ();
		d[i] /= n;
	}
	
	LL sum = 0;
	lpi ( i, 1, n ) sum += d[i];
	if ( sum ) NO ();
	
	sum = 0;
	lpi ( i, 1, n ) sum += a[i];
	if ( sum % ( SC ( LL, n ) * ( n + 1 ) >> 1 ) ) NO ();
	
	cc[n] = 0;
	lpd ( i, n-1, 0 ) cc[i] = cc[i+1] + d[i];
	LL mini = *min_element ( cc+1, cc+1+n );
	lpi ( i, 1, n ) cc[i] += mini;
	sum = 0;
	lpi ( i, 1, n ) sum += i * cc[i];
	
	if ( sum > a[1] ) NO ();
	
	cout << "YES" << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define Rep1(i,k,n) for(int i=k ; i<=n ; i++)
#define rrep(i,n) for(int i=n ; i>=0 ; i--)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

//vi prime(1000000,0);
vector<bool> isp;

void makePrime(int n){
    isp.assign(n+1,true);
    int id = 0;
    for(int i=2 ; i <= n ; i++){
        if(!isp[i]) continue;

        for(int k = i*2 ; k <= n ; k += i){
            isp[k] = false;
        }
        /*
        prime[id] = i;
        id++;
        */
        
        //prime.pb(i);
    }
    //Sort(prime);
}

ll check(int a, int b){
    ll ans = 0;
    if(a-b <= 2) ans++;
    int s;
    if((a-b)%2 == 0) s = a-b+1;
    else s = a - b;

    for(int i = max(s,3); i <= min(a+b,999983) ; i += 2) {
        if(isp[i]) ans++;
    }
    return ans;
}
int main(){
    makePrime(999983);
    //cout << prime.size() << endl;
    //cout << binary_search(ALL(prime),2) << endl;
    int n; 
    while(true){
        cin >> n;
        if(n == 0) break;
        ll ans = 0;
        rep(i,n){
            int a,b; cin >> a >> b;
            //cout << check(a,b) << endl;
            int tmp = check(a,b);
            //cout << "check: " <<  tmp << endl;
            ans += check(a,b)-1;
            
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3220
def get_sharp_or_dot(number):
    if number % 2 == 0:
        return '#'
    else:
        return '.'


num = 0
while True:
    [H, W] = [int(x) for x in raw_input().split()]
    if [H, W] == [0, 0]:
        break
    for x in range(H):
        print("".join([get_sharp_or_dot(i) for i in range(x, W + x, 1)]))

    print('')

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

typedef long long LL;

LL ans;
LL n, a, b;

int main()
{
    while(~scanf("%lld%lld%lld", &n, &a, &b)){
        LL minx=a+b+(n-2)*a;
        LL maxx=a+b+(n-2)*b;
        ans=maxx-minx+1;
        if(a>b)ans=0;
        if(ans<0)ans=0;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
 	fmt.Scanf("%d %d", &a, &b)
 	ans := (b - 1) / (a - 1)
    if (b - 1) % (a - 1) == 0 {
      fmt.Println(ans)
    } else {
      fmt.Println(ans+1)
    }
}

Measured memory_bytes: 512
arr=list(map(int,input().rstrip().split()))
N=arr[0]
M=arr[1]
arr=list(map(int,input().rstrip().split()))
summ=0
for i in range(M) :
    summ+=arr[i]
if summ>N :
    print(-1)
else :
    print(N-summ)


Measured memory_bytes: 10060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vi to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
  if (i > j) swap(i,j);
  return id[i][j];
}

bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int v) {
  if (visited[v]) {
    if (!calculated[v]) return -1;
    return dp[v];
  }
  visited[v] = true;
  dp[v] = 1;
  for (int u : to[v]) {
    int res = dfs(u);
    if (res == -1) return -1;
    dp[v] = max(dp[v],res+1);
  }
  calculated[v] = true;
  return dp[v];
}

int main () {
  int n; cin >> n;
  vvi a(n,vi(n-1));
  REP(i,n) {
    REP(j,n-1) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }

  int V = 0;
  REP(i,n)REP(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }
  }

  REP(i,n) {
    REP(j,n-1) {
      a[i][j] = toId(i,a[i][j]);
    }
    REP(j,n-2) {
      to[a[i][j+1]].push_back(a[i][j]);
    }
  }

  int ans = 0;
  REP(i,V) {
    int res = dfs(i);
    if (res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans,res);
  }
  cout << ans << endl;
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;


const int MAX = 2e6+5;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD; 
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD; 
    }
}


ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    COMinit();
    ll res=0;
    res=((COM(r2+c2+2, r2+1)+COM(r1+c1, r1))%MOD-(COM(r2+c1+1, r2+1)+COM(r1+c2+1, r1))%MOD)%MOD;
    if(res < 0) res+=MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 50452
import java.util.*;

public class Main {
    static long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] a=new long[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        long sum = 0;
        for(int i=0;i<n;i++){
            long sum2 = 0;
            long sum3 = 0;
            for(int j=0;j<n;j++){
                if(a[i]>a[j])sum3++;
                if(j>=i+1){
                    if(a[i]>a[j]){
                        sum2++;
                    }
                }
            }
            long tmp = ((k*(k-1))/2)%mod;
            tmp = (tmp*sum3)%mod;
            sum2 = (sum2*k)%mod;
            sum = (sum + sum2 + tmp)%mod;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 27624
H,W=map(int,input().split())
N = int(input())
Alist = list(map(int,input().split()))
C = [[0]*W for _ in range(H)]
def change(x,y):
    return (-y,x)
h = 0
w = 0
(x,y) = (1,0)
i = 1
for a in Alist:
    while a > 0:
        C[h][w] = i
        h += y
        w += x
        a -= 1
        if w == W or h == H or w == -1 or h == -1 or C[h][w] != 0:
            h -= y
            w -= x
            (x,y) =change(x,y)
            h += y
            w += x
    i += 1
for c in C:
    print(*c)

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

int main(){
  int n, m; cin >> n >> m;
  int st = 1, la = n;
  int cnt = 0;
  
  for (int i = 0; i < m; i++){
    int l, r;
    cin >> l >> r;
    st = max(st, l);
    la = min(la, r);
    
    cnt = la - st + 1;
    if(cnt < 0) {cnt = 0; break;}
    
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;
typedef long long LL;


int main() {

	string a,b,c;
	
	cin >> a >> b;

	for (int i=0; i < a.size(); i++) {
		c += a.substr(i, 1);
		c += b.substr(i, 1);
	}

	cout << c;
	
	//int abc;
	//cin >> abc ;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
int lldown(const void *a, const void *b){return *(ll*)a>*(ll*)b?-1:1;}

int x, y, z, k;
ll a[1001], b[1001], c[1001], d[1001001], e[3003003];
int main(){
    scanf("%d%d%d%d", &x, &y, &z, &k);
    for(int i=0; i<x; i++)scanf("%lld", &a[i]);
    for(int i=0; i<y; i++)scanf("%lld", &b[i]);
    for(int i=0; i<z; i++)scanf("%lld", &c[i]);
    for(int i=0; i<x; i++){
        for(int j=0; j<y; j++){
            d[i*y+j] = a[i] + b[j];
        }
    }
    qsort(d, x*y, 8, lldown);
    for(int i=0; i<z; i++){
        for(int j=0; j<min(k, x*y); j++){
            e[i*min(k, x*y)+j] = c[i] + d[j];
        }
    }
    qsort(e, z*min(k, x*y), 8, lldown);
    for(int i=0; i<k; i++)printf("%lld\n", e[i]);
    return 0;
}

Measured memory_bytes: 54920
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - TAKOYAKI FESTIVAL 2019
            int N = int.Parse(Console.ReadLine());
            var d = ReadLine();

            var lib = new Library.Combination();
            var combis = lib.AllCombinations<int>(d, 2);
            int sum = 0;

            foreach(var c in combis)
            {
                sum += c[0] * c[1];
            }

            Console.WriteLine(sum);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

namespace Library
{
    class Combination
    {
        public IEnumerable<List<T>> AllCombinations<T>(List<T> source, int n,
                                                       bool isAllowDupication = false)
        {
            //[summary]異なる要素から、n個を選ぶ組み合わせを列挙する
            //"isAllowDupication"を"true"にすると、重複を許可する
            //(重複を許可して、nを要素数と同じにすると、順列を列挙する)

            if (n == 1)
            {
                foreach (var s in source)
                {
                    yield return new List<T> { s };
                }

                yield break;
            }
            else
            {
                for (int i = 0; i < source.Count; i++)
                {
                    List<T> clone;

                    if (isAllowDupication)
                    {
                        //重複を許可する場合は、その要素のみを削除
                        clone = new List<T>(source);
                        clone.RemoveAt(i);
                    }
                    else
                    {
                        //重複を許可しない場合は、自分よりも前の要素はすべて削除
                        clone = new List<T>(source.Skip(i + 1));
                    }

                    //再帰処理
                    var items = AllCombinations(clone, n - 1, isAllowDupication);

                    foreach (var item in items)
                    {
                        item.Insert(0, source[i]);
                        yield return item;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


const double PI = acos(-1);
const int M = 1000005;

int n,w;

vector<int> a;

bool rec(int i, int sum){
    
    if(i == n){
        if(sum == w)return true;
        else return false;
    }
    
    if(rec(i+1, sum + a[i])){
        return true;
    }
    if(rec(i, sum)){
        return true;
    }
    
    return false;
}

int main(){
    ll n,d;
    cin>>n>>d;
    
    vector<ll> x(n);
    vector<ll> y(n);
    for(ll i = 0; i<n; i++){
        cin>>x[i];
        cin>>y[i];
    }
    
    ll ans  = 0;
    for(ll i = 0; i<n; i++){
        if(sqrt(x[i]*x[i] + y[i]*y[i]) <= d){
            ans ++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6496
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int INF = 1 << 30;
const int MAX_N = 100000 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
int32_t main(){
    IOS;
    string s;
    cin >> s;
    int ans = 0;
    int count = 0;
    for(int i=0; i<s.size();i++ ){
        if(s[i] == 'R') count++;
        else count = 0;
        if(count > ans) ans = count;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  int n,m; cin>>n>>m;
  int l,r; cin>>l>>r;  
  int L=l,R=r;
  for(int i=1;i<m;i++){
    int l,r; cin>>l>>r;  
    L=max(L,l);
    R=min(R,r);
  }
  if(R-L>=0) cout<<R-L+1<<endl;
  else cout<<0<<endl;
}  

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<String, Integer> map = new HashMap<>();
        map.put("AC", 0);
        map.put("WA", 0);
        map.put("TLE", 0);
        map.put("RE", 0);
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            map.merge(s, 1, Integer::sum);
        }
        System.out.println("AC x " + map.get("AC"));
        System.out.println("WA x " + map.get("WA"));
        System.out.println("TLE x " + map.get("TLE"));
        System.out.println("RE x " + map.get("RE"));
    }
}

Measured memory_bytes: 58720
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	/* ----- 変数宣言 ----- */
	int n;
	cin >> n;
	int ans;

	int i;
	vector<int> d(n);

	/* ----- 入力 ----- */
	for (i = 0; i < n; i++) {
		cin >> d[i];
	}

	/* ----- 計算 ----- */
	sort(d.begin(), d.end());
	d.push_back( 0 );

	ans = 0;
	for (i = 0; i < n; i++) {
		if (d[i] != d[i + 1])	ans++;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 500010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}


void solve(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll sum = 0;
  rep(i, N) sum ^= A[i];
  rep(i, N){
    cout << (A[i] ^ sum) << " ";
  }
  cout << endl;
}

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


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


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

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

    int n;
    cin>>n;
    vector<vector<int>> a(n, vector<int>(n));

    for (int i = 0; i<n; i++)
        for (int j = 0; j<n; j++) cin>>a[i][j];

    ll res = 0;

    for (int i = 0; i<n; i++)
        for (int j = i+1; j<n; j++)
        {
            bool good = true;
            for (int k = 0; k<n; k++)
            {
                if (a[i][k] + a[k][j]<a[i][j]) {cout<<-1; return 0;}
                if (a[i][k]>0 && a[k][j]>0 && a[i][k] + a[k][j] == a[i][j]) good = false;
            }
            if (good) res+=a[i][j];
        }
    cout<<res;

}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
using namespace std;

#define rep(i,end)          rep2(i,0,(end))
#define rep2(i,beg,end)   for (int i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi v = get_n_array(n);
    int last = v[0] -1;
    bool answer = true;
    rep2(i, 1, v.size())
    {
        if (v[i] < last) {
            answer = false;
            break;
        }
        else {
            if (v[i] - 1 > last) last = v[i] - 1;
            else if (v[i] == last) last = v[i];
        }
    }
    if (answer) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int LINE_MAX = 1024;
    char buf[LINE_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0)
    {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main(){
  int x,y;
  while (1) {
  cin >> x >> y;
  if (x == 0 && y == 0) break;
  if (x > y)cout << y << " " << x << endl;
  else cout << x << " " << y << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		long t[] = new long[n];

		for (int i = 0; i < n; i++) {
			t[i] = Long.parseLong(br.readLine());
		}

		long l = 1;

		for (int i = 0; i < n; i++) {
			l = lcm(t[i], l);
		}

		System.out.println(l);
	}

	static long gcd(long a, long b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static long lcm(long a, long b) {
		long g = gcd(a, b);
		return a / g * b; // Be careful not to overflow
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
double x[10],y[10],sum;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>x[i]>>y[i];
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)if(i!=j)sum+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
	cout<<fixed<<setprecision(10)<<sum/n<<endl;
	return 0;
}


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

int main(void){
  int N;
  cin>>N;
  int* A = (int*)malloc(sizeof(int)*(N+1));
  int* B = (int*)malloc(sizeof(int)*N);
  for(int i=0;i<N+1;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  long long kill=0;
  int rest=0;
  for(int i=0;i<N;i++){
    if(A[i]<=rest){
      kill+=A[i];
      rest=B[i];
    }
    else if(A[i]<=rest+B[i]){
      kill+=A[i];
      rest=rest+B[i]-A[i];
    }
    else{
      kill=kill+rest+B[i];
      rest=0;
    }
  }
  kill+=min(rest,A[N]);
  cout<<kill<<endl;
  return 0;
}


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

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

int main() {
    int N, K, d, a, ans = 0;
    cin >> N >> K;
    vector<int> A(N, 1);
    for(int i = 0; i < K; ++i) {
        cin >> d;
        for(int j = 0; j < d; ++j) {
            cin >> a;
            A[a-1] -= 1;
        }
    }

    rep(i, N) {
        if (A[i] > 0) {
            ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<stack>
#include<queue>
#include<limits>

using namespace std;

int main(){
    int n;
    string a;

    cin >> n;
    cin >> a;
    for( int i=0; i< a.size(); i++){
        a[i] = 'A' + (int(a[i]-'A')+n)%26;
    }
    cout << a;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main() 
    { 
    long long int a; 
    double b; 
    cin >> a >> b; 
    long long int r = a * (long long int)round(b * 100.0) / 100; 
    cout << r << "\n"; 
    return 0; 
} 


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	double sum = 0;
	for(int i=0;i<n;i++)
	{
		double a;
		cin>>a;
		sum += 1 / a;
	}
	double rez = 1 / sum;
	cout<<setprecision(10)<<endl;
	cout<<fixed<<rez<<endl;
	return 0;
}

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

int main() {
  	long double A, B, H, M;
  	cin >> A >> B >> H >> M;
  
  	long double A_, B_;
  	A_ = (H * 60 + M) / 720;
  	B_ = M / 60;
  
  	long double res1, res2;
  	res1 = abs(A * sin(A_ * 2 * 3.141592653589793) - B * sin(B_ * 2 * 3.141592653589793));
  	res1 = res1 * res1;
  	res2 = abs(A * cos(A_ * 2 * 3.141592653589793) - B * cos(B_ * 2 * 3.141592653589793));
  	res2 = res2 * res2;
  
  	cout << fixed << setprecision(10);
  	cout << sqrt(res1 + res2) << endl;
}

Measured memory_bytes: 4172
N = int(input())
a = []

for i in range(N):
    a.append(int(input()))

i = 0
now = 0
while True:
    if now == 1:
        print(i)
        break
    if i == N:
        print("-1")
        break
    now = a[now] - 1
    i = i + 1

Measured memory_bytes: 7084
#include<iostream>
using namespace std;
int s, b, nS, nB, w;
int a[101], r[101];
int main(){
    cin >> nS >> nB;
    for(s=1; s<=nS; s++){cin>>a[s];}
    for(b=1; b<=nB; b++){
        for(s=1; s<=nS; s++){
            r[s] = a[s]%b;
        }
        for(s=1; s<=nS-1; s++){
            if(r[s] > r[s+1]){
                swap(a[s], a[s+1]);
                swap(r[s], r[s+1]);
            }
        }
    }
    for(s=1; s<=nS; s++){
        cout << a[s] << endl;
    }
}
void swap(int x, int y){
     w = x;
     x = y;
     y = w;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 8;


int main()
{
    #ifdef LOCAL
    freopen("a.txt", "r", stdin);
    //freopen("a.out", "w", stdout);
    int T = 4;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    LL n, a, b;
    cin >> n >> a >> b;
    LL ans = abs(a - b) - 1;
    if(ans & 1) cout << "Alice" << endl;
    else cout << "Borys" << endl;



    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



Measured memory_bytes: 256
X = int(input())

x = int(pow(X, 0.2) // 1)
y1 = x - pow(10, 6)
y2 = x + pow(10, 6)
#print(y1, y2)

for B in range(y1, y2 + 1):
  A = pow(X + pow(B, 5), 0.2) 
  #print(A)
  if type(A) != complex:
    if abs(int(A) - A) < pow(10, -6):
      print(int(A), B)
      quit()

Measured memory_bytes: 9516
def main():
  x=int(input())
  
  for a in range(pow(10,3)):
    if a**5>x:
      for b in range(pow(10,3)):
        if a**5-b**5==x:
          print(a,b)
          exit()
    else:
      for b in range(-pow(10,3),1):
        if a**5-b**5==x:
          print(a,b)
          exit()
if __name__=='__main__':
  main()

Measured memory_bytes: 9136
/*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define setbits                 __builtin_popcount
#define zerobits                __builtin_ctzll
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)               __gcd(a,b)
#define lcm(a, b)               ((a)*(b))/gcd(a,b)
#define watch(x)                cout << (#x) << " is " << (x) << endl
#define TEST_CASES()            ll t;cin>>t;while (t--)
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

   ll sum=0,a,total,n;
   cin>>total>>n;
    for (ll i=0;i<n;i++){cin>>a;sum+=a;}
    if ((total-sum)<0) cout<<-1<<endl;
    else cout<<total-sum<<endl;


}


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

using namespace std;

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

using ll = long long;
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 double eps = 1e-10;
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;
}

struct RollingHash {
    const int base = 9973;
    const int mod[2] = {999999937, 1000000007};
    vector<int> s;
    vector<ll> hash[2], pow[2];

    RollingHash(const vector<int> &cs) : s(cs) {
        int n = s.size();
        for (int id = 0; id < 2; ++id) {
            hash[id].assign(n+1, 0);
            pow[id].assign(n+1, 1);
            for (int i = 0; i < n; ++i) {
                hash[id][i+1] = (hash[id][i] * base + s[i]) % mod[id];
                pow[id][i+1] = pow[id][i] * base % mod[id];
            }
        }
    }

    // get hash of s[l:r)
    ll get(int l, int r, int id = 0) {
        ll res = hash[id][r] - hash[id][l] * pow[id][r-l] % mod[id];
        if (res < 0) res += mod[id];
        return res;
    }
};


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

  int n; cin >> n;
  vi a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  for(int i=0;i<n;++i) {
    cin >> b[i];
  }

  vi xa(n), xb(n);
  for(int i=0;i<n;++i) {
    xa[i] = a[i] ^ a[(i+1)%n];
  }
  for(int i=0;i<n;++i) {
    xb[i] = b[i] ^ b[(i+1)%n];
  }

  for(int i=0;i<n;++i) {
    xa.push_back(xa[i]);
  }

  RollingHash rha(xa), rhb(xb);

  for(int i=0;i<n;++i) {
    if(rha.get(i, i+n) == rhb.get(0, n)) {
      cout << i << " " << (a[i] ^ b[0]) << endl;
    }
  }



}


Measured memory_bytes: 28528
n, m = [int(i) for i in input().split()]
ab = []
for a in range(n):
	a, b = [int(i) for i in input().split()]
	ab.append((a, b))
cnt_m = 0
sum_money = 0
while(True):
	for a, b in sorted(ab):
		buy_n = min(m - cnt_m, b)
		sum_money += buy_n * a
		cnt_m += buy_n
	if cnt_m == m:
		break
print (sum_money)

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

int main() {
  int N;
  cin >> N;
  int total = 0;
  
  for ( int i = 0 ; i < N ; i++ ) {
    int x;
    int y;
    
    cin >> x >> y;
    total += y - x + 1;
  }
  
  cout << total << endl;
  
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int aa = a;
		int bb = b;
		for(int i=0; i<b-1; i++) {
			aa = aa * 10 + a;
		}
		for(int i=0; i<a-1; i++) {
			bb = bb * 10 + b;
		}
		System.out.println(Math.max(aa, bb));
	}
}

Measured memory_bytes: 21844
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int M = 1'000'000'007;

//              LEN   SUM
static int memo[1024][2048];

int solve(const int len, const int sum)
{
    assert(len < 1024);
    assert(sum < 2048);

    if (len == 0) {
        return (sum == 0 ? 1 : 0);
    }
    if (sum < 0) {
        return 0;
    }
    auto& m = memo[len][sum];
    if (m >= 0) {
        return m;
    }

    if (3 * len > sum) {
        m = 0;
        return 0;
    }
    const auto maxval = 3 + (sum - 3 * len);
    auto cases = 0LL;
    for (auto val = 3; val <= maxval; ++val) {
        cases += solve(len - 1, sum - val);
    }
    cases %= M;
    m = cases;
    return m;
}

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

    for (auto& x : memo) {
        for (auto& y : x) {
            y = -1;
        }
    }

    auto cases = 0LL;
    auto maxlen = sum / 3;
    for (auto len = 1; len <= maxlen; ++len) {
        cases += solve(len, sum);
    }
    cases %= M;

    cout << cases << endl;
    return 0;
}


Measured memory_bytes: 11808
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	string s;
	cin >> s;
	int memo = 0,ans = 0;
	
	rep(i,0,s.size()){
		ans += (int)s[i]-48;
	}
	
	rep(i,0,s.size()){
		memo = 0;
		rep(j,0,s.size()){
			if(j < i){
				memo += (int)s[j]-48;
			}
			else if(j == i){
				memo += (int)s[j]-49;
			}
			else{
				memo += 9;
			}
		}
		ans = max(memo,ans);
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 256