akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long 

signed main(void){
  
  int N,M; cin >> N >> M;
  
  if( M % 2 == 1 ){ cout << "-1" << endl; return 0;}
  
  vector<vector<int>> to(N);
  
  for(int i = 0; i < M; i++){ 
    int a,b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  vector<pair<int,int>> depth(N);
  for(int i = 0; i < N; i++){ 
    depth[i] = {-1,i};
  }
  depth[0] = {0,0};
  
  queue<int> Q; Q.push(0);
  
  while(!Q.empty()){ 
   
    int p = Q.front(); Q.pop();
    
    for(auto q : to[p]){ 
      if( depth[q].first != -1 ){ continue;}
      
      depth[q].first = depth[p].first+1;
      
      Q.push(q);
      
    }
  }

  sort(depth.rbegin(),depth.rend()); //深い順にソートする
  
  vector<bool> used(N,false);
  vector<bool> even(N,true);
  
  //depthが深いから決めていく
  
  set<pair<int,int>> ans;
  
  for(int i = 0; i < N; i++){ 
    
    int p = depth[i].second;
    
    for(auto q : to[p]){
      if( used[q] ){ continue; } //全て埋めてしまった点については何も見ない
      
      if( even[p] ){ // qからpに辺をはる
        even[q] = !even[q];
        ans.insert({q,p});
      }
      else{ //pからqに辺をはる
        even[p] = true;
        ans.insert({p,q});
      }
    }
    
    used[p] = true;
  }
 
  for(auto ne : ans ){ 
    cout << ne.first+1 << " " << ne.second+1 << endl;
  }
  
  return 0;
}
  

Measured memory_bytes: 15232
#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>>;
    
int main(){
    char s;
    cin >> s;
    if(isupper(s)) cout << 'A' << endl;
    else cout << 'a' << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
const ll INF = numeric_limits<ll>::max();

vector<ll> a;
vector<vector<ll>> net;
vector<ll> ans;
vector<ll> dp;

void solve(ll cur, ll par){
    const ll ai = a.at(cur);
    const ll idx = lower_bound(ALL(dp), ai) - dp.begin();
    const ll prev = dp.at(idx);
    dp.at(idx) = min(prev, ai);
    ans.at(cur) = idx + 1;
    if(par != -1){
        ans.at(cur) = max(ans.at(cur), ans.at(par));
    }
    for(ll nxt : net.at(cur)){
        if(nxt == par){ continue; }
        solve(nxt, cur);
    }
    dp.at(idx) = prev;
}

int main(){
    ll n;
    cin >> n;
    a.resize(n);
    REP(i, n){
        cin >> a.at(i);
    }
    net.resize(n);
    REP(i, n - 1){
        ll ui, vi;
        cin >> ui >> vi;
        ui--; vi--;
        net.at(ui).push_back(vi);
        net.at(vi).push_back(ui);
    }

    ans.resize(n);
    dp.resize(n);
    fill(ALL(dp), INF);
    solve(0, -1);
    for(ll x : ans){
        cout << x << endl;
    }
}


Measured memory_bytes: 33168
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> route(n);
    for(auto &x : route){
        cin >> x.first >> x.second;
    }
    auto mincost = 1001;
    for(auto &x : route){
        if(x.second <= t){
            mincost = min(mincost, x.first);
        }
    }
    if(mincost == 1001){
        cout << "TLE";
    }else{
        cout << mincost;
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int a[200];
int b[200];
int main(void){
    int i,j;
    int acnt,bcnt;
    char x;
    for(i=0;i<200;i++){
        a[i]=-1;
        b[i]=-1;
    }
    j=0;
    acnt=0;
    bcnt=0;
    while(1){
        scanf("%c",&x);
        if(x=='\n'){
            j++;
            if(j==2){
                break;
            }
        }else if(j==0){
            a[acnt]=x;
            acnt++;
        }else if(j==1){
            b[bcnt]=x;
            bcnt++;
        }
    }
    j=0;
    if(acnt==bcnt){
        for(i=0;i<200;i++){
            if(a[i]>b[i]){
                printf("GREATER\n");
                j=999;
                break;
            }else if(a[i]<b[i]){
                printf("LESS\n");
                j=999;
                break;
            }
        }
        if(j!=999){
            printf("EQUAL\n");
        }
    }else if(acnt>bcnt){
        printf("GREATER\n");
    }else{
        printf("LESS\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    cout << r * r << endl;

    return 0;
}


Measured memory_bytes: 256
k = int(input())
a = tuple(map(int, input().split()))

l, r = 2, 2
ans = (-1,)
for x in reversed(a):
    l = ((l + x - 1) // x) * x
    # print(x, l, r)
    if r < l:
        break
    r = ((r // x) * x) + (x - 1)
else:
    ans = (l, r)
print(*ans)


Measured memory_bytes: 63984
N = int(input())
z = 0
f = False
for i in range(N):
    r = list(map(int, input().split()))
    if r[0] == r[1]:
        z += 1
        if z == 3:
            f = True
    elif not f:
        f = False
        z = 0
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


bool prime(ll n) {
	if (n == 1)return false;
	if (n == 2)return true;
	for (int i = 2; i < (int)sqrt(n) + 1;i++) {
		if (n%i == 0)return false;
	}
	return true;
}
vector<ll>sosu;
map<ll, int>mp;
int main() {
	ll N, P;
	cin >> N >> P;
	FOR(i, 2, 1000020) {
		if (prime(i))sosu.pb(i);
	}
	
	if (N == 1) {
		p(P);
		return 0;
	}
	ll x = P;
	if (P == 1) {
		p(1);
		return 0;
	}
	while (x >= 2) {
		for (auto i:sosu) {
			if (x%i == 0) {
				mp[i]++;
				x /= i;
				break;
			}
			if (i >= (ll)sqrt(P))goto END;
		}
	}
	END:
	ll ans = 1;
	for (auto x : mp) {
		while (x.second / N > 0) {
			ans *= x.first;
			x.second -= N;
		}
	}
	p(ans);
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n,k;cin>>n>>k;
	ll ans=0;
	if(k==0)cout<<n*n<<endl;
	else{
		for(int i=k+1;i<=n;++i){
			int m=n%i;
			ans+=(i-k)*(n/i);
			if(m>=k){
				ans+=(m-k+1);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        boolean[][] dp = new boolean[n + 1][2001];
        for (int i = a.length - 1; i >= 0; i--) {
            dp[i][a[i]] = true;
            for (int j = dp[i + 1].length - 1; j >= 0 ; j--) {
                if (j > a[i] && dp[i + 1][j - a[i]] || dp[i + 1][j]) dp[i][j] = true;
            }
        }
        int q = scanner.nextInt();
        for (int i = 0; i < q; i++) {
            System.out.println(dp[0][scanner.nextInt()] ? "yes": "no");
        }
        /**
        for (boolean[] b : dp) {
            for (boolean bb : b) {
                System.out.print(String.valueOf(bb) + " ");
            }
            System.out.println("");
        }
        **/
    }
}

Measured memory_bytes: 26548
import itertools
a=input()
n=len(a)
l=list(itertools.product(range(2),repeat=n-1))
wl=[]
for i in range(len(l)):
    w=a[0]
    for j in range(n-1):
        if l[i][j]==1:
            w+="+"
        w+=a[j+1]
    wl.append(w)
print(sum(map(eval,wl)))

Measured memory_bytes: 3188
n = int(input())
ans = [0]*n
#print(ans)
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      temp = x**2+y**2+z**2+x*y+y*z+z*x
      if temp <= n:
        #print(temp)
        ans[temp-1] += 1
[print(ans[i]) for i in range(n)]

Measured memory_bytes: 9424
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {
    int n,m;
    cin >> n >> m;
    int array[100];
    int sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> array[i];
        sum += array[i];
    }
 
    sort(array, array+n, greater<int>());
 
    //for(int i = 0; i < n;i ++){
    //    cout << array[i] << endl;
    //}
 
    float cmp = (float)sum / (4*m); 
    if(array[m-1] < cmp)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
 
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<vector<int>> d(n,vector<int>(n));
  rep(i,n){
    string s;cin >> s;
    rep(j,n)d[i][j] = s[j]-'0';
  }
  vector<vector<int>> v(n);
  rep(i,n)for(int j = i+1;j < n;j++){
    if(d[i][j] == 0)continue;
    v[i].push_back(j);
    v[j].push_back(i);
  }
  bool is = true;
  {
    queue<int> que;
    que.push(0);
    vector<int> col(n,-1);
    col[0] = 0;
    while(!que.empty()){
      int ov = que.front();que.pop();
      for(auto nv : v[ov]){
        if(col[nv] != -1){
          if(col[nv] == col[ov]){
            cout << -1 << endl;
            return 0;
          }
          continue;
        }
        col[nv] = 1-col[ov];
        que.push(nv);
      }
    }
  }
  ll res = 2;
  rep(i,n)rep(j,n)if(i != j && d[i][j] == 0)d[i][j] = 1 << 29;
  rep(k,n)rep(i,n)rep(j,n)d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
  rep(i,n)rep(j,n)res = max(res,1ll*d[i][j]+1);
  cout << res << endl;



  




  return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

	vector<pair<int, int>> v(m);

	REP(i, m){
		int l, r;
		cin >> l >> r;
		v[i] = make_pair(l, r);
	}

	sort(v.begin(), v.end(), [](auto &left, auto &right) {
		return left.second < right.second;
	});

	int count = 0;
	int p = -1;
	for(pair<int, int> x : v){
		if(x.first < p){
			continue;
		}
		p = x.second;
		count ++;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

int main()
{
	char s[200001];
	int i, A, Z, A_flag;

	scanf("%s", s, 200000);
	A = 0;
	Z = 0;
	A_flag = 0;

	for (i = 0; s[i]!= '\0' ; i++) {
		if (s[i] == 'A' & A_flag == 0){
			A = i; A_flag = 1; 
		}
		if (s[i] == 'Z') {
			Z = i;
		}

	}

	printf("%d", Z - A + 1);

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std ;
int main(){
    double a , b , h , m , c , th ;
    cin >> a >> b >> h >> m ;
    th = abs( ((h*60 + m)/720)*(2*M_PI) - (m/60)*(2*M_PI) ) ; 
    c = a*a + b*b - 2*a*b*cos(th) ;
    cout << fixed << setprecision(9) << sqrt(c) << "\n" ;
    return 0 ;
}

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

int main()
{   
   char c[55][55]; int H,W,cnt=0;
   cin>>H>>W;
   for(int i=1;i<=H;i++){
       for(int j=1;j<=W;j++) cin>>c[i][j];
   }
   for(int i=1;i<=H;i++){
       for(int j=1;j<=W;j++){
           if(c[i][j]=='#' && c[i][j-1]!='#' && c[i-1][j]!='#' && c[i][j+1]!='#' && c[i+1][j]!='#') cnt++;
       }
   }
   if(cnt==0) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    
    
}

Measured memory_bytes: 256
from collections import Counter

def main():
    n = int(input())
    a = tuple([int(t)for t in input().split()])

    d_1 = {}
    d_2 = {}

    for i,a_i in enumerate(a):
        d_1.setdefault(i+a_i,0)
        d_1[i+a_i]+=1

    for j,a_j in enumerate(a):
        d_2.setdefault(j-a_j,0)
        d_2[j-a_j]+=1

    ans = 0
    for key in d_1.keys():
        if key in d_2.keys():
            ans += d_1[key]*d_2[key]

    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 59560
#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>;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    vector<int> cnt(N, 0);

    rep(i, N - 1) if (S[i] == 'R' && S[i + 1] == 'L') {
        cnt[i] = 1;
        cnt[i + 1] = 1;
    }

    vector<int> sum(2, 0);
    for (int i = 0; i < N; ++i) {
        if (cnt[i] == 0 && S[i] == 'R') ++sum[i % 2];
        if (cnt[i] > 0) {
            cnt[i] += sum[i % 2];
            sum[i % 2] = 0;
        }
    }
    for (int i = N - 1; i >= 0; --i) {
        if (cnt[i] == 0 && S[i] == 'L') ++sum[i % 2];
        if (cnt[i] > 0) {
            cnt[i] += sum[i % 2];
            sum[i % 2] = 0;
        }
    }
    rep(i, N) cout << cnt[i] << " ";
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, m, r;
    cin >> n >> m >> r;

    vector<int> root(r);
    for (int i = 0; i < r; i++) {
        cin >> root[i];
    }

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

    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                t[i][j] = min(t[i][j] ,t[i][k] + t[k][j]);
            }
        }
    }

    sort(ALL(root));
    int mn = 1000000000;
    do {
        int x = 0;
        for (int i = 1; i < r; i++) {
            x += t[root[i - 1]][root[i]];
        }
        mn = min(mn, x);
    } while(next_permutation(ALL(root)));

    cout << mn << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=55,INF=0x7f7f7f7f;
int n,ans=INF;
struct node
{
	int x,y;
	node(){}
	node(int xx,int yy)
	{
		x=xx,y=yy;
	}
}a[MAXN];
bool cmp(node a,node b)
{
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
map<pair<int,int>,int>M;
int vis[MAXN],Ti;
int force(int p,int q)
{
	int jans=0;
	Ti++;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==Ti)
			continue;
		jans++;
		int x=a[i].x,y=a[i].y;
		while(M[make_pair(x,y)]!=0)
		{
			vis[M[make_pair(x,y)]]=Ti;
			x+=p;
			y+=q;
		}
		x=a[i].x,y=a[i].y;
		while(M[make_pair(x,y)]!=0)
		{
			vis[M[make_pair(x,y)]]=Ti;
			x-=p;
			y-=q;
		}
	}
	return jans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&a[i].x,&a[i].y);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		M[make_pair(a[i].x,a[i].y)]=i;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int p=a[j].x-a[i].x,q=a[j].y-a[i].y;
			ans=min(force(p,q),ans);
		}
	}
	printf("%d\n",ans);
}

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

int main() {
  int x, n, p;
  cin>>x >>n;
  vector<int> num(102);
  for(int i=0;i<n;i++){
  	cin>>p;
    num.at(p)++;
  }
  int y=min(x,(101-x));
  for(int i=0;i<=y;i++){
  	if(num.at(x-i)==0){
    	cout<<x-i<<endl;
        break;
    }else if(num.at(x+i)==0){
    	cout<<x+i<<endl;
      	break;
    }
  }
}


Measured memory_bytes: 3644
f = [0] * 10001
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = x * x + y * y + z * z + x * y + y * z + z * x
            if n > 10000:
                break
            f[n] += 1

N = int(input())

for i in range(1, N + 1):
    print(f[i])


Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
#define M 100005
int a[M],b[M];
vector<int>d[M];
priority_queue<int>q;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;++i)d[a[i]].push_back(b[i]);
	int ans=0;
	for(int i=1;i<=m;++i){
		for(int j=0;j<(int)d[i].size();++j)q.push(d[i][j]);
		if(!q.empty())ans+=q.top(),q.pop();
	}
	printf("%d",ans);
}

Measured memory_bytes: 6400
<?php
fscanf(STDIN, "%d %d", $N, $M);
$rangeStart = ($N===1) ? 0 : pow(10, (intval($N) - 1));
$rangeEnd = pow(10, intval($N)) - 1;

for ($m=0; $m<$M; $m++) {
    fscanf(STDIN, "%d %d", $position, $value);
    $hints[] = [
        'position' => intval($position)-1,
        'value' => (string)$value
    ];
}

$targets = range($rangeStart, $rangeEnd);
$suitable = array_filter($targets, function($num) use ($hints) {
    $result = true;
    $numStr = (string)$num;
    foreach($hints as $hint) {
        $result = $result & (substr($numStr, $hint['position'], 1) === $hint['value']);
        if (!$result) break;
    }
    return $result;
});
echo (!!$suitable ? min($suitable) : -1);


Measured memory_bytes: 4604
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const unsigned int N = 123456*2;
int isPrimes[N+1];

bool makePrimes();

int main (void) {
    int i = 0, j = 0;
    vector<unsigned int> xs;
    unsigned int count;

    makePrimes();

    do {
        int x;
        cin >> x;
        xs.push_back(x);
    } while(xs[i++] > 0);

    while (j <= i-2) {
        count = 0;
        for (int x = xs[j] + 1; x <= 2 * xs[j]; x++) {
            if (isPrimes[x]) { count++; }
        }
        cout << count << endl;
        j++;
    }

    return 0;
}

bool makePrimes() {

    isPrimes[0] = false;
    isPrimes[1] = false;

    for (int i=2; i<=N; i++) {
        isPrimes[i] = true;
    }

    for (int i=2; i<=N; i++) {
        if (pow(float(i), 2) > N) { break; }
        if (isPrimes[i] == true) {
            for (int j=i+i; j<=N; j+=i) {
                isPrimes[j] = false;
            }
        }
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md = 1e9+7;

int main()
{
	int n;
	cin >> n;
	int matching[n][n];
	for (int q = 0; q < n; q++)
	{
		for (int w = 0; w < n; w++)
		{
			cin >> matching[q][w];
		}
	}
	ll dp[1<<n];
	dp[0] = 1;
	for (int q = 1; q < (1<<n); q++)
	{
		dp[q] = 0;
		int m = __builtin_popcount(q);
		for (int w = 0; w < n; w++)
		{
			if ((q & (1 << w)) > 0)
			{
				if (matching[w][m-1] == 1)
				{
					dp[q] = (dp[q] + dp[q ^ (1 << w)]) % md;
				}
			}
		}
	}
	cout << dp[(1<<n)-1] << "\n";
	return 0;
}


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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1; i<=n; ++i) {
    int a = i;
    int count = 0;
    while(a) {
      a /= 10; ++count;
    }
    if(count%2) ans++;
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vv vector<ll>
#define pp pair<ll,ll>
#define ff first
#define ss second
#define vp vector<pp>
#define ld long double
#define pb push_back
#define mp make_pair

int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<pair<ll,ll> > p[n+1];
    for(ll i=0;i<n-1;i++)
    {
    	ll x,y,w;
    	cin>>x>>y>>w;
    	p[x].pb(mp(y,w));
    	p[y].pb(mp(x,w));
	}
	ll ans[n+1];
	memset(ans,-1,sizeof(ans));
	ans[1]=1;
	queue<ll> q;
	q.push(1);
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		ll z=ans[x];
		//cout<<x<<endl;
		for(ll i=0;i<p[x].size();i++)
		{
			if(ans[p[x][i].ff]==-1)
			{
				q.push(p[x][i].ff);
				if(p[x][i].ss%2==0)
				{
					ans[p[x][i].ff]=z;
				}
				else
				{
					if(z==1)
					{
						ans[p[x][i].ff]=0;
					}
					else
					{
						ans[p[x][i].ff]=1;
					}
				}
			}
		}
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<ans[i]<<endl;
	}
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	char X, Y;
	cin >> X >> Y;
	if (X == Y)cout << "=" << endl;
	else cout << (X > Y ? ">" : "<") << endl;
	return 0;
}

Measured memory_bytes: 256
def b_even_degrees(N, M, Edges):
    """
    N頂点M辺の単純連結無向グラフが与えられる。
    それのすべての辺に向きをつけ、任意の頂点から出る辺の本数も偶数となるような
    有向グラフを作れるか判定し、可能なら1つ構成せよ。

    すべての辺はどこかの頂点から出なければならないので、辺の数が奇数だと作れない。
    偶数の場合は必ず構成できる。
    ・適当な根付き全域木を取り、残りの辺を適当に向き付ける
    ・木の頂点vとその親を結ぶ辺の向きを決めるときは、vの出次数が偶数になるようにする
    これで、根以外の出次数は偶数になっており、根の出次数は、全体の出次数の
    和が偶数であることから偶数である。
    """
    # 参考: https://atcoder.jp/contests/agc035/submissions/6392673
    if M % 2 == 1:
        return -1

    import sys
    sys.setrecursionlimit(10**6)

    # 以下、1-basedとする
    graph = [[] for _ in range(N + 1)]
    for a, b in Edges:
        graph[a].append(b)
        graph[b].append(a)

    def make_spanning_tree(current, ret=None, is_visit=None):
        if ret is None:
            ret = [set() for _ in range(N + 1)]  # ret[v]: 頂点vの子の集合
        if is_visit is None:
            is_visit = [False] * (N + 1)
            is_visit[current] = True

        for next_vertex in graph[current]:
            if is_visit[next_vertex]:
                continue
            ret[current].add(next_vertex)
            is_visit[next_vertex] = True
            ret = make_spanning_tree(next_vertex, ret, is_visit)
        return ret

    # 全域木の構成
    root_vertex = 1
    spanning_tree = make_spanning_tree(root_vertex)

    # 出次数の計算
    outdegree = [0] * (N + 1)
    ans = []
    # 全域木に使わなかった辺は a -> b となるように向きをつける
    for a, b in Edges:
        if a not in spanning_tree[b] and b not in spanning_tree[a]:
            ans.append((a, b))
            outdegree[a] += 1

    def dfs(current):
        # 全域木の current - child を結ぶ辺に向きをつける
        # 葉から考えれば、出次数の帳尻を合わせるように辺の向きを決めればよくなる
        for child in spanning_tree[current]:
            if spanning_tree[child]:
                dfs(child)  # currentが葉でない場合
            if outdegree[child] % 2 == 0:
                ans.append((current, child))
                outdegree[current] += 1
            else:
                ans.append((child, current))
                outdegree[child] += 1

    dfs(root_vertex)
    ans.sort()  # 本質的にはいらない
    return '\n'.join(' '.join(map(str, row)) for row in ans)

N, M = [int(i) for i in input().split()]
Edges = [[int(i) for i in input().split()] for j in range(M)]
print(b_even_degrees(N, M, Edges))

Measured memory_bytes: 169844
#include <stdio.h>

#include <string.h>

int main() {
	char N[100];
	int n, a, m;
	m = 0;
	scanf("%s", &N);
	n = strlen(N);
	if (n % 2 == 0) {
		a = n / 2;
	}
	else {
		a = n / 2 + 1;
	}
	for (int i = 0; i < a; i++) {
		if (N[i]==N[n - i - 1]) {
		}
		else {
			m++;
		}
	}
	printf("%d",m);
	return 0;
}

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

using namespace std;

class team_obj{
	public:
	int ansNum;
	int penalty;
	int wrongNum[10];
	int teamNum;
};

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

int main(){

	team_obj team[50];
	int ansLine[20];

	for(int i=0;i<50;i++){
		team[i].ansNum=0;
		team[i].penalty=0;
		for(int j=0;j<10;j++){
			team[i].wrongNum[j]=0;
		}
		team[i].teamNum=i;
	}

	int t,p,r;
	while(cin>>t>>p>>r){
		if(t==0 && p==0 && r==0)break;
			
		int tid,pid,time;
		string str;
		for(int i=0;i<50;i++){
			team[i].ansNum=0;
			team[i].penalty=0;
			for(int j=0;j<10;j++){
				team[i].wrongNum[j]=0;
			}
			team[i].teamNum=i;
		}
		for(int i=0;i<20;i++)ansLine[i]=0;

		for(int i=0;i<r;i++){
			cin>>tid>>pid>>time>>str;

			tid--;
			pid--;

			if(team[tid].wrongNum[pid]==-1)continue;

			if(str=="WRONG"){
				team[tid].wrongNum[pid]++;
			}
			else{
				team[tid].penalty+=team[tid].wrongNum[pid]*1200+time;
				team[tid].wrongNum[pid]=-1;
				team[tid].ansNum++;
			}
		}
/*
		for(int i=0;i<t;i++){
			cout<<"i="<<i<<endl;
			cout<<team[i].ansNum<<" "<<team[i].penalty<<endl;
		}
		*/
		//答え数のソートを行う。
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].ansNum>=team[j-1].ansNum){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}
		//答え数の数を数える。
		for(int i=0;i<t;i++){
			ansLine[team[i].ansNum]++;
		}

		//次はペナルティにてソートを行う。
		//ペナルティにてソートを行う際、回答数が同じ場合のみ交換を行う。
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].penalty<=team[j-1].penalty && team[j].ansNum == team[j-1].ansNum){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}
		//最後にチーム番号にてソートを行う。
		//回答数とペナルティ数が同じ場合のみソートを実行
		for(int i=0;i<t;i++){
			for(int j=t-1;j>i;j--){
				if(team[j].teamNum<=team[j-1].teamNum && team[j].ansNum == team[j-1].ansNum && team[j].penalty == team[j-1].penalty){
					int tmp = team[j].ansNum;
					team[j].ansNum = team[j-1].ansNum;
					team[j-1].ansNum =tmp;
					
					tmp = team[j].penalty;
					team[j].penalty = team[j-1].penalty;
					team[j-1].penalty = tmp;

					tmp = team[j].teamNum;
					team[j].teamNum = team[j-1].teamNum;
					team[j-1].teamNum = tmp;
				}
			}
		}

		//解答出力
		for(int i=0;i<t;i++){
			team[i].teamNum++;
			cout<<team[i].teamNum<<" "<<team[i].ansNum<<" "<<team[i].penalty<<endl;
		}


	}

	return 0;
}

