akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    X = [x - A for x in X]

    base = 2500
    dp = [0] * 5001
    dp[base] = 1
    for i in range(N):
        dp, dp_prev = dp[:], dp
        for j in range(5001):
            if 0 <= j - X[i] <= 5000:
                dp[j] += dp_prev[j - X[i]]

    print(dp[base] - 1)

    return


if __name__ == '__main__':
    main()


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

#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define dprint(a,x) cout<<setprecision(x)<<fixed<<a<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef set<int> SI;
typedef set<LL> SL;
typedef set<string> SS;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef queue<int> QI;

/* Direction Array */

// int fx[]={1,-1,0,0};
// int fy[]={0,0,1,-1};
// int fx[]={0,0,1,-1,-1,1,-1,1};
// int fy[]={-1,1,0,0,1,1,-1,-1};

template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

inline LL power(LL a, LL b)
{
	LL multiply=1;
	REP(i,1,b)
	{
		multiply*=a;
	}
	return multiply;
}
inline LL ABS(LL a){return (a>=0)?a:-a;}

/*end of header*/
int n;
PII a[100001];
int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
    cin>>n;
    REP(i,1,n)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a+1,a+n+1);
    int cnt=0;
    REP(i,1,n)
    {
        if(i%2!=a[i].second%2)cnt++;
    }
    cnt/=2;
    print(cnt);
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long 
#define inf 0x7fffffff
#define infll 0x7fffffffffffffff
#define clr(c) memset(c,0,sizeof(c))
using namespace std;
int mod=998244353;
const int M=1e6+10;
const int N=3e5+10;
inline ll read(){
    ll b=1,sum=0; char c=getchar();
    while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
    while(isdigit(c)){sum=sum*10+c-'0'; c=getchar();}
    return b*sum;
}
int T,n,m,k;
int ans;
//int a[N];
int a,b,c,d;
int main()
{
    int i,j;
	ans=0;
	a=read(),b=read(),c=read(),d=read();
	int cc=0;
	while(a>0&&c>0) {
		if(cc==0) {
			c-=b;
			cc=1;
		}
		else {
			cc=0;
			a-=d;
		}
	}	
	if(a>0) printf("Yes");
	else printf("No");
	printf("\n");
    return 0;
}


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

