akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef pair<long long, long long>pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 100050;
const double pi = acos(-1); constexpr double EPS = 1e-12;
constexpr ll INF = 1e16;
void yes(bool c) { if (c)print("Yes"); else print("No"); };


int dp[200010][70];
int nxt[200010];
void solve() {
	int N, K; cin >> N >> K;
	REP(i, N) {
		cin >> nxt[i];
		nxt[i]--;
	}
	REP(i, N) {
		dp[i][0] = nxt[i];
	}
	REP(k, 61) {
		REP(i, N) {
			dp[i][k + 1] = dp[dp[i][k]][k];
		}
	}
	int now = 0;
	REPR(i, 60) {
		if (K&(1LL << i)) {
			now = dp[now][i];
		}
	}
	print(now + 1);
}

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



Measured memory_bytes: 114608
n=int(input())
txy = [list(map(int,input().split())) for _ in range(n)]
f=0
for i in range(n):
    if(txy[i][0]<txy[i][1]+txy[i][2] or txy[i][0]%2!=(txy[i][1]+txy[i][2])%2):
        f=1
        print("No")
        break
if f==0:
    print("Yes")

Measured memory_bytes: 60120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n=0;
  int frag=0;
  cin >> n;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
      cin >> vec.at(i);
  }
  
  for (int i = 0; i < n; i++) {
      if(vec.at(i)%2==0){
          if(vec.at(i)%3!=0 && vec.at(i)%5!=0){
              frag=1;
          }
      }
  }
  
  if(frag==1){
      cout<<"DENIED"<<endl;
  }
  else{
      cout<<"APPROVED"<<endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int N;
	int s[101]={};
	ll sum=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>s[i];
		sum+=s[i];
	}
	sort(s,s+N);
	if(sum%10){
		cout<<sum<<endl;
		return 0;
	}
	else{
		for(int i=0;i<N;i++){
			if(s[i]%10){
				cout<<sum-s[i]<<endl;
				return 0;
			}
		}
		cout<<0<<endl;
		return 0;
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;

int h,w;
char a[55][55];
int b[55][55];

int main(){
  //  freopen("test.txt","r",stdin);
    cin >> h >> w;

    for (int i =1 ; i <= h ; i++) {
        for (int j =1 ; j <= w; j++) {
            cin >> a[i][j];
            if ( a[i][j] == '#') {
                b[i+1][j]++;
                b[i-1][j]++;
                b[i][j+1]++;
                b[i][j-1]++;
                b[i+1][j+1]++;
                b[i+1][j-1]++;
                b[i-1][j-1]++;
                b[i-1][j+1]++;
            }
        }
    }

    for (int i =1 ; i <= h ; i++) {
        for (int j =1 ; j <= w; j++) {
            if ( a[i][j] == '#') {
               cout << a[i][j];
            } else {
                cout << b[i][j];
            }
        }
        cout << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



#define MX 12820

int main() {

    int h,w;
    scanf("%d %d",&h,&w);
    vvi a(h,vi(w)),b(h,vi(w)),ab(h,vi(w));
    rep(i,h)rep(j,w){
        scanf("%d",&a[i][j]);
    }
    rep(i,h)rep(j,w){
        scanf("%d",&b[i][j]);
        ab[i][j]=abs(a[i][j]-b[i][j]);
    }
    vector<vector<bitset<2*MX>>> dp(h+1,vector<bitset<2*MX>>(w+1));

    dp[0][0][MX+ab[0][0]]=1;
    dp[0][0][MX-ab[0][0]]=1;
    rep(i,h){
        rep(j,w){
            if(i+1<h)dp[i+1][j] |= dp[i][j] << ab[i+1][j];
            if(i+1<h)dp[i+1][j] |= dp[i][j] >> ab[i+1][j];
            if(j+1<w)dp[i][j+1] |= dp[i][j] << ab[i][j+1];
            if(j+1<w)dp[i][j+1] |= dp[i][j] >> ab[i][j+1];
        }
    }
    int ans=INF;
    rep(i,MX*2){
        if(dp[h-1][w-1][i])chmin(ans,abs(i-MX));
    }
    fin(ans);
}


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

int n;
double D;

int main(){
	cin >> n >> D;
	int cnt = 0;
	rep(i, n){
		double x, y;
		cin >> x >> y;
		if(sqrt(x*x + y*y) <= D) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"::"<<x<<endl;
using namespace std;
#define maxi 1e18+10;
typedef long long ll;

void solve()
{
	ll n,w;
	cin>>n>>w;
	vector<ll>wt(n);
	vector<ll>val(n);
	for(ll i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	ll y=n*1000+1;
	vector<vector<ll> >dp(n+1,vector<ll>(y));
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<y;j++)
		{
			dp[i][j]=maxi;
		}
	}
	for(ll i=0;i<=n;i++)
	{
		dp[i][0]=0;
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<y;j++)
		{
			if(j>=val[i-1])
				dp[i][j]=min(dp[i-1][j-val[i-1]]+wt[i-1],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}

	ll final_ans=0;
	for(ll i=y-1;i>=0;i--)
	{
		if(dp[n][i]<=w){
			final_ans=i;
			break;
		}
	}
	cout<<final_ans<<'\n';
}

int main()
{
	int t;
	t=1;
	while(t--)
		solve();
	return 0;
}

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

pair<int, int> x[111111];
int d[111111];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        x[i] = {a + b, b};
    }
    sort(x, x + n);
    for(int i = 0; i < n; i++) {
        int k = lower_bound(
                    x, x + n,
                    make_pair(x[i].first - x[i].second * 2 + 1, (int)-2e9)) -
                x;
        d[i + 1] = max(d[i], d[k] + 1);
    }
    cout << d[n] << endl;
    return 0;
}


Measured memory_bytes: 1408
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result}

const main = ()=>{
  let [H,W,h,w] = [...nrin(4)];
  out((H-h)*(W-w));
}
main();

Measured memory_bytes: 7372
<?php
$N = trim(fgets(STDIN));

for($i=0; $i<$N; $i++) {
    $four = 4 * $i;

    for($j=0; $j<$N; $j++) {
        $seven = 7 * $j;

        if(($four + $seven) == $N) {
            echo 'Yes';
            exit;
        }
    }
}

echo 'No';


Measured memory_bytes: 4604
def main():
  num = [str(input()) for i in range(3)]
  turn = 0

  while True:
    if len(num[turn])==0 :
      if turn==0:
        print('A')
      elif turn==1:
        print('B')
      else:
        print('C')
      break
    if num[turn][0]=='a':
      next_turn=0
    elif num[turn][0]=='b':
      next_turn=1
    else:
      next_turn=2
    num[turn]=num[turn][1:]
    turn=next_turn
    
main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
 

int main() {
    int ans,n,s;
    ans=0;

    
   
    
   
       cin>>n>>s;
       

    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            
                if(0<=s-(i+j)&&s-(i+j)<=n) ans++;
            
             
       
         }
   }
   
   

    cout<<(ans)<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stdio.h>
#include <string.h>

#define rep(i, n) for (int i = 0; i < n; ++i)
typedef unsigned long long ll;

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

const int maxn=2e5+5,mod=1e9+5;

typedef long long ll;


int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i,a[maxn];
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int minc=a[1],ans=1;
        for(i=2;i<=n;i++)
        {
            if(a[i]<minc)
            {
                ans++;
                minc=a[i];
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/python3


(n, k, c) = map(int, input().split())
s = input()

#forward pattern
fp = []
idx = 0
while idx < n and len(fp) < k:
    if s[idx] == 'o':
        fp.append(idx + 1)
        idx += c
    idx += 1
    
#reverse pattern
rp = []
idx = n - 1
while 0 <= idx and len(rp) < k:
    if s[idx] == 'o':
        rp.append(idx + 1)
        idx -= c
    idx -= 1

if len(fp) < k or len(rp) < k:
    print('wrong case')
    exit()

fp.sort()
rp.sort()
    
for i in range(k):
    if fp[i] == rp[i]:
        print(fp[i])

Measured memory_bytes: 20604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
const int INF=2e9;
const int maxv= 100000+10;
int V;
struct Edge{int to,cost;};
vector<Edge> g[maxv];
int d[maxv];
typedef pair<int,int> P;

void dijkstra(int s)
{
    fill(d,d+V,INF);
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,s));
    d[s]=0;
    while(!que.empty())
    {
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<g[v].size();i++)
        {
            Edge &e=g[v][i];
            if(d[v]!=INF&&d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }

    }

}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&V);
    int u,v,cost;
    while(~scanf("%d%d%d",&u,&v,&cost))
    {
        g[u].push_back((Edge){v,cost});
         g[v].push_back((Edge){u,cost});
    }
    dijkstra(0);
    int target=0;
    int res=0;
    for(int i=0;i<V;i++)
    {
        if(d[i]==INF) continue;
        if(d[i]>res)
        {
            res=d[i];
            target=i;
        }
    }

    dijkstra(target);
    res=0;
    for(int i=0;i<V;i++)
    {
        if(d[i]==INF) continue;
        res=max(res,d[i]);
    }
    printf("%d\n",res);
    return 0;

}