Measured memory_bytes: 1216
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, K: int, V: "List[int]"):
    a = 0
    answer = []
    reverse_V = V[::-1]
    for i in range(1,min(N,K)+1): ##iコまで宝石をとる
        for left in range(i+1): ##左からleftこ
            right = i-left
            if left>0 and right>0:
                answer =  V[:left]+reverse_V[:right]
            elif left>0:
                answer = V[:left]
            elif right>0:
                answer = V[:right]
            else:
                answer = []
            answer.sort()
            zero_index = bisect.bisect_left(answer,0)
            # 小さいものからK-iこすてる
            answer = answer[min(zero_index,K-i):]
            a = max(a,sum(answer))
    
    print(a)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

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

using ll = long long;
using pii = pair<int, int>;                                   

const int INF32 = INT_MAX;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, p;
    cin >> n >> p;
    int a = 0;
    for (int i = 0, x; i < n; i++) 
        cin >> x, a += x & 1;
    vector<vector<ll>> c(n + 1, vector<ll>(n + 1, 0));
    c[0][0] = 1;
    for (int i = 1; i <= n; i++) { 
        c[i][0] = 1;
        for (int k = 1; k <= i; k++)
            c[i][k] = c[i - 1][k] + c[i - 1][k - 1];
    }
    ll x = 0, y = 0;
    for (int i = p; i <= a; i += 2) 
        x += c[a][i];
    for (int i = 0; i <= n - a; i++)
        y += c[n - a][i];
    cout << ll(x * y);
    return false;                                                       
}

