akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
ll INF = 100100100100100ll;
    
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    vector<ll> dp(n, INF);
    dp[0] = 0;
    for(int i=1; i<n; i++){
        for(int j=1; i<=k ? j<=i : j<=k; j++){
            ll m = dp[i-j] + abs(h[i]-h[i-j]);
            dp[i] = min(dp[i], m);
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
import numpy as np
p,q= input().split()
a,b =(int(p), int(q))
list_np = np.arange(-1000000, 1000000,1)
ans_list = []
for i in range(a):
    ans_list.append(b + i)
    ans_list.append(b - i)
ans_list.pop(0)
ans_list.sort()
ans=''

for i in range(a*2 -1):
    if i < a * 2 -1 :
        ans += str(ans_list[i])
        ans +=' '
    else:
        ans +=str(ans_list[i])
        break
print(ans)

Measured memory_bytes: 28068
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll R, G;
    cin>>R>>G;
    cout<<G*2-R<<endl;
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  
  int c = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a >= k) ++c;
  }
  cout << c << endl;
}

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

int main(void) {
    string s;
    cin >> s;
    int ans = 1e9;
    for (int i = 0; i < (int)s.size() - 2; i++) {
        ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int r;
    scanf("%d", &r);
    if (r < 1200) printf("ABC\n");
    else if (r < 2800) printf("ARC\n");
    else printf("AGC\n");
    return 0;
}


Measured memory_bytes: 128
//author Eterna King
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<numeric>
#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#define lowbit(x) ((x) & (-(x)))
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.in", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.out", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define memset0(arr) memset(arr, 0, sizeof(arr))
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 2e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
il int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll quick_pow(ll base, ll index) {
	ll res = 1;
	while (index) {
		if (index & 1)res = res * base % mod;
		base = base * base % mod;
		index >>= 1;
	}
	return res;
}
int cnt[maxn + 5];
int n, m, res;
int main()
{
	n = read_int(), m = read_int();
	for (int i = 1, l, r; i <= m; ++i) {
		cin >> l >> r;
		++cnt[l];
		--cnt[r + 1];
	}
	for (int i = 1; i <= n; ++i)cnt[i] += cnt[i - 1];
	for (int i = 1; i <= n; ++i)if (cnt[i] == m)++res;
	cout << res << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const int MAX_C = 100010;
int t[101][101][101][101];
void SimpleKnapsack() {

	int n;
	ll W;
	cin >> n >> W;
	ll wf = -1;
	ll ar[4] = {0,0,0,0};
	int res = 0;

	for (size_t i = 0; i < n; i++)
	{
		ll w;
		int v;
		cin >> w >> v;
		if (wf == -1) {
			wf = w;
		}
		int mi = w - wf;
		for (short j = ar[0]; j >= 0; j--)
		{
			ll tj = j * wf;
			for (short k =ar[1]; k >= 0; k--)
			{
				ll tk = tj + k * (wf + 1);
				for (short g = ar[2]; g >= 0; g--)
				{
					ll tg = tk + g * (wf + 2);
					for (short u = ar[3]; u >= 0; u--)
					{
						ll tu = tg + u * (wf + 3);
						if (tu + w <= W) {
							if (t[j + (mi == 0)][k + (mi == 1)][g + (mi == 2)][u + (mi == 3)]
								< t[j][k][g][u] + v) {
								int aa = t[j][k][g][u] + v;
								t[j + (mi == 0)][k + (mi == 1)][g + (mi == 2)][u + (mi == 3)] = aa;
								res = max(aa, res);
							}
						}
					}
				}
			}
		}
		ar[mi]++;
	}
	cout << res << endl;

}
int main() {

	SimpleKnapsack();
	return 0;
}


Measured memory_bytes: 203008
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main(){
    int n;
    cin >> n;
    ii arr[n];
    for (int i = 0; i < n; i++){
        cin >> arr[i].first;
        arr[i].second = i;
    }
    sort(arr,arr+n);
    int num = 0;
    for (int i = 0; i < n; i++) {
        //cout << i << " " << arr[i].first << " " << arr[i].second << "\n";
        num += (abs(arr[i].second-i)%2)==1;
    }
    cout << num/2;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,x=0;
  string s="";
  cin >> n >> s;
  if(n%2 == 0)
  {
    k = n/2;
    for(int t =0;t<k;t++)
    {
       if(s[t] == s[k+t]){++x;}
      
    }
    if(x==k){cout << "Yes" << endl;}
    else{cout << "No" <<endl;}
   }
  else{cout << "No"<<endl;}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int i;
  int Count = 0;
  int N;
  int sum = 0;
  int ave = 0;
  int los = 0;
  int Cost = 0;
  scanf("%d", &N);

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

  ave = sum / N;
  los = sum % N;

  if(N/2 < los)
    ave++;
  

  for(i = 0; i < N; i++)
    Cost += (a[i] - ave) * (a[i] - ave);

  printf("%d\n", Cost);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll n,m;
    cin>>n>>m;
    if(m-n*2>=0) cout<<n+(m-n*2)/4<<endl;
    else cout<<m/2<<endl;

    return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string s, t;

void zAlgorithm(string & S, vi & zTable){
        zTable[0] = S.size();
        int i = 1, j = 0;
        while (i < S.size()) {
            while (i+j < S.size() && S[j] == S[i+j]) ++j;
            zTable[i] = j;
            if (j == 0) { ++i; continue;}
            int k = 1;
            while (i+k < S.size() && k+zTable[k] < j) zTable[i+k] = zTable[k], ++k;
            i += k; j -= k;
        }

        zTable.erase(zTable.begin(), zTable.begin() + t.size() + 1);
}

int main(void){
    for(; cin >> s >> t;){
        string S = t + "$" + s;
        vi zTable(S.size());
        zAlgorithm(S, zTable);

        string srev = s, trev = t;
        reverse(all(srev));
        reverse(all(trev));
        string Srev = trev + "$" + srev;
        vi zTable_rev(Srev.size());
        zAlgorithm(Srev, zTable_rev);

        int res = 0;
        rep(i, s.size() - t.size() + 1){
            if(zTable[i] + zTable_rev[s.size() - (i + t.size())] + 1 == t.size()){
                res++;
            }
        }

        cout << res << endl;
    }

	return 0;
}

Measured memory_bytes: 6492
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		while(sc.hasNextInt()){
			
			
			
			int n=sc.nextInt();
			if(n==0) break;
			int count=0;
			boolean judge=true;
			for(int i=0;i<n;i++){
				int singi=sc.nextInt();
				if(singi>0) count++;
				if(singi>1) judge=false;
			}
			if(judge) System.out.println("NA");
			else System.out.println(count+1);
		}
	}

}

Measured memory_bytes: 158524
#include<bits/stdc++.h>
using namespace std;
int n,k,ans,p;
int mmap[12][6]={{4,2,0,9,7},{1,10,8,6,4},{9,7,5,3,1},{6,4,2,0,9},{3,1,10,8,6},{0,9,7,5,3},{8,6,4,2,0},{5,3,1,10,8},{2,0,9,7,5},{10,8,6,4,2},{7,5,3,1,10}};
int main()
{
    scanf("%d%d",&n,&k);n-=2;
    p=n%11;n/=11;
    ans=n*5;
    for(int i=0;i<p;i++)
     for(int j=0;j<5;j++)
      if(mmap[i][j]==k)ans++;
    printf("%d\n",ans);
    return 0;
}

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

long long mod=1000000007;

long long modp(long long d,long long p){
    if (p==0){
        return 1 ;
    } else if (p==1){
        return d%mod ;
    } else if (p%2==0){
        return ((modp(d,p/2)%mod)*(modp(d,p/2))%mod)%mod;
    } else {
        return ((modp(d,p/2)%mod)*(modp(d,p/2))%mod)*d%mod;
    }
}

long long ncr(long long a,long long b){
    long long combinationans=1;
    long long combinationanss=1;
    long long combinationansm=1;
    for (long long i=0; i<b; i++){
        combinationanss=(combinationanss*(a-i))%mod;
        combinationansm=(combinationansm*modp(i+1,mod-2))%mod;
    }
    combinationans=(combinationanss*combinationansm)%mod;
    return (combinationans);
}

int main(void){
    long long n,m,p,ans=1;
    scanf("%lld%lld",&n,&m);
    p=m;
    for (long long i=2; i<=p; i++){
        long long count=0;
        while(p%i==0){
            p/=i;
            count++;
        }
        if (count!=0){
            ans=(ans*ncr(count+n-1,count))%mod;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    d = defaultdict(lambda: 0)
    for a in A:
        d[a] += 1
        if d[a] >= 3:
            d[a] -= 2

    ans = 0
    dup = 0
    for key in d.keys():
        if d[key] == 1:
            ans += 1
        else:
            dup += 1

    ans += 2 * (dup // 2)

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 18584
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := iScan()
	for i := x; ; i++ {
		p := PrimeFactors(i)
		if len(p) == 1 {
			fmt.Println(i)
			break
		}
	}
}
func PrimeFactors(n int) (pfs []int) {
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}
	if n > 2 {
		pfs = append(pfs, n)
	}
	return
}


Measured memory_bytes: 1780
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int[] a = new int[N];
                for (int i = 0; i < N; i++) {
                        a[i] = sc.nextInt();
                }
                int ans = 1 << 29;
                for (int i = -100; i <= 100; i++) {
                        int memo = 0;
                        for (int j = 0; j < N; j++) {
                                memo += Math.pow((a[j] - i) ,2);
                        }
                        ans = Math.min(memo, ans);
                }
                System.out.println(ans);
        }
}

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

class Program
{
    static void Main(string[] args)
    {
    	var sc = new Scanner();
    	int n = sc.NextInt();
    	int k = sc.NextInt();
    	int[] a = new int[n];
    	int one = -1;
    	for (int i = 0; i < n; i++)
    	    if (sc.NextInt() == 1) one = i;
    	
    	Console.WriteLine(1 + Math.Ceiling((double)(n - k) / (k - 1)));
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }
    
    public double NextDouble()
    {
    	CheckNext();
    	return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

Measured memory_bytes: 16864
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
using namespace std;
/*#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;*/


void Main()
{
	int n;cin >> n;
    vector<ll> a(n+1);
    vector<ll> b(n);
    rep(i,n+1) cin >> a.at(i);
    rep(i,n) cin >> b.at(i);
    ll count =0;
    rep(i,n){
        if (a.at(i)>=b.at(i)) count+=b.at(i);
        else {
            count+=(a.at(i)+min(a.at(i+1),b.at(i)-a.at(i)));
            a.at(i+1) = max(0ll,a.at(i+1)-(b.at(i) - a.at(i)));
        }
    }
    cout<<count<<endl;

}

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

Measured memory_bytes: 1792
S=input()
N=int(input())
for i in range(N):
    command=input().split()
    if command[0]=="replace":
        a=int(command[1])
        b=int(command[2])
        x=command[3]
        A=S[:a]
        B=S[b+1:]
        S=A+x+B
    elif command[0]=="reverse":
        a=int(command[1])
        b=int(command[2])
        A=S[:a]
        B=S[a:b+1]
        C=S[b+1:]
        T=""
        for p in range(len(B)):
            T+=B[len(B)-1-p]
        S=A+T+C
    else:
        #command[0]=="print"
        a=int(command[1])
        b=int(command[2])
        print(S[a:b+1])



Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <set>
#include <string>
#define ll long long
using namespace std;
int min(int a,int b)
{
    if(a>b)
        return b;
    else
        return a;
}
int main()
{
    string sz;
    char a[2];
    a[0]='0';
    a[1]='1';
    char b[2];
    b[1]='0';
    b[0]='1';
    int yi=0,er=0;
    cin>>sz;
    for(int i=0;i<sz.size();i++)
    {
       // cout<<" asd";
        if(sz[i]!=a[i%2])
        {
            yi++;
        }
        if(sz[i]!=b[i%2])
        {
            er++;
        }
    }
    //cout<<a<<" "<<b;
    cout<<min(yi,er)<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		Arrays.sort(nums);
		
		for(int i = 0; i < n - 2; i++) {
			for(int j = i + 1; j < n - 1; j++) {
				for(int k = j + 1; k < n; k++) {
					if(nums[k] < nums[i] + nums[j]) ans++;
				}
			}
		}
		
		
		System.out.println(ans);

	}

	

}


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

namespace Volume0_0027
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input; 
            while( (input = Console.ReadLine().Split(' ').Select( s => Convert.ToInt32(s)).ToArray() )[0] != 0)
            {
                Console.WriteLine(new DateTime(2004, input[0], input[1]).DayOfWeek);
            }
        }
    }
}

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