Measured memory_bytes: 9888
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <iostream>
#include <map>
using namespace std;
int main() {
	string s;
	cin >> s;
	long long int a, b, c;
	a = s.size();
	b = 1000, c = -1;
	for (int i = 0; i < a; i++) {
		if (s[i] == 'C') {
			b = i;
			break;
		}
	}
	for (int i = a - 1; i >= 0; i--) {
		if (s[i] == 'F') {
			c = i;
			break;
		}
	}
	if (b < c)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = ll;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n; cin >> n;
    ll ans = 1;
    eFOR(i, 1, n)(ans *= i) %= mod;
    cout << ans << "\n";
}

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

int main()
{
  int64_t ans = 0, H;
  int64_t func(int64_t H);
  
  cin >> H;
  ans = func(H);
  cout << ans << endl;
  return 0;
}

int64_t func(int64_t H){
  if(H != 1){
    H /= 2;
    return 2*func(H) + 1;
  }else{
    return 1;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    string s;
    cin >> s;
    vector<string> strs = {"maerd", "remaerd", "esare", "resare"};
    reverse(all(s));
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        string ss = "";
        bool judge = 0;
        int cnt = 0;
        while (i < s.size() && cnt <= 7) {
            ss += s[i];
            cnt++;
            i++;
            if (cnt == 5) {
                if (ss == strs[0] || ss == strs[2]) {
                    judge = 1;
                    break;
                }
            }
            if (cnt == 6) {
                if (ss == strs[3]) {
                    judge = 1;
                    break;
                }
            }
            if (cnt == 7) {
                if (ss == strs[1]) {
                    judge = 1;
                    break;
                }
            }
        }
        i--;
        if (!judge) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3760
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};

// [NOTE] つかうときには trim() 入れないと RE になるので注意
// abcde
fn read_as_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}

