akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#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 gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  vvi to(n);
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  queue<int> q;
  vi deg(n);
  rep(i,n) {
    deg[i] = sz(to[i]);
    if (deg[i] == 1) q.push(i);
  }
  while (sz(q)) {
    int v = q.front(); q.pop();
    if (deg[v] < 0) {
      continue;
    }
    deg[v] = -1;
    int nv = -1;
    for (int u : to[v]) {
      if (deg[u] > 0) nv = u;
    }
    deg[nv] = -1;
    for (int u : to[nv]) {
      deg[u]--;
      if (deg[u] == 0) {
        puts("First");
        return 0;
      }
      if (deg[u] == 1) {
        q.push(u);
      }
    }
  }
  puts("Second");
  return 0;
}






















Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }


void solve(long long A, long long B, long long C, long long D){
	ll res = 0;
	ll bc = B/C;
	ll bd = B/D;
	ll bcd = B/lcm(C, D);
	ll b = B - bc - bd + bcd;
	A--;
	ll ac = A/C;
	ll ad = A/D;
	ll acd = A/lcm(C, D);
	ll a = A - ac - ad + acd;
	res = b - a;

	cout << res << "\n";
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
import math

n = input()
prime = []
#find prime numbers in 1-sqrt(n)
m = int(math.sqrt(n))
for i in range(m+1):
    prime.append(True)
prime[0] = False
prime[1] = False

for i in range(2, int(math.sqrt(m))):
    if not prime[i]:
        continue
    else:
        for j in range(i+1, int(math.sqrt(m))):
            if j % i == 0:
                prime[j] = False

s = []
i = 2
num = n
while True:
    if i == int(math.sqrt(num))+1:
        s.append(str(n))
        break

    if not prime[i] or n % i != 0:
        i += 1
        continue

    if n % i == 0:
        s.append(str(i))
        n /= i
        if n == 1:
            break

st = " ".join(s)
print "%d: %s" % (num, st)

Measured memory_bytes: 7692
N = int(input())
S = input()

W = []
for i in range(N):
    if i == 0:
        if "W" == S[i]:
            W.append(1)
        else:
            W.append(0)
    else:
        if "W" == S[i]:
            W.append(1+W[i-1])
        else:
            W.append(0+W[i-1])

E = []
for i in range(N):
    if i == 0:
        if "E" == S[N-1-i]:
            E.append(1)
        else:
            E.append(0)
    else:
        if "E" == S[N-1-i]:
            E.append(1+E[i-1])
        else:
            E.append(0+E[i-1])
E.reverse()

ans = 10 ** 9
for i in range(N):
    ans = min(ans, W[i]+E[i]-1)
print(ans)
\

Measured memory_bytes: 27396
T=input()
L=len(T)
if L==1:
  if T=='?': print('D')
  else: print(T)
else:
  X=list(T)
  for i in range(L-1):
    if X[i]!='?': continue
    if i==0:
      if X[1]=='P': X[0]='D'
      else:X[0]='P'
    else:
      if X[i-1]=='P' or X[i+1]=='P':X[i]='D'
      else:X[i]='P'
  if X[-1]=='?':X[-1]='D'
  print("".join(X))

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int sum = n;
    for (int i = 0; i < n-1; i++){
        if(s.at(i) == s.at(i+1)){
            sum--;
        }
    }
    cout << sum << endl;
}

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