Measured memory_bytes: 256
N,M = map(int,input().split())
amax = 1
for i in range(1,int(M**0.5)+1):
    if M%i==0:
        b = i
        c = M//i
        if b>=N and c>=N:
            a = max(b,c)
        elif c<N<=b:
            a = c
        elif b<N<=c:
            a = b
        else:
            a = 1
        amax = max(amax,a)
print(amax)

Measured memory_bytes: 64144
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

//matp G(N);
void graphmake(ll E,matp &G){
  rep(i,E){
    ll a,b,c;
    cin >> a >> b >> c;
    G.at(a-1).push_back(P(b-1,c));
    G.at(b-1).push_back(P(a-1,c));//有向なら消す
  }
}
//vec d(N);
void dijkstra(ll s,vec &d, matp &G,ll V){
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,V) d.at(i)=INF;
  d.at(s)=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    ll v=p.second;
    if(d.at(v)<p.first) continue;
    rep(i,G.at(v).size()){
      P e=G.at(v).at(i);
      if(d.at(e.first)>d.at(v)+e.second){
        d.at(e.first)=d.at(v)+e.second;
        que.push(P(d.at(e.first),e.first));
      }
    }
  }
}


int main(){
  ll N,Q,K;
  cin >> N;
  matp G(N);
  vec d(N);
  graphmake(N-1,G);
  cin >> Q >> K;
  K--;
  dijkstra(K,d,G,N);
  rep(i,Q){
    ll x,y;
    cin >> x >> y;
    cout << d.at(x-1)+d.at(y-1) << endl;
  }
}
          
          