// -3.2
fn read_as_primitive<T: FromStr>() -> T {
    let s = read_as_line();
    s.trim().parse().ok().expect("failed to parse input")
}

// 1 -3 0 999
fn read_as_collection<U: FromStr, T: FromIterator<U>>() -> T {
    let s = read_as_line();
    s.trim().split_whitespace().map(|s| s.parse().ok().expect("failed to parse")).collect()
}

// #.#.###..
fn read_as_chars<T: FromIterator<char>>() -> T {
    let s = read_as_line();
    s.trim().chars().collect()
}

// 1 abc
fn read_as_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let s = read_as_line();
    let mut it = s.trim().split_whitespace();
    (
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
    )
}

// 1.5 -2 abc
fn read_as_triple<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let s = read_as_line();
    let mut it = s.trim().split_whitespace();
    (
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
    )
}

// Sorting ParitialOrd primitives like f64
// let mut v: Vec<f64> = vec![0.1, 1.0, 2.0];
// v.sort_by_key(|&x| Total(x));
// 
// src: https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e
//      https://github.com/rust-lang/rust/pull/53938
//
#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}


fn main() {
    let (n, d): (i64, i64) = read_as_pair();
    let mut ans = (n + 2 * d)/ (2 * d + 1);
    println!("{}", ans);

}

