akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define M 1000005
#define N 1005
using namespace std;
typedef pair<int,int> P;
int dp[M];
P ab[N];

int main(){
  int n,a[N],b[N];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>ab[i].second>>ab[i].first;
  sort(ab,ab+n);
  for(int i=0;i<n;i++)
    a[i]=ab[i].second,b[i]=ab[i].first;
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=b[i];j>=0;j--){
      if(dp[j]<0)continue;
      if(j+a[i]>b[i])continue;
      dp[j+a[i]]=max(dp[j+a[i]],dp[j]+1);
      ans=max(ans,dp[j+a[i]]);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6988
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;

int a, b;

int main() {
	scanf("%d %d", &a, &b);
	if (a <= 0 && 0 <= b) {
		puts("Zero");
	} else {
		int cnt = 0;
		if (b < 0) {
			cnt = b - a + 1;
		} else if (a < 0) {
			cnt = 0 - a;
		}
		if (cnt % 2 == 0) {
			printf("Positive\n");
		} else {
			printf("Negative\n");
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch PickingUp | diff PickingUp.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address PickingUp.cpp && ./a.out

/*
 
 6/15/2019
 
 5:03-
 
 */

const int MAX_N=100+1;
LL X[MAX_N],Y[MAX_N];
int N;

void solve() {
  vector<pair<LL,LL>> A;
  REP(i,N)A.emplace_back(X[i],Y[i]);
  //sort(ALL(A));
  set<pair<LL,LL>> S(ALL(A));
  LL res=N;
  REP(i,N)REP(j,N)if(i!=j) {
    LL dx=A[i].first-A[j].first,dy=A[i].second-A[j].second;
    LL sum=N;
    REP(k,N) {
      pair<LL,LL> cur={A[k].first,A[k].second};
      if(S.count({cur.first+dx,cur.second+dy}))--sum;
    }
     SMIN(res,sum);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>X[i]>>Y[i];
  solve();
  
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	map<string,int> m;
	int n;
	cin>>n;
	while(n--)
	{
		string s;
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<'\n';
	cout<<"WA x "<<m["WA"]<<'\n';
	cout<<"TLE x "<<m["TLE"]<<'\n';
	cout<<"RE x "<<m["RE"]<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3624
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef deque<ll> dqll;

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

  vll mens(N);
  vll foods(N);

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

  for (int i = 0; i < N; i++) {
    cin >> foods[i];
  }
  sort(foods.begin(), foods.end());
  sort(mens.begin(), mens.end());
  reverse(mens.begin(), mens.end());

  ll l = -1LL;
  ll r = 1e12;
  while (l + 1 < r) {
    ll c = (l + r) / 2;
    bool ok = [&] {
      ll sum = 0;
      for (ll i = 0; i < N; i++) {
        sum += max(0LL, mens[i] - c / foods[i]);
      }
      return sum <= K;
    }();
    if (ok) r = c; else l = c;
  } // while

  ll ans = r;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

ll resolve(ll m){
    if (m<=3) {
        return 1;
    }
    ll h = m/3;
    if (h*3<m) {
        h++;
    }
    return 1+resolve(h);
}

int main(){
    int n;
    cin >> n;
    cout << resolve(n)<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
 
const int mod = 1e9 + 7;
// const long double pi_2 = acos(0);
 
template <typename Type>
istream &operator>>(istream &in, vector<Type> &vec) {
    int n = vec.size();
    for (int i = 0; i < n; i++)
        in >> vec[i];
    return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &vec) {
    for (auto val : vec)
        out << val << " ";
    return out;
}

int a, b, n;

int f(int x, vector<int> v)
{
	int dec = a - b;
	for(int i = 0;i < n;i++)
		v[i] = max(0ll, v[i] - x * b);
	int cnt = 0;
	for(int i = 0;i<n;i++)
		cnt += v[i] / dec + (bool)(v[i] % dec);
	return cnt <= x;
}

#undef int
int main()
{
#define int long long int
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>a>>b;
    vector<int> v(n);
    cin>>v;
    int l = 0, h = 1000000000;
    while(h - l > 1)
    {
    	int m = (l + h) / 2;
    	if(f(m, v))
    		h = m;
    	else
    		l = m;
    }
    cout<<h<<endl;
 
    return 0;
}

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

#include<string>

using namespace std;


int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i=0;i<N;i++) cin >> S.at(i);
    sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        cout << S.at(i);    
    }



    return 0;
}

Measured memory_bytes: 256
#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;
    vector<ll> ans(n+1, 0);
    rep(i, 0, n-1){
        ll a;
        cin >> a;
        ans[a]++;
    }
    rep(i, 1, n+1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main(){
  int n; cin >> n;
  vector<string> s(n);
  string S;
  for(int i=0; i<n; i++){
    cin >>S;
    sort(S.begin(),S.end());
    s[i] = S;
  }
  unordered_map<string, ll> um(n);
  ll ans =0;
  for(int i=0; i<n; i++){
    um[s[i]]++;
    ans += um[s[i]] -1;
  }


    cout << ans << endl;
  }


Measured memory_bytes: 11264
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        boolean[] isPrime = new boolean[N+1];
        Arrays.fill(isPrime, true);
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i <= N; i++){
            if(isPrime[i]){
                for(int j = i*2; j <= N; j+=i){
                    isPrime[j] = false;
                }
            }
        }
        
        int ans = 0;
        for(int i = 1; i <= N; i+=2){
            int[] primes = new int[N+1];
            for(int j = 2; j <= N; j++){
                if(isPrime[j]){
                    int target = i;
                    while( target % j== 0 ){
                        target /= j;
                        primes[j]++;
                    }
                }
            }
            
            int cnt = 1;
            for(int j = 2; j <= N; j++){
                if( primes[j] > 0 ) cnt *= (primes[j]+1);
            }
            if(cnt == 8) ans++;
        }
        
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 22608
// https://atcoder.jp/contests/abc088/tasks/abc088_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int c[9];

bool chk(int s)
{
  int t = c[s] - c[s + 1];
  if (t != c[s + 3] - c[s + 4] || t != c[s + 6] - c[s + 7])
    return false;

  s *= 3;
  t = c[s] - c[s + 3];
  if (t != c[s + 1] - c[s + 4] || t != c[s + 2] - c[s + 5])
    return false;

  return true;
}
int main()
{
  REP(i, 9)
  {
    cin >> c[i];
  }

  cout << (chk(0) && chk(1) ? "Yes" : "No") << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string s; cin >> s;
	int a = 0;
	rep(i, s.size() - 1){
		a += s[i] != s[i + 1];
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 512
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define FORA(i, a, n) for (int i = (a); i < (n); ++i)


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}


const int MOD = (int)1e9 + 7;

void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto k = next<int>(in);
  auto a = next_vec<int>(in, n);

  vec<int> f(k + 1, 1);

  auto sum = [&] (int from, int to) -> int {
    if (from == 0) {
      return f[to];
    } else {
      return (f[to] - f[from - 1] + MOD) % MOD;
    }
  };

  FOR(i, n) {
    vec<int> f2(k + 1, 0);
    FOR(j, k + 1) {
      f2[j] += sum(max(0, j - a[i]), j);
      if (f2[j] >= MOD) f2[j] -= MOD;
    }
    f[0] = f2[0];
    if (i < n-1) {
      FORA(i, 1, k + 1) {
        f[i] = f[i-1] + f2[i];
        if (f[i] >= MOD) f[i] -= MOD;
      }
    } else {
      f = f2;
    }
  }
  out << f[k] << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()

    (if (judge(calc(s), calc(t).reversed())) "Yes" else "No")
            .let(::println)
}

fun calc(s: String): List<Char> {
    return s.toCharArray().sorted()
}

fun judge(s: List<Char>, t: List<Char>): Boolean {
    for (i in 0 until Math.max(s.size, t.size)) {
        if (i >= s.size) {
            return true
        }
        if (i >= t.size) {
            return false
        }
        if (s[i].toInt() < t[i].toInt()) {
            return true
        }
        if (s[i].toInt() > t[i].toInt()) {
            return false
        }
    }
    return false
}


Measured memory_bytes: 35944
#include <stdio.h>

main() {
  int a, b, c, i;

  while(scanf("%d%d", &a, &b) != EOF) {
    i=1;
    c=a+b;
    while(c>=10) {
      c=c/10;
      i++;
    }
    printf("%d\n", i);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (ll)(n); ++i)
#define repk(i,k, n) for (int i = k; i < (ll)(n); ++i)
#define MAX 50000001
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans,cnt;


int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	vector<int> t(n);
	rep(i, n) {
		cin >> s[i] >> t[i];
	}
	string X;
	cin >> X;

	rep(i, n) {
		if (s[i] == X) {
			repk(j, i + 1, n) {
				ans += t[j];
			}
			break;
		}
	}
	

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 100005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int sums[MN],sumt[MN];
int a,b,c,d,q,ls,lt,res1,res2;
char s[MN],t[MN];
int main()
{
	scanf("%s%s",s,t);q=in();
	ls=strlen(s);lt=strlen(t);
	for (int i=1;i<=ls;++i)
	sums[i]=sums[i-1]+1+(s[i-1]=='B'); 
	for (int i=1;i<=lt;++i)
	sumt[i]=sumt[i-1]+1+(t[i-1]=='B');
	for (int i=1;i<=q;++i){
		a=in();b=in();c=in();d=in();
		res1=sums[b]-sums[a-1];
		res2=sumt[d]-sumt[c-1];
		if ((res1%3)==(res2%3)) puts("YES");else puts("NO");
	} return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
//0:white
//1:black
long long int dp[100005][2],n,cnt=0;
bool visited[100005]={0};
vector< long long int >tree[100005];
long long int solve(long long int node,long long int clr)
{
	if(cnt==0)
		return 1;
    if(dp[node][clr]!=-1)
    	return dp[node][clr];
	long long int clrc,ans=1,i,j,k,sum;
	clrc=(clr==0)?1:0;
	if(clr)
	{
		for(i=0;i<tree[node].size();i++)
			if(!visited[tree[node][i]])
			{
				visited[tree[node][i]]=true;
				sum=solve(tree[node][i],clrc);
				visited[tree[node][i]]=false;
				ans*=sum;
				ans%=mod;
			}	
	}
	else
	{
		for(i=0;i<tree[node].size();i++)
			if(!visited[tree[node][i]])
			{
				visited[tree[node][i]]=true;
				sum=(solve(tree[node][i],clrc)+solve(tree[node][i],clr))%mod;
				visited[tree[node][i]]=false;
				ans*=sum;
				ans%=mod;
			}	
	}
	dp[node][clr]=ans%mod;
	return dp[node][clr];
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
	long long int i,j,k,a,b,ans=0;
	cin >> n;
	for(i=1;i<n;i++)
	{
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	memset(dp,-1,sizeof(dp));
	visited[1]=true;
	cnt=n-1;
	ans=solve(1,0);
	//cout << ans << endl;
	cnt=n-1;
	ans+=solve(1,1);
	ans%=mod;
	/*for(i=1;i<=n;i++)
	  for(j=0;j<2;j++)
	    cout << dp[i][j] << endl;*/ 
	//cout << solve(1,0) << endl;
    cout << ans << endl;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    int h, cnt = 0;
    rep(0, n) {
        cin >> h;
        if (k <= h) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

struct BIT {
	ll n;
	vl bit;
	
	BIT(ll n): n(n) { bit.resize(n+2); }

	void add(ll i, ll v) {
		for (++i; i <= n+1; i += i & -i) bit[i] += v;
	}

	ll getSum(ll i) {
		ll res = 0;
		for (; i; i -= i & -i) res += bit[i];
		return res;
	}
};

ll inversions(vl p) {
	ll n = sz(p), res = n*(n-1)/2;
	BIT bit(2*n+10);
	FOR(i,0,n) {
		res -= bit.getSum(p[i]);
		bit.add(p[i],1);
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vvl a(n,vl(3));

	FOR(j,0,3) FOR(i,0,n) {
		cin >> a[i][j];
	}
	
	vl peven, podd;
	bool valid = true;
	ll flipeven = 0, flipodd = 0;

	for (ll i = 0; i < n; i += 2) {
		bool flip = (a[i][0] > a[i][1]);
		if (flip) swap(a[i][0],a[i][2]);
		if (a[i][0] % 6 != 1 || a[i][1] != a[i][0]+1 || a[i][2] != a[i][1]+1) valid = false;
		ll x = (a[i][0] / 3)/2, y = i/2;
		if ((x-y+flip) % 2) flipeven++;
		peven.pb(x);
	}
	for (ll i = 1; i < n; i += 2) {
		bool flip = (a[i][0] > a[i][1]);
		if (flip) swap(a[i][0],a[i][2]);
		if (a[i][0] % 6 != 4 || a[i][1] != a[i][0]+1 || a[i][2] != a[i][1]+1) valid = false;
		ll x = (a[i][0] / 3)/2, y = i/2;
		if ((x-y+flip) % 2) flipodd++;
		podd.pb(x);
	}
	cerr << valid << endl;
	
//	FOR(i,0,sz(peven)) if (peven[i] % 2) valid = false;
//	FOR(i,0,sz(podd)) if (podd[i] % 2 == 0) valid = false;
	
	if ((inversions(peven)-flipodd) % 2 || (inversions(podd)-flipeven) % 2) valid = false;
	
	cout << (valid ? "Yes" : "No") << endl;	

}



Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

int main(){
          int n;
          cin >> n;
          int a[n+2];
          FOR(i,1,n+1) cin >> a[i];
          int ans[n];
          a[0]=0;
          a[n+1]=0;
          REP(i,n)  ans[i]=0;
          int total=0;
          REP(_,n+1)  total+=abs(a[_+1]-a[_]);
          REP(i,n+1){
                    ans[i]=total+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]));
          }
          FOR(i,1,n+1)  cout << ans[i] << endl;
          return 0;
}


Measured memory_bytes: 2048
n, m = map(int, input().split())
S = set()
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    S.add((a, b))

for i in range(1, n-1):
    if (0, i) in S and (i, n-1) in S:
        print('POSSIBLE')
        exit()
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 108128
V = [int(i) for i in input().split()]
N = int(input())
V2 = [V[i]*(8//(2**i)) for i in range(4)]
V1 = [V2[i]//2 for i in range(3)]
ans = N//2*min(V2) + (N%2)*min(V1)
print(ans)

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($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, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! { n: i64 }
    let ans = {n * (n-1)}/ 2;
    puts!("{}\n",ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

Measured memory_bytes: 2232
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n,m=mi()
c = li()
dp=list(range(n+1))
for i in c:
    if(i==1):
        continue
    for j in range(i,n+1):
        dp[j] = min(dp[j], dp[j-i]+1)
print(dp[n])


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NL = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = NL[0];
            int L = NL[1];
            List<int> listA = new List<int>();
            List<int> listB = new List<int>();
            int[] abc = new int[N];
            for(int i = L; i < N + L; i++)
            {
                listA.Add(i);
                int Z = Math.Abs(i);
                listB.Add(Z);
            }
            if(listA[N -1] < 0)
            {
                listA.RemoveAt(N - 1);
            }
            else
            {
                listA.Remove(listB.Min());
            }
            Console.WriteLine(listA.Sum());
        }
    }
}

Measured memory_bytes: 13396
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで毎回include
//以下プログラム

using namespace std;

int main() {
	long long n;
	cin >> n;
	vector<int> data(floor(log10(n)) + 1);
	for (int i = 0; i < data.size(); i++) {
		data.at(data.size() - 1 - i) = n % 10;
		n /= 10;
	}
	for (int i = 0; i < data.size(); i++) {
		if (i != 0) {
			if (data.at(i) != 9) {
				cout << (data.at(0) - 1) + 9 * (data.size() - 1) << endl;
				return 0;
			}
		}
	}
	cout << data.at(0) + 9 * (data.size() - 1) << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
//dp[i][j]: i??\???j???????????????c_x_(i)-c_x_(i-1)????????§???
int dp[201][201];
int main(){
    int d,n,ans=0;
    cin>>d>>n;
    int a[201],b[201],c[201],tem[201];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<d;i++)
        cin>>tem[i];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    for(int m=1;m<d;m++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(a[i]<=tem[m]&&tem[m]<=b[i]  &&  a[j]<=tem[m-1]&&tem[m-1]<=b[j])
                    dp[m][i]=max(dp[m][i],abs(c[i]-c[j])+dp[m-1][j]);
    for(int i=0;i<n;i++)
        ans=max(ans,dp[d-1][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 1324
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let mut map: HashMap<i64, i64> = HashMap::new();
    let vec: Vec<i64> = (0..n).map(|_| read()).collect();

    for &i in vec.iter() {
        *map.entry(i).or_insert(0) += 1;
    }

    let mut count = 0;

    for (&key, &value) in map.iter() {
        if value > key {
            count += value - key;
        } else if value < key {
            count += value;
        }
    }

    println!("{}", count);
}

fn calc_distance(x: i32, y: i32, target_x: i32, target_y: i32) -> i32 {
    let diff_x = (target_x - x).abs();
    let diff_y = (target_y - y).abs();

    return diff_x + diff_y;
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 12540
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	char s[1010];
	scanf("%s",&s);
	bool bo1,bo2,bo3,bo4;
	bo1=bo2=bo3=bo4=false;
	for(int i=0;s[i]!='\0';i++)
	{
		if(s[i]=='N')
			bo1=true;
		if(s[i]=='S')
			bo2=true;
		if(s[i]=='W')
			bo3=true;
		if(s[i]=='E')
			bo4=true;
	}
	if(bo1==bo2&&bo3==bo4)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll w,h,ans=0;
    cin>>w>>h;
    vector<pll> v;
    rep(i,w){
        ll p;
        cin>>p;
        v.emplace_back(pll(p,0));
    }
    rep(i,h){
        ll p;
        cin>>p;
        v.emplace_back(pll(p,1));
    }
    sort(all(v));
    h++;w++;
    rep(i,v.size()){
        if(v[i].sc==0){
            ans+=v[i].fi*h;
            w--;
        } else{
            ans+=v[i].fi*w;
            h--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6512
import math

N, D = map(int, input().split())
XY = []
for _ in range(N):
    XY.append(list(map(int, input().split())))

ans = 0
for xy in XY:
    if math.sqrt(xy[0]**2 + xy[1]**2) <= D:
        ans += 1
print(ans)


Measured memory_bytes: 45344
n,m=map(int,input().split(' '))
ans=0
Alist = [-1]*n
for i in range(m):
    s,c = map(int,input().split(' '))
    if s == 1 and c == 0 and n != 1:
        ans = -1
    elif Alist[s-1] not in [-1,c]:
        ans = -1
    else:
        Alist[s-1] = c
if ans == -1:
    print(ans)
else:
    ans = ''
    if Alist[0] == -1 and n != 1:
        Alist[0] = 1
    for a in Alist:
        if a == -1:
            ans += '0'
        else:
            ans += str(a)
    print(ans)
    

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
int h,w,n;
char map[1005][1005];
bool vis[1005][1005];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int cnt;
int f[1001*1001];

int BFS(int x,int y,int t)
{
	int m;
	memset(vis,0,sizeof vis);
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(map[i][j]=='X')
			{
				vis[i][j]==1;
			}
		}
	}
	queue<int> q;
	q.push(x*1001+y);
	int xxx,yyy;
	while(!q.empty())
	{
		int xx=q.front()/1001,yy=q.front()%1001;
		q.pop();
		if(map[xx][yy]=='0'+t)
		{
			xxx=xx,yyy=yy;
			break;
		}
		for(int i=0;i<4;i++)
		{
			if(!vis[xx+dx[i]][yy+dy[i]]&&map[xx+dx[i]][yy+dy[i]]!='X')
			{
				q.push((xx+dx[i])*1001+yy+dy[i]);
				vis[xx+dx[i]][yy+dy[i]]=1;
				f[(xx+dx[i])*1001+yy+dy[i]]=xx*1001+yy;
			}
		}
	}
	m=1;
	int s=xxx*1001+yyy;
	while(f[s]!=x*1001+y)
	{
		m++;
		s=f[s];
	}
	return m;
}

int bfs(int f,int t)

{
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(map[i][j]-'0'==f)
			{
				//cout<<i<<j;
				return(BFS(i,j,t));
			}
		}
	}
}



int main()
{
	cin>>h>>w>>n;
	cnt=0;
	memset(map,'X',sizeof map);
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>map[i][j];
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(map[i][j]=='S')
			{
				map[i][j]='0';
			}
		}
	}
	for(int i=0;i<n;i++)
		cnt+=bfs(i,i+1);
	cout<<cnt<<endl;
}


Measured memory_bytes: 8936
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define tms(x) ___ = x; while(___--)
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int ___;
string w[200];
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a = next<int>(), b = next<int>();
	rep(i, 0, a) cin>>w[i];
	sort(w, w+a);
	rep(i, 0, a) cout<<w[i];
	cout<<endl;
	return ~~(0-0);
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}



Measured memory_bytes: 256
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-


n, m = MAP()
a = LIST()

for x in a:
    n -= x

if n >= 0:
    print(n)
else:
    print(-1)


Measured memory_bytes: 11388
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int n,m;
  cin>>n>>m;
  long long a[n],b[n],c[m],d[m];
  REP(i,n){
    cin>>a[i]>>b[i];
  }
  REP(i,m){
    cin>>c[i]>>d[i];
  }
  int ans[n];
  int check=-1;
  long long dist=inf;
  REP(i,n){
    for(int j=m-1;j>=0;j--){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<=dist){
        dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
        check=j;
      }
    }
    ans[i]=check;
    check=-1;
    dist=inf;
  }
  REP(i,n){
    ans[i]++;
    cout<<ans[i]<<endl;
  }
  return 0;
}


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

using namespace std;

#define ge getchar()
#define Re read()

inline int read() {
	int x = 0, ch;
	while(!isdigit(ch = ge)) ;
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = ge;
	return x;
}

const int MAXN = 200000;

int n, N;
int a[MAXN + 1];
int v[MAXN + 1];
int x[MAXN + 1];

inline int chk() {
	int l = n, r = n, res = x[n]; x[0] = x[1], x[N + 1] = x[N];
	for(; l >= 1 && x[l] != x[l - 1] && x[r] != x[r + 1]; --l, ++r) res ^= 1;
	return res;
}

int main() {
	n = Re, N = (n << 1) - 1;
	for(int i = 1; i <= N; i++) v[i] = a[i] = Re;
	sort(v + 1, v + 1 + N); int l = 1, r = N, res = v[r];
	while(l <= r) {
		int mid = (l + r) >> 1, val = v[mid];
		for(int i = 1; i <= N; i++) x[i] = a[i] > val;
		if(!chk()) res = val, r = mid - 1;
		else l = mid + 1;
	} printf("%d\n", res);
	return 0;
}

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

int main()
{
	// Variable declaration
	int n = 0, x = 0, ans = 0;

	while (1)
	{
		// Input n, x
		cin >> n >> x;

		// Check of value
		if (n == 0 && x == 0)
		{
			// End of Input.
			break;
		}
		else if (n < 3 || n > 100)
		{
			continue;
		}

		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				for (int k = j + 1; k <= n; k++)
				{
					if ((i + j + k) == x)
					{
						ans++;
					}
				}
			}
		}
		// Output
		cout << ans << endl;
		ans = 0;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args){
        int N, K;
        {int[] a = in.ii(); N = a[0]; K = a[1];}

        ArrayList<int[]> sushi = new ArrayList(N);
        for(int i= 0; i < N; i++)
            sushi.add(in.ii()); 
        sushi.sort((x, y) -> -x[1]+y[1]);

        long point = 0;

        boolean[] kind = new boolean[N];
        PriorityQueue<int[]> heap = new PriorityQueue<>((x, y) -> x[1]-y[1]);
        long x = 0;

        for(int i = 0; i < K; i++){
            int[] s = sushi.get(i);
            if(kind[s[0]-1]){
                heap.add(s);
            } else {
                kind[s[0]-1] = true;
                x++;
            }
            point += s[1];
        }
        point += x*x;

        long max = point;
        for(int i = K; i < N && !heap.isEmpty(); i++){
            int[] w = sushi.get(i);
            if(!kind[w[0]-1]){
                int[] v = heap.poll();
                point += 2*x+1 + w[1] - v[1];
                if(max < point)
                    max = point;
                kind[w[0]-1] = true;
                x++;
            }
        }
        
        out.println(max);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 48708
package main

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

func main() {
	scanInit()

	d := nextInt()
	t := nextInt()
	s := nextInt()

	if d <= t*s {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
	return

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c;
    x= a-b;
    y= c-x;
    if (y>0)
        cout<<y<<endl;
    else 
        cout<<"0"<<endl;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Class1
    {
        static void Main(string[] args)
        {
            byte r,D;
            int x;

            string[] input = Console.ReadLine().Split(' ');

            r = byte.Parse(input[0]);
            D = byte.Parse(input[1]);
            x = int.Parse(input[2]);

            for(byte i = 1; i <= 10; i++)
            {
                x = r * x - D;
                Console.WriteLine(x);
            }
        }

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;

struct data{
    int s;
    int c;
};
int main()
{
    int n,m;
    cin >> n >> m;

    struct data p[6];

    rep(i,m){
        cin >> p[i].s >> p[i].c;
    }

    rep(x,1000){
        vector<int> d(1,x%10);//d(要素数,値)　初めから一の位は代入
        int nx = x/10;
        int size = 1;
        while(nx){
            size++;
            d.push_back(nx%10);
            nx /= 10;
        }
        reverse(d.begin(),d.end());
        if(size != n) continue;//ループの最初にとぶ
        bool ok = true;
        rep(i,m){
            if(d[p[i].s - 1] != p[i].c){
                ok = false;
            }
        }

        if(ok){
            cout << x << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

int getpair(int v){
    int res = 1;
    while(res <= v) res *= 2;
    return res - v;
}

int main(){
    int n, a;
    cin >> n;
    multiset<int> ms;
    rep(_, n){
        scanf("%d", &a);
        ms.insert(a);
    }
    int cnt = 0;
    while(!ms.empty()){
        auto maxv = end(ms);
        ms.erase(--maxv);
        auto p = ms.find(getpair(*maxv));
        if(p != end(ms)){
            ms.erase(p);
            cnt++;
        }
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll inv(int n) {
    int m = P, y = 0, v = 1;
    while (1) {
        int q = m / n;
        int r = m % n;
        if (r == 0) return v < 0 ? v + P : v;
        y -= v * q;
        swap(y, v);
        m = n;
        n = r;
    }
}

vector<int> prime_vector(int n) {
    int m = (int)sqrt(n - 1);

    vector<bool> q(n);
    for (int i = 2; i <= m; i++) {
        if (q[i]) continue;
        for (int j = i * i; j < n; j += i) {
            q[j] = true;
        }
    }

    vector<int> p; p.reserve(n / log(n * 0.329));
    for (int i = 2; i < n; i++) {
        if (!q[i]) p.push_back(i);
    }
    return p;
}

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

    int n;
    cin >> n;

    auto pv = prime_vector((int)1e6);
    int k = pv.size();

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

    for (int i = 0; i < n; i++) {
        int t = a[i];
        for (int j = 0; t > 1 && j < k; j++) {
            int x = 0, p = pv[j];
            if (t < p * p) {
                x = 1;
                p = t;
                t = 1;
            } else {
                while (t % p == 0) t /= p, x++;
            }
            if (x > b[p]) b[p] = x;
        }
    }
    ll l = 1;
    for (int i = 0; i < (int)1e6; i++) {
        for (int j = 0; j < b[i]; j++) {
            l = l * i % P;
        }
    }

    ll r = 0;
    for (int i = 0; i < n; i++) {
        r += l * inv(a[i]) % P;
    }
    r %= P;

    cout << r << endl;

    //最小公倍数
    //そもそもmodPの値しかわからんのに最大公約数わかるんか？

    return 0;
}

Measured memory_bytes: 4864
h, w = map(int, input().split(' '))
s = [input() for _ in range(h)]
sy, sx = 0, 0
gy, gx = h - 1, w - 1

move = [(1, 0), (-1, 0), (0, 1), (0, -1)]
que = [(sy, sx)]
d = [[float('inf') for _ in range(w)] for _ in range(h)]
d[sy][sx] = 0

while len(que) > 0:
    y, x = que.pop(0)

    for dy, dx in move:
        ny = y + dy
        nx = x + dx

        if ny >= 0 and ny < h and nx >= 0 and nx < w and s[ny][nx] != '#' and d[ny][nx] == float('inf'):
            que.append((ny, nx))
            d[ny][nx] = d[y][x] + 1

if d[gy][gx] == float('inf'):
    print(-1)
else:
    n_white = 0
    for i in s:
        n_white += i.count('.')
    print(n_white - d[gy][gx] - 1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;

bool IsPrime[MAX + 1];

int main()
{
	int m, a, b;
	fill(IsPrime, IsPrime + MAX + 1, true);
	IsPrime[0] = IsPrime[1] = false;
	for (int i = 2; i * i <= MAX; i++) {
		if (IsPrime[i]) {
			for (int j = i * 2; j <= MAX; j += i) {
				IsPrime[j] = false;
			}
		}
	}
	while (cin >> m >> a >> b, m || a || b) {
		int h;
		bool flag = false;
		for (int i = m; i >= 0; i--) {
			for (int j = ceil(sqrt((double)i * a / b)); j * j <= i; j++) {
				if (IsPrime[j] && i % j == 0) {
					h = i / j;
					if (IsPrime[h]) {
						cout << j << ' ' << h << endl;
						flag = true;
						break;
					}
					else {
						break;
					}
				}
			}
			if (flag) break;
		}
	}
	return 0;
}

Measured memory_bytes: 3180
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
			
		String s=sc.next();
		char a[]=s.toCharArray();
		int count=0;
		if(a[0]=='R'&&a[1]=='R'&&a[2]=='R') {
			count=3;
		}else if(a[0]=='R'&&a[1]=='R') {
			count=2;
		}else if(a[1]=='R'&&a[2]=='R') {
			count=2;
		}else if(a[0]=='R'||a[1]=='R'||a[2]=='R') {
			count=1;
		}else {
			count=0;
		}
				System.out.println(count);		
			
	}
	   
}


Measured memory_bytes: 35544
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int min = 0;
        for (int i = 0; i <= 100000; i++) {
            int price = i * 2 * c
                    + Math.max(0, x - i) * a
                    + Math.max(0, y - i) * b;
            if (min > price || i == 0) {
                min = price;
            }
        }
        System.out.println(min);
    }

}


Measured memory_bytes: 23252