int main(){
    ll n;
    cin >> n;
    ll ans = 1e9;
    rep(i, 0, n+1){
        ll cnt = 0;
        ll t6 = 1, t9 = 1;
        ll nn = i;
        while(nn > 0){
            cnt += (ll)((nn%(6*t6))/t6);
            nn -= (ll)(nn%(6*t6));
            t6 *= 6;
        }
        nn = n-i;
        while(nn > 0){
            cnt += (ll)((nn%(9*t9))/t9);
            nn -= (ll)(nn%(9*t9));
            t9 *= 9;
        }
        //if(n<4)cerr << cnt << endl;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;
typedef vector<long long int> vll;

int main() {
	int x, y;
	cin >> x >> y;
	if (x%y == 0) cout << -1 << endl;
	else cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
main()
{
	int N,Q;cin>>N>>Q;
	UF uf(N);
	for(int i=0;i<Q;i++)
	{
		int t,u,v;cin>>t>>u>>v;
		if(t==0)uf.unite(u,v);
		else cout<<uf.same(u,v)<<endl;
	}
}

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

int main(){
	int a,b,c,x,i,j,k,ans=0;
	cin >> a >> b >> c >> x;
	for(i = 0;i <= a;i++){
		j = 0;
		k = 0;
		for(j = 0;j <= b;j++){
			k = 0;
			for(k = 0;k <= c;k++){
				if(500*i + 100*j + 50*k == x){
					ans++;
				}

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

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL X, K, D;
    cin >> X >> K >> D;

    X = llabs(X);
    if(K >= X / D) {
        K -= X / D;
        X = X % D;
        if(K % 2 != 0) X -= D;
    } else {
        X -= K * D;
        K = 0;
    }

    cout << llabs(X) << endl;

    return 0;
}



Measured memory_bytes: 3648
K,N = map(int,input().split())
A = list(map(int,input().split()))
B = [] # 逆向き
for i in range(N-1):
  tmp = A[i+1]-K
  B.append(tmp)
B.extend(A)


tmp_sum = 0
j = 0
#print(B)
dist = []
for i in range(1,len(B)):
  d = abs(B[i]-B[i-1])
  tmp_sum += d
  dist.append(d)
  if(i == N-1):
    ans = tmp_sum 
    #print('ans :',ans)
  elif(i >= N):
    tmp_sum -= dist[j]
    j += 1
    ans = min(ans,tmp_sum)
    #print('ans :',ans)
print(ans)    
    

Measured memory_bytes: 27920
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

typedef Point Vector;

class Circle {
    public:
    double r;
    Point c;

    Circle(double r = 0, Point c = Point()): r(r) {}
};

void print(Point p0, Point p1);

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    Circle k1, k2;
    Point cross0, cross1;
    cin >> k1.c.x >> k1.c.y >> k1.r;
    cin >> k2.c.x >> k2.c.y >> k2.r;
    if ( k1.r < k2.r ) {
        swap(k1.r, k2.r);
        swap(k1.c.x, k2.c.x);
        swap(k1.c.y, k2.c.y);
    }

    double d = ( k1.c - k2.c ).abs();
    
    if ( ( d == k1.r + k2.r ) || ( d == k1.r - k2.r ) ) {
        Vector v1 = k2.c - k1.c;
        v1 = v1 * k1.r / v1.abs();
        cross0 = k1.c + v1;
        print(cross0, cross0);
    }
    else {
        Vector v0 = k2.c - k1.c;
        v0 = v0 * ( k1.r*k1.r - k2.r*k2.r + d*d ) / (2*d) / v0.abs();
        Point x1 = k1.c + v0;
        Vector v1;
        v1.x = v0.y;
        v1.y = - v0.x;
        v1 = v1 * sqrt( k1.r*k1.r - v0.abs()*v0.abs() ) / v1.abs();
        cross0 = x1 + v1;
        cross1 = x1 - v1;
        print(cross0, cross1);
    }

    return 0;
}

void print(Point p0, Point p1) {
    double x0, y0, x1, y1;
    if ( p0.x < p1.x ) {
        x0 = p0.x;
        y0 = p0.y;
        x1 = p1.x;
        y1 = p1.y;
    }
    else if ( p0.x > p1.x ) {
        x0 = p1.x;
        y0 = p1.y;
        x1 = p0.x;
        y1 = p0.y;
    }
    else {
        if ( p0.y < p1.y ){
            x0 = p0.x;
            y0 = p0.y;
            x1 = p1.x;
            y1 = p1.y;
        }
        else{
            x0 = p1.x;
            y0 = p1.y;
            x1 = p0.x;
            y1 = p0.y;
        }
    }
    cout << fixed << setprecision(11) << x0 << " " << y0 << " " << x1 << " " << y1 << endl;
}


Measured memory_bytes: 3320
N = int(input())
s = [input().split() for i in range(N)]
gift = []
for i in range(N):
    if s[i][1] =="JPY":
        gift.append(int(s[i][0]))
    if s[i][1] == "BTC":
        gift.append(float(s[i][0])*380000)
print(sum(gift))


Measured memory_bytes: 2940
N = int(input())

# kth entry: [max up to ak, bk, ck]
max_happiness = [[None] * 3 for _ in range(N)]

for k in range(N):
    if k == 0:
        max_happiness[k] = [int(n) for n in input().split()]
    else:
        ak, bk, ck = [int(n) for n in input().split()]

        a_opt, b_opt, c_opt = max_happiness[k-1]
        max_happiness[k][0] = ak + max(b_opt, c_opt)
        max_happiness[k][1] = bk + max(a_opt, c_opt)
        max_happiness[k][2] = ck + max(a_opt, b_opt)

print(max(max_happiness[-1]))


Measured memory_bytes: 22772
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let s = iter.next().unwrap();
    println!("{}", if n < 3200 { "red" } else { s });
}


Measured memory_bytes: 4352
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); i++)

using namespace std;
typedef long long ll;
const int MAX_N = 100;
const int MAX_W = 1000000000;
static const int INF = 1<<29;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0); //この2行はより速度を向上させる
    // 追加２, 以降 cin の入力元が 'input.txt' になる
    //提出時に消す！！

    int L,R,ans=2019;
    cin >> L >> R;
    int a,b;
    for(int i=L;i<R;i++){
        for(int j=i+1;j<=R;j++){
            a=i%2019;
            b=j%2019;
            ans=min(ans,(a*b)%2019);
            if(ans==0){
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    ll N, L;
    ll eat = 10000, sum = 0;
    ll ans = 0;
    cin >> N >> L;
    vector<pair<ll, ll> > C;
    for(int i = 0; i < N; i++){
        sum += L + i;
        if(abs(eat) > abs(L + i)) eat = L + i;
    }
    cout << sum - eat<< endl; 
}

Measured memory_bytes: 888
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}
import Data.Maybe
import Data.Char
import Data.List
import Data.Int
import Data.Bits
import Data.Ratio
import Data.IORef
import Data.Array.IO
import Control.Monad
import Control.Applicative
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map              as Map
import qualified Data.Set              as Set
import Text.Printf
import Debug.Trace
import System.Exit

getints :: IO [Int]
getints = map fst . mapMaybe BS.readInt . BS.words <$> BS.getLine

main = do
    as <- sort <$> getints
    if as == [5, 5, 7]
        then putStrLn "YES"
        else putStrLn "NO"


Measured memory_bytes: 380
N,x = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = 0
for i in range(1, N+1):
    x -= A.pop(0)
    if x == 0:
        ans = i
        break
    elif x < 0:
        ans = i-1
        break
else:
    ans = N-1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;

signed main(){
    
    int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
    vector<int> e(T);   
    vector<int> c(T);
    for(int i = 0; i < T; i++) cin >> e[i] >> c[i];

    vector<int> h(N);   
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> h[i] >> a[i];
    
    
    vector<vector<vector<int>>> dp1(T + 1, vector<vector<int>> (U + 1, vector<int> (S + 1, -1)));
    dp1[0][0][0] = 0;

    vector<vector<int>> dp2(N + 1, vector<int> (1000005, 0));
    dp2[0][0] = 0;

    // 1
    for(int i = 0; i < T; i++){
        for(int j = 0; j <= U; j++){
            for(int k = 0; k <= S; k++){
                if(dp1[i][j][k] == -1) continue;
                // しない
                dp1[i + 1][j][k] = max(dp1[i + 1][j][k], dp1[i][j][k]);

                // 運動する
                if(j + 1 <= U && k + e[i] <= S)  dp1[i + 1][j + 1][k + e[i]] = max(dp1[i + 1][j + 1][k + e[i]], dp1[i][j][k] + c[i]);
            }
        }
    }
    
    /*
    for(int i = 0; i <= T; i++){
        for(int j = 0; j <= U; j++){
            for(int k = 0; k <= S; k++){
                cout << i << " " << j << " " << k << " " << dp1[i][j][k] << endl;
           }
        }
    }
    */

    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 100000; j++){
            if(j < a[i]){
                dp2[i + 1][j] = dp2[i][j];
            }else{
                dp2[i + 1][j] = max(dp2[i][j], dp2[i + 1][j - a[i]] + h[i]);
            }
        }
    }
    
    for(int j = 1; j <= 100000; j++) dp2[N][j] = max(dp2[N][j], dp2[N][j - 1]);

    /*
    cout << endl;
    cout << endl;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= 20; j++){
            cout << dp2[i][j] << " ";
        }
        cout << endl;
    }

    cout << endl;
    */
    
    vector<vector<int>> dp(D + 1, vector<int> (S + 1, -1));
    dp[0][S] = 0;
    
    for(int i = 0; i < D; i++){
        for(int j = 0; j <= S; j++){
            if(dp[i][j] == -1) continue;
            int cur = min(S, j + O);
            
            for(int use = 0; use <= cur; use++){
//                cout << i << " " << j << " " << use << endl;
                int nxt = cur - use;
                int cal = dp1[T][U][use];
                if(cal == -1) continue;
                int add = dp2[N][cal];
                dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][j] + add);
            }
        }
    }
    

    int ans = -1;
    for(int i = 0; i <= S; i++) ans = max(ans, dp[D][i]);
    cout << ans << endl;
    return 0;
}



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

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

    int n, s = 0;
    cin >> n;
    vector<int> d(n);
    rep(i, 0, n) cin >> d[i];
    vector<int> e(13);
    rep(i, 0, n) e[d[i]]++;

    rep(i, 0, 13) if (e[i]) {
        s = i;
        break;
    }
    rep(i, 1, 13) if (e[i] > 2 - (i / 12)) s = 0;
    if (s == 0) {
        cout << 0 << endl;
        return 0;
    }

    set<int> st;
    vector<int> t;
    st.insert(0);
    st.insert(24);

    rep(i, 1, 13) {
        if (e[i] == 2 - (i / 12)) {
            st.insert(i);
            st.insert(24 - i);
        } else if (e[i] == 1) {
            t.push_back(i);
        }
    }

    int m = t.size();
    s = 0;

    rep(i, 0, 1 << m) {
        set<int> sx = st;
        rep(j, 0, m) if (i & (1 << j)) { sx.insert(t[j]); }
        else {
            sx.insert(24 - t[j]);
        }
        int k = 24, l = -24;
        for (auto x : sx) {
            k = min(k, x - l);
            l = x;
        }
        s = max(s, k);
    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep1(i,N+1) ans+=i*(N/i)*(N/i+1);
cout<<ans/2<<endl;

}
	

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
template<typename T> void read(T &x){
	char c=getchar();x=0;int f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}