Measured memory_bytes: 14096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll ans=0;
	ll ch=0;
	for(ll i=0;i<s.size();i++){
		if(s[i]=='W'){
			ans+=i-ch;
			ch++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n+1);
	fill(a.begin(), a.end(), 0);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[x]++;
	}
	sort(a.begin(), a.end(), greater<int>());
	int ans = 0;
	for (int i = k ; i <= n; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t L;
  cin >>L;
  if (L>100){
  int64_t ans=L*L*L/27;
  cout <<ans<<endl;
  }
  else{
    double T=L;
    double ans=T*T*T/27;
  cout <<ans<<endl;
  }
    

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200010
long long a[N];
long long b[N];
long long c[N];
long long d[N];


int main() {
	f(i, N) {
		a[i] = MOD;
		b[i] = 0;
		c[i] = 0;
		d[i] = 0;
	}
	long long n, k, x, y, z, s, ss,yy;
	scanf("%lld %lld", &n, &k);
	x = min(n, (long long)100000);
	f(i, x) {
		a[i + 1] = i + 1;
		b[i + 1] = 1;
		c[i + 1] = 1;
	}
	x = n / (100001);
	z = x;
	while (z >= 1) {
		y = n / z;
		a[100001 + x - z] = y;
			b[100001 + x - z] = y - a[100000 + x - z];
			c[100001 + x - z] = y - a[100000 + x - z];
		z--;
	}
	z = x;
	f(i, k - 1) {
		x = 1;
		if (n <= 100000)y = n;
		else y = 100000 + z;
      yy=y;
		s = 0;    
		while (y > 0) {
          if(x>yy){
				d[y] = (b[y] * s) % MOD;
				y--;
			}
          else if ((a[x] * a[y])<=n){
				s = (s + c[x]) % MOD;
				x++;
			}
			else {
				d[y] = (b[y] * s) % MOD;
				y--;
			}
		}
      
		f(j, N)c[j] = d[j];
	}
	s = 0;
	f(i, N)s = (s + c[i]) % MOD;
	printf("%lld\n", s);

	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main() {
    SPEED;
    int arr[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> arr[i][j];
        }
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (arr[j][k] == temp) {
                    arr[j][k] = -1;
                }
            }
        }
    }

    int flag = 0;
    if ((arr[0][0] == -1 && arr[0][1] == -1 && arr[0][2] == -1) ||
        (arr[1][0] == -1 && arr[1][1] == -1 && arr[1][2] == -1) ||
        (arr[2][0] == -1 && arr[2][1] == -1 && arr[2][2] == -1) ||
        (arr[0][0] == -1 && arr[1][0] == -1 && arr[2][0] == -1) ||
        (arr[0][1] == -1 && arr[1][1] == -1 && arr[2][1] == -1) ||
        (arr[0][2] == -1 && arr[1][2] == -1 && arr[2][2] == -1) ||
        (arr[0][0] == -1 && arr[1][1] == -1 && arr[2][2] == -1) ||
        (arr[0][2] == -1 && arr[1][1] == -1 && arr[2][0] == -1)) {
            flag = 1;
        }

        if (flag == 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }

    return 0;
}

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

