akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
using ll = long long;
#define rep(i, j, n) for (int i = j; i < n; ++i)

class suffix_array {
  int n;
  std::string s;
  std::vector<int> suf;
  std::vector<int> rank;
  std::vector<int> lcp;

public:
  suffix_array() = default;
  suffix_array(const std::string& _s)
    : n(_s.length()), s(_s), suf(n), rank(n), lcp(n) {
    std::iota(suf.begin(), suf.end(), 0);
    for (int i = 0; i < n; ++i) rank[i] = s[i];
    int itr = 1;
    auto cmp = [&](int a, int b) {
      if (rank[a] != rank[b]) return rank[a] < rank[b];
      int l = a + itr < n ? rank[a + itr] : -1;
      int r = b + itr < n ? rank[b + itr] : -1;
      return l < r;
    };
    std::vector<int> buff(n);
    for (; itr < n; itr <<= 1) {
      std::sort(suf.begin(), suf.end(), cmp);
      buff[suf[0]] = 0;
      for (int i = 1; i < n; ++i)
        buff[suf[i]] = buff[suf[i - 1]] + cmp(suf[i - 1], suf[i]);

      buff.swap(rank);
    }
    for (int i = 0; i < n; ++i) rank[suf[i]] = i;

    int now = 0;
    for (int i = 0; i < n; ++i) {
      int x = rank[i];
      if (x == n - 1) continue;
      int y = x + 1;
      int j = suf[y];
      if (0 < now) now--;
      for (; now + std::max(i, j) < n; now++)
        if (s[i + now] != s[j + now]) break;

      lcp[x] = now;
    }
  }

  bool find(std::string& t) {
    int ng = -1, ok = (int)s.length() - 1;
    while (ok - ng > 1) {
      int mid = (ok + ng) / 2;
      if (s.substr(suf[mid], t.length()) < t)
        ng = mid;
      else
        ok = mid;
    }
    return s.substr(suf[ok], t.length()) == t;
  }

  std::vector<int> get_suf() const { return suf; }
  std::vector<int> get_lcp() const { return lcp; }
};

int main() {
  std::string s;
  std::cin >> s;
  ll n = s.length();
  suffix_array sa(s);
  ll ans = n * (n + 1) / 2;
  for (int x : sa.get_lcp()) ans -= x;
  std::cout << ans << '\n';
  return 0;
}


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

static bool S(string s){
    bool a = true;
    for(int i = 0; i < s.length(); i++){
        if(i%2 == 0){
            if(s[i] == 'L'){
                a = false;
                break;
            }
        }
        else{
            if(s[i] == 'R'){
                a = false;
                break;
            }
        }
    }

    return a;
}

int main(){
    string s;
    cin >> s;
    cout << (S(s) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

ll f(ll H, ll W) {
    ll res = LLONG_MAX;
    if (H >= 3) {
        if (H % 3 == 0)return 0ll;
        else {
            smin(res, W);
        }
    }
    vll a(3);
    for (ll h = 1; h < H; ++h) {
        ll s1 = h*W;
        ll s2 = W / 2 * (H - h), s3 = (W + 1) / 2 * (H - h);
        a[0] = s1;
        a[1] = s2;
        a[2] = s3;
        sort(all(a));
        smin(res, a[2] - a[0]);
    }
    return res;
}

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

    ll H, W;
    while (cin >> H >> W) {
        cout << min(f(H, W), f(W, H)) << endl;
    }
}


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

using namespace std;

using ll = long long;


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

    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; ++i) {
        cin >> d[i];
    }
    
    sort(d, d +N);
    
    cout << d[N / 2] - d[N / 2 - 1] << '\n';


    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
using namespace std;
using ll = long long;
const static int MOD = 1000000007;