const int N=1e5+7;
int fa[N],n,m,ans;
struct OO{int a,b;}a[N];
int getfa(int x){
	if(x==fa[x])return x;
	fa[x]=getfa(fa[x]);return fa[x];
}
bool cmp(OO x,OO y){return x.b>y.b;}
int main(){
	read(n);read(m);
	for(int i=1;i<=n;i++){read(a[i].a);read(a[i].b);}
	sort(a+1,a+n+1,cmp);for(int i=1;i<=m+1;i++)fa[i]=i;
	for(int i=1;i<=n;i++){
		int f=getfa(min(a[i].a,m+1));
		if(f==m+1)continue;
		ans+=a[i].b;fa[f]=f+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(100000) 
H, A = map(int, input().split())

def calc_atack(H, A, counter =0):
    H -= A
    counter += 1
    if H <= 0:
        return counter
    else:
        return calc_atack( H, A, counter = counter)


print(calc_atack(H, A))

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

long long a[100010];

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

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

    int zero = 0;
    for (int i = 0; i < N; ++i) if (a[i] == 0) zero++;

    if (zero > 0) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 1;
    for (int i = 0; i < N; ++i) {
        if (a[i] <= 1000000000000000000 / ans) {
            ans *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int maxn = 55;
int a[maxn];
int temp[maxn],n,m;

int main(){
  int i,ans=0;
  cin >> n >> m;
  for(i=1;i<=n;i++)
    cin>>a[i];
  for(int l=0;l<=n;l++)
    {
      for(int r=n+1;r>l;r--)
        {
          int cnt=0,sum=0;
          for(i=1;i<=l;i++)
            temp[++cnt]=a[i];
          for(i=n;i>=r;i--)
            temp[++cnt]=a[i];
          if(m<cnt)
            continue;
          sort(temp+1,temp+cnt+1);
          for(i=cnt;i>=0;i--)
            {
              if(i<=m-cnt)
                sum+=max(temp[i],0);
              else
                sum+=temp[i];
            }
          ans=max(ans,sum);
        }
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            List<TaskC.Point> pointA = new ArrayList<>();
            List<TaskC.Point> pointB = new ArrayList<>();
            Comparator<TaskC.Point> xComparator = Comparator.comparing(TaskC.Point::getX);
            Comparator<TaskC.Point> yComparator = Comparator.comparing(TaskC.Point::getY);

            for (int i = 0; i < n; i++) {
                pointA.add(new TaskC.Point(in.nextInt(), in.nextInt()));
            }
            for (int i = 0; i < n; i++) {
                pointB.add(new TaskC.Point(in.nextInt(), in.nextInt()));
            }

            pointA.sort(xComparator.reversed());
            pointB.sort(yComparator);
            int ans = 0;
            int index = 0;
            while (index < pointA.size()) {
                TaskC.Point ca = pointA.get(index);
                for (int i = 0; i < pointB.size(); i++) {
                    TaskC.Point cb = pointB.get(i);
                    if (ca.getX() < cb.getX() && ca.getY() < cb.getY()) {
                        pointA.remove(ca);
                        pointB.remove(cb);
                        ans++;
                        break;
                    } else if (i == pointB.size() - 1) {
                        index++;
                    }
                }
            }
            out.println(ans);
        }

        static class Point {
            private int x;
            private int y;

            public Point(int x, int y) {
                this.x = x;
                this.y = y;
            }

            public int getX() {
                return this.x;
            }

            public int getY() {
                return this.y;
            }

        }

    }
}



Measured memory_bytes: 27092
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  string a,b;
  cin >> a >> b;
  rep(i,0,3){
      if(a[i] != b[2-i]){
        NO;
        ret 0;
      }
  }

  YES;
  ret 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>,
  rb_tree_tag, tree_order_statistics_node_update>;

// cur.order_of_key(2)
// the number of elements in the set less than 2
// *cur.find_by_order(1)
// the 1-st smallest number in the set(0-based)

const int MAX_N = 1e5 + 5;

typedef long long ll;

int n;
int arr [MAX_N];

// # of substrings with median <= x
ll countle (int x) {
  ll ans = 0;
  
  ordered_set<pair<int, int>> pref;
  pref.insert(make_pair(0, -1));
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] <= x) {
      cur++;
    } else {
      cur--;
    }
    
    ans += pref.order_of_key(make_pair(cur, -10));
    pref.insert(make_pair(cur, i));
  }

  return ans;
}

