akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fr(i,n) for(int i=0;i<(n);++i)
#define foor(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,n) for(int i=(n);i--;)
#define roof(i,b,a) for(int i=(b);i>=(a);--i)
#define all(x) x.begin(),x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define print(x) cout<<(x)<<endl
using namespace std;            typedef vector<int>  vi;
typedef long long ll;           typedef vector< ll>  vl;
typedef unsigned long long ull; typedef vector<ull>  vu;
typedef double dbl;             typedef vector<dbl>  vd;
typedef string str;             typedef vector<str>  vs;
typedef pair<int,int>pii;       typedef vector<pii>vpii; typedef map<int,int>mii;
typedef pair< ll, ll>pll;       typedef vector<pll>vpll; typedef map< ll, ll>mll;
typedef pair<dbl,dbl>pdd;       typedef vector<pdd>vpdd; typedef map<dbl,dbl>mdd;
typedef pair<str,str>pss;       typedef vector<pss>vpss; typedef map<str,str>mss;
typedef pair< ll,int>pli;       typedef vector<pli>vpli; typedef map< ll,int>mli;
typedef pair<dbl,int>pdi;       typedef vector<pdi>vpdi; typedef map<dbl,int>mdi;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T>multiset<T>&operator<<(multiset<T>&m,const T t){m.insert(t);return m;}
template<typename T>set<T>&operator<<(set<T>&s,const T t){s.insert(t);return s;}
template<typename T,typename U>PQ<T,vector<T>,U>&operator<<(PQ<T,vector<T>,U>&q,const T t){q.push(t);return q;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T>istream&operator>>(istream&s,vector<T>&v){fr(i,v.size()){s>>v[i];}return s;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto a:v){s<<a<<endl;}return s;}
const int MD=1e9+7;
vpli dijkstra(const int N,const vpli E[],const int s,const ll inf){vpli d;fr(i,N)d<<pli{inf,i};d[s].first=0;PQ<pli,vpli,greater<pli>>pq;pq<<(d[s]=pli{0,s});while(pq.size()){pli a=pq.top();pq.pop();int v=a.second;if(d[v].first>=a.first){for(pli e:E[v]){if(d[v].first+e.first<d[e.second].first){d[e.second]=pli{d[v].first+e.first,v};pq<<pli{d[v].first+e.first,e.second};}}}}return d;}
ll gcd(const ll a,const ll b){return a?gcd(b%a,a):b;}
ll pow(const ll a,const ll n,const int m){ll t;return n?(n&1?a>=0?a%m:~-m+~a%m:1)*(t=pow(a,n>>1,m),t*t%m)%m:1;}
ll C2(const int n){return(ll)n*~-n/2;}
ll sum(const vl a){ll s=0;for(ll e:a){s+=e;}return s;}
template<typename T>T max(const vector<T>a){T m=a[0];for(T e:a){m=max(m,e);}return m;}
template<typename T>T min(const vector<T>a){T m=a[0];for(T e:a){m=min(m,e);}return m;}
// (int) * (int) => (int)
// (int) / (int) => (int)

main(){cin.tie(0);ios::sync_with_stdio(false);
	ll N;
	cin>>N;
	str S;
	cin>>S;
	map<pss,ll>m1,m2;
	fr(i,1<<N){
		str s1="",s2="",t1="",t2="";
		fr(j,N){
			(i>>j&1?s1:s2)+=S[j];
			(i>>j&1?t1:t2)+=S[2*N-1-j];
		}
		++m1[{s1,s2}];
		++m2[{t1,t2}];
	}
	ll z=0;
	for(auto s:m1){
		z+=s.second*m2[s.first];
	}
	print(z);
}


Measured memory_bytes: 110336
n, m = list(map(int, input().split()))

left = 1
right = n
for i in range(m):
    l, r = list(map(int, input().split()))
    left = max(l, left)
    right = min(r, right)

if left > right:
    print(0)
else:
    print(right - left + 1)


Measured memory_bytes: 3060
import sys

N, M = map(int, input().split())
lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]
lst.sort()    
#print (lst)
count = M
yen = 0

for i in range(N):
    yen += lst[i][0] * min(count, lst[i][1])  
    count -= min(count, lst[i][1])
#    print (count)
    if count <= 0:
        print (yen)
        sys.exit()

Measured memory_bytes: 27760
#!/usr/bin/env ruby

n, as = readlines
as = as.strip.split(' ').map(&:to_i).sort.reverse

odd_sum = 0
even_sum = 0
as.each_with_index do |item, i|
  if (i + 1).odd? then
    odd_sum += item
  else
    even_sum += item
  end
end

puts odd_sum > even_sum ? odd_sum - even_sum : even_sum - odd_sum

Measured memory_bytes: 1788
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>
#include <ext/rope>
 
#define F1(x,y,z) for(int x=y;x<z;x++)
#define F2(x,y,z) for(int x=y;x<=z;x++)
#define F3(x,y,z) for(int x=y;x>z;x--)
#define F4(x,y,z) for(int x=y;x>=z;x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second
 