namespace AtCoder_Cs
{
    public class Program
    {
        public static void Main()
        {
            var cnt = int.Parse(Console.ReadLine());
            var lst = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Array.Sort(lst);
            Array.Reverse(lst);

            int A = 0;
            int B = 0;

            for (int i = 0; i <= lst.Count()- 1; i++)
            {
                if (i % 2 == 0)
                {
                    A += lst[i];
                }
                else
                {
                    B += lst[i];
                }
            }

            Console.WriteLine($"{A - B}");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*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;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a < b * 2 ? 0 : a - b * 2) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter, deque

INF = float('inf')
weekly = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']


def main():
    S = input().rstrip()
    index = weekly.index(S)
    print(-(index - len(weekly)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;








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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

map<int, int> p, q;
set<int> s;

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		int a; scanf("%d", &a);
		p[i-a]++;
		q[i+a]++;
		s.emplace(i-a);
		s.emplace(i+a);
	}
	ll ans = 0;
	for(int a : s) ans += 1LL * p[a] * q[a];
	printf("%lld\n", ans);
}


Measured memory_bytes: 54856
#include<bits/stdc++.h>
using namespace std;
int minn,maxx;
map<string,int>a;
string s[8]={"hui","zong","lv","qing","lan","huang","cheng","hong"}; 
int main()
{
	int n;
	bool v=false,v1=false;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(x<400)
		{
			a["hui"]++;
			continue;
		}
		if(x<800)
		{
			a["zong"]++;
			continue;
		}
		if(x<1200)
		{
			a["lv"]++;
			continue;
		}
		if(x<1600)
		{
			a["qing"]++;
			continue;
		}
		if(x<2000)
		{
			a["lan"]++;
			continue;
		}
		if(x<2400)
		{
			a["huang"]++;
			continue;
		}
		if(x<2800)
		{
			a["cheng"]++;
			continue;
		}
		if(x<3200)
		{
			a["hong"]++;
			continue;
		}
		if(x>3199)
		{
			a["tql"]++;
			v1=true;
			continue;
		}
	}
	for(int i=0;i<=7;i++)
	{
		if(a[s[i]]!=0) minn++,maxx++;
	}
	if(v1==true&&minn>0)
		maxx+=a["tql"];
	if(v1==true&&minn==0)
		minn=1,maxx=a["tql"];
	cout<<minn<<" "<<maxx<<endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
    while 1:
        N, M = list(map(int, input().split(" ")))
        if M < 2:
            print(0)
        elif M >= 2 * N:
            print(N + (M - 2 * N) // 4)
        elif M < 2 * N:
            print(M // 2)

        break


solve()

Measured memory_bytes: 2940
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl;
#define DPUT(x) printf("%.15lf\n",x);;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, bool>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };



int main(void) {

	int n;
	cin >> n;
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		m[t]++;
	}

	int answer = 0;

	for (auto t : m) {
		if(t.first <= t.second){
			answer += t.second - t.first;
		}
		else {
			answer += t.second;
		}

	}

	cout << answer << endl;


}

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

int main(){
	string S;
	cin >> S;
	bool flg = true;
	if(S[2] != S[3])
		flg = false;
	if(S[4] != S[5])
		flg = false;
	cout << (flg?"Yes":"No") << endl;

	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define pb push_back 
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(v) (int((v).size()))
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 5e5+5;
int main(){
	int n;
	cin >> n;
	vector<pair<int,int> > arr(n);
	for(int i = 0; i < n; ++i){
		cin >> arr[i].first;
		arr[i].second = i;
	}
	sort(all(arr));
	int chain = 1;
	int max_chain = 1;
	for(int i = 1; i < n; ++i){
		if(arr[i].second > arr[i-1].second)
			++chain;
		else
			chain = 1;
		max_chain = max(max_chain,chain);
	}
	cout << n - max_chain << '\n';
}



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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int64_t> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	int64_t ans = 0;
	sort(vec.begin(), vec.end());
	if (M >= N) {
		cout << 0 << endl;
		return 0;
	}
	else{
	for (int i = 0; i < N-M; i++) {
		ans = ans + vec.at(i);
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 1792
N = int(input())
cntA, cntB, cntBoth, ans = 0, 0, 0, 0

for i in range(N):
    s = input()
    L = len(s)
    if s[0] == 'B':
        cntB += 1
    if s[L-1] == 'A':
        cntA += 1
    if s[0] == 'B' and s[L-1] == 'A':
        cntBoth += 1
    for i in range(L-1):
        if s[i:i+2] == 'AB':
            ans += 1
# print(ans, cntA, cntB, cntBoth)
ans += min(cntA, cntB)
if cntA == cntB and cntA == cntBoth and cntBoth > 0:
    ans -= 1
print(ans)


Measured memory_bytes: 3064
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)

ans = "APPROVED"
A.each do |a|
  if a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)
    ans = "DENIED"
  end
end

puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	int N;
	cin >> N;
	int a = 1000000009,ind=0;
	FOR(i,0,N){
		int k;
		cin >> k;
		if(k<a){
			a = k;
			ind = i+1;
		}
	}
	cout << ind << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int n;
  cin >> n ;
  vl a(n);
  rep(i,n) cin >> a[i];
  vl s(n+1,0);
  rep(i,n){
    s[i+1] += (s[i]+a[i])%mod;
    s[i+1]%=mod;
  }
  mint ans = 0;
  rep(i,n-1){
    ans+=a[i]*(s[n]-s[i+1]);
  }
  cout<<ans.x<<endl;
  return 0;
}

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

#define BIGNUM 1000000007

long long calcP(int num) {
  long long ans=1;
  for (int i=2; i<=num; i++) {
    ans *= i;
    ans %= BIGNUM;
  }

  return ans;
}

int main() {
  int n, m;
  cin >> n >> m;
  if (abs(n-m) >= 2) {
    printf("0\n");
    return 0;
  }

  long long permN = calcP(n);
  long long permM = calcP(m);
  if (abs(n-m) == 1) {
    cout << permN*permM%BIGNUM << endl;
    return 0;
  }

  cout << 2*permN*permM%BIGNUM << endl;

  return 0;
}


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

// macro
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ll unsigned long long
#define FOR(i, m, n) for(ll i = m;i < n;i++)

using namespace std;

// Factorial
// need init
ll factorial_memo[5001];
ll factorial(ll n) {
  factorial_memo[0] = 1;
  if(factorial_memo[n] != -1) return factorial_memo[n];
  factorial_memo[n] = (factorial(n-1) * n) % MOD;
  return factorial_memo[n];
}

// Combination(nCr)
// need init
ll nCr_memo[5001][5001];
ll nCr(ll n, ll r) {
  if(r*2 > n) r = n-r;
  if(r == 1) return n;
  if(r == 0) return 1;
  if(nCr_memo[n][r] != -1) return nCr_memo[n][r];
  nCr_memo[n][r] = (nCr(n-1, r) + nCr(n-1, r-1)) % MOD;
  return nCr_memo[n][r];
}

void solve() {
  string s;
  cin >> s;
  int i = s.size() - 8;
  cout << s.substr(0, i) << "\n";
}

int main() {
  // init
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


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

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
        return gcd(b, a%b);
    }
}
int main(void){
    int n, x[100000+5];
    scanf("%d", &n);
    scanf("%d", &x[n]);
    for(int i=0; i<n; i++)scanf("%d", x+i);
    qsort(x, n+1, sizeof(int), compare_int);
    int ans=x[1]-x[0];
    for(int i=2; i<n+1; i++){
        ans=gcd(ans, x[i]-x[i-1]);
    }
    printf("%d\n", ans);
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'

int main()
{
    fastio;
    int n;
    cin>>n;
    vinput(a,n-1);
    vector<int> ans(n);
    rep(i,n-1,0)ans[a[i]-1]++;
    rep(i,n,0)cout<<ans[i]<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N,M; cin >> N >> M;
    vector<bool> f(N+1,false);

    ll ac = 0, pn = 0;
    vector<int> lp(M);
    vector<string> lS(M);
    vector<bool> is_ac(N+1,false);
    for (int i = 0;i < M;i++){
        cin >> lp[i] >> lS[i];
        if(lS[i] == "AC") is_ac[lp[i]] = true;
    }

    for (int i = 0;i < M;i++){
        ll p; string S;
        p = lp[i];
        S = lS[i];
        if(S == "WA"){
            if(!f[p] && is_ac[p]) pn++;
        }else{
            if(!f[p]){ ac++; f[p] = true;}
        }
    } 

    cout << ac << " " << pn << endl;

    return 0;

}

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

int f(int n){
    int res = 0;
    for(;n;n/=10)res += (n % 10);
    return res;
}

int main(){

    int N;
    cin>>N;
    int ans = f(1) + f(N - 1);
    for(int a=1;a<N;a++){
        ans = min(ans, f(a) + f(N-a));
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int c = 0;
    for(int i = 0;i<n;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      c += b - a + 1;
    }
    System.out.println(c);
  }
}


Measured memory_bytes: 24168
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

N,M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def dfs(i, visited):
    if all(visited):
        return 1
    total = 0
    for ni in graph[i]:
        if not visited[ni]:
            nvisited = visited[:]
            nvisited[ni] = True
            total += dfs(ni,nvisited)
    return total


def main():
    """ main """
    visited = [False]*N
    visited[0] = True
    print(dfs(0, visited))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
/**
 * @Author:      WeakestRookie
 * @Email:       1311053296@qq.com
 * @DateTime:    2019-05-19 20:41:30
 * @Description: Description 
 */
#include<bits/stdc++.h>
using namespace std;

#define rep(x, y, z) for(int x = y; x < z; ++x)
#define dwn(x, y, z) for(int x = y; x >= z;--x)
#define mst(a, b) memset(a, b, sizeof(a));
#define clr(a) mst(a, 0);
#define lbit(x) (x & (-x))
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;

const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
const int maxn = 1e5+10;

int head[maxn],nex[maxn*2],ver[maxn*2];
ll edge[maxn*2];
int tot;

void add(int x,int y,ll z){
	ver[++tot] = y,edge[tot] = z;
	nex[tot] = head[x],head[x] = tot;
}

bool t[maxn];

void dfs(int x,int fa,int f){
	for(int i = head[x];i;i = nex[i]){
		int y = ver[i];
		if(y == fa) continue;
		int vv = f;
		if(edge[i]&1) vv ^= 1;
		t[y] = vv;
		dfs(y,x,vv);
	}
}

int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;cin >> n;
	int x,y,z;
	for(int i = 0;i < n-1;i++){
		cin >> x >> y >> z;
		add(x,y,z);
		add(y,x,z);
	}
	t[1] = 0;
	dfs(1,0,0);
	for(int i = 1;i <= n;i++)
		cout << t[i] << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

ll hist[110000];
vector<P> sushi;
int main()
{
  ll N, K;
  cin >> N >> K;
  REP(i, N) {
    ll t, d; cin >> t >> d;
    sushi.PB(MP(d, t));
  }
  sort(ALL(sushi), greater<P>());

  ll sum = 0, x = 0;
  REP(i, K) {
    if (hist[sushi[i].SE] == 0) x++;
    hist[sushi[i].SE]++;
    sum += sushi[i].FI;
  }
  ll ans = sum + x*x;

  // 2個以上あるネタをpushする
  priority_queue<P, vector<P>, greater<P>> pq1;
  REP(i, K) {
    if (hist[sushi[i].SE] >= 2) pq1.push(sushi[i]);
  }

  // 手持ちにないネタをpushする
  priority_queue<P> pq2;
  for (int i = K; i < N; i++) {
    if (hist[sushi[i].SE] == 0) pq2.push(sushi[i]);
  }

  while (1) {
    if (pq2.empty()) break;
    P e2 = pq2.top(); pq2.pop();
    while (!pq2.empty() && hist[e2.SE] > 0) {
      e2 = pq2.top();
      pq2.pop();
    }
    if (hist[e2.SE] > 0) break;
    hist[e2.SE]++;

    if (pq1.empty()) break;
    P e1 = pq1.top(); pq1.pop();
    while (!pq1.empty() && hist[e1.SE] == 1) {
      e1 = pq1.top();
      pq1.pop();
    }
    if (hist[e1.SE] == 1) break;
    hist[e1.SE]--;

    sum = sum - e1.FI + e2.FI;
    x++;
    ans = max(ans, sum + x*x);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5744
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
D = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i * j * k > K:
                break
            D.append(A[i] + B[j] + C[k])
D.sort(reverse=True)
for ans in D[:K]:
    print(ans)


Measured memory_bytes: 135868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 1e18
int main()
{
	ll n,p;
	string s;
	cin>>n;
	char u;
	while(n!=0)
	{
	    n--;
	    p=n%26;
		u=(char)(p+65);
	    s=u + s;
		n=n/26;
	}
	for(int i=0;i<s.length();i++)
	{
		s[i]=s[i]+32;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 3628
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] c = new int[10][10];
		for(int i = 0; i < 10; i++)
			for(int j = 0; j < 10; j++)
				c[i][j] = sc.nextInt();
		
		for(int k = 0; k <= 9; k++)
			for(int i = 0; i <= 9; i++)
				for(int j = 0; j <= 9; j++)
					if(c[i][k] + c[k][j] < c[i][j]) c[i][j] = c[i][k] + c[k][j];
		
		long ans = 0;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				int A = sc.nextInt();
				if(A != -1) ans += c[A][1];
			}
		}
		
		System.out.println(ans);
	}
	
}

class Pair{
	int vertex;
	int cost;
	public Pair(int v, int c){
		vertex = v;
		cost = c;
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23124
n = gets.chomp.to_i
arr = []
n.times do |i|
    a = gets.chomp.to_i
    arr << a
end
i = 1
kazu = Array.new(n-1,0)
kazu.unshift(1)
count = 0
while true
    i = arr[i-1] #このiは次光るボタン(i)
    if kazu[i-1] == 0 && i != 2
        kazu[i-1] += 1
        count += 1
    else
        if i == 2
            count += 1
            puts count
            break
        else
            puts "-1"
            break
        end
    end
end

Measured memory_bytes: 16472
// Author - Sumit 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx")
 
#define ll long long 
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
 

void solve(){
	int n,m;
    cin>>n>>m;
    int x=n/m;
    int mm=(x*m);
    int ans = abs(mm-n);
    ans=min(m-ans,ans);
    debug(ans);
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);



    clock_t clk=clock();
    
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    cerr<<((long double)(1.00*clock()-clk)/CLOCKS_PER_SEC)<<"\n";
}

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

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	int n, f = 0, i;