int main(){
    string S1,S2;
    cin>>S1;
    S2=S1;
    reverse(S2.begin(),S2.end());
    bool ans=true;
    for(int i=0;i<S1.size();i++){
        if((S1[i]=='b'&&S2[i]!='d')||(S1[i]=='d'&&S2[i]!='b')||(S1[i]=='p'&&S2[i]!='q')||(S1[i]=='q'&&S2[i]!='p')){
            ans=false;
            break;
        }
    }
    cout<<(ans?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005;
int n,m,v,p,a[maxn],ans;
ll b[maxn];
inline int cmp1(int x,int y){
	return x>y;
}
inline int read(){
	int res=0,f_f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f_f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)-'0'+ch,ch=getchar();
	return res*f_f;
}
int main(){
	n=read(),m=read(),v=read(),p=read(),ans=p;
	for (int i=1;i<=n;i++){
		a[i]=read();
	}
	sort(a+1,a+n+1,cmp1);
	for (int i=1;i<=n;i++){
		b[i]=b[i-1]+a[i];
	}
	for (int i=p+1;i<=n;i++){
		if(a[i]+m<a[p]) continue;
		ll delta=1ll*max(0,v-(p-1)-(n-i+1))*m;
		if(delta==0){
			ans++;
			continue;
		}
		ll w=1ll*m*(i-p)-(b[i-1]-b[p-1]-1ll*a[i]*(i-p));
		if(w>=delta) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4940
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m;
    cin >> n >> m;

    Graph G(n);
    for (ll i = 0; i < m; ++i) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b); G[b].push_back(a);
    }

    vector<ll> dist(n, -1);
    dist[0] = 0;
    queue<ll> que;
    que.push(0);

    
    while(!que.empty()){
        ll now = que.front();
        que.pop();

        rep(i, G[now].size()){
            ll next = G[now][i];
            //cout << "next = " << next << endl;
            if(dist[next] == -1){
                //まだ行ってない
                que.push(next);
                //cout << "push " << next << endl;
                dist[next] = now;
            }else{
                //もういった
                continue;
            }
        }
    }
    rep(i,n){
        if(dist[i] == -1){
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i,n){
        if(i == 0){
            cout << "Yes" << endl;
        }else{
            cout << dist[i] + 1 << endl;
        }
        
    }
    

}

Measured memory_bytes: 12844
n = gets.to_i
t = gets.split( " " ).map { |val| val.to_i }
q = gets.to_i
s = gets.split( " " ).map { |val| val.to_i }

cnt = 0
for i in ( 0 ... q )
	for j in ( 0 ... n )
		if s[i] == t[j]
			cnt += 1
			break
		end
	end
end

puts( cnt )

Measured memory_bytes: 6392
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

const int kMaxV = 100010;
const int kInf = 0x3F3F3F3F;

using namespace std;

struct Edge {
  int from;
  int to;
  int dist;

  Edge(int from, int to, int dist): from(from), to(to), dist(dist) {}
};

struct HeapNode {
  int d, u;

  HeapNode(int d, int u): d(d), u(u) {}
  bool operator < (const HeapNode & rhs) const {
    return d > rhs.d;
  }
};

struct Dijkstra {
  int v, e;
  vector<Edge> edges;
  vector<int> g[kMaxV];
  int dist[kMaxV];
  int parent[kMaxV];

  Dijkstra(int v): v(v) {}

  void AddEdge(int from, int to, int dist) {
    edges.emplace_back(from, to, dist);
    g[from].push_back(edges.size() - 1);
  }

  void Solve(int source) {
    for (int i = 0; i < v; ++i) {
      dist[i] = kInf;
    }
    dist[source] = 0;
    bool done[kMaxV] = {false};
    priority_queue<HeapNode> q;
    q.emplace(0, source);
    while (!q.empty()) {
      auto x = q.top();
      q.pop();
      if (done[x.u]) {
        continue;
      }
      done[x.u] = true;
      for (auto e_num: g[x.u]) {
         auto e = edges[e_num];
         if (dist[e.to] > dist[e.from] + e.dist) {
           dist[e.to] = dist[e.from] + e.dist;
           parent[e.to] = e.from;
           q.emplace(dist[e.to], e.to);
         }
      }
    }
  }
};

int main() {
  int v, e, r;
  scanf("%d %d %d", &v, &e, &r);
  auto solver = new Dijkstra(v);
    for (int i = 0; i < e; ++i) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    solver->AddEdge(s, t, d);
  }
  solver->Solve(r);
  for (int i = 0; i < v; ++i) {
    if (solver->dist[i] == kInf) {
      printf("INF\n");
    } else {
      printf("%d\n", solver->dist[i]);
    }
  }
}