#define MAX 100005
#define AMAX 1500
#define MOD 1000000007
 
#define f(c,d) ((1<<(c))*(d))
 
using namespace std;
using namespace __gnu_cxx;
 
int n;
LL x[MAX],ans,ta;
 
int main(){
	scanf("%d",&n);
	F1(a,0,n)scanf("%lld",x+a);
	F1(a,0,n){
		ans+=x[a]/2;
		x[a]%=2;
		if(x[a]&&x[a+1])ans++,x[a+1]--;
		/*
		ta=min(x[a],x[a+1]);
		x[a+1]-=ta;
		ans+=ta;
		ans+=(x[a]-ta)/2;
		*/
	}
	printf("%lld\n",ans);
	#ifdef LOCAL_PROJECT
    system("pause");
    #endif
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <vector <bool>> v(n, vector <bool> (n, 0));
  vector <ll> color(n, 0);
  vector <ll> d(n, INF);
  queue <ll> q;
  rep(i, n) {
    ll a, b, c;
    cin >> a >> b;
    rep(j, b) {
      cin >> c;
      v.at(a-1).at(c-1) = 1;
    }
  }
  color.at(0) = 1;
  d.at(0) = 0;
  q.push(0);
  while (!q.empty()) {
    ll i = q.front();
    q.pop();
    rep(j, n) {
      if (v.at(i).at(j) && color.at(j)==0) {
        color.at(j) = 1;
        d.at(j) = d.at(i) + 1;
        q.push(j);
      }
    }
    color.at(i) = 2;
  }
  rep(i, n) {
    if (d.at(i) == INF) {
      cout << i+1 << ' ' << -1 << endl;
    } else {
      cout << i+1 << ' ' << d.at(i) << endl;
    }
  }
}