	cin >> n;
	for (i = n; i != 0; i /= 10) {
		f += i % 10;
	}
	if (n % f == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main(int argc, char *argv[]){
  int N,M;
  cin>>N>>M;
  vector<int> A(N);
  int a;
  for(int i=0; i<N; i++){
    cin>>a;
    A[i]=a;
  }
  sort(A.begin(),A.end());
  int b,c;
  map<int,int> cb;
  for(int i=0; i<M; i++){
    cin>>b>>c;
    if(cb.count(c)){
      cb[c]+=b;
    }
    else{
    cb.insert(make_pair(c,b));
    }
  }
  int index=0;
  for(auto itr=cb.rbegin();itr!=cb.rend(); itr++){
    int m=itr->second;
    int value=itr->first;
    
    for(int j=index,k=0;k<m; k++){
      if(A[index]<value){
	A[index++]=value;
      }
      else break;
    }
    // sort(A.begin(),A.end());
  }
  long long sum=0;
  for(int i=0; i<N; i++){
    //cout<<A[i]<<endl;
    sum+=A[i];
  }
  cout<<sum<<endl;
}

	      


Measured memory_bytes: 5376
#include <cstdio>

int pn = 1;
long long prm[1000007];
void make_prime(void) {
  prm[0] = 2;
  for(int i=3;i<1000003;i+=2) {
    int is_prime=1;
    for(int j=0;j<pn;j++) {
      if(i % prm[j] == 0) {
		is_prime=0;
        break;
      }
      if(prm[j]*prm[j] > i) break;
    }
	if(is_prime) prm[pn++] = i;
  }
}
int main() {
  int N;
  long long P;
  scanf("%d%lld",&N,&P);
  if(N==1) {
    printf("%lld\n", P);
    return 0;
  }
  make_prime();
  long long sol=1;
  for(int i=0;i<pn;i++) {
    int cnt = 0;
    while(P % prm[i] == 0) {
      P /= prm[i];
      cnt++;
    }
    for(int j=0;j<(cnt/N);j++) sol *= prm[i];
  }
  printf("%lld\n", sol);
  return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();

        List<Integer> list = new ArrayList<>();

        for (int i = A; i < A + K && i <= B; i++) {
            list.add(i);
        }

        for (int i = B; i > B - K && i >= A; i--) {
            if (list.contains(i)) continue;

            list.add(i);
        }

        Collections.sort(list);

        for (int i : list) {
            System.out.println(i);
        }
    }
}

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



class list {
public:
    int val;
    list* prev;
    list* next;
};
list* nil;

void initialize()
{
    nil = new list;
    nil->prev = nil;
    nil->next = nil;
}

void insert_(int val)
{
    list* p = new list;
    p->val = val;
    p->prev = nil;
    p->next = nil->next;
    p->next->prev = p;
    p->prev->next = p;
}

list* search(int val)
{
    for (list* p = nil->next; p != nil; p = p->next) {
        if (p->val == val) return p;
    }
    return nil;
}

void delete_(list* p)
{
    if (p == nil) return;
    p->prev->next = p->next;
    p->next->prev = p->prev;
    delete p;
}


void trace()
{
    for (list* p = nil->next; p != nil; p = p->next) {
        cout << p->val;
        if (p->next != nil) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}

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

    list* head;

    for (int i = 0; i < n; i++) {
        string command;
        cin >> command;
        if (command == "deleteFirst") {
            delete_(nil->next);
            continue;
        }
        if (command == "deleteLast") {
            delete_(nil->prev);
            continue;
        }
        int val;
        cin >> val;
        if (command == "insert") {
            insert_(val);
        } else {
            delete_(search(val));
        }
    }
    trace();
}

Measured memory_bytes: 34428
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr ll INF = 1e18 + 10;
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;
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

vector<pair<ll, ll>> primeFactorize(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0;

        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }

    if (N != 1)
        res.push_back({N, 1});
    return res;
}

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

    int s;
    cin >> s;
    vector<bool> f(1000000, false);
    f[s] = true;
    int count = 1;
    while (true)
    {
        count++;
        if (s % 2 == 0)
        {
            s /= 2;
            if (f[s])
            {
                break;
            }
        }
        else
        {
            s = 3 * s + 1;
            if (f[s])
            {
                break;
            }
        }
        f[s] = true;
    }
    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
const int q=1000000007;
int n,f[1000010],s[1000010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%d",&n);
	f[0]=1;
	f[1]=n;
	s[0]=1;
	s[1]=n+1;
	for(i=2;i<=n;i++)
	  {
	   f[i]=(f[i-1]+(i>=3?s[i-3]:0)+(L)(n-1)*(n-1)+n-i+1)%q;
	   s[i]=(s[i-1]+f[i])%q;
	  }
	printf("%d\n",f[n]);
	return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef vector<ll> Vl;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


ll x, y, a, b, c, acnt, bcnt, ccnt, ans;
Pll p[300005];

int main() {

	cin >> x >> y >> a >> b >> c;
	rep(i, a) {
		ll tmp;
		cin >> tmp;
		p[i] = make_pair(tmp, 1);
	}
	rep(i, b) {
		ll tmp;
		cin >> tmp;
		p[i + a] = make_pair(tmp, 2);
	}
	rep(i, c) {
		ll tmp;
		cin >> tmp;
		p[i + a + b] = make_pair(tmp, 3);
	}

	sort(p, p + (a + b + c));
	reverse(p, p + (a + b + c));

	rep(i, a + b + c) {
		if (x + y == acnt + bcnt + ccnt) {
			break;
		}
		else {
			if (p[i].second == 1) {
				if (acnt < x) {
					ans += p[i].first;
					acnt++;
				}
			}
			else if (p[i].second == 2) {
				if (bcnt < y) {
					ans += p[i].first;
					bcnt++;
				}
			}
			else {
				ans += p[i].first;
				ccnt++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n, m, k;
    cin >> n >> m >> k;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i * j + (n - i) * (m - j) == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
<?php
$N = trim(fgets(STDIN));
$restaurants = [];
for($i=0; $i<$N; $i++){
	$restaurant = explode(" ", fgets(STDIN));
	$restaurants[] = $restaurant;
}

function compare($a1, $a2){
	if($a1[0]!==$a2[0]){
		$ret = strcmp($a1[0], $a2[0]) < 0 ? -1 : 1;
	}else{
		$ret = strnatcmp($a1[1], $a2[1]) < 0 ? 1 : -1;
	}
	return $ret;
}

uasort($restaurants, "compare");
foreach ($restaurants as $key => $value) {
	echo $key+1 . "\n";
}
?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
int n;
const int maxN = (int)1e6 + 10;
int a[maxN];
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin >> n;
    vector < pair < int, int > > all;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        all.emplace_back(a[i], i);
    }
    sort(all.begin(), all.end());
    reverse(all.begin(), all.end());
    set < int > s;
    s.insert(0);
    s.insert(-1);
    s.insert(n + 1);
    s.insert(n + 2);
    ll ans = 0;
    for (auto it : all) {
        int ind = it.second;
        auto it1 = s.lower_bound(ind);
        auto it2 = it1;
        it2--;
        int pos2 = *it2;
        it2--;
        int pos1 = max(*it2, 0);
        int pos3 = *it1;
        ++it1;
        int pos4 = min(*it1, n + 1);
        s.insert(ind);
        if (pos2 == 0 && pos3 == n + 1) continue;
        ans += 1LL * a[ind] * (pos4 - pos3) * (ind - pos2) + 1LL * a[ind] * (pos2 - pos1) * (pos3 - ind);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6132
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
  int n; cin >> n;
  vector<long long> a(n);
  long long sum_all = 0, sum_part = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum_all += a[i];
  }

  long long min_ = 100000000000;
  for(int i = 0; i < n - 1; i++) {
    sum_part += a[i];
    long long k = abs(sum_all - 2 * sum_part);
    min_ = min(min_, k);
  }
  cout << min_ << endl;
}


Measured memory_bytes: 1792
s=input()
count=0
if s[0]=='A' and s[1].islower() and s[-1].islower():
  for i in range(len(s)-2):
    if s[i+1].isupper():
      count+=1
    else:
      continue
  if count==1 and 'C' in s:
    print('AC')
  else:
    print('WA')
else:
  print('WA')

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

int main(void) {
    int N;
    cin >> N;
    int h[N];
    REP(i, N) {
        cin >> h[i];
    }

    int ans = 0;
    REPS (i, 100) {
        bool flg = false;
        REP (j, N) {
            if (i <= h[j]) { 
                flg = true;
            }
            if (i > h[j]) {
                if (flg) {
                    ans++;
                }
                flg = false;
            }
        }
        if (flg) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n, m, r = gets.strip.split.map(&:to_i)
r = gets.strip.split.map(&:to_i)

roads = Array.new(n+1) { [10**8]*(n+1) }

readlines.each do |line|
  a, b, c = line.strip.split.map(&:to_i)
  roads[b][a] = roads[a][b] = c
end

(1..n).each do |via|
  (1..n).each do |from|
    (1..n).each do |to|
      next if from==to
      cc = roads[from][via] + roads[via][to]
      roads[from][to] = cc if cc < roads[from][to]
    end
  end
end

def all_route_cost(current, nexts, roads, cc)
  return cc if nexts.empty?
  nexts.map {|e| 
    all_route_cost(e, nexts-[e], roads, roads[current][e] + cc)
  }.min
end

p r.map{|e| all_route_cost(e, r-[e], roads, 0) }.min



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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n;
	cin>>n;
	string s;
	cin>>s;
	if(n&1){
		cout<<"No";
	}
	else{
		int f=0;
		long long int i,j;
		for(i=0,j=n/2;i<n/2,j<s.size();i++,j++){
			if(s[i]!=s[j]){
				f=1;
				break;
			}
		}
		if(f==0){
			cout<<"Yes";
		}
		else{
			cout<<"No";
		}
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define nl "\n"
#define llong long long
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(s)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define PI 3.1415926

using namespace std;

const int MXN = 1e5 + 7;
const long long MOD = 1e9 + 7;
const int N = 1e5;
const long long INF = 1e18 + 1;

int main() {

    naj;
    //freopen("(a).in", "r", stdin);
    //freopen("(a).out", "w", stdout);
    int a, b, c = 3;
    cin >> a >> b;
    if((a * b * c) % 2 == 1) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int a[maxn*3];

int main(){
	int n = read();
	for(int i=0; i<3*n; i++)
		a[i] = read();

	sort(a,a+3*n);

	int cnt = 0;
	ll sum = 0;
	for(int i=3*n-2; i>=0; i-=2){
		sum += a[i];
		cnt++;
		if(cnt == n) break;
	}

	cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    string s;
    cin>>n>>k>>s;
    char x=s[k-1];
    x=tolower(x);
    s[k-1]=x;
    cout<<s<<endl;
}

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

#include <atcoder/all>

// #LIB#

using namespace std;
using namespace atcoder;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#ifdef ONLINE_JUDGE
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');
#endif

int main() {
  ll k;
  cin >> k;
  rep(i, k) cout << "ACL";
  cout << endl;
}


Measured memory_bytes: 3708
n=int(input())
a=list(map(int,input().split()))
d=[]
while a:
  f=True
  for i in range(len(a)):
    if a[-i-1]==len(a)-i:
      d=[len(a)-i]+d
      a[len(a)-i-1:]=a[len(a)-i:]
      f=False
      break
  if f:
    break
if a:
  print(-1)
else:
  for i in d:
    print(i)

Measured memory_bytes: 63920
import sys
from itertools import groupby


def input():
    return sys.stdin.readline()[:-1]


def solve():
    N = int(input())
    P = list(map(int, input().split()))
    m = float('inf')
    ans = 0
    for p in P:
        if p <= m:
            ans += 1
        m = min(m, p)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 25248