akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cctype>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e15;
typedef pair<ll,ll> P;
typedef string::const_iterator State;
class ParseError {};
int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);
int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}
int expression(State &begin){
    int ret = term(begin);
    for(;;){
        if (*begin == '+'){
            begin++;
            ret += term(begin);
        }
        else if (*begin == '-'){
            begin++;
            ret -= term(begin);
        }
        else{
            break;
        }
    }
    return ret;
}
int factor(State &begin){
    if (*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    }
    else{
        return number(begin);
    }
}
int term(State &begin){
    int ret = factor(begin);
    for(;;){
        if (*begin == '*'){
            begin++;
            ret *= factor(begin);
        }
        else if(*begin == '/'){
            begin++;
            ret /= factor(begin);
        }
        else{
            break;
        }
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    cin.ignore();
    rep(i,N){
        string s;
        getline(cin,s);
        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll  long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	int c[n], s[n], f[n], ans[n];
	for (int i=0; i<n-1; ++i) cin>>c[i]>>s[i]>>f[i];
	ans[n-1] = 0;
	for (int i=0; i<n-1; ++i){
		int t=s[i] + c[i];
		for(int j=i+1; j<n-1; ++j) {
			if (t<=s[j]) t+=(s[j] - t);
			else t+= ((t-s[j])%f[j] ? f[j]-(t-s[j])%f[j]: 0);
			t+=c[j];
		}
		ans[i] = t;
	}
	for (int i=0; i<n; ++i) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 500009
#define MOD 998244353
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  vector<int> a(N,0),m(N,0),M(N,0);
  for(int i=0;i<N;i++){
    int n=S.at(i).size();
    for(int j=0;j<n;j++){
      if(S.at(i).at(j)=='('){
        a.at(i)++;
        M.at(i)=max(a.at(i),M.at(i));
      }else{
        a.at(i)--;
        m.at(i)=min(a.at(i),m.at(i));
      }
    }
  }

  int ans1=0,ans2=0;
  vector<pair<int,int>> ma,Ma;
  set<int> s;
  for(int i=0;i<N;i++){
    if(m.at(i)==0){
      ans1+=a.at(i);
    }else if(m.at(i)==a.at(i)){
      ans2-=a.at(i);
    }else if(a.at(i)>0){
      ma.push_back(make_pair(m.at(i),a.at(i)));
    }else if(a.at(i)<0){
      Ma.push_back(make_pair(m.at(i)-a.at(i),-a.at(i)));
    }else{
      s.insert(i);
    }
  }
  sort(ma.begin(),ma.end());
  reverse(ma.begin(),ma.end());
  sort(Ma.begin(),Ma.end());
  reverse(Ma.begin(),Ma.end());

  bool flag=true;
  int n=ma.size();
  for(int i=0;i<n;i++){
    if(ans1+ma.at(i).first<0){
      flag=false;
    }
    ans1+=ma.at(i).second;
  }
  n=Ma.size();
  for(int i=0;i<n;i++){
    if(ans2+Ma.at(i).first<0){
      flag=false;
    }
    ans2+=Ma.at(i).second;
  }
  n=s.size();
  for(int i=0;i<n;i++){
    if(ans1+m.at(i)<0){
      flag=false;
    }
  }
  if(flag&&ans1==ans2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

int main(){
    char p[100],s[100],t[100]={0};
    int i,k,result=0,ls,lp;
    scanf("%s", p);
    scanf("%s", s);
    lp=strlen(p);
    ls=strlen(s);
    for(i=0;i<lp+ls;i++){
        for(k=0;k<ls;k++){
            t[k]=p[(i+k)%lp];
        }
        if(strcmp(s,t)==0){
            result=1;
            break;
        }
    }
    if(result)printf("Yes\n");
    else printf("No\n");
    
    return 0;
}

Measured memory_bytes: 1768
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  int H[N];
  for(int i = 0; i < N; ++i)
    cin >> H[i];

  int maxMT = H[0], cnt = 1;
  for(int i = 1; i < N; ++i) 
    if(H[i] >= maxMT) {
      maxMT = H[i];
      ++cnt;
    }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    long long sum = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0) sum += i;
    }
    printf("%lld\n", sum);

    return 0;
}


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

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

map<ll,ll> mp;

// 約数列挙関数
vector<ll> enum_divisors(ll n){

    vector<ll> res;
    for(ll i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            // 重複しない場合には加える
            if(n/i != i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

vector<ll> makePrimeList(const ll &n){

    if(n <= 1){
        vector<ll> null;
        return null;
    }

    vector<ll> prime_list(1,2);
    for(ll i = 2; i <= n; i++){
        bool is_prime = true;
        for(ll j = 0; j < prime_list.size(); j++){
            ll now_prime = prime_list[j];
            if(i%now_prime==0){
                is_prime = false;
                break;
            }else if(now_prime*now_prime > n){
                break;
            }
        }
        if(is_prime){
            prime_list.push_back(i);
        }
    }
    return prime_list;
}

void factorization(const ll &n, const vector<ll> prime_list){
    // nの素因数分解をしたvectorを返す．
    // 少なくともnまでの素数を含むprime_listを渡す

    // vector<P> res;
    ll now = n;
    ll i = 0;
    while(now!=1){
        P p;
        p.first = prime_list[i];
        p.second = 0;
        while(now%p.first==0){
            p.second++;
            now /= p.first;
        }
        if(p.second!=0){
            mp[p.first]+=p.second;
        }
        i++;
    }

    return;
}

int main(){
    ll n; cin >> n;
    vector<ll> prim_list = makePrimeList(n);

    for(ll i = 1; i <= n; i++){
        factorization(i, prim_list);
    }
    
    ll ans = 1;
    ll mod = 1e9+7;
    for(auto it : mp){
        ans*=(it.second+1);
        ans=ans%mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val input=io.Source.stdin.getLines.toIndexedSeq.head.split(' ').map(_.toInt)
  val N=input(0)
  val Y1000=input(1)/1000
  val const=Y1000-N  

  private def func(){
  (0 to const/9).foreach{ a =>
    val b=(const-9*a)/4
    val c=N-a-b
    if(b>=0 && c>=0 && (const-9*a)%4==0) return println(a+" "+b+" "+c)
  }
  println("-1 -1 -1")
  }
  func()
}


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

struct edge
{
    int u, v, cost;
};

bool comp(const edge &e1, const edge &e2)
{
    return e1.cost < e2.cost;
}

int n, E, A[100][100];
int p[10010];
vector<edge> es(0);

void init(int n)
{
    rep(i, n) p[i] = i;
}

int root(int a)
{
    if (p[a] == a)
        return a;
    return (p[a] = root(p[a]));
}

bool is_same_set(int a, int b)
{
    return root(a) == root(b);
}

void unite(int a, int b)
{
    p[root(a)] = root(b);
}

int kruskal()
{
    int sum = 0;
    E = 0;
    rep(i, n) rep(j, i)
    {
        if (A[i][j] != -1)
        {
            E++;
            edge e;
            e.u = i;
            e.v = j;
            e.cost = A[i][j];
            es.push_back(e);
        }
    }
    sort(es.begin(), es.end(), comp);
    rep(i, E)
    {
        edge e = es[i];
        if (!is_same_set(e.u, e.v))
        {
            unite(e.u, e.v);
            sum += e.cost;
        }
    }
    return sum;
}

int main()
{
    cin >> n;
    rep(i, n) rep(j, n) cin >> A[i][j];
    init(n);
    int ans = kruskal();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3268
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
	vector<string> a;
	string k;
	char end;
	int n;
	cin>>n;
	cin>>k;
	end=k[k.size()-1];
	a.push_back(k);
	for(int i=1;i<n;i++){
		cin>>k;
		int c=0;
		for(int j=0;j<a.size();j++){
			if(k==a[j]){
				cout<<"No";
				return 0;
			}
		}
		if(k[0]!=end){
			cout<<"No";
			return 0;
		}
		end=k[k.size()-1];
		a.push_back(k);
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
a[:] = map(int, input().split())
max = -2000000
min = 2000000
sum = 0
for _ in range(0,n):
    sum += a[_]
    if (a[_]>max):
        max = a[_]
    if (a[_]<min):
        min = a[_]
print('{} {} {}'.format(min, max, sum))



Measured memory_bytes: 6604
N = int(input())
a = [int(x) for x in input().split()]
ite = 0
count = 0
while (ite < N):
    if a[ite] % 2 == 0:
        count += 1
        a[ite] = a[ite] // 2
    else:
        ite += 1
print(count)


Measured memory_bytes: 4148
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
  	map<int,int> mp;
  	int n,x;
  	cin>>n;
  	for(int i=0;i<n;i++)
    {
      cin>>x;
      mp[x]=i+1;
    }
  	for(auto it: mp)
      cout<<it.se<<" ";
	return 0;
}

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

int main()
{
    int n,i;cin>>n;int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    int m=0;
    for(i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            m=max(m,abs(a[i]-a[j]));
        }
    }
    cout<<m;


}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int N, M;

int main() {
	cin >> N >> M;
	int cx = M + 1, cnts = 0;
	for (int i = M; i >= 1; i--) {
		if (N % 2 == 0 && (cx - i) * 2 >= N && cnts == 0) { cx++; cnts = 1; }
		cout << i << " " << cx << endl;
		cx++;
	}
	return 0;
}

Measured memory_bytes: 3584
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

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

Measured memory_bytes: 256
a = int(input())
if a <10:
  print("{}".format(a))
elif a <100:
  print("9")
elif a < 1000:
  print("{}".format(9+a-99))
elif a < 10000:
  print('909')
elif a < 100000:
  print("{}".format(909+a-9999))
else:
  print('90909')

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

#define ll long long

using namespace std;

int main(void){
    int N, K;
    cin >> N >> K;
    vector<int> L(K), R(K);
    for(int i = 0; i < K; i++){
        cin >> L[i] >> R[i];
    }
    vector<ll> cumsum(N, 0), diff(N, 0);
    const ll mod = 998244353;
    for(int j = 0; j < K; j++){
        int l = L[j];
        int r = R[j];
        if(l < N){
            diff[l] += 1;
            diff[l] %= mod;
        }
        if(r + 1 < N){
            diff[r + 1] += mod - 1;
            diff[r + 1] %= mod;
        }
    }

    // for(int i = 0; i < N; i++) cout << cumsum[i] << " ";
    // cout << endl;
    // for(int i = 0; i < N; i++) cout << diff[i] << " ";
    // cout << endl;

    for(int i = 1; i < N; i++){
        cumsum[i] = cumsum[i - 1];
        cumsum[i] += diff[i];
        cumsum[i] %= mod;
        for(int j = 0; j < K; j++){
            int l = i + L[j];
            int r = i + R[j];
            if(l < N){
                diff[l] += cumsum[i];
                diff[l] %= mod;
            }
            if(r + 1 < N){
                diff[r + 1] += mod - cumsum[i];
                diff[r + 1] %= mod;
            }
        }


    //         for(int i = 0; i < N; i++) cout << cumsum[i] << " ";
    // cout << endl;
    // for(int i = 0; i < N; i++) cout << diff[i] << " ";
    // cout << endl;
    }
    // for(int i = 0; i < N; i++) cout << cumsum[i] << " ";
    // cout << endl;
    // for(int i = 0; i < N; i++) cout << diff[i] << " ";
    // cout << endl;
    cout << cumsum[N - 1] % mod << endl;
    return 0;
}


Measured memory_bytes: 6396
def calculate_sum_of_digits(n):
    result = 0
    while n != 0:
        result += n % 10

        n //= 10

    return result


n, a, b = map(int, input().split())
result = 0
for i in range(1, n + 1):
    sum_of_digits = calculate_sum_of_digits(i)
    if a <= sum_of_digits <= b:
        result += i

print(result)


Measured memory_bytes: 2940
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        int N = int.Parse(line);
        if (N % 111 == 0)
        {
            Console.WriteLine(line);
        }
        else
        {
            Console.WriteLine(111 * ((N / 111) + 1));
        }

    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

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


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int32_t main() {
    int n; cin >> n;
    vector<int> a(n); cin >> a;
    sort(all(a));
    vector<int> s(n+1);
    rep (i,n) s[i+1] = a[i];
    rep (i,n) s[i+1] += s[i];
    int i = n-1;
    while (i >= 0 && s[i]*2 >= a[i]) i--;
    cout << n-i << endl;    
}


Measured memory_bytes: 1920
n = input(); t = dict(zip(range(1,n+1),[0]*n))
for i in xrange(n*(n-1)/2):
    a,b,c,d=map(int, raw_input().split())
    if c==d:
        t[a]+=1; t[b]+=1;
    elif c>d:
        t[a]+=3
    else:
        t[b]+=3
c = 0; cnt = 0; p = -1;
for k, v in sorted(t.items(), key = lambda x:x[1], reverse=True):
    cnt += 1;
    if p!=t[k]:
        c = cnt; p = t[k];
    t[k] = c
for v in t.values():
    print v

Measured memory_bytes: 4276
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
    int main() {
      int N,Alice,Bob;
      cin >> N;
      vector<int> Cards(110);
      
      rep (i,N) {
        cin >> Cards.at(i);
      }   
      sort(Cards.begin(),Cards.end());
      reverse(Cards.begin(),Cards.end());
      
      
      rep (i,N) {
        if (i % 2 == 0){
          Alice += Cards.at(i);
      }
      else {
        Bob += Cards.at(i);
      }
      }
      //  Alice += Cards.at(i*2);
      //  Bob += Cards.at(i*2+1);
      //}
      cout << Alice - Bob << endl;
      
	}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length();
	
	vector<vector<int>> dp(n+1, vector<int>(2));
	dp[0][1] = 1;
	for(int i = 1; i <= n; i++) {
		for(int c = 0; c < 2; c++) {
			int& ans = dp[i][c] = (int) 1e9;
			int val = (s[i-1] - '0') + c;
			if(val < 10) ans = min(ans, dp[i-1][0] + val);
			ans = min(ans, dp[i-1][1] + (10 - val));
		}
	}
	
	cout << dp[n][0] << endl;
}


Measured memory_bytes: 55964
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n - 1), b(n - 1);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--; b[i]--;

		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
	}

	std::vector<int> h(n);
	auto dfs = [&](auto&& dfs, int v, int par, int now) -> void {
		h[v] = now;
		
		for(int id: g[v]) {
			int to = a[id] ^ b[id] ^ v;
			if(to == par) continue;

			dfs(dfs, to, v, (now == 1 ? 2 : 1));
		}
	};
	dfs(dfs, 0, -1, 1);

	int X = 0, Y = 0, Z = 0, A = 0, B = 0;
	for(int i = 1; i <= n; i++) {
		X += (i % 3 == 1);
		Y += (i % 3 == 2);
		Z += (i % 3 == 0);
	}
	for(auto v: h) {
		A += (v == 1);
		B += (v == 2);
	}
	if(B < A) {
		std::swap(A, B);
		for(auto& v: h) v = (v == 1 ? 2 : 1);
	}

	if(A < X) {
		for(auto& v: h) {
			if(v == 1) {
				v = 0;
				Z--;
			} else {
				if(X) v = 1, X--;
				else if(Y) v = 2, Y--;
				else if(Z) v = 0, Z--;
			}
		}
	} else {
		for(auto& v: h) {
			if(v == 1 and A > X) {
				v = 0;
				A--;
			}
			if(v == 2 and B > Y) {
				v = 0;
				B--;
			}
		}
	}

	int x = 3, y = 1, z = 2;
	for(auto v: h) {
		if(v == 0) printf("%d ", x), x += 3;
		if(v == 1) printf("%d ", y), y += 3;
		if(v == 2) printf("%d ", z), z += 3;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 15872
import java.io.IOException;
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			FastScanner s = new FastScanner();
			int a = s.nextInt();
			int p = s.nextInt();
			int x = 3*a+p;
			System.out.println(x/2);
	}

static   class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}


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

int main () {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  
  int a = Z, b = Y+Z, ans = 0;
  while (a+b <= X) {
    a += b;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
x = gets.split(" ").map(&:to_i)
n = x[0]
m = x[1]
a = []
for i in 0..n-1 do
  a << gets.split(" ").map(&:to_i)
end

b = []
for i in 0..m-1 do
  b << gets.to_i
end

for i in 0..n-1 do
  v = 0
  for j in 0..m-1 do
    v += a[i][j] * b[j]
  end
  puts v
end


Measured memory_bytes: 6972
a=[int(input()) for i in range (5)]
m=[]
s=0
for j in range(5):
    x=a[j]%10
    if x!=0:
        s+=a[j]+10-x
    else:
        s+=a[j]
for k in range(5):
    y=a[k]%10
    b=s
    if y!=0:
        n=10-y
        b=b-n
        m.append(b)
    else:
        m.append(b)
print(min(m))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using namespace std;

int64_t mod(int64_t a, int64_t m)
{
   while (1)
   {
      if (a > 0)
         return a % m;

      a += m;
   }
}

void Main()
{
   int N;
   cin >> N;
   int64_t a[N], c[N], g[N], t[N], tot[N];
   a[0] = 1;
   c[0] = 1;
   g[0] = 1;
   t[0] = 1;
   tot[0] = 4;
   a[1] = 4;
   c[1] = 4;
   g[1] = 4;
   t[1] = 4;
   tot[1] = 16;
   a[2] = 14;
   c[2] = 16;
   g[2] = 15;
   t[2] = 16;
   tot[2] = 61;
   for (int i = 3; i < N; i++)
   {
      a[i] = tot[i - 1] - g[i - 2] - c[i - 2] - 3 * c[i - 3]; // gc-, cg-, gtc-, tgc-, ggc-;
      c[i] = tot[i - 1];
      g[i] = tot[i - 1] - c[i - 2] + g[i - 3]; // ac-
      t[i] = tot[i - 1];
      tot[i] = mod(a[i] + c[i] + g[i] + t[i], 1000000007);
   }
   std::cout << tot[N - 1] << endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> a >> b;
	if (b % a == 0)
		cout << a + b << endl;
	else
		cout << b - a << endl;

	return 0;
}

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

int main(){
  string s,t;
  cin>>s>>t;
  int d;
  int dmin=t.size();
  for(int i=0;i<=s.size()-t.size();i++){
    d=0;
    for(int j=0;j<t.size();j++){
      if(s.at(i+j)!=t.at(j)){
        d++;
      }
    }
    if(d<dmin){
      dmin=d;
    }
  }
  cout<<dmin<<endl;
}

Measured memory_bytes: 3564
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

typedef pair<long long int, long long int> P;

int main(){
	
	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0){
			break;
		}
		int F[20][20];
		for(int i = 0; i < H; i++){
			for(int j = 1; j <= W; j++){
				cin >> F[i][j];
			}
		}
		long long int DP[20][20] = {};
		for(int i = 1; i <= W; i++){
			DP[0][i] = 1;
		}
		for(int i = 0; i < H - 1; i++){
			for(int j = 1; j <= W; j++){
				if(F[i][j] == 0){
					if(F[i + 1][j - 1] == 0){
						DP[i + 1][j - 1] += DP[i][j];
					}
					if(F[i + 1][j + 1] == 0){
						DP[i + 1][j + 1] += DP[i][j];
					}
					DP[i + 1][j] += DP[i][j];
				}else if(F[i][j] == 2){
					DP[i + 2][j] += DP[i][j];
				}
			}
		}
		long long int ans = 0;
		for(int i = 1; i <= W; i++){
			if(F[H - 1][i] != 1){
				ans += DP[H - 1][i];
			}
			ans += DP[H][i];
		}
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int K;
  cin >> K;
  vector<int> encountered;
  if (7 % K == 0){
    cout << 1;
    return 0;
  }
  else {
    int modK = 7 % K;
    for (int digit = 2; digit <= K; digit++){
      modK = (modK * 10 + 7) % K;
      if (modK == 0){
        cout << digit;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}

Measured memory_bytes: 3664
import java.util.*

fun <T> permutationList(sortedList: Array<T>): List<List<T>> {
    val permutations = mutableListOf<List<T>>()
    val queue = ArrayDeque<List<T>>().apply { addLast(listOf()) }
    while (queue.isNotEmpty()) {
        val p = queue.removeLast()

        if (p.size == sortedList.size) {
            permutations.add(p)
        } else {
            sortedList.filterNot { p.contains(it) }
                .forEach { queue.addLast(p + it) }
        }
    }

    return permutations
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    permutationList((1..n).toList().toTypedArray())
        .let { it.indexOf(p) - it.indexOf(q) }
        .let(Math::abs)
        .let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 46252
#include<cstdio>
#include <iostream>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

int main(){
	string S, T, U;
	cin >> S >> T;
	int A, B;
	scanf("%d %d\n", &A, &B);
	cin >> U;
	if(U == S){
		printf("%d %d\n", A-1, B);
	}else{
		printf("%d %d\n", A, B-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  while(cin>>N && N){
    vector<int> l(N);
    REP(i, N) cin>>l[i];
    int M = 256;
    int as, aa, ac;
    double ent = 1e32;
    REP(S, 16)REP(A, 16)REP(C, 16){
      vector<int> R(N + 1);
      R[0] = S;
      REP(i, N) R[i + 1] = (A * R[i] + C) % M;
      REP(i, N) R[i + 1] = (R[i + 1] + l[i]) % M;
      map<int, int> cnt;
      REP(i, N) cnt[R[i + 1]] += 1;
      double e = 0;
      FORIT(it, cnt){
        double c = it->second;
        e += -c/N * log(c/N);
      }
      if(e + EPS < ent){
        ent = e;
        as = S, aa = A, ac = C;
      }
    }
    printf("%d %d %d\n", as, aa, ac);
  }
  return 0;
}

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

int main() {
  int N; cin >> N;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (N-i != i) ans++;
  }
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 256
k = gets.to_i
# 1 2 3 4 5 6 7 8 9
# 10 11 12
# 21 22 23
# 32 33 34
# ...
# 87 88 89
# 98 99
# 101 110 111 121 122 123
# 210 211 221 222 223 232 233 234
list = [[1,2,3,4,5,6,7,8,9]]
while k > list.last.size
  k -= list.last.size
  nlist = []
  list.last.each do |a|
    mod = a % 10
    if mod != 0
      nlist.push(a * 10 + mod - 1)
    end
    nlist.push(a * 10 + mod)
    if mod != 9
      nlist.push(a * 10 + mod + 1)
    end
    list.push(nlist)
  end
end
puts list.last[k-1]

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


int main()
{
 long long a,b;
 cin >> a >> b;
 
 long long c = gcd(a,b);
 
 cout << a * b / c;
 
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    ll r=a%b;
    while(r)a=b,b=r,r=a%b;
    return b;
}

int main(){
    int x,y;cin>>x>>y;
    cout<<x+y-gcd(x,y)+1<<endl;
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vec;
typedef std::vector<ld> vecld;
typedef std::vector< std::vector<ll> > vecvec;
typedef std::pair<ll, ll> pr;
typedef std::vector< pr > vpr;

#define tin ll t;cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define sz(a) (ll)((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define trvect(c,i) for(vector<ll>::iterator i = (c).begin(); i != (c).end(); i++)
#define trset(c,i) for(set<ll>::iterator i = (c).begin(); i != (c).end(); i++)
#define trmap(c,i) for(map<ll,ll>::iterator i = (c).begin(); i != (c).end(); i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define present(c,x) ((c).find(x) != (c).end())
#define ff first
#define ss second
#define mk make_pair
#define sq(a) (a)*(a)
#define cube(a) (a)*(a)*(a)
#define cnti(x) (__builtin_popcount(x)) //number of set bits in x
#define mst(c) memset((c),0,sizeof((c)))


int main(){


	//fio;

	/////////////////////////////////////////

	ll n;
	cin>>n;
	ll h[n];
	rep(i,0,n) cin>>h[i];
	
	ll dp[n];
	dp[1]=abs(h[1]-h[0]);
	dp[0]=0;
	
	rep(i,2,n){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
		
	}

	cout<<dp[n-1]<<"\n";



	////////////////////////////////////////////////




    return 0;












}


Measured memory_bytes: 1792
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($n, $m) = split / /, <STDIN>);
chomp (my @x = split / /, <STDIN>);
@x = sort {$a <=> $b} @x;
if ($n >= $m) {
  say 0;
  exit;
} elsif ($n == 1) {
  say (max(@x)-min(@x));
  exit;
}
#unshift @x, min(@x);
#push @x, max(@x);
my $sum = max(@x) - min(@x);
my @y;
for my $i (0..$m-2) {
  $y[$i] = $x[$i+1] - $x[$i];
}
@y = sort { $b <=> $a } @y;
for my $i (0..$n-2) {
  $sum -= $y[$i];
}
say $sum;

Measured memory_bytes: 19604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main 
{
	public static void main(String[] Arguments) throws IOException
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
		char b = BR.readLine().charAt(0);
		if (b == 'A')
		{
			System.out.println("T");
		}
		if (b == 'T')
		{
			System.out.println("A");
		}
		if (b == 'C')
		{
			System.out.println("G");
		}
		if (b == 'G')
		{
			System.out.println("C");
		}
	}
}


Measured memory_bytes: 32696
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	int K;
	cin>>K;
	long long result = 0;
	for(int a=1; a<=K; a++)
	{
		for(int b=1; b<=K; b++)
		{
			int ab = gcd(a,b);
			for(int c=1; c<=K; c++)
			{
				result += gcd(ab,c);
			}
		}
	}
	cout<<result<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename S> using umap = unordered_map<T, S>;
#define rep(i , n , k) for(ll i=n; i<(ll)k; ++i)
#define per(i , n , k) for(ll i=n; i>(ll)k; --i)

void solve() {
  string s, t;
  cin>>s>>t;
  t.pop_back();
  if(s==t) cout<<"Yes\n";
  else cout<<"No\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout<<fixed;
  solve();
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()
{
    int minv;
    int d[MAX], color[MAX];

    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;
    while (1)
    {
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++)
        {
            if (minv > d[i] && color[i] != BLACK)
            {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1)
        {
            break;
        }
        color[u] = BLACK;
        for (int v = 0; v < n; v++)
        {
            if (color[v] != BLACK && M[u][v] != INFTY)
            {
                if (d[v] > d[u] + M[u][v])
                {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 3112
n = int(input())

repdigitCount = 0

for i in range(n):
    D = [int(x) for x in input().split()]
    if D[0] == D[1]:
        repdigitCount += 1
        if repdigitCount == 3:
            print('Yes')
            exit()
    else:
        repdigitCount = 0
print('No')


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

const int MOD = 998244353;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    vector<vector<ll> > dp(c + 1, vector<ll>(d + 1, 0));

    dp[a][b] = 1;

    for (int i = a; i <= c; i++) for (int j = b; j <= d; j++)
        if (!(i == a && j == b))
            dp[i][j] = ((dp[i - 1][j] * j) + (dp[i][j - 1] * i) - (dp[i - 1][j - 1] * (i - 1) * (j - 1)) % MOD + MOD) % MOD;

    cout << dp[c][d] << '\n';
    return 0;
}


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

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


Measured memory_bytes: 3632
/**
 *   author: Shubham Srivastava
 *   created: 10 August 2019  17:34:16
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k;cin>>n>>k;
    int left = k-n+1;
    int right = k+n-1;
    for(int i=left;i<=right;i++)
        cout<<i<<" ";
return 0;
}

Measured memory_bytes: 256
r,c = map(int,input().split())

a = [[0 for i in range(c+1)] for j in range(r+1)]

for i in range(r):
    a_tmp = list(map(int,input().split()))
    for j in range(c):
        a[i][j] = a_tmp[j]
        a[i][c] += a_tmp[j]
        a[r][j] += a_tmp[j]
        a[r][c] += a_tmp[j]

for i in range(r+1):
    print(' '.join(str(x) for x in a[i]))

Measured memory_bytes: 7764
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ans=float('inf')
for i in range(4**n):
    abc=[[] for i in range(4)]
    for j in range(n):
        abc[i%4].append(l[j])
        i//=4
    A,B,C,x=abc
    if len(A)==0 or len(B)==0 or len(C)==0:
        continue
    ans=min(ans,abs(sum(A)-a)+abs(sum(B)-b)+abs(sum(C)-c)+(len(A)+len(B)+len(C)-3)*10)
print(ans)

Measured memory_bytes: 49244
#include <bits/stdc++.h>
using namespace std;
    
int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    n=n/2-1;
    int m=n+1,ans=d.at(m)-d.at(n);   
  	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        int[] friend = new int[n+1];
        UnionFind uf = new UnionFind(n+1);
        for(int i = 0; i < m; i++){
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            friend[a]++;
            friend[b]++;
            uf.unite(a, b);
        }
        int[] block = new int[n+1];
        for(int i = 0; i < k; i++){
            int c = Integer.parseInt(sc.next());
            int d = Integer.parseInt(sc.next());
            if(uf.same(c, d)){
                block[c]++;
                block[d]++;
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <= n; i++){
            sb.append(uf.size[uf.root(i)] - 1 - friend[i] - block[i]).append(" ");
        }
        System.out.println(sb);
    }
    
    static class UnionFind {
        int[] parent;
        int[] size;

        public UnionFind(int n) {
            parent = new int[n];
            size = new int[n];
            for(int i = 0; i < n; i++){
                parent[i] = i;
                size[i] = 1;
            }
        }
        int root(int x){
            if(parent[x] == x){
                return x;
            }else{
                return parent[x] = root(parent[x]);
            }
        }
        void unite(int x, int y){
            x = root(x);
            y = root(y);
            if(x == y) return;
            
            if(size[x] < size[y]){
                parent[x] = y;
                size[y] += size[x];
            }else{
                parent[y] = x;
                size[x] += size[y];
            }
        }
        boolean same(int x, int y){
            return root(x) == root(y);
        }
    }
}

Measured memory_bytes: 65920
#include <stdio.h>
#include <stdlib.h> 
int main (void)
{
    int b, i, tmp = 0, tmp1 = 0, min, min1, ans;
    scanf("%d", &b);
    int a [1000];
    for (i = 0; i < b; i++)
    {
        scanf("%d", &a[i]);
        tmp += a[i];
    }
    for (i = 0; i < b - 1; i++)
    {
        tmp1 += a[i];
        min = tmp - tmp1 * 2;
        if (abs(min) < abs(min1))
        {
            ans = abs(min);
        }
        min1 = min;
    }
    printf("%d\n", ans);
    return 0;
}

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

int main(void){
  
  int N,D,X,A[105],eat,i,j;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  D=atoi(p);
  p=strtok(NULL," \n");
  X=atoi(p);
  
  for(i=0;i<N;i++){
    fgets(str,sizeof(str),stdin);
    A[i]=atoi(str);
  }
  for(i=0,eat=0;i<N;i++){
    for(j=0;j*A[i]<D;j++){
     eat++; 
    }
  }
  
  printf("%d\n",eat+X);
  
 return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535
#define EPS (1e-10)
#define rep(i,n) for (int i = 0; i < (n); ++i)


int main()
{
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, n) cin >> a[i], sum += a[i];
  sort(a.begin(), a.end(), greater<ll>());
  if(4 * m * a[m - 1] >= sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

use std::cmp;

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize
    }
    let ans = cmp::min(b / a, c);
    println!("{}", ans);
}


Measured memory_bytes: 4352
N,K = map(int,input().split())
*A, = sorted(set(map(int,input().split())))
if A[-1]<K:print("IMPOSSIBLE");exit()
if len(A)==1:
    if A[0]==K:print("POSSIBLE")
    else:print("IMPOSSIBLE")
    exit()
d = min(A[i+1]-a for i,a in enumerate(A[:-1]))
K%=d
for a in A:
    if a%d==K:print("POSSIBLE");break
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 19728
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

signed main() {
  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < n; i++) {
    if (i % 2 == 1) {
      if (s[i] == 'R') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (s[i] == 'L') {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,x;
ll comb[3005][3005];


int main(void){
    comb[0][0]=1;
    for(int i=1;i<=3000;i++){
        for(int j=1;j<i;j++){
            comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%MOD;
        }
        comb[i][0]=1;
        comb[i][i]=1;
    }

    scanf("%d%d",&n,&x);
    ll ans=0;
    // 1 no kosuu
    for(int i=0;i<=n;i++){
        for(int j=0;(j+i)<=n;j++){
            //printf("%d %d %lld\n",i,j,ans);
            if(i+j*2<x){
                ll val=comb[i+j][i];
                val=comb[n][i+j]*val%MOD;
                ans+=val;
                ans%=MOD;
            }else{
                int diff=i+j*2-x;
                if(diff%2==0LL)continue;
                int u2=(i+j*2-(x-1))/2;
                if(u2*2>j && i!=0)continue;
                ll val;
                if(i==0){
                    val=1;
                }else{
                    val=comb[i+j-u2*2][i];
                }
                val=comb[n][i+j]*val%MOD;
                ans+=val;
                ans%=MOD;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 68992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

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

			String in = br.readLine();
			BigDecimal n = new BigDecimal(in);
			BigDecimal di = new BigDecimal("3");
			@SuppressWarnings("deprecation")
			BigDecimal ans = n.divide(di,4, BigDecimal.ROUND_HALF_UP);
			System.out.println(ans.setScale(0,RoundingMode.DOWN));

		}
	}
}

Measured memory_bytes: 25496