int main () {
  ios::sync_with_stdio(false);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  ll half = 1 + ((ll) n * (ll) (n + 1) / 2) / 2;

  if (countle(0) >= half) {
    cout << 0 << endl;
    return 0;
  }
  
  int ans = 0;
  for (int k = 1 << 29; k != 0; k /= 2) {
    if (countle(ans + k) < half) {
      ans += k;
    }
  }
  cout << ans + 1 << endl;
}


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

typedef struct a{
    int num;
	struct a *next,*before;
}Node;

void insert(int n,Node* nil){
    Node* node = (Node*)malloc(sizeof(Node));
    node->num=n;
    nil->next->before = node;
    node->next = nil->next;
    node->before = nil;
    nil->next = node;
}

void delete(Node* node){
    node->next->before = node->before;
    node->before->next = node->next;
    free(node);
}

void dsearch(Node* nil,int x){
    Node* node;
    for(node=nil->next;node!=nil;node = node->next){
        if(node->num==x){
            delete(node);
            break;
        }
    }
}

int main(void){
    int n,i,x;
    char str[16];
    Node *nil;
    Node *aa;
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->before = nil;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",str);
        if(strcmp(str,"deleteFirst")==0){
            delete(nil->next);
        }else if(strcmp(str,"deleteLast")==0){
            delete(nil->before);
        }else if(strcmp(str,"insert")==0){
            scanf("%d",&x);
            insert(x,nil);
        }else if(strcmp(str,"delete")==0){
            scanf("%d",&x);
            dsearch(nil,x);
        }
    }
    for(aa=nil->next;aa!=nil;aa=aa->next){
        printf("%d",aa->num);
        if(aa->next!=nil){
            printf(" ");
        }
    }
    printf("\n");
	return 0;
}




Measured memory_bytes: 32916
S = input()


def check(s):
    flag = True
    for i in range(len(s)//2):
        if s[i] != s[-i-1]:
            flag = False
            break
    return(flag)


if check(S) and check(S[0:(len(S)-1)//2]) and check(S[(len(S)+3)//2-1:len(S)]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int n, m, k;
    cin >> n >> m >> k;

    bool flg = false;
    rep(i, n+1){
        rep(j, m+1){
            int black = i*m + j*n - i*j*2;
            if(black == k) flg = true;
        }
    }

    if(flg) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans = [1]*n

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]<h[b-1]:
        ans[a-1]=0
    elif h[a-1]>h[b-1]:
        ans[b-1]=0
    else:
        ans[a-1]=0
        ans[b-1]=0
sum=0  
for i in range(n):
    sum+=ans[i]
print(sum)

Measured memory_bytes: 20044
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto X = RD;
	auto ans = X / 500 * 1000;
	X %= 500;
	ans += X / 5 * 5;

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 256