Measured memory_bytes: 4352
/*Enter your code here. Read input from STDIN. Print your output to STDOUT*/
#include <iostream>
using namespace std;
#include<vector>
int main()
{
	int n;
	cin >> n;
	vector<int>vec(n);
	for (int i = 0; i < n; i++)
		vec[i] = 0;

	int boss;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> boss;
		++vec[boss - 1];
	}

	for (int i = 0; i < n; i++)
	{
		cout << vec[i];
		if (i != n - 1)
			cout << endl;
	}

	//int xx;
	//cin >> xx;
}


Measured memory_bytes: 4056
while true
	b, r, g, c, s , t = gets.split.map(&:to_i)
	
	exit unless b+r+g+c+s+t>0
	
	coin = 100
	bonus = b*5 + r*3
	
	coin += (bonus+b+r)*15 + g*7 + c*2
	coin -= (t-s)*3 - bonus
	
	puts coin
end

Measured memory_bytes: 6104
# 自力
N, M = map(int, input().split())
AB = [0]*M
for i in range(M):
    a, b = map(int, input().split())
    AB[i] = a, b

def key(ab):
    a, b = ab

AB.sort()

a0, b0 = AB[0]
cnt = 1
for a, b in AB[1:]:
    #print(cnt, (a0, b0), " : ", (a, b))
    if b0 > a:
        a0 = max(a, a0)
        b0 = min(b, b0)
    else:
        a0, b0 = a, b
        cnt += 1
#print((a0,b0))
print(cnt)





Measured memory_bytes: 17372
import sys

s = ""
for n in map(int, sys.stdin):
    if n == 0:
        break
    (ct, i) = (0,1)
    while True:
        r = n // ( 5 ** i )
        if r <= 0:
            break
        ct += r
        i += 1
    s += str(ct) + "\n"
print(s, end="")

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
int n; // number of vertices
vector<vector<int>> adj; // adjacency list of graph
vector<bool> visited;
vector<int> ans;

void dfs(int v) {
    visited[v] = true;
    for (int u : adj[v]) {
        if (!visited[u])
            dfs(u);
    }
    ans.push_back(v);
}

void topological_sort() {
    visited.assign(n, false);
    ans.clear();
    for (int i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
    reverse(ans.begin(), ans.end());
}
int main() {
  int M,x,y;
  cin >> n;
  vector<int> parents[n],d(n);
  adj = vector<vector<int>>(n);
  for (cin >> M; M; M--) {
    cin >> x >> y;
    adj[--x].push_back(--y);
    parents[y].push_back(x);
  }
  topological_sort();
  for (int i = 1; i < n; i++) {
    for (int j : parents[ans[i]]) {
      d[ans[i]] = max(d[ans[i]],d[j]+1);
    }
  }
  cout << *max_element(d.begin(),d.end());
}

Measured memory_bytes: 17216
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 c = sc.nextInt();
        if (!((a==b&&b==c)||(a!=b&&b!=c&&c!=a)))System.out.println("Yes");
        else System.out.println("No");
    }
       
}


Measured memory_bytes: 35664
#include <iostream>
using namespace std;
int assign(int, int);

int main(){
	long n;
  	cin >> n;
  	
  	long i = 0;
  	long input, a[n];
  	while(cin >> input){
    	a[i] = input;
      	i++;
    }
  
  	long sum = 1;
    int sign;
  	for(i = 0; i < n - 2; i++){
        sign = assign(a[i], a[i + 1]);
    	for(int j = i + 1; j < n - 1; j++){
            if( (sign == 1 && assign(a[j], a[j + 1]) == -1) || (sign == -1 && assign(a[j], a[j + 1]) == 1) ){
                sum++;
                i = j;
                break;
            }else if( sign == 0 ){
                sign = assign(a[j], a[j + 1]);
            }
            if( j == n - 2 ){
                cout << sum << endl;
  	            return 0;
            };
        }
    }  
  	cout << sum << endl;
  	return 0;
}

