akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
typedef pair<int, int> pii;
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
const int N = 1e5 + 10;
int n, m, a[N];
int main() {	
	scanf("%d%d",&n,&m); int cnt = 0;
	rep(i,1,m) {
		scanf("%d",a + i);
		if (a[i] & 1) { cnt++; swap(a[1], a[i]); }
	}
	rep(i,2,m - 1) if (a[i] & 1) swap(a[i], a[m]);
	if (m == 2) {
		rep(i,1,m) printf("%d ",a[i]); printf("\n");
		printf("%d\n",(a[1] == 1) ? m - 1 : m);
		if (a[1] - 1) printf("%d ",a[1] - 1);
		rep(i,2,m) printf("%d ",(i < m) ? a[i] : a[i] + 1); printf("\n");
	} else if (cnt > 2) printf("Impossible\n");
	else if (m == 1) {
		rep(i,1,m) printf("%d ",a[i]); printf("\n");
		if (a[1] == 1) printf("1\n1\n");
		else printf("2\n%d %d\n",a[1] - 1, 1);
	} else {
		rep(i,1,m) printf("%d ",a[i]); printf("\n");
		printf("%d\n",(a[1] == 1) ? m - 1 : m);
		if (a[1] - 1) printf("%d ",a[1] - 1);
		rep(i,2,m) printf("%d ",(i < m) ? a[i] : a[i] + 1); printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n;
    cout<<3*n*n;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

const int N = 257;
using namespace std;

int main(void){
  while( true ){
    int n;
    int ans = 0;
    int G[N][N] = {{0,},};
    int H[N][N][4] = {{{0,},},};
    
    cin >> n;
    if(n == 0)break;
    
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	char c;
	cin >> c;
	G[i+1][j+1] = c - '0';
      }
    }
    for(int j = 1; j < n + 1; j++){
      if( G[1][j] ){
	for(int k = 0; k < 4; k++){
	  if ( k == 0 ){
	    H[1][j][k] = H[1][j - 1][0] + 1;
	  }else{
	    H[1][j][k] = 1;
	  }
	}
      }
    }
    for(int i = 2; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	if( G[i][j] ){
	  H[i][j][0] = H[i][j - 1][0] + 1;
	  H[i][j][1] = H[i - 1][j - 1][1] + 1;
	  H[i][j][2] = H[i - 1][j][2] + 1;
	  H[i][j][3] = H[i - 1][j + 1][3] + 1;
	}
      }
    }
    for( int i = 1; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	for(int k = 0; k < 4; k++){
	  ans = max( ans, H[i][j][k] );
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[(MAX / 2) + 2], R[(MAX / 2) + 2];
int cnt = 0;

void merge(int A[], int n, int left, int mid, int right) 
{
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; k++)
	{
		cnt++;
		if (L[i] <= R[j])
		{
			A[k] = L[i++];
		}
		else
		{
			A[k] = R[j++];
		}
	}

}

void mergeSort(int A[], int n, int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main()
{
	int A[MAX], n , i;
	cin >> n;

	for (i = 0; i < n; i++) cin >> A[i];

	mergeSort(A, n, 0, n);

	for (i = 0; i < n; i++)
	{
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 7000
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,ans,a[2020][2020],b[2020][2020];
char c[2020][2020];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		int cnt=0;
		for(int j=0;j<m;j++)
		{
			if(c[i][j]=='.')
			{
				cnt++;
			}
			else
			{
				cnt=0;
			}
			a[i][j]=cnt;
		}
	}
	for(int j=0;j<m;j++)
	{
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			if(c[i][j]=='.')
			{
				cnt++;
			}
			else
			{
				cnt=0;
			}
			b[i][j]=cnt;
		}
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			if(j<m-1 && a[i][j])
			{
				a[i][j]=max(a[i][j],a[i][j+1]);
			}
			if(i<n-1 && b[i][j])
			{
				b[i][j]=max(b[i][j],b[i+1][j]);
			}
			ans=max(ans,a[i][j]+b[i][j]-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

int main() {
        string S, T;
        cin >> S >> T;

        bool ans = true;
        REP(i, S.length()) {
                if (S[i] != T[i]) ans = false;
        }

        if (ans) cout << "Yes" << endl;
        else cout << "No" << endl;

        return 0;
}


Measured memory_bytes: 3596
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include<algorithm>
#include<string.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef set<string> ss;
typedef set<int> si;
typedef set<ll> sl;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007;
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first;
#define second ss;
#define mk make_pair;
#define line cout<<endl;
#define pb push_back
#define INT_SIZE sizeof(int)
#define INT_BITS INT_SIZE*8-1
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/


int main()
{
	pan;
	int n,no;
	cin>>n;
	vi v(n+1,0);
	for(int i=1;i<n;i++)
	{
		cin>>no;
		v[no]++;
	}
	for(int i=1;i<n+1;i++)
		cout<<v[i]<<endl;
}

Measured memory_bytes: 3992
import sys

read = sys.stdin.read
INF = 1 << 60


def main():
    H, N, *AB = map(int, read().split())

    dp = [INF] * (H + 1)
    dp[0] = 0

    for a, b in zip(*[iter(AB)] * 2):
        for i in range(H + 1):
            if i >= a:
                if dp[i] > dp[i - a] + b:
                    dp[i] = dp[i - a] + b
            else:
                if dp[i] > dp[0] + b:
                    dp[i] = dp[0] + b

    print(dp[H])
    return


if __name__ == '__main__':
    main()


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

int main(){
    int A, B, C;  cin >> A >> B >> C;
    long long K;  cin >> K;
    
    if(K%2==0){
        cout << A-B << endl;    
    }else{
        cout << B-A << endl;
    }
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val pfs = Primes.primeFactorize(n).sorted
    val sb = new StringBuilder(":")
    var x = n
    pfs foreach (p => while (x % p == 0) {x /= p; sb.append(s" $p")})
    println(n + sb.toString())
  }

  object Primes {
    private def mod_exp(x: BigInt, n: Int, m: Int): BigInt = {
      def loop(x: BigInt, n: Int, acc: BigInt): BigInt = {
        if (n == 0) acc
        else loop (
          (x * x) % m,
          n >> 1,
          if ((n & 1) == 1) (acc * x) % m else acc
        )
      }
      loop(x,n,1)
    }
    private def div_pow_2(d: Int, s: Int = 0): (Int, Int) ={
      if ((d % 2) != 0) (d,s)
      else div_pow_2(d/2, s+1)
    }

    private def miller_rabin(n: Int, a: Int): Boolean = {
      val (d,s): (Int, Int) = div_pow_2(n-1)
      val a_exp_d: BigInt = mod_exp(a,d,n)
      def double(x: BigInt): BigInt = mod_exp(x,2,n)
      def loop(e: BigInt, i: Int): Boolean = {
        if (i == 0) false
        else if (e == n-1) true
        else loop(double(e), i-1)
      }
      a_exp_d == 1 || loop(a_exp_d, s)
    }
    def miller_rabin_test(n: Int, k: Int = 20): Boolean = {
      def loop(i: Int): Boolean = {
        if (i == 0) true
        else {
          val a = scala.util.Random.nextInt(n-1)+1
          if (miller_rabin(n,a)) loop(i-1)
          else false
        }
      }
      if (n < 2) false
      else loop(k)
    }
    def primeFactorize(n: Int): Seq[Int] = {
      val ab = collection.mutable.ArrayBuffer.empty[Int]
      var x = n
      while (x !=1) {
        if (isPrime(x)) {ab += x; x = 1}
        else {
          val p = rho(x)
          if (isPrime(p)) {
            while (x % p == 0) x /= p
            ab += p
          } else {
            val ps = primeFactorize(p)
            ps foreach {p => while (x % p == 0) x /= p; ab += p}
          }
        }
      }
      ab
    }
    def rho(n: Int): Int = {
      def f(x: Int, c: Int): Int = (x * x + c) % n
      def loop(x: Int, y: Int, d: Int, c: Int = 1): Int =
        if (d != 1) {
          if (d == n) loop(2,2,1,c+1)
          else d
        }
        else {
          val a = f(x, c)
          val b = f(f(y, c), c)
          loop(a, b, gcd(Math.abs(a-b), n), c)
        }
      if (n % 2 == 0) 2
      else loop(2,2,1)
    }
    def gcd(x: Int, y: Int): Int = {
      if (x < y) gcd(y, x)
      else {
        if (y > 0) {
          val r = x % y
          gcd(y, r)
        } else x
      }
    }
    def isPrime(n: Int): Boolean = Primes.miller_rabin_test(n)
  }
}

Measured memory_bytes: 44580
#実験 貼り付けコード
h,w,m = map(int,input().split())
s = [list(map(int,input().split())) for _ in range(m)]

r = [0] * (h + 1)
c = [0] * (w + 1)
for x, y in s:
    r[x] += 1
    c[y] += 1
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = sum(x in nr and y in nc for x, y in s)
print(R + C - (len(nr) * len(nc) == count))

Measured memory_bytes: 216836
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ACirclePond {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      double r; cin >> r;
      cout << setprecision(10) << fixed;
      cout << r*2*PI << endl;
    }
};

signed main() {
  ACirclePond solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3796
from itertools import product

abcd = input()

for pattern in product(["-", "+"],repeat=3):
    pattern = list(pattern)
    res = int(abcd[0])
    f = [abcd[0]]
    for v, op in zip(abcd[1:], pattern):
        f.append(op)
        f.append(v)
        if op == "+":
            res += int(v)
        elif op == "-":
            res -= int(v)
    if res == 7:
        f.append("=7")
        print("".join(f))
        break


Measured memory_bytes: 3060
/**
 *    author:  [itmo] enot.1.10
 *    created: 04.09.2016 15:00:22       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */



int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    ll a, b, c;
    cin >> a >> b >> c;
    if (a %2 == 0 || b % 2 == 0 || c % 2 == 0) return 0 * printf("0\n");
    else cout << min({a * b, a * c, b * c}) << endl;    
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


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

using namespace std;

int main(void){
  string str;
  cin >> str;
  
  if((str[0] == str[1] and str[1] == str[2]) or
    (str[1] == str[2] and str[2] == str[3]))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
struct Record {
    int id, ac, ct;
    int acm[11], wa[11];
    
    bool operator<(const Record& rhs) const {
        if (ac != rhs.ac)
            return ac > rhs.ac;
        if (ct != rhs.ct)
            return ct < rhs.ct;
        return id > rhs.id;
    }
};
int main()
{
    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M | T | P | R) {
        Record team[T + 1];
        rep(i, T + 1) team[i] = {i};
        while (R--) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if (j > 0)
                ++team[t].wa[p];
            else {
                team[t].ct += m + 20 * team[t].wa[p];
                ++team[t].ac;
            }
        }
        sort(team, team + T + 1);
        rep(i, T + 1) {
            if (team[i].id == 0) continue;
            cout << team[i].id;
            if (i < T - 1) {
                if (team[i].ac == team[i+1].ac && team[i].ct == team[i+1].ct)
                    cout << "=";
                else cout << ",";
            }
        }
        cout << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
#define R(i,n) for(int i = 1; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
  int n,k,count=0;
  cin >> n >> k;
  vector<int> v(n,0);
  r(i,n)cin >> v.at(i);
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  r(i,k)count+=v.at(i);
  cout << count << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(m)]
d=[[float("inf")]*n for _ in range(n)]

for a,b,c in l:
  d[a-1][b-1]=c
  d[b-1][a-1]=c

for k in range(n):
  for i in range(n):
    for j in range(n):
      d[i][j]=0 if i==j else min(d[i][j],d[i][k]+d[k][j])

ans=m
for i,(a,b,c) in enumerate(l):
  f=False
  for s in range(n):
    if d[s][a-1]+c==d[s][b-1]:
      f=True
  if f:ans-=1

print(ans)

Measured memory_bytes: 47836
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <cassert>
#include <random>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}
const int N = 2e5 + 5;
int seg[4*N];
void update(int cur, int l, int r, int tar, int val){
	int mid = (l+r)/2;
	if(!(l <= tar && tar <= r)) return;
	if(l == r){
		seg[cur] = (seg[cur] + val) % mod2;
		return;
	}
	update(2*cur, l, mid, tar, val);
	update(2*cur+1, mid+1, r, tar, val);
	seg[cur] = (seg[2*cur] + seg[2*cur+1]) % mod2;
}
int get(int cur, int l, int r, int tl, int tr){
	int mid = (l+r)/2;
	if(tl > r || l > tr) return 0;
	if(tl <= l && r <= tr) return seg[cur];
	return (get(2*cur, l, mid, tl, tr) + get(2*cur+1, mid+1, r, tl, tr)) % mod2;
}
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int n=5e4, k=10; cin>>n>>k;
	int l[k], r[k];
	for(int i = 0; i < k; i++){
		l[i] = rand()%n;
		r[i] = min(n, l[i] + rand()%n);
		cin>>l[i]>>r[i];
	}
	update(1, 0, n, 1, 1);
	for(int i = 2; i <= n; i++){
		int res = 0;
		for(int j = 0; j < k; j++){
			res = (res + get(1, 0, n, max(0, i - r[j]), max(0, i - l[j]))) % mod2;
		}
		update(1, 0, n, i, res);
	}
	cout<<get(1, 0, n, n, n)<<"\n";
}

Measured memory_bytes: 5664
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')
EPS = 1e-8

from math import tan, degrees, pi, atan2

def sol():
    a, b, x = map(int, input().split())
    deg1 = atan2(b, a)

    def isOk(deg):
        if deg > deg1:
            z = min(a, b / tan(deg))
            value = b * z * a / 2
            if x <= value:
                return True
            else:
                return False
        else:
            deg = pi / 2 - deg
            z = min(b, a / tan(deg))
            value = a * a * b - (z * a * a / 2)
            if x <= value:
                return True
            else:
                return False

    ok = 0.0
    ng = pi / 2

    while abs(ok - ng) > EPS:
        mid = (ok + ng) / 2
        if isOk(mid):
            ok = mid
        else:
            ng = mid

    print(degrees(ok))

sol()

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


#define ll                      long long
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define eb                      emplace_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define vpll                    vector<pll>
#define umap                    unordered_map
#define all(x)                  x.begin(),x.end()
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(ll i=0; i<n;++i)
#define fr1(i, n)               for(ll i=1; i<=n; ++i)
#define rfr(i, n)                for(ll i=n-1; i>=0; --i)
#define precise(x)              cout<<fixed<<setprecision(x)
#define wh                        while
#define mp                        make_pair
#define le                        length()



ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll lcm(ll a,ll b) 
{ return (a*b)/__gcd(a,b); }

ll power(ll x,ll y,ll p) 
{ ll res=1; x=x%p;
    while(y>0) 
    { if (y&1) res=(res*x)%p; 
      y=y>>1; x=(x*x)%p; } 
    return res; } 
    
bool inside(ll x,ll y,ll n,ll m)
{
    return(x>=0&&x<n&&y>=0&&y<=m);
}   


/*void dfs(int s)
{
        if(vis[s])return;
        
        vis[s]=true;
        nodes++;
        for(auto u:g[s])
        {
            if(!vis[u])
            {
                dfs(u);    
            }        
        }
}*/

void solve()
{    
	ll n;
	cin>>n;
	vector<ll> a(n);
	fr(i,n)
	{
		cin>>a[i];
	}
	
	sort(all(a),greater<ll>());
	ll ans=0;

	ll p=0;
	ll i=0;
	wh(p<n-1)
	{
//		cout<<p<<" "<<ans<<endl;
		if(p==0)
		{
			ans+=a[i];
			i++;
			p++;
		}
		else if(p+2<=n-1)
		{
			ans+=2*a[i];
			i++;
			p+=2;
		}
		else
		{
			ans+=a[i];
			i++;
			p++;
		}
	}
	cout<<ans<<endl;
}

int main()
{
//    int t;
//    cin>>t;
//    wh(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4840
use std::cmp;
use std::collections::BTreeSet;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m = 1 << n;
    let mut top2 = vec![((0, m), (0, m)); m];
    for i in 0..m {
        let a: u64 = sc.read();
        top2[i].0 = (a, i);
    }

    for mask in 0..(1 << n) {
        let mut set = BTreeSet::new();
        let (a, b) = top2[mask];
        set.insert(a);
        set.insert(b);
        for i in 0..n {
            if mask & (1 << i) != 0 {
                let (a, b) = top2[mask - (1 << i)];
                set.insert(a);
                set.insert(b);
            }
        }
        let mut iter = set.into_iter();
        let a = iter.next_back().unwrap();
        let b = iter.next_back().unwrap();
        top2[mask] = (a, b);
    }

    let mut max = 0;
    for i in 1..m {
        let ((a, _), (b, _)) = top2[i];
        max = cmp::max(max, a + b);
        println!("{}", max);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 15356
n = int(input())
v = input().split(" ")
c = input().split(" ")
plus_list = []

for i in range(n):
    res = int(v[i]) - int(c[i])
    if res > 0:
        plus_list.append(res)

r = len(plus_list)
if r > 0:
    print(sum(plus_list))
else:
    print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
using ll = long long;

// ----- Compressor -----
// referring to ymatsux-san's code:
// https://atcoder.jp/contests/abc168/submissions/13337691

template <typename T = ll>
class Compressor
{
  vector<T> raw;
  map<T, int> index;

public:
  Compressor() {}

  template <typename Container>
  Compressor(Container const &V) { append(V); }

  template <typename Iter>
  Compressor(Iter first, Iter last) { append(first, last); }

  template <typename Container>
  void append(Container const &V) { append(V.begin(), V.end()); }

  template <typename Iter>
  void append(Iter first, Iter last)
  {
    set<T> S(first, last);
    raw = vector<T>(S.begin(), S.end());
    sort(raw.begin(), raw.end());
    for (auto i = size_t{0}; i < raw.size(); ++i)
    {
      index[raw[i]] = i;
    }
  }

  T to_raw(int i) { return raw[i]; }
  int to_index(T t) { return index[t]; }
};

// https://atcoder.jp/contests/abc113/tasks/abc113_c

int main()
{
  int N, M;
  cin >> N >> M;
  using Pref = tuple<int, int>;
  vector<Pref> P(M);
  for (auto i = 0; i < M; ++i)
  {
    cin >> get<0>(P[i]) >> get<1>(P[i]);
  }
  vector<vector<int>> V(N);
  for (auto i = 0; i < M; ++i)
  {
    V[get<0>(P[i]) - 1].push_back(get<1>(P[i]));
  }
  vector<Compressor<int>> C(N);
  for (auto i = 0; i < N; ++i)
  {
    C[i].append(V[i]);
  }
  for (auto i = 0; i < M; ++i)
  {
    int pref, code;
    tie(pref, code) = P[i];
    cout << setw(6) << setfill('0') << pref
         << setw(6) << setfill('0') << C[pref - 1].to_index(code) + 1 << endl;
  }
}


Measured memory_bytes: 22528
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		int n = sc.nextInt();
		int pay = 0;
		while(pay < n){
			pay += 1000;
		}

		n = pay - n;
		System.out.println(n);
	}
}

Measured memory_bytes: 35824
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	char s[1000];
	ll k;
	cin >> k;
	cin >> s;
	if(strlen(s)<=k)
		cout << s << endl;
	else{
		rep(i,k){
			cout << s[i];
		}
		cout << "..." << endl;
	}
}

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

int main(){
  int n,m,count=0;
  cin >> n >> m;
  bool reached[n+1];
  vector< pair<int,int> > mp(m);
  for(int i=0;i<m;i++)cin >> mp.at(i).second >> mp.at(i).first;
  sort(mp.begin(),mp.end());
  for(int i=0;i<n+1;i++)reached[i]=false;
  for(int i=0;i<m;i++){
    int a=mp.at(i).second,b=mp.at(i).first;
    for(int j=a;j<b;j++){
      if(reached[j]==true)break;
      reached[j]=true;
      if(j==b-1)count++;
    }
  }
  cout << count << endl;
}


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

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1]){
        if(s[2]==s[3]){
            if(s[1]!=s[2]){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    if(s[0]==s[3]){
        if(s[1]==s[2]){
            if(s[0]!=s[1]){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    if(s[0]==s[2]){
        if(s[1]==s[3]){
            if(s[0]!=s[1]){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    while (a >= MOD) 
        a -= MOD;

    while (a < 0) 
        a += MOD;
}

int main() {
    int n; cin >> n;
    int64_t k; cin >> k;
    
    vector<vector<int>> a(n, vector<int> (n, 0));

    for (int i = 0; i < n; i += 1)
        for (int j = 0; j < n; j += 1)
            cin >> a[i][j];
    
    vector<vector<int>> ans(n, vector<int> (n, 0));
    for (int i = 0; i < n; i += 1)
        ans[i][i] = 1;
    
    auto multiply = [&] (auto a, auto b) {
        vector<vector<int>> c(n, vector<int> (n, 0));

        for (int i = 0; i < n; i += 1)
            for (int j = 0; j < n; j += 1)
                for (int k = 0; k < n; k += 1)
                    add(c[i][j], 1LL * a[i][k] * b[k][j] % MOD);

        return c;
    };

    for (int i = 0; (1LL << i) <= k; i += 1) {
        if ((1LL << i) & k) 
            ans = multiply(ans, a);
        a = multiply(a, a);
    }
    
    int sol = 0;

    for (int i = 0; i < n; i += 1) 
        for (int j = 0; j < n; j += 1)
            add(sol, ans[i][j]);

    cout << sol << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 105, MOD = 1e9 + 7;
int f[MAXN][MAXN][MAXN], a[MAXN], n;
void add(int &x, int a) { x += a - MOD, x += x >> 31 & MOD; }

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n * 2; i++) scanf("%d", a + i);
	sort(a + 1, a + n * 2);
	f[n][1][0] = 1;
	for (int i = n; i > 1; i--) {
		int al = a[i] != a[i - 1], ar = a[n * 2 - i] != a[n * 2 - i + 1];
		for (int j = 1; j <= 2 * (n - i) + 1; j++)
		for (int k = 0; k <= 2 * (n - i); k++) if (f[i][j][k]) {
			int cur = f[i][j][k];
			for (int l = 0; l < j + al; l++)
				add(f[i - 1][j - l + al][ar + k + (l > 0)], cur);
			for (int l = 0; l < k + ar; l++)
				add(f[i - 1][j + al + 1][k - l + ar - 1], cur);
		}
	}
	int res = 0;
	for (int i = 0; i < 2 * n; i++)
	for (int j = 0; j < 2 * n; j++) add(res, f[1][i][j]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

bool mycomp(pair<pair<string, ll>, int> x, pair<pair<string, ll>, int> y)
{
    return (x.fi.fi == y.fi.fi ? x.fi.se > y.fi.se : x.fi.fi < y.fi.fi);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<pair<string, ll>, int>> r(n);
    forn(i, n) cin >> r[i].fi.fi >> r[i].fi.se, r[i].se = (i + 1);
    sort(allele(r), mycomp);
    forn(i, n) cout << r[i].se << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
# define ll long long
const int N = 2e5 + 10, mod = 1e9 + 7, INF = 1e9 + 100;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    int x, y;
    cin >> x >> y;
    cout << (x + y - 1) / y << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	ll N, M;
	std::cin >> N >> M;
	vll H(N + 1);
	vector<bool> isGood(N + 1, true);
	isGood[0] = false;
	repeq(i, 1, N) {
		std::cin >> H[i];
	}

	ll A, B;
	rep(i, 0, M) {
		std::cin >> A >> B;
		if (H[A] <= H[B]) {
			isGood[A] = false;
		}
		if (H[A] >= H[B]) {
			isGood[B] = false;
		}
	}

	ll ans = 0;
	repeq(i, 1, N) {
		if (isGood[i]) {
			ans++;
		}
	}

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


Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;

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

	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	int v = 0;
	int w = 0;
	int x = 0;
	int y = 0;
	int z = 1;
	repr(i, 1, n+1) {
		if (v + w + x + y + z >= a && v + w + x + y + z <= b) {
			ans += v * 10000 + w * 1000 + x * 100 + y * 10 + z;
		}
		z++;
		if (z > 9) {
			z = 0;
			y++;
		}
		if (y > 9) {
			y = 0;
			x++;
		}
		if (x > 9) {
			x = 0;
			w++;
		}
		if (w > 9) {
			w = 0;
			v++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        long X = int.Parse(Console.ReadLine());

        int max = 0;

        for (int i = 1; i <= 1000; i++)
        {
            for (int j = 2; j <= 1000; j++)
            {
                int val = (int)Math.Pow(i, j);
                if (val > X) break;

                max = Math.Max(max, val);
            }
        }

        Console.WriteLine(max);

        //long X = int.Parse(Console.ReadLine());

        //long K = (int)(Math.Sqrt(X));
        
        //if (X == 1)
        //{
        //    Console.WriteLine(1);
        //    return;
        //}

        //long max = 1;

        //for(int i = 2; i <= K; i++)
        //{
        //    var val = Enumerable.Range(2, 10000000).Select(n => (long)Math.Pow(K, n)).TakeWhile(n => n <= X).Last();
        //    max = Math.Max(max, val);
        //}

        //Console.WriteLine(max);
    }
    
}


static class MathUtil
{
    public static T Max<T>(params T[] datas)
    {
        return datas.Max();
    }

    public static T Min<T>(params T[] datas)
    {
        return datas.Min();
    }

    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<stdlib.h>

typedef long long ll;

using namespace std;

void chmin(ll &a,ll b){
  if(a > b) a = b;
}

int main(){
  ll N;
  ll h[111111];
  ll i;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> h[i];
  ll dp[111111];
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(i=2;i<=N-1;i++)
    dp[i] = 11111111111111;
  for(i=0;i<=N-1;i++){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
  if(N>2) cout << dp[N-1] << endl;
  else cout << abs(h[1] - h[0]);
}

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

int main() {
	int n, a;
	cin >> n;
	int ans = 0, j = 1;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a == j) j++;
		else ans++;
	}
	if (ans == n) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m, cnt;
int num[100005];
vector<int>edge[100005];
void dfs(int x) {
	num[x] = cnt;
	for (auto& y : edge[x]) {
		if (num[y])continue;
		dfs(y);
	}
}
int main(){
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	for (int i = 1; i <= n; ++i) {
		if (num[i])continue;
		++cnt;
		dfs(i);
	}
	cout << cnt - 1 << endl;
	return 0;
}

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

using namespace std;


#define MAXN 101
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, n, c[MAXN*MAXN], ans[MAXN][MAXN];
  cin >> h >> w >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }
  int cur = 1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      while (!c[cur]) cur++;
      ans[i][j] = cur;
      c[cur]--;
    }
    if (++i==h) break;
    for (int j = w-1; j >= 0; --j) {
      while (!c[cur]) cur++;
      ans[i][j] = cur;
      c[cur]--;
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();

		if(N%K == 0) {
			System.out.println(0);
		} else {
			long remainder = N%K;
			long diff = Math.abs(remainder-K);
			System.out.println(Math.min(remainder, diff));
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

void encode(string &s) {
	int i = 0;
	char ss[10];
	while (i < s.size()) {
		char c = s[i];
		int end = i;
		while (end < s.size() && s[end] == c) end++;
		sprintf(ss, "%d%c", end-i, c);
		s.replace(i, end-i, ss);
		i += strlen(ss);
	}
}

int main() {
	int n;
	string s;
	while (cin >> n, n) {
		cin >> s;
		for (int i = 0; i < n; i++)
			encode(s);
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1044
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
const int INF = 1 << 29;
int N, M;
vector<vector<pii>> A;
vector<vector<int>> edge;
vector<int> min_cost;
vector<int> from;
vector<bool> is_finish;
vector<bool> is_used;
void dijkstra() {
	for (int i = 1; i <= N; ++i) {
		priority_queue<pii, vector<pii>, greater<pii>> pq;
		pq.push(pii(0, i));
		fill(min_cost.begin(), min_cost.end(), INF);
		fill(is_finish.begin(), is_finish.end(), false);
		min_cost[i] = 0;
		while (!pq.empty()) {
			pii now = pq.top(); pq.pop();
			int now_cost = now.first;
			int now_id = now.second;
			if (is_finish[now_id]) continue;
			is_finish[now_id] = true;
			if (now_id != i) is_used[edge[from[now_id]][now_id]] = true;
			for (int j = 0; j < A[now_id].size(); ++j) {
				int next_cost = A[now_id][j].first;
				int next_id = A[now_id][j].second;
				if (now_cost + next_cost < min_cost[next_id]) {
					from[next_id] = now_id;
					min_cost[next_id] = now_cost + next_cost;
					pq.push(pii(min_cost[next_id], next_id));
				}
			}
		}
	}
}
int main(void) {
	cin >> N >> M;
	A.resize(N + 1);
	edge.resize(N + 1, vector<int>(N + 1));
	min_cost.resize(N + 1);
	from.resize(N + 1);
	is_finish.resize(N + 1);
	is_used.resize(M, false);
	for (int i = 0; i < M; ++i) {
		int a, b, cost; cin >> a >> b >> cost;
		A[a].push_back(pii(cost, b));
		A[b].push_back(pii(cost, a));
		edge[a][b] = edge[b][a] = i;
	}
	dijkstra();
	int ans = count(is_used.begin(), is_used.end(), false);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [n, k]
    | k == 1 = 0
    | otherwise = n - k

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  for(ll i=N;i>0;i--)
  {
    double D = sqrt(i);
    int d = D;
      if(i==d*d)
      {
        cout << i << endl;
        return 0;
      }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, y;
    scanf("%d%d", &n, &y);
    for(int man=0; man<=n; man++){
        for(int gosen=0; gosen + man <= n; gosen++){
            int sen = n - gosen - man;
            if(10000 * man + 5000 * gosen + 1000 * sen == y){
                printf("%d %d %d\n", man, gosen, sen);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  vector<int> p(N);
  double ans = 0,sum = 0;
  for(int i = 0;i < N;i++) {
    cin >> p.at(i);
    if(i < K) sum += (double)(p.at(i)+1)/2;
  }

  ans = max(ans,sum);
  for(int i = K;i < N;i++) {
    sum += (double)(p.at(i)+1)/2 - (double)(p.at(i-K)+1)/2;
    ans = max(ans,sum);
  }

  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define N 36
 
struct Card{
  char value;
  char suit;
};
 
int main(){
  int i,j,n,min,flag=0;
  char a;
  struct Card C1[N],C2[N],tmp;
   
  scanf("%d%c",&n,&a);
  for(i=0 ; i<n ; i++){
    scanf("%c%c%c",&C1[i].suit,&C1[i].value,&a);
  }
 
  for(i=0 ; i<n ; i++){
    C2[i]=C1[i];
  }
   
  //BubbleSort
   for(i=0 ; i<n ; i++){
    for(j=n-1 ; j>i ; j--){
      if(C2[j].value < C2[j-1].value){
    tmp=C2[j];
    C2[j]=C2[j-1];
    C2[j-1]=tmp;
      }
    }
   }
   for(i=0 ; i<n ; i++){
     if(i>0)printf(" ");
     printf("%c%c",C2[i].suit,C2[i].value);
   }
   printf("\n");
   printf("Stable\n");
    
   //SelectionSort
   for(i=0 ; i<n ; i++){
     min=i;
     for(j=i ; j<n ; j++){
       if(C1[j].value<C1[min].value) min=j;
    }
    tmp=C1[i];
    C1[i]=C1[min];
    C1[min]=tmp;
   }
   for(i=0 ; i<n ; i++){
     if(i>0)printf(" ");
     printf("%c%c",C1[i].suit,C1[i].value);
     if(C1[i].suit!=C2[i].suit || C1[i].value!=C2[i].value) flag=1;
   }
   printf("\n");
 
   if(flag==1)printf("Not stable\n");
   else printf("Stable\n");
 
 
return 0; 
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	cin >> s >> t;
	int ans = 0;
	FOR(i, 0, 3) ans += s[i] == t[i];
	cout << ans;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256