Measured memory_bytes: 17384
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  string s;
  cin >> s;
  int a[4];
  for (int i = 0; i < 4; i++) {
    a[i] = s[i] - '0';
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int sum = a[0];
        string t;
        t.push_back(a[0] + '0');
        if (i == 0) {
          sum += a[1];
          t.push_back('+');
        } else {
          sum -= a[1];
          t.push_back('-');
        }
        t.push_back(a[1] + '0');
        if (j == 0) {
          sum += a[2];
          t.push_back('+');
        } else {
          sum -= a[2];
          t.push_back('-');
        }
        t.push_back(a[2] + '0');
        if (k == 0) {
          sum += a[3];
          t.push_back('+');
        } else {
          sum -= a[3];
          t.push_back('-');
        }
        t.push_back(a[3] + '0');
        t += "=7";
        if (sum == 7) {
          cout << t << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 201000
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    int n,k;
    cin>>n>>k;
    int A[n+1];
    int DP[n+1]={};
    rep(i,1,n) cin>>A[i];
    rep(i,2,n)
    {
        int mi=INF;
        int a=0,j=i-1;
        while(a<k && j>=1) mi=min(mi,DP[j]+abs(A[i]-A[j])),a++,j--;
        DP[i]=mi;
    }
    cout<<DP[n];
}   

Measured memory_bytes: 1792
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0502
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

struct Dice {
    // Left, Right, Front, Back, Down, Up
    int l, r, f, b, d, u;
    Dice() : u(1), f(2), r(3), l(4), b(5), d(6) {}
    bool operator<(const Dice &rhs) const {
        return l * 10 + r < rhs.l * 10 + rhs.r;
    }

    // y軸方向にプラス
    void RollN() {
        // ++y;
        int buff = d;
        d = b;
        b = u;
        u = f;
        f = buff;
    }

    // y軸方向にマイナス
    void RollS() {
        //  --y;
        int buff = d;
        d = f;
        f = u;
        u = b;
        b = buff;
    }

    // x軸方向にプラス
    void RollE() {
        // ++x;
        int buff = d;
        d = r;
        r = u;
        u = l;
        l = buff;
    }

    // x軸方向にマイナス
    void RollW() {
        // --x;
        int buff = d;
        d = l;
        l = u;
        u = r;
        r = buff;
    }

    // 90度→方向に回転
    void RollL() {
        // ----->
        int buff = f;
        f = l;
        l = b;
        b = r;
        r = buff;
    }

    // 90度←方向に回転
    void RollR() {
        // <------
        int buff = f;
        f = r;
        r = b;
        b = l;
        l = buff;
    }
};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    while (true) {
        cin >> N;
        if (N == 0) {
            break;
        }
        auto dice = Dice();
        int sum = 1;
        while (N--) {
            string s;
            cin >> s;
            if (s == "North") {
                dice.RollN();
            } else if (s == "East") {
                dice.RollE();
            } else if (s == "South") {
                dice.RollS();
            } else if (s == "West") {
                dice.RollW();
            } else if (s == "Right") {
                dice.RollR();
            } else if (s == "Left") {
                dice.RollL();
            } else {
                cout << "Error" << endl;
                return 0;
            }
            sum += dice.u;
        }
        cout << sum << endl;
    }

    return 0;
}



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

using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  for(int i = 0; i < N; ++i) cin >> v[i] >> w[i];
  vector<int> dp(W+1, -1);
  dp[0] = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = W; j >= w[i]; --j) {
      if(dp[j-w[i]] == -1) continue;
      dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;

  return 0;
}



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

int main(){
int a;scanf("%d",&a);
int L=a/100;
int R=a%100;
if(1<=L&&L<=12){
if(1<=R&&R<=12)printf("AMBIGUOUS\n");
else printf("MMYY\n");
}else{
if(1<=R&&R<=12)printf("YYMM\n");
else printf("NA\n");
}

return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int[] array = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        System.out.println(array[a-1]);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
ll fac(ll n){
    if(n==0)return 1;
    ll x=(n*fac(n-1));
    return x%1000000007;
}
int main(void){
    ll n,m;cin>>n>>m;
    if(abs(n-m)>1)cout<<0<<endl;
    else if(n!=m) cout<<(fac(n)*fac(m))%1000000007<<endl;
    else cout<<fac(n)*fac(m)*2%1000000007<<endl;
}

Measured memory_bytes: 1792