int main(){
  string s;
  cin>>s;
  string abc ="ABC";
  string arc ="ARC";
  if(s.at(1)=='B'){
    cout<<arc<<endl;
  }
  else {
    cout<<abc<<endl;
  }
}


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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0; i<h; ++i)
        cin >> s[i];

    vector<vector<bool> > v(2*h-1, vector<bool>(2*w-1, true));
    for(int y=0; y<h-1; ++y){
        for(int x=0; x<w-1; ++x){
            int cnt = 0;
            for(int i=0; i<4; ++i){
                if(s[y+i/2][x+i%2] == '#')
                    ++ cnt;
            }
            if(cnt % 2 != 0)
                v[2*y+1][2*x+1] = false;
        }
    }

    int ans = 0;
    vector<int> len(2*h-1, 0);
    for(int x=0; x<2*w-1; ++x){
        for(int y=0; y<2*h-1; ++y){
            if(v[y][x])
                ++ len[y];
            else
                len[y] = 0;
        }

        stack<pair<int, int> > stk;
        for(int y=0; y<2*h-1; ++y){
            int y2 = y;
            while(!stk.empty() && stk.top().first > len[y]){
                y2 = stk.top().second;
                int a = stk.top().first;
                int b = y - stk.top().second;
                ans = max(ans, (a + 1) * (b + 1) / 4);
                stk.pop();
            }
            if(stk.empty() || stk.top().first < len[y])
                stk.push(make_pair(len[y], y2));
        }
        while(!stk.empty()){
            int a = stk.top().first;
            int b = (2 * h - 1) - stk.top().second;
            ans = max(ans, (a + 1) * (b + 1) / 4);
            stk.pop();
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  ll cost = 1000000000LL * 30;
  for (int i = 0; i < (1 << (n-1)); i++) {
    ll temp_cost = 0;
    bitset<14>b(i); //一番左は絶対見える
    if (b.count() != k-1) continue; //残りk-1色を見たい
    ll height = a[0];
    for (int j = 0; j < n-1; j++) {
      if (i & (1 << j)) {
        //height = max(height + 1, a[j+1]);
        height++;
        if (height < a[j+1]) height = a[j+1];
        temp_cost += (height - a[j+1]);
      }
      else if (height < a[j+1]) height = a[j+1];
    }
    //cost = min(cost, temp_cost);
    if (cost > temp_cost) cost = temp_cost;
  }

  cout << cost << endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    counter = [0]*N
    
    for i in range(M):
      A,B = map(int,input().split())
      A -= 1
      B -= 1
      counter[A] = max(counter[A],H[B])
      counter[B] = max(counter[B],H[A])
    ans = 0
    for i in range(N):
      if counter[i] < H[i]:
          ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

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

using namespace std;

using ll = long long;

constexpr int inf = 1<<30;
vector<int> e[2020];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n-1;++i){
        int a,b;
        cin>>a>>b;a--;b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    auto bfs = [=](auto && e,int i){
        vector<int> dict(n,inf);
        dict[i] = 0;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int cur = q.front(); q.pop();
            for(auto to : e[cur]){
                if(dict[to] != inf) continue;
                dict[to] = dict[cur] + 1;
                q.push(to);
            }
        }
        return dict;
    };
    vector<vector<int>> target(n);
    vector<int> sz(n);
    for(int i=0;i<n;++i){
        auto d = bfs(e,i);
        for(int j=0;j<n;++j){
            if(d[j] > k){
                target[i].push_back(j);
                sz[i]++;
            }
        }
    }
    int ret = 0;
    while(true){
        auto it = max_element(sz.begin(),sz.end());
        if(*it == 0) break;
        int n = it - sz.begin();
        sz[n] = 0;
        for(auto to : target[n]){
            sz[to]--;
        }
        ret++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    ll N, P; cin >> N >> P;
    int flg = 0;
    rep(i, N) {
        ll a; cin >> a;
        if (a % 2) flg = 1; 
    }

    ll ans = 0;
    if (flg) {
        ans = pow(2, N - 1);
    } else {
        if (P) {
            ans = 0;
        } else {
            ans = pow(2, N);
        }
        
    }

    COUT(ans);
}

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

using namespace std;

long long n;

int main() {
    cin >> n;
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
        long long tmp = n / i;
        ans += i * (tmp + 1) * tmp / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<cstdio>

int main() {
	int x, a, b;
	int da,db;
	scanf("%d%d%d",&x,&a,&b);
	da = ((a-x > 0)?a-x:x-a);
	db = ((b-x > 0)?b-x:x-b);
	printf(da < db?"A\n":"B\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
{
	int n,i,s=0;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		cin>>b[i];
	for(i=0;i<n-1;i++)
		cin>>c[i];
	for(i=0;i<n;i++)
	{
		s=s+b[a[i]-1];
		if(a[i+1]-a[i]==1)
			s=s+c[a[i]-1];
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
ls = []
for _ in range(m):
    k, *s, = map(lambda x: int(x)-1, input().split())
    ls.append(s)
p = list(map(int, input().split()))


def base_n(x, n, zero_padding=8):
    retval = [[], ['0']][x == 0]
    while x > 0:
        x, r = divmod(x, n)
        retval.append(str(r))
    cnt = zero_padding - len(retval)
    pad = ['', '0'*cnt][cnt > 0]
    return pad+''.join(retval[::-1])


ans = 0
for i in range(2**n):
    base_2 = base_n(i, 2, n)
    for j in range(m):
        switchs = ls[j]
        cond = p[j]

        on_cnt = 0
        for switch in switchs:
            if int(base_2[switch]):
                on_cnt += 1
        if on_cnt % 2 != cond:
            break

    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
char s[100005];
int n;
int K;
int main(){
  scanf("%s%d",s,&K);
  n=strlen(s);

  REP(i,n){
    int need=('z'-s[i]+1)%26;
    if(K>=need){
      K-=need;
      s[i]='a';
    }
  }
  if(K>0){
    K%=26;
    int val=s[n-1]-'a';
    val=(val+K)%26;
    s[n-1]='a'+val;
  }
  printf("%s\n",s);
  return 0;
}




Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>E[101010];
vector<ll>A(101010);
int root;

void err() {
	puts("NO");
	exit(0);
}

void dfs(int now, int p) {
	int cnt = 0;
	priority_queue<ll>q;
	ll sum1 = 0;
	fore(x, E[now]) {
		if(x != p){
			dfs(x,now);
			q.push(A[x]);
			sum1 += A[x];
			cnt++;
		}
	}
	if (cnt == 0)return;

	if (now == root) {
		if (A[now] == sum1)puts("YES");
		else puts("NO");
	}
	else {
		ll sum2 = 0;
		while (q.size()) {
			ll mx = q.top();
			q.pop();
			if (q.size() == 0)break;
			ll mx2 = q.top();
			q.pop();
			sum2 += mx2;
			mx -= mx2;
			q.push(mx);
		}
		ll x = sum1 - A[now];
		if (x < 0)err();
		if (A[now] - x < 0)err();
		if (x > sum2)err();
		A[now] -= x;
	}
}

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

	int N;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
	}

	

	for (int i = 0; i < N; i++) {
		if (E[i].size() == 1) {
			root = i;
			dfs(i,-1);
			exit(0);
		}
	}


	return 0;
}


Measured memory_bytes: 19072
from operator import itemgetter
A=[]
n,m=[int(i) for i in input().split()]
B=[1]*(n+1)
for i in range(m):
    a=[int(j) for j in input().split()]
    a.append(i)
    A.append(a)
A.sort(key=itemgetter(1))
for i in range(m):
    A[i].append(B[A[i][0]])
    B[A[i][0]]+=1
A.sort(key=itemgetter(2))
for i in range(m):
    c=6-len(str(A[i][0]))
    d=6-len(str(A[i][3]))
    print("{}{}{}{}".format("0"*c,A[i][0],"0"*d,A[i][3]))

Measured memory_bytes: 29808
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

struct Point {
    int t,x,y;
    Point(int t_, int x_, int y_) :
        t(t_), x(x_), y(y_) {}
};
 
int main(){
  ll n;cin>>n;
  ll t,x,y;
  vector<Point> p;
  p.emplace_back(0,0,0);
  rep(i,n){
    cin>>t>>x>>y;
    p.emplace_back(t,x,y);
  }
  // 一個前から次のところまでマンハッタン距離と時差の偶奇は一致する．
  // さらに，時差がマンハッタン距離より大きくなければならない．
  ll dif_t,dif_dis;
  bool flg=true;
  rep(i,n){
    dif_t=p[i+1].t-p[i].t;
    dif_dis=abs(p[i+1].y-p[i].y)+abs(p[i+1].x-p[i].x);
    if(dif_dis%2==dif_t%2&&dif_t>=dif_dis){
      //pass
    }else{
      flg=false;
      break;
    }
  }
  if(flg){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1912
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;

IL int Input(){
	RG int x = 0, z = 1; RG char c = getchar();
	for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
	for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * z;
}

const int maxn(5e4 + 5);

int son[26][maxn], len[maxn], num[maxn], fa[maxn], vis[maxn];
int tot, n, last;
char s[maxn], t[maxn];

IL void Extend(RG int pos, RG int c){
	RG int p = last;
	while(s[pos - len[p] - 1] != s[pos]) p = fa[p];
	if(!son[c][p]){
		RG int np = ++tot, q = fa[p];
		while(s[pos - len[q] - 1] != s[pos]) q = fa[q];
		len[np] = len[p] + 2, fa[np] = son[c][q];
		son[c][p] = np;
	}
	last = son[c][p], ++num[last];
}

int main(){
	scanf(" %s %s", s + 1, t + 1), n = strlen(s + 1);
	fa[0] = fa[1] = tot = 1, len[1] = -1;
	for(RG int i = 1; i <= n; ++i) Extend(i, s[i] - 'A');
	n = strlen(t + 1);
	for(RG int i = 1, nw = 1; i <= n; ++i){
		RG int c = t[i] - 'A';
		while(nw != 1 && (!son[c][nw] || t[i - len[nw] - 1] != t[i])) nw = fa[nw];
		if(son[c][nw] && t[i - len[nw] - 1] == t[i]) nw = son[c][nw];
		++vis[nw];
	}
	for(RG int i = tot; i; --i) num[fa[i]] += num[i], vis[fa[i]] += vis[i];
	RG ll ans = 0;
	for(RG int i = 2; i <= tot; ++i) ans += 1LL * num[i] * vis[i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 9160
m=10**9+7

n=int(input())
a=list(map(int,input().split()))

b=max(a)
k=0

while b!=0:
    b=b//2
    k+=1

ans=0

for i in range(k):
    x=0
    y=0
    for j in range(n):
        if (a[j]>>i)%2==1:
            x+=1
        else:
            y+=1
    ans+=((2**i)%m) * ((x*y)%m)
print(ans%m)

Measured memory_bytes: 122936
#include<stdio.h>
#include<string.h>
main(){
  int number,A=0,B=0,O=0,AB=0;
  char blood[3];
  while(scanf("%d,%s",&number,&blood) != EOF){
    if(strcmp(blood,"A")==0){
      A++;
    }
    else if(strcmp(blood,"B")==0){
      B++;
    }
    else if(strcmp(blood,"O")==0){
      O++;
    }
    else{
      AB++;
    }
  }
  printf("%d\n%d\n%d\n%d\n",A,B,AB,O);
  return 0;
}

Measured memory_bytes: 596
#include <cstdio>

typedef long long ll;

ll ms(int a[], int l, int r) {
    if (l == r) {
        return 0;
    }

    ll ret = 0;
    int mi = (l + r) / 2;
    ret += ms(a, l, mi);
    ret += ms(a, mi + 1, r);

    int t[r-l+1];
    int i1 = l, i2 = mi + 1;
    for (int i = 0; i < r - l + 1; i++) {
        if (i2 == r + 1 || i1 <= mi && a[i1] <= a[i2]) {
            t[i] = a[i1++];
            ret += r + 1 - i2;
        } else {
            t[i] = a[i2++];
        }
    }
    
    for (int i = 0; i < r - l + 1; i++) {
        a[l+i] = t[i];
    }
    
    return ret;
}

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    int l = 0, r = 1e9+1;
    while (r - l > 1) {
        int m = (l + r) / 2;

        int b[n+1];
        for (int i = 1; i <= n; i++) {
            b[i] = a[i-1] >= m ? 1 : -1;
        }

        b[0] = 0;
        for (int i = 1; i <= n; i++) {
            b[i] += b[i-1];
        }
        
        if (ms(b, 0, n) * 2 >= 1ll * (n + 1) * n / 2) {
            l = m;
        } else {
            r = m;
        }
    }

    printf("%d\n", l);

    return 0;
}

Measured memory_bytes: 1280
//A*
//优先对“起点到当前位置的成本+当前位置到目标状态的推测值”最小的状态进行状态迁移
#include<bits/stdc++.h>
 
using namespace std;
 
#define N 4
#define N2 16
 
const int dx[4]={0,-1,0,1};
const int dy[4]={1,0,-1,0};
const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];
 
struct Puzzle{
    int f[N2],space,MD;
    int cost;
    bool operator < (const Puzzle &p)const{
        for(int i=0;i<N2;i++){
            if(f[i]==p.f[i]){
                continue;
            }
            return f[i]<p.f[i];
        }
        return false;
    }
};
 
struct state{
    Puzzle puzzle;
    int estimated;
    bool operator < (const state &s)const{
        return estimated>s.estimated;
    }
};
 
int getALLMD(Puzzle pz)
{
    int sum=0;
    for(int i=0;i<N2;i++){
        if(pz.f[i]==N2){
            continue;
        }
        sum+=MDT[i][pz.f[i]-1];
    }
    return sum;
}
 
int astar(Puzzle s)
{
    priority_queue<state>pq;
    s.MD=getALLMD(s);
    s.cost=0;
    map<Puzzle,bool>V;
    Puzzle u,v;
    state initial;
    initial.puzzle=s;
    initial.estimated=getALLMD(s);
    pq.push(initial);
    while(!pq.empty()){
        state st=pq.top();
        pq.pop();
        u=st.puzzle;
        if(u.MD==0){
            return u.cost;
        }
        V[u]=true;
        int sx=u.space/N;
        int sy=u.space%N;
        for(int r=0;r<4;r++){
            int tx=sx+dx[r];
            int ty=sy+dy[r];
            if(tx<0||ty<0||tx>=N||ty>=N){
                continue;
            }
            v=u;
            v.MD-=MDT[tx*N+ty][v.f[tx*N+ty]-1];
            v.MD+=MDT[sx*N+sy][v.f[tx*N+ty]-1];
            swap(v.f[sx*N+sy],v.f[tx*N+ty]);
            v.space=tx*N+ty;
            if(!V[v]){
                v.cost++;
                state news;
                news.puzzle=v;
                news.estimated=v.cost+v.MD;
                pq.push(news);
            }
        }
    }
    return -1;
}
 
int main()
{
    for(int i=0;i<N2;i++){
        for(int j=0;j<N2;j++){
            MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
        }
    }
//    for(int i=0;i<N2;i++){
//        for(int j=0;j<N2;j++){
//            cout<<MDT[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    Puzzle in;
    for(int i=0;i<N2;i++){
        cin>>in.f[i];
        if(in.f[i]==0){
            in.f[i]=N2;
            in.space=i;
        }
    }
    cout<<astar(in)<<endl;
    return 0;
}



Measured memory_bytes: 257620
# -*- coding: utf-8 -*-
from collections import Counter

N = int(input())
D = Counter(tuple(map(int, input().split())))
M = int(input())
T = Counter(tuple(map(int, input().split())))

for k in T:
    if D[k] < T[k]:
        print("NO")
        break
else:
    print("YES")

Measured memory_bytes: 55136
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll n;
	ll res = 0;
	char s[11];
	char t[12];
	scanf("%s", s);
	scanf("%s", t);
	if (strlen(s) + 1 != strlen(t)) {
		printf("No\n");
		return(0);
	}
	FOR(i, 0, strlen(s)-1) {
		if (s[i] != t[i]) {
			printf("No\n");
			return(0);
		}
	}
	printf("Yes\n");
	return(0);
}

Measured memory_bytes: 3200
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int W = scan.nextInt();
        int H = scan.nextInt();
        int C = scan.nextInt();
        int g;
        int b;
        int x;
        int t;
        int y;
        if (W > H) {
            t = W;
            y = H;
            while (W % H != 0) {
                g = W;
                W = H;
                H = g % H;
            }
            b = H * H;
            x = (t * y) / b;
            System.out.println(x * C);
        } else if (W < H) {
            t = W;
            y = H;
            while (H % W != 0) {
                g = H;
                H = W;
                W = g % W;

            }
            b = W * W;
            x = (t * y) / b;
            System.out.println(x * C);
        } else if (H == W) {
            System.out.println(C);
        }
    }
}



Measured memory_bytes: 26344
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MM 1000000007
using namespace std;

int main()
{
	ll n;
	cin>>n;
	
	cout<<((n)*(n-1))/2LL;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pf push_front
#define acm ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
 ll a,b;
 cin>>a>>b;
 if(b>a || (b==a && b!=1))
    cout<<"NO";
 else if(a%2!=0 && b<=(a/2)+1)
    cout<<"YES";
 else if((a%2==0 && b<=(a/2)) || (a==1 && b==1))
    cout<<"YES";
 else cout<<"NO";
}


Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
 
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()
 
const int oo=1000000000;
 
int n,m;
int f[1<<15][16][16];
int g[16][16];
 
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	while (cin>>n>>m)
	{
		memset(g,255,sizeof(g));
		REP(i,m)
		{
			int x,y,z;
			cin>>x>>y>>z;
			--x;
			--y;
			g[x][y]=g[y][x]=z;
		}
		REP(set,two(n))
		{
			REP(x,n) REP(y,n) f[set][x][y]=oo;
			if (!contain(set,0)) continue;
			if (contain(set,n-1) && set!=two(n)-1) continue;
			REP(x,n) f[set][x][x]=0;
			for (int set1=set-1;set1>0;set1=((set1-1)&set))
			{
				if (!contain(set1,0)) continue;
				int set2=(set^set1);
				int base=0;
				REP(x,n) if (contain(set1,x)) REP(y,n) if (contain(set2,y) && g[x][y]>=0) base+=g[x][y];
				REP(x,n) if (contain(set1,x)) REP(y,n) if (contain(set1,y)) REP(z,n) if (contain(set2,z) && g[y][z]>=0)
				{
					ckmin(f[set][x][z],base+f[set1][x][y]-g[y][z]);
				}
			}
		}
		printf("%d\n",f[two(n)-1][0][n-1]);
#ifndef _MSC_VER
		system("pause");
#endif
	}
	return 0;
}

Measured memory_bytes: 33272
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/07/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  auto color = [&](int r) -> int {
    return r/400;
  };
  int n; cin>>n;
  set<int> cs;
  int cnt_king = 0;
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    if (a >= 3200) {
      cnt_king++;
    } else {
      cs.insert(color(a));
    }
  }
  cout << max((int)cs.size(),1) << " " << cs.size()+cnt_king << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>

typedef struct{
    int r;
    int c;
}matrix;

int table[100][100];

int calc(matrix* m, int l, int r){
    if(r<=l+1)return 0;
    if(table[l][r]>0)return table[l][r];
    int i, tmp;
    int ans = INT_MAX;
    for(i=l+1;i<r;i++){
        tmp = m[l].r*m[i].r*m[r-1].c + calc(m,l,i) + calc(m,i,r);
        if(tmp<ans)ans = tmp;
    }
    table[l][r] = ans;
    return ans;
}

int main(){
    int i, j, n;
    matrix m[100];
    scanf("%d",&n);
    for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            table[i][j] = 0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&(m[i].r),&(m[i].c));
    }
    printf("%d\n",calc(m,0,n));
    return 0;
}



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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll N, K;
string s;