int main(){
	int N;
	scanf("%d", &N);
	int C[N];
	scanf("%d", C);
	int id = 0;
	for (int i = 0; i < N - 1; ++i){
		int tmp;
		scanf("%d", &tmp);
		if(tmp != C[id]) C[++id] = tmp;
	}
	int last[200001];
	memset(last, -1, sizeof last);
	ll dp[N];
	dp[0] = 1;
	last[C[0]] = 0;
	for (int i = 0; i < id; ++i){
		dp[i + 1] = dp[i];
		if(last[C[i + 1]] >= 0){
			(dp[i + 1] += dp[last[C[i + 1]]]) %= MOD;
		}
		last[C[i + 1]] = i + 1;
	}
	printf("%lld\n", dp[id]);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  string s;
  cin >> s;
  int n = s.size();
  if(s.at(0) != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  int cnt = 0;
  for(int i=2;i<n-1;i++){
    if(s.at(i) == 'C') cnt++;
  }
  if(cnt != 1){
    cout << "WA" << endl;
    return 0;
  }
  for(int i=1;i<n;i++){
    if(s.at(i) == 'C') continue;
    int tmp = s.at(i) - 'a';
    if(tmp < 0 || tmp > 26){
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main() {
    cin>>a>>b>>c;
    if((a%2)+(b%2)+(c%2)<3){
        cout<<0<<endl;
        return 0;
    }
    cout<<min(a*b,min(a*c,b*c))<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(4,0);
  vector<string> result = {"AC", "WA", "TLE","RE"};
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for(int j = 0; j < 4; j++) {
      if(s==result.at(j))
        vec.at(j)++;
    }
  }
  for(int i = 0; i < 4; i++) {
    cout << result.at(i) << " x " << vec.at(i) << endl;
  }
}

Measured memory_bytes: 3604
#include<stdio.h>

int main (void) {
    int a, b;
    scanf("%d %d", &a, &b);

    if(a > b) {
        printf("a > b\n");
    }
    else if(a < b) {
        printf("a < b\n");
    }
    else {
        printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template<typename T>
void vecin(vector<T>& v, int n = 0){
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n-1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}
void print(string s){
    cout << s << endl;
}

vector<int> ans(200'008);
vector<vector<int>> G(200008);
vector<int> counter(200'008);

int dfs(int now, int from, int sum){
    for (int edge : G[now]){
        if (edge != from){
            dfs(edge, now, sum + counter[edge]);
        }
    }
    ans[now] = sum;
}

int main()
{
    ciosup;
    string s, t;
    cin >> s >> t;
    ll szs = s.size(), szt = t.size();
    unordered_map<char, vector<int>> ma;
    REP(i,szs){
        ma[s[i]].emplace_back(i);
    }
    ll ans = 0, prev = -1;
    REP(i, szt)
    {
        if (ma[t[i]].size())
        {
            auto ite = lower_bound(ma[t[i]].begin(), ma[t[i]].end(), prev+1);
            if (ite == ma[t[i]].end())
            {
                ans += szs - 1 - prev;
                auto ite2 = lower_bound(ma[t[i]].begin(), ma[t[i]].end(), 0);
                if (ite2 == ma[t[i]].end())
                {
                    cout << -1 << endl;
                    return 0;
                }
                else
                {
                    prev = (*ite2);
                    ans += prev + 1;
                }
            }
            else
            {
                ans += (*ite) - prev;
                prev = *ite;
            }
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7376
import sys
from heapq import*
input=sys.stdin.buffer.readline
def solve():
    n=int(input())
    x,y=[],[]
    for _ in range(n):
        k,l,r=map(int,input().split())
        if l>r:
            x+=(k,l,r),
        else:
            y+=(n-k,r,l),
    x.sort()
    y.sort()
    s=0
    h=[]
    for i in range(len(x),0,-1):
        while x and x[-1][0]>=i:
            k,l,r=x.pop()
            heappush(h,(r-l,l,r))
        if h:s+=heappop(h)[1]
    s+=sum(r for _,_,r in x+h)
    h=[]
    for i in range(len(y),0,-1):
        while y and y[-1][0]>=i:
            k,l,r=y.pop()
            heappush(h,(r-l,l,r))
        if h:s+=heappop(h)[1]
    s+=sum(r for _,_,r in y+h)
    return s
t=int(input())
print('\n'.join(str(solve())for _ in range(t)))

Measured memory_bytes: 116412
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
    for (int i = 0; i < N; i++) {
      string S;
      cin >> S;
      if (S == "Y") {
        cout << "Four" << endl;
        break;
      }
      else if (i == N - 1) {
        cout << "Three" << endl;
    }
    }
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	getline(cin,s);
	int i;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='A')  cout<<'T';
		if(s[i]=='C')  cout<<'G';
		if(s[i]=='G')  cout<<'C';
		if(s[i]=='T')  cout<<'A';
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[7];
    scanf("%s",s);
    if(s[2]-'0'==s[3]-'0'&&s[4]-'0'==s[5]-'0') printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int main()
{
    int r,g,b,n,ans=0;
    scanf("%d%d%d%d",&r,&g,&b,&n);
    for(int i=0; i<=n/r; i++)
        for(int j=0; j<=(n-i*r)/g; j++)
        {
            //printf("%d %d %d\n",i,j,(n-i*r-j*g));
            if(!((n-i*r-j*g)%b))
            {
                ans++;
            }
        }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>s(n);
	int sum = 0;
	REP(i, n) {
		cin >> s[i];
		sum += s[i];
	}
	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else {
		sort(s.begin(), s.end());
		REP(i, n) {
			if (s[i] % 10 != 0) {
				sum -= s[i];
				cout << sum << endl;
				return 0;
			}
			else {
				if (i == n - 1) {
					cout << 0 << endl;
				}
				else {
					continue;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int m[1600][1600];
int dp[1600][1600][2];
bool prime[1000010];

int main(){
    int a = 800,b = 800;
    int dir; //今向いている方向
    m[a][b] = 1;
    b += 1;
    m[a][b] = 2;
    a -= 1;
    dir = 1;
    for(int i = 3;i <= 1000000;i++){
        m[a][b] = i;
        if(dir == 0){ //→
            if(m[a-1][b] != 0){
                b += 1;
            }else{
                a -= 1;
                dir = 1;
            }
        }else if(dir == 1){ // ↑
            if(m[a][b-1] != 0){
                a -= 1;
            }else{
                b -= 1;
                dir = 2;
            }
        }else if(dir == 2){ //←
            if(m[a+1][b] != 0){
                b -= 1;
            }else{
                a += 1;
                dir = 3;
            }
        }else{ //↓
            if(m[a][b+1] != 0){
                a += 1;
            }else{
                b += 1;
                dir = 0;
            }
        }
    }

    prime[1] = true;
    for(int i = 2;i <= 1000000;i++){ //エラトス
        if(prime[i] == false){
            for(int j = 2;i*j <= 1000000;j++){
                prime[i*j] = true;
            }
        }
    }
    int mm,n;
    while(true){
        cin >> mm >> n;
        if(mm == 0 && n == 0)break;
        for(int i = 0;i < 1500;i++){
            for(int j = 0;j < 1500;j++){
                dp[i][j][0] = 0;
                dp[i][j][1] = 0;
                if(m[i][j] == n){
                    a = i;
                    b = j;
                }
            }
        }
        //cout << "a:" << a << ",b:" << b << endl;
        int aans = 0,bans = 0;
        if(prime[n] == false){
            dp[a][b][0] = 1;
            dp[a][b][1] = n;
            aans = 1;
            bans = n;
        }
        for(int i = a+1;i < 1500;i++){
            for(int j = b-(i-a);j <= b+(i-a);j++){
                if(m[i][j] == 0 || m[i][j] > mm)continue;
                int amax = 0,bmax = 0;
                for(int k = -1;k <= 1;k++){
                    if(amax < dp[i-1][j+k][0]){
                        amax = dp[i-1][j+k][0];
                        bmax = dp[i-1][j+k][1];
                    }else if(amax == dp[i-1][j+k][0] && bmax < dp[i-1][j+k][1]){
                        bmax = dp[i-1][j+k][1];
                    }
                }
                if(prime[m[i][j]] == false){
                    amax++;
                    bmax = m[i][j];
                }
                dp[i][j][0] = amax;
                dp[i][j][1] = bmax;
                if(aans < amax){
                    aans = amax;
                    bans = bmax;
                }else if(aans == amax && bans < bmax){
                    bans = bmax;
                }
            }
        }
        cout << aans << " " << bans << endl;
    }


}


Measured memory_bytes: 28984
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
 typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell=998244353;
 
 int power(int a,int b)
 {
  if(b==0)return 1LL;
  if(b==1)return a;
  int t=power(a,b/2);
  t*=t;
  t%=hell;
  if(b&1)return (t*a)%hell;
  else return t;
 }
 int inverse(int a)
 {
    return power(a,hell-2);
 }
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;
    a%=10000000000LL;}
  return a;
}
 
int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}
 
bool cmp(pii a,pii b)
{
  return a.SS<b.SS;
}
 
 
int solve()
{  

int a,b,c;
cin>>a>>b>>c;
cout<<max(0LL,b+c-a);
return 0;
}
 
signed main()
{  int t=1;
//pri();
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
 

 
  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
 //cin>>t;
 
    int k=1;
     
   while(t--)
     {
      //cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
} 

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

typedef struct{
    int upface;
    int Eface;
    int Nface;
    int Sface;
    int Wface;
    int botface;
} dice;

int main () {
    dice d = {1,3,5,2,4,6};
    int face[6+1];
    int inf, save;
    char root[100];
    for (int i = 0; i < 6; i++) {
        scanf("%d", &inf);
        face[i+1] = inf;
    }
    scanf("%s", root);
    for(int i = 0; i < strlen(root); i++) {
        switch (root[i]) {
            case 'E':
                save = d.upface;
                d.upface = d.Wface;
                d.Wface = d.botface;
                d.botface = d.Eface;
                d.Eface = save;
                break;
            case 'N':
                save = d.upface;
                d.upface = d.Sface;
                d.Sface = d.botface;
                d.botface = d.Nface;
                d.Nface = save;
                break;
            case 'S':
                save = d.upface;
                d.upface = d.Nface;
                d.Nface = d.botface;
                d.botface = d.Sface;
                d.Sface = save;
                break;
            case 'W':
                save = d.upface;
                d.upface = d.Eface;
                d.Eface = d.botface;
                d.botface = d.Wface;
                d.Wface = save;
                break;
        }
    }
    printf("%d\n",face[d.upface]);
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
const int inf=1e9+7;
const ll INF=1e18;


int main() {
  int n;
  cin>>n;
  cout<<n*(n+1)/2<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N, -1);
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (A[A[i]] == i) ans++;
        }
        Console.WriteLine(ans / 2);
    }

}


class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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


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

using namespace std;

int main()
{
    int N,M,cnt=0;
    cin >> N >> M;
    vector<bool> c(N,true);

    int tmpl = 1;
    int tmpr = N;

    for(int i=0; i<M; i++){
        int l,r;
        cin >> l >> r;

        if(l > tmpl){
            for(int j=tmpl-1; j<l-1; j++){
                c.at(j) = false;     
            }
            tmpl = l;
        }
        if(r < tmpr){
            for(int j=r; j<tmpr; j++){
                c.at(j) = false;       
            }
            tmpr = r;
        }

        /*for(int j=0; j<N; j++)
            cout << c.at(j) <<flush;
        cout << endl; */
    }

    for(int i=0; i<N; i++){
        if(c.at(i) == true)
            cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int cnt = 0;
int a[1000500];

void insertsort(int a[], int n, int g){
	for (int i = g; i < n; i++){
		int v = a[i];
		int j = i - g;
		while (j >= 0 && a[j] > v){
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}
		a[j + g] = v;
	}
}

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

	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}

	// 3g + 1
	vector <int> kotori;
	for (int g = 1; g <= n; g = 3 * g + 1){
		kotori.push_back(g);
	}

	for (int i = kotori.size() - 1; i >= 0; i--){
		insertsort(a, n, kotori[i]);
	}
	
	reverse(kotori.begin(), kotori.end());
	cout << kotori.size() << endl;
	for (int i = 0; i < kotori.size(); i++){
		cout << kotori[i] << (i + 1 == kotori.size() ? '\n' : ' ');
	}
	cout << cnt << endl;

	for (int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 7000
#include<stdio.h>

int  main()
{
    int x1, x2, x4, x3, y1, y2, y3, y4;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x3=x2-y2+y1;
    y3=y2+x2-x1;
    x4=x1+y1-y2;
    y4=y1+x2-x1;
    
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    
    return 0;
}
    

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;
const int INF = 1000000001;
const int N = 200000;
int n;
int a[N], L[N], R[N];

ll merge(int l, int m, int r) {
  ll res = 0LL;
  int i, j, k;
  int nl = m - l;
  int nr = r - m;
  for (i=0; i<nl; i++)
    L[i] = a[l + i];
  for (i=0; i<nr; i++)
    R[i] = a[m + i];
  
//  L[nl] = R[nr] = INF;
  
  k = l;
  i = j = 0;
  while (i<nl || j<nr) {
    if (i==nl)
      a[k++] = R[j++]; 
    else if (j==nr)
      a[k++] = L[i++];
    else if (L[i] <= R[j])
      a[k++] = L[i++];
    else {
      a[k++] = R[j++]; 
      res += (ll)(nl - i);
    }
  }

/*
  i = j = 0;
  for (k=l; k<r; k++) {
    if (L[i] <= R[j]) {
      a[k] = L[i++];
//      res += j;
    } else {
      res += (ll)(nl - i);
      a[k] = R[j++];
    }
  }
*/

  return res;
}

ll merge_sort(int l, int r) {
  ll res = 0;
  if (l+1<r) {
    int m = (l+r)/2;
    res = merge_sort(l, m);
    res += merge_sort(m, r);
    res += merge(l, m, r);
  }
  return res;
}

int main() {
  scanf("%d ", &n);
  for (int i=0; i<n; i++)
    scanf("%d ", a+i);

  printf("%lld\n", merge_sort(0, n));

  return 0;
}

Measured memory_bytes: 2760
function main()
  
  (a,b) = map(x -> parse(Int,x), split(readline()))

  for i in 1:998
    
    x_a = Int(0.5*(i*(i+1))) - a
    x_b = Int(0.5*((i+1)*(i+2))) - b
    
    if x_a == x_b && x_a > 0 && x_b > 0
      println(x_a)
      break
    end
    
  end
  
end

main()

Measured memory_bytes: 111372
import           Control.Monad
import           Data.IORef
import           Data.List.Split
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
  n <- getLine
  s <- getLine

  print $ solve s [0]

solve :: String -> [Int] -> Int
solve "" ans = maximum ans
solve (s : ss) ans | s == 'I'  = solve ss $ ans ++ [last ans + 1]
                   | otherwise = solve ss $ ans ++ [last ans - 1]

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

int main()
{
	double a[8];
	
	while (1){
		for (int i = 0; i < 8; i++){
			if (scanf("%lf", &a[i]) == EOF){
				return 0;
			}
		}
		
		printf(!(a[4] > a[2] || a[5] > a[3] || a[6] < a[0] || a[7] < a[1]) ? "YES\n" : "NO\n");
	}
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

Measured memory_bytes: 3616
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int A,B,C;
  cin >>A>>B>>C;
  int X,Y;
  cin>>X>>Y;
  int P,Q,R;
  P = A*X+B*Y;
  if(X>Y) 
  {
    Q = 2*C*X;
    R = 2*C*Y+(X-Y)*A;
  }
  if(X<=Y) 
  {
    Q = 2*C*X+(Y-X)*B;
    R = 2*C*Y;
  }
  if(P<Q&&P<R) cout << P << endl;
  if(Q<=P&&Q<=R) cout << Q << endl;
  if(R<P&&R<Q) cout << R << endl;
  return 0;
}
 

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

#define LINE_BUF_SIZE 256

int main(){

    int i,j,k;
    int v;
    int N,M,X;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d %d %d", &N,&M,&X);

    int A[100+1];

    for(i=0;i<101;i++)A[i] = 0;

    for(i=0;i<M;i++){
        scanf("%d",&v);
        A[v] = 1;
    }

    int ans = 0,ans_b=0;

    for(i=X;i<=N;i++){
        if(A[i] == 1)ans+=1;
    }

    for(i=X;i>=0;i--){
        if(A[i] == 1)ans_b+=1;
    }

    if(ans<=ans_b){
        printf("%d",ans);
    return 0;
    }

    else printf("%d",ans_b);

}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ld = long double;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  REP(n, 1, N + 1) {
    ll ans = 0;
    REP(i, 1, 101) {
      REP(j, 1, 101) {
        ll left = n - i * i - j * j - i * j;
        if (left > 0) {
          REP(k, 1, (ll) sqrt(left)+1) {
            ll right = i * k + j * k + k * k;
            if (left == right) {
//              cout << left << " == " << right << " i:" << i << ",j:" << j
//                   << ",k:" << k << endl;
              ans++;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2, mod);
	x = (x*x) % mod;
	if(e&1) x = (x*a) % mod;
	return x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	if(N == 2) {
		cout << "1\n";
		return 0;
	}
	cat mod = 1000000007;
	vector<cat> fac(N+1, 1);
	for(int i = 1; i <= N; i++) fac[i] = (i * fac[i-1]) % mod;
	vector<cat> inv(N+1, 1);
	for(int i = 1; i <= N; i++) inv[i] = (pw(i, mod-2, mod) * inv[i-1]) % mod;
	cat ans = 0;
	for(int i = 0; i <= N-3; i++) {
		cat cnt1 = (N-2-2*i < 0) ? 0 : (fac[N-2-i] * inv[N-2-2*i] % mod * fac[N-1-i] % mod);
		cat cnt2 = (N-2-2*(i+1) < 0) ? 0 : (fac[N-2-i-1] * inv[N-2-2*(i+1)] % mod * fac[N-2-i] % mod);
		ans = (ans + (cnt1-cnt2) * (N-1-i)) % mod;
	}
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 15872
#include <iostream>
#include <string>

#define MAX_ 72

using namespace std;

int main(int argc, char const *argv[])
{
	int h,w;
	string f[MAX_][MAX_];
	string mx;

	while(1){
		cin>>w>>h;
		if(h+w==0) break;

		for(int i1=0;i1<MAX_;i1++){
			for(int i2=0;i2<MAX_;i2++){
				f[i1][i2]="@";
			}
		}

		for(int i1=1;i1<=h;i1++){
			string temp;
			cin>>temp;	
			for(int i2=1;i2<=w;i2++){
				if(temp[i2-1]>='A' && temp[i2-1]<='Z') {}
				else f[i1][i2]=temp[i2-1];
			}
		}

		mx="";
		for(int i1=1;i1<=h;i1++){
			for(int i2=1;i2<=w;i2++){
				if(f[i1][i2]!="@"){
					string su="";
					string sl="";
					if(f[i1-1][i2]!="@" && f[i1-1][i2]!="0") su=f[i1-1][i2];
					if(f[i1][i2-1]!="@" && f[i1][i2-1]!="0") sl=f[i1][i2-1];

					if(su.size()>sl.size()) f[i1][i2]=su+f[i1][i2];
					else if(su.size()<sl.size()) f[i1][i2]=sl+f[i1][i2];
					else {
						if(su>sl) f[i1][i2]=su+f[i1][i2];
						else f[i1][i2]=sl+f[i1][i2];
					} 

					if(mx.size()<f[i1][i2].size()) mx=f[i1][i2];
					else if(mx.size()==f[i1][i2].size()) mx=max(mx,f[i1][i2]);
				}
			}
		}

		cout<<mx<<endl;

	}
	return 0;
}

Measured memory_bytes: 1592
#include <stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d",&a);
    b=a/3600;//h
    c=(a-b*3600)/60;//m
    d=a-b*3600-c*60;//s
    printf("%d:%d:%d\n",b,c,d);
    return 0;
}



Measured memory_bytes: 2088
#include "bits/stdc++.h"
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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 lint mod = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;

lint X[100002], Y[100002], R[100002], N;
vector<Pa> to[100002];
double dp[100002];

double range(lint u, lint v) {
	lint dx = X[u] - X[v];
	lint dy = Y[u] - Y[v];
	return max(0., sqrt(dx * dx + dy * dy) - R[u] - R[v]);
}

int main() {
	lint sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	cin >> N;
	lint s = 0, g = N + 1;
	X[s] = sx; Y[s] = sy; X[g] = gx; Y[g] = gy;
	REP(i, N) {
		cin >> X[i + 1] >> Y[i + 1] >> R[i + 1];
	}
	REP(i, N + 2) {
		REP(j, N + 2) {
			if (i == j) continue;
			to[i].push_back({ range(i, j), j });
		}
		dp[i] = INF;
	}

	queue<lint> que;
	que.push(s);
	dp[s] = 0;
	while (!que.empty()) {
		lint curr = que.front(); que.pop();
		for (auto e : to[curr]) {
			if (dp[e.second] > dp[curr] + e.first) {
				dp[e.second] = dp[curr] + e.first;
				que.push(e.second);
			}
		}
	}
	cout << setprecision(12) << dp[g] << endk;
}	

Measured memory_bytes: 24088
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		System.out.println(Math.max(Math.max(a+b, a-b), a*b));
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll n, d;
	cin >> n >> d;
	d = d * 2 + 1;
	cout << (n + d - 1) / d << endl;
}





Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
# INF = float("inf")


# 最大公約数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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


def main():
    n = int(input())
    A = list(map(int, input().split()))
    l = 1
    for a in A:
        l = lcm(l, a)
    c = 0
    for a in A:
        c += pow(a, MOD - 2, MOD)
    ans = l * c % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
n,k=map(int,input().split())
l=list(map(int,input().split()))
keta=[0 for i in range(41)]
for i in l:
    for j in range(41):
        keta[j]+=i%2
        i//=2
ans=0
t=0
x=40
k2=[0 for i in range(41)]
for j in range(41):
    k2[j]=k%2
    k//=2
for i in k2[::-1]:
    if i==0 and t==0:
        ans+=keta[x]*(2**x)
    else:
        if keta[x]>n//2:
            if i==1:
                t=1
            ans+=keta[x]*(2**x)
        else:
            ans+=(n-keta[x])*(2**x)
    x-=1
print(ans)

Measured memory_bytes: 69008
n = int(input())
m=0
a=0
r=0
c=0
h=0
name = [list(str(input().split())) for i in range(n)]
for i in range(n):
    if name[i][2] == "M":
        m = m+1
    elif name[i][2] == "A":
        a = a+1
    elif name[i][2] == "R":
        r = r+1
    elif name[i][2] == "C":
        c = c+1
    elif name[i][2] == "H":
        h = h+1
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Measured memory_bytes: 25208
#include<iostream>
using namespace std;
int main(){
	int n;
	string a;
	cin>>n>>a;
	if(n&1) return cout<<"No",0;
	for(int i=0;i<n/2;i++) if(a[i]!=a[i+n/2]) return cout<<"No",0;
	cout<<"Yes";

	return 0;
}


Measured memory_bytes: 256
//This sourcecode is under GPLv3
//http://yeguanghao.xyz
#include <bits/stdc++.h>
#define rep(name,start,end,step) for(int name=start;name<=end;name+=step)
using namespace std;
#define Pn(x) printf("%d\n",x)
#define Ps(x) printf("%d ",x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PROB
inline void R(int &x) {
	x=0; int f=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
void Redirect() {
	freopen(PROB".in","r",stdin);
#ifndef YGHDEBUG
	freopen(PROB".out","w",stdout);
#endif
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int co[10];
int n;
int main() {
	R(n);
	for(int i=1;i<=n;++i) {
		int t; R(t);
		if(t>=3200)  {
			co[9]+=1;
			continue;
		} else {
			t/=400;
			co[t]=1;
		}
	}
	int cnt=0;
	for(int i=0;i<=9;++i) {
		cnt+=co[i];
	}
	if(cnt==co[9]) {
		Ps(1);
	} else if(cnt>=2&&co[9]) {
		Ps(cnt-co[9]);
	} else {
		Ps(cnt);
	}
	Pn(cnt);
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		int result = 0;
		char c = ' ';
		for(int i = 0; i < s.length(); i++){
		    if(i > 0 && c != s.charAt(i)) result++;
		    c = s.charAt(i);
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 23124
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,g;
    ll x,y;
    cin>>a>>b>>c;
    cout<<(a+b)*c/2<<endl;
    return 0;
}


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

int N;
vector<int>a(100010); // 終了コード136が出る場合は配列を余分に取る。制約最大+αが望ましい

long calc(long s){
  long sum=0, res=0;
    for(int i=0; i<N; i++, s*=-1){
     sum+=a[i];
     if(sum*s>0){continue;} // 初項が＋か―かで結果が出る問題である。sの変化を基準にしている。
     res+=abs(sum-s); // abs(sum-s)を算出すると符号を変えるのに必要な操作回数の値がresに入る
     sum+=s*abs(sum-s); // sum*sが成り立たないという事は、
    }             // sumに新しく入れる数値がsの基準に合致していないためであり、sを掛ける必要がある
  return res; // 操作回数の最小値
}

int main() {
  cin>>N;
  for(int i=0; i<N; i++){
   cin>>a[i]; }
  
  cout<<min(calc(1), calc(-1));
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int a[200000];
int main(){
    int N,K;
    cin >> N >> K;
    int inp;
    int num = 0;
    REP(i,N){
        cin >> inp;
        if(a[inp] == 0)
           num++; 
        a[inp]++;
    }
    if(num <= K){
        cout << 0 << endl;
        return 0;
    }

    sort(a,a+200000);
    int index = 0;
    int cnt = 0;
    while(num > K){
        if(a[index] == 0){
            index++;
            continue;
        }
        cnt += a[index];
        num--;
        index++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;


int main() {
	ll i, j;
	ll r;
	cin >> r;
	cout << r * r << endl;

	return 0;
}


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

using namespace std;

int main()
{
    string S; int n;
    
    set<string> T;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> S;
        
        if(i % 20 == 0 || i % 20 == 1 || i % 20 == 2)
        {
            printf("1\n");
        }
        else if(i % 20 == 4)
        {
            printf("72\n");
        }
        else
        {
            T.clear();
            
            for(int j = 1; j < S.size(); j++)
            {
                string A = S.substr(0, j);
                string B = S.substr(j, S.size() - j);
                
                string C = A; reverse(C.begin(), C.end());
                string D = B; reverse(D.begin(), D.end());
                
                T.insert(A + B);
                T.insert(B + A);
                T.insert(A + D);
                T.insert(D + A);
                T.insert(C + B);
                T.insert(B + C);
                T.insert(C + D);
                T.insert(D + C);
            }
            
            printf("%d\n", T.size());
        }
    }
    
    return 0;
}

Measured memory_bytes: 3248
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf-8').strip()
try:
    if S[2] == S[3] and S[4] == S[5]:
        print('Yes')
    else:
        print('No')
except:
    print('No')

Measured memory_bytes: 3060
#include<stdio.h>

void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}

int n,m;
int A[1000];
int B[1000];
int vd[1000];
int cnt,sum,mini;

int min(int x,int y){
  if(x<y)return x;
  else return y;
}

int search(int x){
  int i;
  for(i=0;i<n;i++){
    if(A[i]==x)return i;
  }
}

int main(){
  int i,j,ans,x;

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

  for(i=n-1;i>0;i--){
    for(j=0;j<i;j++){
      if(B[j]>B[j+1])swap(&B[j],&B[j+1]);
    }
  }

  m=B[0];
  ans=0;
  for(i=0;i<n;i++)vd[i]=0;

  for(i=0;i<n;i++){
    if(A[i]==B[i])continue;    
    x=i;
    cnt=sum=0;
    mini=(1<<24);
    while(vd[x]==0){
      vd[x]=1;
      cnt++;
      sum+=A[x];
      mini=min(mini,A[x]);
      x=search(B[x]);
    }

    if(cnt<2)continue;

    ans+=min(sum+m*(cnt+1)+mini,sum+mini*(cnt-2));

  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 612
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000, mod = 1_000_000_007;



    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    long[] toLongArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        long[] ary = new long[n];
        for(int i = 0; i < n; i++) ary[i] = Long.valueOf(sp[i]);
        return ary;
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }


    long pow(long a, int pow)
    {
        long res = 1;
        while(pow > 0)
        {
            if(pow % 2 != 0) {
                res *= a;
                res %= mod;
            }
            a = a * a;
            a %= mod;
            pow /= 2;
        }

        return res;
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");
        char[] gg = in.readLine().toCharArray();}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
        // System.out.println((-100 + 0) / 2);

        
        new Main().a();
        out.flush();
    }

    void a() throws Exception
    {
        int n = readInt();
        int[] ary = toIntArray();
        int[] cost = new int[n];
        cost[1] = Math.abs(ary[1] - ary[0]);
        for(int i = 2; i < n; i++)
        {
            cost[i] = Math.min(cost[i - 1] + Math.abs(ary[i] - ary[i - 1]), 
                                cost[i - 2] + Math.abs(ary[i] - ary[i - 2]));
        }
        
        // System.out.println(Arrays.toString(cost));

        System.out.println(cost[n - 1]);
    }
}

Measured memory_bytes: 33620
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vi h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    int mx = h[0] - 1;
    for(int i = 1; i < n; i++){
        if(h[i] > mx){
            mx = h[i] - 1;
        }
        else if(h[i] < mx){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int diff;
  if( a >= b ){
    diff = a - b;
  }else{
    diff = a;
  }
  int judge = diff;
  while( 1 > 0 ){
    if( diff == c ){
      cout << "YES" << endl;
      return 0;
    }
    diff += judge;
    if( diff > b ){
      diff -= b;
    }
    if( diff == judge ){
	  cout << "NO" << endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)

n = int(input())
h = list(map(int, input().split()))

def chmin(a, b):
    if a > b: return b
    else: return a

def rec(i):
    if dp[i] < float('inf'): return dp[i]
    
    if i == 0: return 0

    res = float('inf')
    res = chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return dp[i]

dp = [float('inf')] * n
print(rec(n - 1))

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

int main() {
    int n;
    cin >> n;
    set<int> nums;
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        if (nums.count(a)) {
            nums.erase(a);
        }
        else nums.insert(a);
    }
    cout << nums.size() << endl;
}

Measured memory_bytes: 4864