Measured memory_bytes: 3124
unittest
{
	assert( [ "1", "1000000000" ].parse.expand.solve == 999999993 );
	assert( [ "2", "5 8" ].parse.expand.solve == 124 );
	assert( [ "5", "52 67 72 25 79" ].parse.expand.solve == 269312 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto cs = input.front.split.to!( long[] );
	return tuple( cs );
}

auto solve( long[] cs )
{
	// コストが小さい順に操作するのが最適
	cs.sort();
	
	// S ^ T = X として、Xの全パターンの操作コストを合計
	auto ans = 0L;
	auto cp = 2.powMod( cs.length.signed - 1 );		// 全パターンからi番目が0のパターンを除いた数
	auto rp = 2.powMod( cs.length.signed - 2 );		// 全パターンからi番目とj番目が0のパターンを除いた数
	foreach( i, c; cs )
	{
		// i番目を1に固定したときの操作コストを計算
		auto rn = cs.length.signed - 1 - i;
		auto rb = ( rn <= 0 ) ? 0 : rp.mulMod( rn );
		auto cb = cp;
		auto ct = cb.addMod( rb ).mulMod( c );
		ans = ans.addMod( ct );
	}
	
	// Xから元のSとTは2^^桁数パターン作れる
	ans = ans.mulMod( 2.powMod( cs.length ) );
	
	return ans;
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}


Measured memory_bytes: 10996
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*b, c*d)<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


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

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(n, i) {
        cin >> a[i];
    }
    int ans = INF;
    rep(n - k + 1, i) {
        int res = 0;
        if (a[i + k - 1] * a[i] < 0) {
            res += min(abs(a[i + k - 1]), abs(a[i]));
            res *= 2;
            res += max(abs(a[i + k - 1]), abs(a[i]));
        } else {
            res += max(abs(a[i + k - 1]), abs(a[i]));
        }
        // cout << res << endl;
        ans = min(res, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import math
A,B,H,M = list(map(int,input().split()))
H = H%12*30+30*(M/60)
M = M/60*360
X = max(H,M)-min(H,M)
X = min(X,360-X)
print(math.sqrt(A**2+B**2-2*A*B*math.cos(math.pi*(X/180))))


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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;

const ULL fr = 1000000007;

int N;
V<ULL> T;
V<ULL> A;
V<ULL> X;
V<ULL> C;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        ULL x;
        cin >> x;
        T.push_back(x);
    }
    REP(i, N) {
        ULL x;
        cin >> x;
        A.push_back(x);
    }

    ULL mt = T[0];
    ULL ma = A[0];
    X.push_back(min(T[0], A[0]));
    FOR(i,1,N) {
        if(mt < T[i]) mt = T[i];
        if(ma < A[i]) ma = A[i];
        if(T[i-1] > T[i] || A[i-1] < A[i]) {
            cout << 0 << "\n";
            return 0;
        }
        if(T[i-1] < T[i] && T[i] > A[i]) {

        }
        if(A[i-1] > A[i] && A[i-1] > T[i-1]) {
            cout << 0 << "\n";
            return 0;
        }
        X.push_back(min(T[i], A[i]));
    }

    if (mt != ma) {
        cout << 0 << "\n";
        return 0;
    }


    REP(i, N) {
        int ct = 0;
        C.push_back(1);
        int e = C.size()-1;

        FOR(j,i+1,N) {
            if(X[i] != X[j]) break;
            ct++;
        }
        int y = ct;
        if(A[i+ct] == T[i+ct]) y--;
        REP(j,y) {
            C[e] *= (X[i] % fr);
            C[e] = (C[e] % fr);
        }

        i += ct;
    }

    ULL ans = 1;
    REP(i, C.size()) {
        ans *= (C[i] % fr);
        ans = (ans % fr);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 4212
# coding: utf-8
# Your code here!

import sys
mod = 998244353
n = int(input())
dl = list(map(int,input().split()))

if dl[0] != 0:
    print(0)
    sys.exit()
dl = sorted(dl)

before = 0
for i in dl:
    if i - before > 1:
        print(0)
        sys.exit()
    before = i
    
if dl.count(0) > 1:
    print(0)
    sys.exit()    
    

ans = 1
before_e = 1
now_e = 0
now = 0

for d in dl:
    if now != d:
        if now_e == 0:
            print(0)
            sys.exit()
        before_e = now_e
        now_e = 0
        now += 1
    now_e += 1
    ans *= before_e
    ans %= mod

print(ans)
    

Measured memory_bytes: 54828
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c;
  cin>>a;
  b=a/500;
  a-=500*b;
  c=a/5;
  cout<<b*1000+c*5;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong x;

bool isPrime(llong n) {
    for (llong i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    cin >> x;

    while (!isPrime(x)) x++;

    cout << x << endl;

    return 0;
}


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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int goal, t, l, b;
	while (cin >> goal >> t >> l >> b, goal) {
		set<int> yasumi;
		set<int> modoru;
		REP(i, l) {
			int a;
			cin >> a;
			yasumi.insert(a);
		}
		REP(i, b) {
			int a;
			cin >> a;
			modoru.insert(a);
		}
		vector<double> mass(goal);
		vector<double> yasu(goal);
		mass[0] = 1.0;
		double ans = 0;
		while (t--) {
			vector<double> mass2=yasu;
			REP(i, yasu.size())
				yasu[i] = 0.0;
			REP(i, mass.size()) {
				REP(j, 6) {
					int me = j + 1;
					if (i + me == goal) {
						ans += mass[i] / 6.0;
						continue;
					}
					 if (i + me > goal) {
						 me -= (i + me - goal)*2;
					}
					 if (yasumi.find(i + me) != yasumi.end()) {
						 yasu[i + me] += mass[i] / 6.0;
						 continue;
					 }
					 if (modoru.find(i + me) != modoru.end()) {
						 mass2[0] += mass[i] / 6.0;
						 continue;
					 }
					 mass2[i+me] += mass[i] / 6.0;
				}
			}
			mass = mass2;
		}
		printf("%.6lf\n", ans);
	}
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
  int b[n];
  b[0]=0;
  b[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
      int m=INT_MAX;
      for(int j=1;j<=k;j++){
          if((i-j)>=0){
      m=min(b[i-j]+abs(a[i]-a[i-j]),m);}
      }
      b[i]=m;
  }
    cout<<b[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const double EPS = 1e-6;

int main(void) {
	int N;
	while (cin >> N, N) {;
		vector<string> F(N);
		VI W(N), S(N);
		for (int i = 0; i < N; i++) {
			cin >> F[i] >> W[i] >> S[i];
		}

		VI p(N);
		iota(p.begin(), p.end(), 0);

		double ans = 1e+8;
		VI best_p(p.begin(), p.end());

		do {
			double g = 0, gt = 0;
			for (int i = 0; i < N; i++) {
				g += (i + 1) * W[p[i]];
				gt += W[p[i]];
			}
			g /= gt;

			if (g - EPS > ans) { continue; }

			int total = 0;
			bool flg = true;
			for (int i = N - 1; i >= 0; i--) {
				flg &= total <= S[p[i]];
				total += W[p[i]];
			}

			if (flg && g < ans + EPS) {
				ans = g;
				swap(best_p, p);
			}
		} while (next_permutation(p.begin(), p.end()));

		for (auto i : best_p) {
			cout << F[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1212
from itertools import accumulate

Q = int(input())
LR = [None]*Q
maxr = 0
for i in range(Q):
    l, r = map(int, input().split())
    LR[i] = (l, r)
    maxr = max(maxr, r)

primes = set(range(2, maxr + 1))
for i in range(2, int(maxr ** 0.5 + 1)):
    primes.difference_update(range(i * 2, maxr + 1, i))
c = [0]*((maxr+1) // 2)
for p in primes:
    if p <= (maxr + 1) // 2:
        c[p - 1] = 1
likes = [0]*maxr
for p in primes:
    if p != 2 and c[(p+1) // 2 - 1] == 1:
        likes[p-1] = 1
likes = list(accumulate(likes))
for i in range(Q):
    if LR[i][0] == 1:
        print(likes[LR[i][1] - 1])
    else:
        print(likes[LR[i][1] - 1] - likes[LR[i][0] - 2])


Measured memory_bytes: 27936
N , X = map(int, input().split())
x = list(map(int, input().split()))

from fractions import gcd
from functools import reduce

diff = []
for i in range(1, N):
  diff.append(x[i] - x[i-1])

left = diff[:] + [abs(x[0]-X)]
right = diff[:] + [abs(x[-1]-X)]

print(max(reduce(gcd, left), reduce(gcd, right)))

Measured memory_bytes: 15512
L = $<.read.split
H,W = L.shift(2).map &:to_i
A = Array.new(H*W)
A[0] = L[0][0]==?. ? 0 : 1
1.upto(H+W-1) {|r|
  [H-1,r].min.downto(0) {|h|
    break  if W <= w=r-h
    x = h*W + w
    c = L[h][w]
    a = []
    a << A[x-1] + (L[h][w-1]!=c && c==?# ? 1: 0)  if w > 0
    a << A[x-W] + (L[h-1][w]!=c && c==?# ? 1: 0)  if h > 0
    A[x] = a.min
  }
}
p A[-1]

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;


int main(){
  int i,j;
  int n,k;
  cin>>n>>k;
  ll a[n+1];
  for(i=1;i<=n;i++){
    cin>>a[i];
    a[i]--;
  }
  a[0]=0;
  map<ll,ll> m;
  ll sum=0;
  VI s(n+1,0);
  ll ans=0;
  for(i=0;i<=n;i++){
    sum+=a[i];
    sum%=k;
    ans+=m[sum];
    s[i]=sum;
    m[sum]++;
    if(i>=k-1) m[s[i-(k-1)]]--; 
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main() {
 	string ans = "APPROVED";
  	int x, y;
  	cin >> x;
  	for(int i = 0; i < x; i++) {
	      cin >> y;
	      if(y % 2 == 0 && y % 3 != 0 && y % 5 != 0) ans = "DENIED";
	}
  	cout << ans << endl;
}


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

using namespace std;
#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

int main ()
{
  int a;
  cin >> a;
  cout << a + pow(a,2) + pow(a,3) << endl;
  return 0; 
}

Measured memory_bytes: 4184
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ACircle {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int r; cin >> r;
      cout << r*r << endl;
    }
};

signed main() {
  ACircle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        for k in range(10**8):
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
    else:
        print(tmp)

print(0)


Measured memory_bytes: 42460
#include <bits/stdc++.h>
using namespace std;
vector<int> cplaces[26];

int main() {
    string s,t;
    bool ok =1;
    int cur=0,idx,sz;
    long long itaken=0;
    cin>>s>>t;
    int slen = s.length();
    int tlen = t.length();
    for(int i=0;i<slen;i++)
    {
        cplaces[s[i]-'a'].push_back(i+1);
    }
    for(int i=0;i<tlen&&ok;i++)
    {
        sz=cplaces[t[i]-'a'].size();
        if(sz==0){ok=0;break;}
        idx = upper_bound(cplaces[t[i]-'a'].begin(),cplaces[t[i]-'a'].end(),cur)-cplaces[t[i]-'a'].begin();
        if(idx<cplaces[t[i]-'a'].size())
        {
            itaken += cplaces[t[i]-'a'][idx]-cur;
            cur=cplaces[t[i]-'a'][idx];
        }
        else
        {
            itaken += slen-cur;
            cur=0;
            idx = upper_bound(cplaces[t[i]-'a'].begin(),cplaces[t[i]-'a'].end(),cur)-cplaces[t[i]-'a'].begin();
            itaken += cplaces[t[i]-'a'][idx]-cur;
            cur=cplaces[t[i]-'a'][idx];
        }
    }
    if(ok) cout<<itaken<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

struct Move {
	int x, y, ax, ay;
	Move(){}
	Move(int _y, int _x, int _ay, int _ax) {
		x = _x; y = _y; ax = _ax; ay = _ay;
	}
};


int H, W;

bool check(int y, int x) {
	if (y < 0 || y >= H)return false;
	if (x < 0 || x >= W)return false;
	return true;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> H >> W;
	vvi A(H, vi(W, 0));
	REP(i, H)REP(j, W) {
		cin >> A[i][j];
	}
	vector<Move> VM;
	REP(i, H)REP(j, W) {
		if ( A[i][j] % 2 == 1) {
			if(!check(i,j+1)){
				//必ず下に動かさなければならない
				if (!check(i+1,j))continue;
				A[i][j] -= 1;
				A[i+1][j] += 1;
				VM.push_back(Move(i + 1, j + 1, i + 2, j + 1));
			}
			else {
				A[i][j] -= 1;
				A[i][j + 1] += 1;
				VM.push_back(Move(i + 1, j + 1, i + 1, j + 2));
			}
		}
	}
	cout << SZ(VM) << endl;
	for(Move m : VM){
		cout << m.y << " " << m.x << " " << m.ay << " " << m.ax << endl;
	}
	PAU;
	return 0;
}


Measured memory_bytes: 5484
#include<cstdio>
#include<cstring>
using namespace std;
const int N=300005,mod=1e9+7;
int dp[N][8],t[8][8];
char st[N];
int main()
{
	t[0][1]=1,t[0][0]=2;
	t[1][1]=5,t[1][0]=3;
	t[2][1]=7,t[2][0]=4;
	t[3][1]=1,t[3][0]=6;
	t[4][1]=2,t[4][0]=2;
	t[5][1]=5,t[5][0]=5;
	t[6][1]=3,t[6][0]=3;
	t[7][1]=1,t[7][0]=2;
	scanf("%s",st);
	int len=strlen(st);
	dp[len][1]=1,dp[len][5]=1;
	for(int i=len-1;i>=0;i--)
	{
		for(int j=0;j<=7;j++)
		{
			if(st[i]!='0')
			dp[i][j]=(dp[i][j]+dp[i+1][t[j][1]])%mod;
			if(st[i]!='1')
			dp[i][j]=(dp[i][j]+dp[i+1][t[j][0]])%mod;
		}
	}
	printf("%d",dp[0][0]);
	return 0;
}

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

typedef long long int ll;

const ll MAX_N = 100001;
const int INF = 1e8;

int main(){
  int N;
  cin >> N;
  int a[3] = {9,6};
  int dp[MAX_N];
  for(int i = 0 ; i < MAX_N ; i++){
    dp[i] = i;
  }
  for(int i = 0 ; i <= N ; i++){
    for(int j = 0 ; j < 2 ; j++){
      ll sum = 1;
      sum = 1;
      for(int k = 0 ; sum <= N ; k++){
	sum *= a[j];
	if(i + sum < MAX_N){
	  dp[i + sum] = min(dp[i + sum], dp[i] + 1) ;
	}
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (h <= a && w <= b)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    T = input()
    S_len = len(S)
    T_len = len(T)
    ls = []
    for i in range(S_len-T_len+1):
        ls.append(S[i:i+T_len])
    cnt_max = 0
    for can in ls:
        cnt = 0
        for i,j in zip(T,can):
            if i==j:
                cnt +=1
        if cnt_max < cnt:
            cnt_max = cnt
    print(T_len-cnt_max)
if __name__ == "__main__":
    main()

Measured memory_bytes: 68192
#include <cstring>
#include <iostream>

using namespace std;

#define MAX_N 512
#define MAX_M 10240

int N, M, A[MAX_M], B[MAX_M]; bool LIST[2][MAX_N];

int main()
{
	while (true)
	{
		memset(LIST, false, sizeof(LIST));

		cin >> N >> M;

		if (N == 0 && M == 0) { break; }

		for (int i = 1; i <= M; i++)
		{
			cin >> A[i] >> B[i];

			if (A[i] == 1)
			{
				LIST[0][B[i]] = true;
				LIST[1][B[i]] = true;
			}
		}

		for (int i = 1; i <= M; i++)
		{
			if (LIST[0][A[i]] == true)
			{
				LIST[1][B[i]] = true;
			}

			if (LIST[0][B[i]] == true)
			{
				LIST[1][A[i]] = true;
			}
		}

		int count = 0;

		for (int i = 2; i <= N; i++)
		{
			if (LIST[1][i] == true)
			{
				count++;
			}
		}

		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
let () =
	let a,b,c = Scanf.scanf "%d %d %d\n" (fun a b c-> a,b,c) in
    Printf.printf "%d\n"
    (if a = b && b = c then 1
    else if (a = b && a <> c) || (a = c && a <> b) || (b = c && a <> b) then 2
    else 3)

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();

            int n = cin.nextInt();
            int ans = 0;

            for (int i = 1; i <= n; i++)
            {
                if(i.ToString().Length % 2 != 0)
                {
                    ans++;
                }
            }
            
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

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

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

Measured memory_bytes: 13140
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
for i in range(1,n+1):
    a[i]+=a[i-1]
for i in range(1,n+1):
    a[i]=(a[i]-i)%k
b=[[] for i in range(n+1)]
for i in range(n+1):
    b[i]=[a[i],i]
b.sort()
left=0
right=0
ans=0
while left<n:
    while right<n:
        if b[left][0]==b[right+1][0] and b[right+1][1]-b[left][1]<k:
            right+=1
        else:
            break
    ans+=right-left
    left+=1
print(ans)

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

int main(void){
    int a,b;
    cin >> a >> b;
    int ans=0;
    int n=1;
    while(n<b){
        n+=a-1;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
  string a, b;
  cin >> a >> b;
  int n = stoi(a + b);
  bool flag = false;
  for(int i=0;i<n/2;i++)
  	if(i*i==n) flag = true;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '9')
			s[i] = '1';
		else
			s[i] = '9';
	}
	cout << stoi(s);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
int main() {
	int N, K, f = 0, cost = 1 << 30;
	scanf("%d%d", &N, &K);
	vector<int> x(N);
	rep(i, 0, N) {
		scanf("%d", &x[i]);
		if (x[i] == 0)K--, f = 1;
	}
	if (!f)x.push_back(0), N++;
	sort(all(x));
	int z = lower_bound(all(x), 0) - x.begin(), l = max(0, z - K), r = min(N - 1 - K, z);
	rep(i, l, r + 1) {
		//printf("%d %d\n", i, i + K);
		cost = min(cost, min(x[i + K] * 2 - x[i], x[i + K] - x[i] * 2));
	}
	printf("%d\n", cost);
	return 0;
}


Measured memory_bytes: 1152
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let a = if A == 1 { 14 } else { A };
    let b = if B == 1 { 14 } else { B };

    let ans = if a > b { "Alice" } else if a < b { "Bob" } else { "Draw" };

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int INF = (int)1e9 + 7;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x <<
//cin,coutより遅いので注意
template <class T = int>
void in() //in<string>();とか書く intのときはそのままin();
{
    T x;
    cin >> x;
    return (x);
}
template <class T>
void print(T &x) { cout << x << "\n"; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A;
    int four_cnt = 0, two_cnt = 0, other_cnt = 0;
    REP(i, N)
    {
        int a;
        cin >> a;
        A.push_back(a);
        if (a % 4 == 0)
        {
            four_cnt++;
        }
        else if (a % 2 == 0)
        {
            two_cnt++;
        }
        else
        {
            other_cnt++;
        }
    }
    if (other_cnt <= four_cnt || two_cnt == N)
    {
        print("Yes");
    }
    else if (other_cnt + four_cnt == N && other_cnt == four_cnt + 1)
    {
        print("Yes");
    }
    else
    {
        print("No");
    }
}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=s-1; i>=s; i--)

int main(){

    int n; cin >> n;
    pair<ll, ll> ba[n];
    rep(i, n){
        int t1, t2; cin >> t1 >> t2;
        ba[i] = {t2, t1};
    }

    sort(ba, ba+n);

    ll cnt = 0;
    bool ngflag = false;
    rep(i, n){
        cnt += ba[i].second;
        if(cnt > ba[i].first){
            ngflag = true;
            break;
        }
    }

    cout << (ngflag ? "No" : "Yes");

    return 0;
}

Measured memory_bytes: 3456
import numpy as np
n, k = list(map(int, input().split()))
ndewaru = 0
for p in range(n) :
    if p+1 < k :
        kata = np.floor(np.log2((p+1)/k))
        ndewaru += 2**kata
    else :
        ndewaru += 1
print(ndewaru/n)

Measured memory_bytes: 14408
#include<stdio.h>
int main(){
	int n,i;
	long int sum=0;
	int ai[10000];
	int max=-1000000;
	int min=1000000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&ai[i]);
		sum+=ai[i];
		if(ai[i]>max){
			max=ai[i];
		}
		if(ai[i]<min){
			min=ai[i];
		}
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
#define ALL(a) begin(a), end(a)
int main()
{
    int n;
    priority_queue<int, vector<int>, greater<int>> pq;
    map<int,int> mp;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (++mp[a] == 2) {
            mp[a] = 0;
            pq.push(a);
            if (pq.size() > 2)
                pq.pop();
        }
    }
    if (pq.size() != 2) {
        cout << 0 << endl;
    } else {
        int x = pq.top();
        pq.pop();
        cout << x * 1ll * pq.top() << endl;
    }
}


Measured memory_bytes: 4992
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<vector<int>>edge(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	sort(v.begin(), v.end());
	long long int ans = 0;
	queue<int>Q;
	vector<int>num(N);
	vector<int>dir(N);
	for (int i = 0; i < N; i++) {
		dir[i] = edge[i].size();
		if (dir[i] == 1)Q.push(i);
	}
	int index = 0;
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		num[cn] = v[index++];
		for (auto i : edge[cn]) {
			dir[i]--;
			if (dir[i] == 1)Q.push(i);
		}
	}
	for (int i = 0; i < N; i++) {
		for (auto j : edge[i])ans += min(num[i], num[j]);
	}
	cout << ans / 2 << endl;
	for (auto i : num)cout << i << " ";
	cout << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int N=sc.nextInt();
      int M=sc.nextInt();
      System.out.println();
      int A[]=new int[N];
      int cnt=0;
      int total=0;
      for(int i=0;i<N;i++){
         A[i]=sc.nextInt();
         total+=A[i];
      }
      for(int j=0;j<N;j++){
         if(A[j]>=(float)total/(4*M)){
            cnt++;
         }
      }
      if(cnt>=M){
         System.out.println("Yes");
      }else{
         System.out.println("No");
      }
   }
}


Measured memory_bytes: 36008
def dfs(n):
    if int(n) >= 3234566668:
        return None
    else:
        li.append(int(n))
        if n[-1] == "0":
            dfs(n + n[-1])
            dfs(n + str(int(n[-1]) + 1))
        elif n[-1] == "9":
            dfs(n + str(int(n[-1]) - 1))
            dfs(n + n[-1])
        else:
            dfs(n + str(int(n[-1]) - 1))
            dfs(n + n[-1])
            dfs(n + str(int(n[-1]) + 1))
k = int(input())
l = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
li = []
for i in l:
    dfs(i)
li.sort()
print(li[k - 1])

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int t=0;
		int b[]=new int[a-1];
		for(int i=0;i<a-1;i++) {
			int k =sc.nextInt();
			b[k-1]++;
		}
		for(int j=0;j<a-1;j++) {	
			System.out.println(b[j]);
		}
		System.out.println(0);


	}

}


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

int main() {
  int n;
  cin>>n;
  int a[200005];
  for (int i=1; i<=n; i++) {
    cin>>a[i];
    a[i]-=i;
  }
  sort(a+1,a+n+1);
  int b=a[n/2+1];
  ll ans=0;
  for (int i=1; i<=n; i++) {
    ans+=(ll)abs(a[i]-b);
  }
  cout<<ans<<endl;     
  return 0;
}

Measured memory_bytes: 1024
import sys

input = sys.stdin.readline

def main():
  n, m= map(int, input().split())

  links = [[] for x in range(n + 1)]
  sums = [0 for x in range(n + 1)]
  adds = [0 for x in range(n + 1)]

  links[0].append(1)

  buf = [map(int, input().split()) for _ in range(n - 1)]

  for link in buf:
    a, b= link
    links[a].append(b)
    links[b].append(a)


  buf = [map(int, input().split()) for _ in range(m)]
  for px in buf:
    p, x = px
    adds[p] += x

  que = [0,[1]]
  checked = [0 for x in range(n+1)]

  que = [[-1, [0]]]

  while que:
    link = que.pop()
    par = link[0]
    childs = link[1]

    for child in childs:
      if checked[child] != 1:
        sums[child] = sums[par] + adds[child]
        que.append([child, links[child]])
        checked[child] = 1


  print(*sums[1:])

if __name__ == "__main__":
  main()

Measured memory_bytes: 158596
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W,N;
	cin >> H >> W >> N;//縦、横、個数
	set<pair<int,int> > fld;
	for(int i=0;i<N;++i){
		pair<int,int> temp;
		cin >> temp.first >> temp.second;
		temp.first--;
		temp.second--;
		fld.insert( temp );
	}
	//////
	vector<LL> ans(10,0);
	set<pair<int,int> >::iterator itr,end;
	itr = fld.begin();
	end = fld.end();
	
	for(; itr != end; ++itr){
		vector< vector<bool> > box(5,vector<bool>(5,false));
		int R = itr->first;
		int C = itr->second;
		pair<int,int> temp;
		//周囲の5x5を調べる
		for(int r=0;r<5;++r){
			for(int c=0;c<5;++c){
				temp.first  = R + r -2;
				temp.second = C + c -2;
				if( fld.find(temp) != end ){
					box[r][c] = true;
				}
			}
		}
		for(int r=0;r<3;++r){
			for(int c=0;c<3;++c){
				if( R-2+r < 0 ) continue;
				if( C-2+c < 0 ) continue;
				if( R+r >= H ) continue;
				if( C+c >= W ) continue;
				int sum = 0;
				for(int r1=r;r1<r+3;++r1){
					for(int c1=c;c1<c+3;++c1){
						if( box[r1][c1] ){
							++sum;
						}
					}
				}
				ans[sum] += 1;
			}
		}
	}
	LL res = ((LL)H-2)*((LL)W-2);//全体
	for(int i=1;i<10;++i){
		res -= (ans[i]/i);
	}
	cout << res << endl;
	for(int i=1;i<10;++i){
		cout << ans[i]/i << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 4992
def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist

def get_rate(x):
    if x < 400:
        return 1
    elif x < 800:
        return 2
    elif x < 1200:
        return 3
    elif x < 1600:
        return 4
    elif x < 2000:
        return 5
    elif x < 2400:
        return 6
    elif x < 2800:
        return 7
    elif x < 3200:
        return 8
    else:
        return 9

def submit():
    n, alist = read_input()
    rates = [get_rate(a) for a in alist]

    colors = {}
    for r in rates:
        if r == 9:
            continue

        if r not in colors.keys():
            colors[r] = 1
        else:
            colors[r] += 1

    tops = [r for r in rates if r == 9]
    color_n = len(colors)

    if color_n == 0:
        # minではtopは1色に合わせる
        color_min = 1
        color_max = len(tops)
    else:
        # minではtopは既存に色を合わせる
        color_min = color_n
        color_max = color_n + len(tops)

    print('{} {}'.format(color_min, color_max))


if __name__ == '__main__':
    submit()

Measured memory_bytes: 39024
#include <stdio.h>

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

    scanf("%d %d %d", &a, &b, &c);
    if(a < b){
      if(b < c){
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    } else {
      printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> mochi(N);
    for (int i = 0; i < N; i++){
        cin >> mochi[i];
    }
    sort(mochi.begin(), mochi.end(), greater<int>());
    int top = mochi[0];
    int ans = 1;
    for(int i = 1; i < N; i++){
        if(top > mochi[i]){
            ans ++;
            top = mochi[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ht = list(map(int, input().split()))
rd = [list(map(int, input().split())) for _ in range(m)]
flg = [1] * n
for i in rd:
    if ht[i[0]-1] <= ht[i[1]-1]:
        flg[i[0]-1] = 0
    if ht[i[0]-1] >= ht[i[1]-1]:
        flg[i[1]-1] = 0
print(sum(flg))

Measured memory_bytes: 31984
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int x, y;
	char s[8001];
	scanf("%s", s);
	scanf("%d %d", &x, &y);
	
	int k, n, count[8001] = {};
	for (n = 0, k = 0; s[n] != 0; n++) {
		if (s[n] == 'F') count[k]++;
		else k++;
	}
	
	int i, j, dp[2][16001] = {};
	for (i = 0, dp[0][n] = 1; i * 2 < k; i++) {
		for (j = 0; j <= n * 2; j++) dp[1-i%2][j] = 0;
		for (j = count[i*2+1]; j <= n * 2 - count[i*2+1]; j++) {
			dp[1-i%2][j+count[i*2+1]] |= dp[i%2][j];
			dp[1-i%2][j-count[i*2+1]] |= dp[i%2][j];
		}
	}
	if (dp[i%2][n+y] == 0) {
		printf("No\n");
		fflush(stdout);
		return 0;
	}
	for (j = 0; j <= n * 2; j++) dp[1][j] = 0;
	for (i = 1, dp[1][n+count[0]] = 1; i * 2 <= k; i++) {
		for (j = 0; j <= n * 2; j++) dp[1-i%2][j] = 0;
		for (j = count[i*2]; j <= n * 2 - count[i*2]; j++) {
			dp[1-i%2][j+count[i*2]] |= dp[i%2][j];
			dp[1-i%2][j-count[i*2]] |= dp[i%2][j];
		}
	}
	if (dp[i%2][n+x] == 0) printf("No\n");
	else printf("Yes\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int n)
{
    if (n==1) return 0;
    if (n==2||n==3)
        return 1;
    if (n % 6 != 1 && n % 6 != 5)
        return 0;
    for (int i=5;i*i<=n;i+=6)
        if (n%i==0||n%(i+2)==0) return 0;
    return 1;
}
int main()
{
    int x;
    cin>>x;
    while (!is_prime(x))
    {
        x++;
    }
    cout<<x;
    return 0;
}

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

double dp[310][310][310];
int N;

double solve(int i, int j, int k){
	if(i+j+k == 0) return 0.0;
	if(dp[i][j][k] > -0.5) return dp[i][j][k];
	double p = (double)N /(i+j+k);
	double ret = 0;
	if(i){
		ret += (solve(i-1, j, k)+p)*i/(i+j+k);
	}
	if(j){
		ret += (solve(i+1, j-1, k)+p)*j/(i+j+k);
	}
	if(k){
		ret += (solve(i, j+1, k-1)+p)*k/(i+j+k);
	}
	
	dp[i][j][k] = ret;
	return ret;
}

int main(){
	int n;
	cin >> n;
	N = n;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		if(x == 1) a++;
		else if(x == 2) b++;
		else if(x == 3) c++;
	}

	for(int i = n; i >= 0; i--){
		for(int j = n; j >= 0; j--){
			for(int k = n; k >= 0; k--){
				dp[i][j][k] = -1;
			}
		}
	}
	
	double ans = solve(a, b, c);
	cout << fixed << setprecision(10) << ans << endl;
	
}

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

using namespace std;

int main()
{
	int n ;
	cin>>n; 
	vector<vector<int> >h(n, vector<int> (3));

	for( int i=0 ;i <n; i++ )
		cin>>h[i][0]>>h[i][1]>>h[i][2];

	vector<vector<int>> dp(n, vector<int> (3));
	dp[0][0] = h[0][0];
	dp[0][1] = h[0][1];
	dp[0][2] = h[0][2];

	for( int i=1 ; i<n ; i++ )
	{
		for( int j=0; j<3; j++ )
		{
			if( j==0 )
				dp[i][j] = h[i][j] + max( dp[i-1][1], dp[i-1][2] );
			if( j==1 )
				dp[i][j] = h[i][j] + max( dp[i-1][0], dp[i-1][2] );
			if( j==2 )
				dp[i][j] = h[i][j] + max( dp[i-1][0], dp[i-1][1] );
		}
	}
	
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]) );

	return 0;
}

Measured memory_bytes: 11136