int main() {
    cin >> s >> K;
    REP(i, s.size()) {
        if(s[i]=='a')continue;
        if (K >= 'z' - s[i] + 1) {
            K -= 'z' - s[i] + 1;
            s[i] = 'a';
        }
    }
    REP(i, K % 26) {
        if (s[s.size() - 1] == 'z')s[s.size() - 1] = 'a';
        else s[s.size() - 1]++;
    }
    cout << s << endl;
    return 0;
}



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

int main() {
    int n;
    cin >> n;
    int w[n];
    rep(i, n) cin >> w[i];

    int ans = 10000;
    rep(i, n) {
        int l = 0, r = 0;
        for (int j = 0; j <= i; j++) l += w[j];
        for (int j = i+1; j < n; j++) r += w[j];
        ans = min(ans, abs(l - r));
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n;
    vector<pair<string,pair<int,int> > > v;
    
    string s;
    
    for(int i=0;i<n;i++){
        cin>>s>>k;
        v.pb(make_pair(s,make_pair(k,i)));
    }
    sort(be(v));
    bool maki=false;
    int num=0;
    for(int i=0;i<n;i++){
        if(maki==true){
            if(i!=n-1){
                if(v[i].first!=v[i+1].first){
                    for(int j=i;j>=num;j--){
                        cout << v[j].second.second+1<<endl;
                    }
                    maki=false;
                }
            }
            else{
                for(int j=n-1;j>=num;j--){
                    cout << v[j].second.second+1<<endl;
                }
            }
        }
        else if(i!=n-1){
            if(v[i].first==v[i+1].first){
                maki=true;
                num=i;
            }
            else{
                cout <<v[i].second.second+1<<endl;
            }
        }
        else{
            cout <<v[i].second.second+1<<endl;
        }

    }
    return 0;
}



Measured memory_bytes: 256
def solve():
    K, S = map(int, input().split())
    ans = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - (x + y)
            if z < 0 or K < z:
                continue
            ans += 1

    print(ans)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 40940
import itertools

N, M = map(int, input().split())

path = [[False] * N for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    path[a-1][b-1] = True
    path[b-1][a-1] = True

count = 0
for i in itertools.permutations(list(range(N)),N):
    if i[0] == 0:
        for j in range(N):
            if j == N-1:
                count += 1
                break
            if not path[i[j]][i[j+1]]:
                break
    

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;


int main() {
	IOS;
#ifdef xiaofan
	freopen("in.txt","r",stdin);
#endif

	int a,b,c;
	cin>>a>>b>>c;
	
	if(a==b && a==c)
		cout<<"No"<<endl;
	else{
		if(a==b &&a!=c){
			cout<<"Yes"<<endl;
		}else
		if(a==c && a!=b){
			cout<<"Yes"<<endl;
		}else
		if(b==c && a!=b){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}




	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  double a,b,c,PI=3.1415926535;
  cin >> a >> b >> c;
  printf("%.5f\n",a*b*sin(c*PI/180)/2);
  printf("%.5f\n",sqrt(a*a+b*b-2*a*b*cos(c*PI/180))+a+b);
  printf("%.5f\n",b*sin(c*PI/180));
  return 0;
}



Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template<typename T>
void vecin(vector<T>& v, int n = 0){
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n-1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}
void print(string s){
    cout << s << endl;
}
struct edge{
    int to, from;
};

int main()
{
    ciosup;
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int dkazu = 0;
    FOR(i,1, n)
    {
        if (s[i-1] != s[i]){
            dkazu++;
        }
    }
    dkazu = dkazu - 2 * k;
    cout << min(n - (dkazu + 1), n - 1) << endl;
}

Measured memory_bytes: 512
import heapq

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()))
assert len(A) == X and len(B) == Y and len(C) == Z

# to reverse the order
A = [-x for x in A]
B = [-x for x in B]
C = [-x for x in C]

A.sort()
B.sort()
C.sort()

def val(pos):
    a, b, c = pos
    return A[a] + B[b] + C[c]

def nextpos(pos):
    a, b, c = pos
    if a + 1 < len(A):
        yield (a + 1, b, c)
    if b + 1 < len(B):
        yield (a, b + 1, c)
    if c + 1 < len(C):
        yield (a, b, c + 1)

def cakelist():
    H = []  # heap
    heapq.heappush(H, (val((0, 0, 0)), (0, 0, 0)))
    visited = {(0, 0, 0)}
    while len(H) > 0:
        v, pos = heapq.heappop(H)
        yield -v
        for npos in nextpos(pos):
            if npos not in visited:
                heapq.heappush(H, (val(npos), npos))
                visited.add(npos)

for x, _ in zip(cakelist(), range(K)):
    print(x)


Measured memory_bytes: 4980
solve :: Int -> Int -> Int
solve h w
 | (h > 1) && (w > 1) = ((div (h + 1) 2) * (div (w + 1) 2)) + ((div h 2) * (div w 2))
 | otherwise = 1

main :: IO()
main = do
 [h,w] <- map read . words <$> getLine :: IO [Int]
 print $ solve h w

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    double R; cin >> R;
    printf("%.10Lf",PI*R*2);
    
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n, m, cap;
string src, dest;
int st, en;
map<string,int> ma;
string c[2][8000];
int d[8000];
int counter;
vector<P> e[8000];
vector<P> edge[8000];
set<int> sta;

void make_edge(){
	rep(i,n){
		cin >> c[0][i] >> c[1][i] >> d[i];
		if(ma.count(c[0][i]) == 0){
			ma[c[0][i]] = counter;
			counter++;
		}
		if(ma.count(c[1][i]) == 0){
			ma[c[1][i]] = counter;
			counter++;
		}
	}
	st = ma[src]; en = ma[dest];
	rep(i,n){
		int a = ma[c[0][i]], b = ma[c[1][i]];
		e[a].push_back(P(b,d[i]));
		e[b].push_back(P(a,d[i]));
	}
}

void dijkstra(int start){
	int dist[8000];
	PQ que;
	rep(i,8000) dist[i] = INF;
	dist[start] = 0;
	que.push(P(0,start));
	while(!que.empty()){
		P q = que.top();
		que.pop();
		if(q.first > dist[q.second]) continue;
		rep(i,e[q.second].size()){
			P p = e[q.second][i];
			if(dist[p.first] > q.first+p.second && q.first+p.second <= cap*10){
				dist[p.first] = q.first+p.second;
				que.push(P(dist[p.first],p.first));
			}
		}
	}
	rep(i,counter){
		if(i == start) continue;
		if(sta.count(i) == 0) continue;
		if(dist[i] == INF) continue;
		edge[start].push_back(P(i,dist[i]));
	}
}

void dijkstra(){
	int dist[8000];
	PQ que;
	rep(i,8000) dist[i] = INF;
	dist[st] = 0;
	que.push(P(0,st));
	while(!que.empty()){
		P q = que.top();
		que.pop();
		if(q.first > dist[q.second]) continue;
		rep(i,edge[q.second].size()){
			P p = edge[q.second][i];
			if(dist[p.first] > q.first+p.second){
				dist[p.first] = q.first+p.second;
				que.push(P(dist[p.first],p.first));
			}
		}
	}
	if(dist[en] == INF) dist[en] = -1;
	cout << dist[en] << endl;
}

void solve(){
	ma.clear();
	counter = 0;
	rep(i,8000) e[i].clear();
	rep(i,8000) edge[i].clear();
	sta.clear();
	counter = 0;
	cin >> src >> dest;
	make_edge();
	rep(i,m){
		string tmp; cin >> tmp;
		sta.insert(ma[tmp]);
	}
	sta.insert(st); sta.insert(en);
	rep(i,counter){
		if(sta.count(i) == 0) continue;
		dijkstra(i);
	}
	dijkstra();
}

int main(){
	while(cin >> n >> m >> cap){
		if(n == 0 && m == 0 && cap == 0) break;
		solve();
	}
}

Measured memory_bytes: 4872
n=int(input())
ans=[0]*10800
for x in range(1,108):
  for y in range(1,108):
    for z in range(1,108):
      v=x*x+y*y+z*z+x*y+y*z+z*x
      if 0<=v<10800:
        ans[v]+=1
for i in range(1,n+1):
  print(ans[i])

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<ll>> a(N, vector<ll>(3));

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	ll ans = -1e14;
	for(int i=0;i<8;i++) {
		vector<ll> vec;
		for(int j=0;j<N;j++) {
			ll tmp = 0;
			for(int k=0;k<3;k++) {
				tmp += ((i & (1 << k)) ? a[j][k] : (-1LL) * a[j][k]);
			}
			vec.push_back(tmp);
		}
		sort(vec.rbegin(), vec.rend());
		ll tmp_ans = 0;
		for(int j=0;j<M;j++) tmp_ans += vec[j];
		ans = max(ans, tmp_ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll modpow(ll a, ll t) {
    if(t < 0) assert(false);
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

ll modinv(ll a) {
    return modpow(a, MOD-2);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, s, aa;
    cin >> n >> s;
    vector<vector<ll>> a(n+1, vector<ll>(s+1, 0));
    a[0][0] = modpow(2LL, n);
    ll ans = 0LL;
    for(int i=0;i<n;++i) {
        cin >> aa;
        for(int si=0;si<=s;++si) {
            if(si+aa <= s) {
                a[i+1][si+aa] += (a[i][si] * modinv(2LL)) % MOD;
                a[i+1][si+aa] %= MOD;
            }
            a[i+1][si] += a[i][si];
            a[i+1][si] %= MOD;
        }
        ans += a[i+1][s];
        ans %= MOD;
    }

    cout << a[n][s] << endl;
}


Measured memory_bytes: 73688
#include<iostream>
using namespace std;
int main()
{
  int p , q ,r;
  cin>>p>>q>>r;
 
  if(p==5&&q==7&&r==5||p==5&&q==5&&r==7||p==7&&q==5&&r==5)
        cout<<"YES"<<endl;
  else 
       cout<<"NO"<<endl;
 
}

Measured memory_bytes: 3624