int assign(int x, int y){
    if(x > y) return -1;
    else if(x < y) return 1;
    else return 0;
}

Measured memory_bytes: 4416
#include <stdio.h>

int main(int argc, char *argv[]) {
    int n = 0;
    int x = 0;
    int t = 0;
    int times = 0;
    int ans = 0;

    scanf("%d %d %d", &n, &x, &t);
    times = (n + x - 1) / x;
    ans = t * times;
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1732
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def bs(f, mi, ma):
    mm = -1
    while ma > mi + eps:
        mm = (ma+mi) / 2.0
        if f(mm):
            mi = mm + eps
        else:
            ma = mm
    if f(mm):
        return mm + eps
    return mm

def main():
    xy = sorted([LI() for _ in range(3)])
    x = list(map(lambda _: _[0] - xy[0][0], xy))
    y = list(map(lambda _: _[1] - xy[0][1], xy))
    a = []
    for i in range(3):
        a.append(((x[i] - x[i-1])**2 + (y[i] - y[i-1])**2) ** 0.5)
    ma = max(a)
    s = abs(x[1]*y[2] - x[2]*y[1]) / 2
    r = 2 * s / sum(a)

    def f(i):
        return (1-i/r) * ma - 2*i > 0


    return bs(f, 0, ma)




print(main())



Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j,j<k,i++);
int main(){
    stack<int>S;
    int a,b,x;
    string s;
    while(cin>>s){
        if(s[0]=='+'){
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(a+b);
        }
        else if(s[0]=='-'){
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(b-a);
        }
        else if(s[0]=='*'){
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(a*b);
        }
        else {
            S.push(atoi(s.c_str()));
        }
    }
    cout<<S.top()<<endl;
    return 0;
}


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


int main() {
    int N;
    cin>>N;
    int sum=0;
    int a[N+2];
    a[0]=0;
    a[N+1]=0;
    for(int i=1;i<=N;i++){
        cin>>a[i];
        sum+=abs(a[i]-a[i-1]);
    }
    sum+=abs(a[N]);
    for(int i=1;i<=N;i++){
        cout<<sum-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
    }
}

Measured memory_bytes: 1664
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=[a1,a2,a3]
n=int(input())
q=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(n):
    b=int(input())
    for c in range(3):
        for x in range(3):
            if b==a[c][x]:
                q[c][x]=1

result='No'
for t in range(3):
    if q[t][0]==q[t][1]==q[t][2]==1:
        result='Yes'
        break
    elif q[0][t]==q[1][t]==q[2][t]==1:
        result='Yes'
        break
if q[0][0]==q[1][1]==q[2][2]==1:
    result='Yes'
elif q[0][2]==q[1][1]==q[2][0]==1:
        result='Yes'

print(result)


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

int main()
{
  int n,i;
  float ans=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  
  for(i=0;i<n;i++)
    ans+=1.0/a[i];
  
  ans=1.0/ans;
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 256
fn b() {
    input! {
        n: Chars
    }

    let mut total = 0;

    for v in n.iter() {
        total += v.to_digit(10).unwrap();
    }
    if total % 9 == 0 {
        println!("Yes");
    }
    else {
        println!("No");
    }
}

use proconio::{input, marker::Chars};

fn main() {
    b();
}

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

int main() {
	int n,a,b;
	int count = 0;

	cin >> n >> a >> b;
	for (int i = 0; i <= n; i++) {
		int x = i / 10000 + (i % 10000) / 1000 + (i % 1000) / 100 + (i % 100) / 10 + i % 10;
		if (x >= a && x <= b) {
			count += i;
		}
	}


	cout << count << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int sz=2e5+10, mod=1e9+7;
int su[sz];
int main()
{
    //freopen("input.txt", "r", stdin);
    int n, dp=1;
    cin>>n;
    int ar[n];
    for(int a=0; a<n; a++) scanf("%d", &ar[a]);
    int yk=0;
    while(yk<n)
    {
        int x=ar[yk];
        while(yk<n and ar[yk]==x) yk++;
        su[x]=(su[x]+dp)%mod;
        dp=su[x];
    }
    cout<<dp;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
using namespace std;
int n, m, x, c[15], a[15][15], f[15], b[15], min=1e9;//n是书的数量，m是要学的算法数量,b存算法的总level值 
void dfs(int k, int s){
	int i,j;
	if(k > n){
		memset(b, 0, sizeof(b));
		for(i=1; i<=n; i++){
			for(j=1; j<=m; j++){
				b[j] += a[i][j]*f[i];
			}
		}
		for(i=1;i<=m;i++) {
			if(b[i] < x) return;
		} 
		if(min > s) min=s; 
		
	}else{
		for(i=0; i<=1; i++){
			f[k]=i;
			dfs(k+1, s+c[k]*i);
		}
	}
}
int main()
{
	scanf("%d%d%d", &n, &m, &x);
	for(int i=1; i<=n; i++){
		scanf("%d", &c[i]);
		for(int j= 1; j<=m; j++) scanf("%d",&a[i][j]);
	}
	dfs(1, 0);
	if(min == 1e9) printf("-1");
	else printf("%d", min);
	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>

int main()
{
char s[6];
scanf("%s",s);

int i,j;char t;

for(i=0;i<3;i++)
    for(j=i+1;j<4;j++)
        if(s[i]>s[j]){
            t = s[i];
            s[i] = s[j];
            s[j] = t;
        }

if(s[0] == s[1] && s[2] == s[3]&&s[1] != s[2])
printf("Yes\n");
else 
printf("No\n");
}

Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll N, C, K; cin >> N >> C >> K;
    vl T(N); REP(i, N) cin >> T[i];
    sort(T.begin(), T.end());
    ll ans = 0, now = 0;
    
    ll idx = 0;
    while(idx < N){
        now = T[idx]; ll cur = 0;
        while(idx < N && cur < C && T[idx] - now <= K){
            cur++; idx++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define int ll
#define deb(x) cerr << #x << ":" << x << "\n"

void solve()
{
    int n;
    cin>>n;
    vector<int> v(n);
    map<int,int> mp;
    ll sum=0;
    for(auto &x:v){
        cin>>x;
        sum+=x;
        mp[x]++;
    }
    int q,b,c;
    cin>>q;
    while(q--){
        cin>>b>>c;
        sum-=b*mp[b];
        sum+=c*mp[b];
        mp[c]+=mp[b];
        mp[b]=0;
        cout<<sum<<'\n';
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 9896
import sys
import numpy as np

input = sys.stdin.readline

# N 夏休みの日数
n = int(input())

# 太郎君のとる行動
act = [list(map(int, input().split())) for ii in range(n)]

# 最大値なので0に初期化
dp = np.zeros([3, n+1])

def retmax(a, b):
    if a > b:
        return a
    return b

for i, a_l in enumerate(act):
    # i 夏休みの日数分
    for j in range(3):
        # j 前日にとった行動
        for k in range(3):
            # k 今日とる行動
            if j != k:
                # 前日と同じ鼓動はしない。前日と違う行動のみ。
                dp[k, i+1] = retmax(dp[k, i+1], dp[j, i]+a_l[k])
print(int(np.max(dp[:, n], axis=0)))

Measured memory_bytes: 42300
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    dp = [float('inf') for _ in range(n + 100)]
    dp[0] = 0

    for i in range(1, n + 1):
        dp[i] = min(dp[i - 1] + 1, dp[i])

        six = 6

        while six <= i:
            dp[i] = min(dp[i - six] + 1, dp[i])
            six *= 6

        nine = 9

        while nine <= i:
            dp[i] = min(dp[i - nine] + 1, dp[i])
            nine *= 9

    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 12884
#include<stdio.h>
 
int main(void){
 
  int S,N,i;
 
  while(scanf("%d",&N),N){
    for(i=1,S=-N;i*i<N;i++)if(!(N%i))S+=i+N/i;
 
    if(S==N)printf("perfect number\n");
    else if(S<N)printf("deficient number\n");
    else if(S>N)printf("abundant number\n");
  }
  return 0;
}

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


def solve(X: int, A: int, B: int):
    print((X - A) % B)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(X, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
S = str(input())

a = S[0]
b = S[1]
c = S[2]
d = S[3]

acount = 0
bcount = 0
ccount = 0
dcount = 0

if S.count(a) == 2 and S.count(c) == 2 and S.count(b) == 2 and S.count(d) == 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string s;
	while(cin >> s)
	{
		if(s == "0") break;
	
		vector<string> v;
		v.push_back(s);

		rep(i,2)
		{
			string temp;
			cin >> temp;
			v.push_back(temp);
		}

		bool flag = true;

		rep(i,3)
		{
			if(v[i][0] == v[i][1] && v[i][1] == v[i][2])
			{
				if(v[i][0] == 'b' || v[i][0] == 'w')
				{
					cout << v[i][0] << endl;
					flag = false;
					break;
				}
			}

			if(v[0][i] == v[1][i] && v[1][i] == v[2][i])
			{
				if(v[0][i] == 'b' || v[0][i] == 'w')
				{
					cout << v[0][i] << endl;
					flag = false;
					break;
				}
			}
		}

		if(flag)
		{
			if(v[0][0] == v[1][1] && v[1][1] == v[2][2])
			{
				if(v[0][0] == 'b' || v[0][0] == 'w')
				{
					cout << v[0][0] << endl;
					flag = false;
				}
			}

			else if(v[2][0] == v[1][1] && v[1][1] == v[0][2])
			{
				if(v[2][0] == 'b' || v[2][0] == 'w')
				{
					cout << v[2][0] << endl;
					flag = false;
				}
			}
		}

		if(flag) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	ll n,sec,go;
	string s,t;
	bool a;
	cin >> n;
	vi v(n),w(n),x(n);
	rep(i,n-1)
	{
		cin >> v[i];
		cin >> w[i];
		cin >> x[i];
	}
	//rep(i,n-1)
	//	cout << v[i] << w[i] << x[i] <<endl;
	rep(i,n-1)
	{
		sec = 0;
		sec += v[i] + w[i];
		REP(j,i+1,n-1)
		{
			//ok
			go = w[j];
			//cout << sec <<endl;
			a = true;
			while(a)
			{
				go += x[j];
				if(go >= sec)
					a = false;
				else if(go == sec)
					a = false;
			}
			//go -= x[j];
			if(go - x[j] == w[j] && go / 100 != 0)
				go -= x[j];
			sec = go + v[j];
			//cout << go << sec << endl;
		}
		cout << sec << endl;
	}
	puts("0");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
 
using namespace std;


 
int main(){
    FIN;
    //freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
    int s,w;cin>>s>>w;
    if(s>w){
        cout<<"safe";
    }else{
        cout<<"unsafe";
    }

    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3620
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

ll dp[2010][2010]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<PL> v(n);
  rep(i,0,n){
    cin>>v[i].fs;
    v[i].sc=i;
  }

  sort(all(v));
  reverse(all(v));

  rep(i,0,n){
    rep(j,0,i+1){
      chmax(dp[j+1][i-j],dp[j][i-j]+v[i].fs*abs(v[i].sc-j));
      chmax(dp[j][i-j+1],dp[j][i-j]+v[i].fs*abs(v[i].sc-(n-1-(i-j))));
    }
  }

  ll ans=0;
  rep(i,0,n)chmax(ans,dp[i][n-i]);
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

using namespace std;

int a[4];

int main() {
    int n;
    cin >> n;
    vector<string> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    for (string s : v) {
        if (s == "AC") {
            a[0]++;
            continue;
        }
        if (s == "WA") {
            a[1]++;
            continue;
        }
        if (s == "TLE") {
            a[2]++;
            continue;
        }
        if (s == "RE") {
            a[3]++;
            continue;
        }
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
}


Measured memory_bytes: 6420
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
int i[1111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e,f;
  cin >>a>>b;
  if(a>=b) cout <<"10\n";
  else cout <<"0\n";
  return (0);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

int N, M;
vector<int> g[200201];
vector<bool> visited(200101);

void DFS(int n)
{
	visited[n] = true;
	for (int i = 0; i < g[n].size(); i++)
	{
		int next = g[n][i];
		if (visited[next]) continue;
		DFS(next);
	}
}

int main()
{
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++)
	{
		int K;
		scanf("%d", &K);
		for (int j = 0; j < K; j++)
		{
			int t;
			scanf("%d", &t);
			g[i].push_back(N + t);
			g[N + t].push_back(i);
		}
	}
	DFS(1);

	for (int i = 1; i <= N; i++)
		if (visited[i] == false)
			return !printf("NO");
	printf("YES");
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
VEC<VEC<int>> G;
VEC<int> possible;
VEC<LL> H;
void denpa(int node) {
  // DUMP("denpa", node, possible[node]);
  if (possible[node] == 0) return;
  LL ma = 0;
  REP(i, 0, G[node].size()) {
    int t = G[node][i];
    ma = max(ma, H[t]);
    if (H[t] <= H[node]) {
      possible[t] = 0;
    }
  }
  if (H[node] > ma) possible[node] = 1;
  else possible[node]=0;
  // DUMP("denpa", node, possible[node], H[node],ma);
}

int main() {
  int N, M;
  cin >> N >> M;
  H = VEC<LL>(N);
  REP(i, 0, N) cin >> H[i];

  // auto I = H;
  // sort(ALL(I), greater<int>());
  // map<LL, int> seq;
  // REP(i, 0, N) { seq[I[i]] = i; }
  // VEC<int> decend(N, 0);
  // REP(i, 0, N) { decend[seq[H[i]]] = i; }

  G = VEC<VEC<int>>(N, VEC<int>(0));
  REP(i, 0, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  possible = VEC<int>(N, -1);
  REP(i, 0, N) { denpa(i); }
  // DUMP(possible);
  int cnt=0;
  REP(i,0,N){
    if(possible[i])cnt++;
  }
  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 9592
def main():
    import sys
    input = sys.stdin.readline
    A, B, C = map(int, input().split())
    x = A % B
    for _ in range(B):
        x += A
        x %= B
        if x == C:
            print("YES")
            break
    else:
        print("NO")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
using namespace std;
int main() {
	int n, k, d, x;
	cin >> n >> k;
	unordered_set<int> s;
	for (int i = 0; i < k; i++) {
		int x;
		cin >> x;
		for (int j = 0; j < x; j++) {
			int a;
			cin >> a;
			s.insert(a);
		}
	}
	cout << n - s.size();
}


Measured memory_bytes: 3232
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// Priority Queue
type Item struct {
	priority, index int
}

type PQ []*Item

func (pq PQ) Len() int {
	return len(pq)
}

func (pq PQ) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PQ) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PQ) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PQ) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1
	*pq = old[0 : n-1]
	return item
}

// End Priority Queue

func f(i, j, k, N int, v []int) int {
	if i+j > N {
		return 0
	}
	if i+j < k {
		return 0
	}
	// out(i, j, k)

	pq := make(PQ, 0)
	heap.Init(&pq)
	ret := 0
	// out left
	for x := 0; x < i; x++ {
		heap.Push(&pq, &Item{v[x], 0})
		ret += v[x]
	}
	// out right
	for x := 0; x < j; x++ {
		heap.Push(&pq, &Item{v[len(v)-1-x], 0})
		ret += v[len(v)-1-x]
	}
	// drop
	// out("drop")
	for x := 0; x < k; x++ {
		item := heap.Pop(&pq).(*Item)
		// out(item.priority)
		ret -= item.priority
	}
	// out("--------", ret)

	return ret
}

const inf = 1001001001001

func main() {
	sc.Split(bufio.ScanWords)

	N, K := getInt(), getInt()
	v := make([]int, N)
	for i := 0; i < N; i++ {
		v[i] = getInt()
	}

	ans := -inf

	for i := 0; i <= K; i++ {
		for j := 0; j <= K-i; j++ {
			x := K - i - j
			for k := 0; k <= x; k++ {
				ret := f(i, j, k, N, v)
				// out("ret", ret)
				ans = max(ans, ret)
			}
		}
	}
	out(ans)
}


Measured memory_bytes: 5632