akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
ll n;
double dp[301][301][301];
bool vis[301][301][301];
double count(int x,int y,int z){
    if(vis[x][y][z]){
        return dp[x][y][z];
    }
    vis[x][y][z]=true;
    if(x+y+z==0){
        return dp[x][y][z]=0;
    }
    int total=x+y+z;
    double ans=double(n-total)/double(total);
    if(x>0){
        ans+=(double(x)/double(total)*count(x-1,y,z));
    }
    if(y>0){
        ans+=(double(y)/double(total)*count(x+1,y-1,z));
    }
    if(z>0){
        ans+=(double(z)/double(total)*count(x,y+1,z-1));
    }
    ans+=1;
    return dp[x][y][z]=ans;
}
int main() {
    FIO;
    //test
    {
        cin>>n;
        vector<ll>a(4,0);
        for(int i=0;i<n;i++){
            cin>>a[0];
            a[a[0]]++;
        }
        memset(vis,false,sizeof(vis));
        cout<<fixed<<setprecision(10)<<count(a[1],a[2],a[3])<<endl;
    }
	return 0;
}


Measured memory_bytes: 137832
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;
 
ll dp[5050],dp2[25000001];
ll w[5],w2[5];
ll v[5],v2[5];

int main(){
  ll n;
  cin >> n;
  ll a[2][3];
  rep(i,2){
    rep(j,3)cin >> a[i][j];
  }
  rep(i,3){
    w[i]=a[0][i];
    v[i]=a[1][i];
    w2[i]=a[1][i];
    v2[i]=a[0][i];
  }
  v[3]=1;
  w[3]=1;
  v2[3]=1;
  w2[3]=1;
  for(int i=0;i<4;i++){
    for(int j=0;j<=n;j++){
      if(j<w[i]){
        dp[j]=dp[j];
      }else{
        dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
      }
    }
  }
  ll m=dp[n];
  for(int i=0;i<4;i++){
    for(int j=0;j<=m;j++){
      if(j<w2[i]){
        dp2[j]=dp2[j];
      }else{
        dp2[j]=max(dp2[j],dp2[j-w2[i]]+v2[i]);
      }
    }
  }
  cout << dp2[m] << endl;
return 0;}


Measured memory_bytes: 195584
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream','#')
f=0
for i in s:
    if(i!='#'):
        f=1
        break
if(f==0):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 63360
using System.Collections.Generic;
    using System.Collections;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System;

namespace cysharp_test
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().solve();
        }

        void solve()
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            if (S.Length <= K)
            {
                Console.WriteLine(S);
            }
            else
            {
                Console.Write(S.Substring(0, K));
                Console.WriteLine("...");
            }

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 17580
w, h, x, y, r = map(int, input().split())

if (x >= -100 and x <= 100) and (y >= -100 and y <= 100):
    if (w > 0 and w <= 100) and (h > 0 and h <= 100) and (r > 0 and r <= 100):
        
        if x > w:
            print("No")
        elif y > h:
            print("No")
        elif x < 0:
            print("No")
        elif y < 0:
            print("No")
        elif (x + r) > w:
            print("No")
        elif (y + r) > h:
            print("No")
        elif x < r:
            print("No")
        elif y < r:
            print("No")
        else:
            print("Yes")

Measured memory_bytes: 7708
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,L;
  cin>>N>>L;
  vector<string> S(N);
  string A;
  rep(i,N)cin>>S[i];
  sort(begin(S),end(S));
  rep(i,N)A+=S[i];
  cout<<A<<endl;
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s[0]!='A')
    {
        cout<<"WA"<<endl;
        return 0;
    }
    else
    {
        int c=0,f=0;
        for(int i=2; i<s.size()-1; i++)
        {
            if(s[i]=='C')
            {
                c++;
                s[i]='c';
            }
        }
        if(c!=1)
        {
            cout<<"WA"<<endl;
            return 0;
        }
        for(int i=1; i<s.size(); i++)
        {
            if(s[i]>='A' && s[i]<='Z')
            {
                cout<<"WA"<<endl;
                return 0;
            }
        }
        cout<<"AC"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
vector<int> tree[100001];
ll dp1[100001], dp2[100001];
void solve2(int src, bool vis[], int m, ll par_ans)
{
    vis[src] = 1;
    dp2[src] = ((1+par_ans) * dp1[src]) % m;
    vector<ll> prefix, suffix;
    for(int child : tree[src])
    {
        if(!vis[child]){
        prefix.push_back(1 + dp1[child]);
        suffix.push_back(1 + dp1[child]);}
    }
    for(int i = suffix.size() - 2; i >= 0; i --)
    {
        suffix[i] = (suffix[i] * suffix[i+1]) % m;
    }
    for(int i = 1; i < prefix.size(); i ++)
    {
        prefix[i] = (prefix[i] * prefix[i-1]) % m;
    }
    int cno = 0;
    for(int child : tree[src])
    {
        if(!vis[child])
        {
            ll ways = (1 + par_ans);
            ways = (cno > 0) ? (ways * prefix[cno-1]) % m : ways;
            ways = (cno < suffix.size() - 1) ? (ways * suffix[cno+1]) %m : ways;
            solve2(child, vis, m, ways);
            cno++;
        }
    }
}
 
void solve1(int src, bool vis[], int m)
{
    vis[src] = 1;
    dp1[src] = 1;
    for(int child : tree[src])
    {
        if(!vis[child])
            {
                solve1(child, vis, m);
                dp1[src] = (dp1[src] * (1 + dp1[child]))%m;
            }
    }
}
 
int main() {
   int n,m; 
   cin >> n >>m;
   for(int i = 0; i < n-1; i++)
   {
       int u,v;
       cin >> u>> v;
       tree[u].push_back(v);
       tree[v].push_back(u);
   }
   bool vis[n+1];
   memset(vis, 0, sizeof vis);
   solve1(1, vis, m);
   memset(vis, 0, sizeof vis);
   solve2(1, vis, m, 0);
   for(int i = 1; i <= n; i++)
    cout<<dp2[i]<<'\n';
   return 0;
}

Measured memory_bytes: 25344
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vb=vector<bool>;
ll n,a,b;

map<int,int> int_counter(vi vec) {
    map<int,int> counter;
    for(auto v:vec) {
        counter[v]++;
    }
    return counter;
}

int main() {
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int max_passed = a+b,passed = 0;
    int rank = 1;
    for(auto v:s){
        bool res = false;
        if(v=='a')if(passed<max_passed)res=true;
        if(v=='b')if(passed<max_passed&&rank <= b){res=true;rank++;}
        cout << (res?"Yes":"No") << endl;
        if(res)passed++;
    }
    return 0;
}


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

int main(int argc, const char * argv[]) {
    int X, Y;
    cin >> X;
    cin >> Y;
    for (int i = 0; i <= X; i++) {
        int ans = i * 2 + (X - i) * 4;
        if (ans == Y) {
            std::cout << "Yes";
            return 0;
        }
    }
    
    std::cout << "No";
    return 0;
}

Measured memory_bytes: 3128
def card_eater():
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	total_cards = len(a)
	total_distinct_cards = len(list(set(a)))
	numofcards_to_remove = total_cards-total_distinct_cards
	if numofcards_to_remove%2==0:
		print total_distinct_cards
	else:
		print total_distinct_cards-1


if __name__ == "__main__":
	card_eater()

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

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

	int total,i,j;
	int books[9], res[10];
	
	j = 0;

	while(1){

		cin >> total;
		if(total == 0) break;
		for(i=0; i<9; i++) cin >> books[i];
		for(i=0; i<9; i++) total -= books[i];
		res[j] = total;
		j++;
	}
	
	j = 0;

	while(1){
		if(res[j] == 0) break;
		else	printf("%d\n", res[j]);
		j++;
	}

	return 0;
}

Measured memory_bytes: 1192
n = int(input())
li = list(map(int, input().split()))
num = 0
count = 0
for item in li:
    if (item % 2 == 0):
        num += 1
        if(item % 3 == 0 or item % 5 == 0):
            count += 1
if(num == count):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
int main()
{
    ll b,l;
    double c,a;
    cin>>l;
    c=l*1.0/3.0;
    a=c*c*c;
    printf("%0.12lf\n",a);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#ifndef NULL
#define NULL 0
#endif
using namespace std;

const int MAXN = 50000 + 10;
const double pi = acos(-1.0);
const double inf = 1e100;
const double eps = 1e-12;

int zhengfu(double d)
{
    if (fabs(d) < eps)
        return 0;
    if (d > 0)
        return 1;
    return -1;
}
int bijiao(double x, double y)
{
    if (fabs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}
struct vec {
    double x, y;
    double p;
    vec(double x, double y)
    {
        this->x = x;
        this->y = y;
    }
    vec() {}
    vec operator*(const vec& i_T) const
    {
        return vec(x * i_T.x, y * i_T.y);
    }
    vec operator*(double u) const
    {
        return vec(x * u, y * u);
    }
    bool operator==(const vec& i_T) const
    {
        return x == i_T.x && y == i_T.y;
    }
    vec operator/(double u) const
    {
        return vec(x / u, y / u);
    }
    vec operator+(const vec& i_T)
    {
        return vec(x + i_T.x, y + i_T.y);
    }
    vec operator-(const vec& i_T)
    {
        return vec(x - i_T.x, y - i_T.y);
    }
    friend bool operator<(vec a, vec b)
    {
        return a.p < b.p;
    }

} p[MAXN];

double chaji(vec A, vec B)
{
    return A.x * B.y - A.y * B.x;
}
double xuanzhuan(vec a, vec b, vec c)
{
    return chaji(b - a, c - a);
}
vec q[MAXN],tp;
int n;
void Graham(int& tail)
{
    int zz = 0;
    for (int i = 0; i < n; i++)
        if (p[i].y < p[zz].y || (p[i].y == p[zz].y && p[zz].x > p[i].x))
            zz = i;
    swap(p[0], p[zz]);

    for (int i = 1; i < n; i++) {
        p[i] = p[i] - p[0];
        p[i].p = atan2(p[i].y, p[i].x);
    }
    p[0].x = p[0].y = 0;
    sort(p + 1, p + n);

    q[0] = p[0];
    tail = 0;
    for (int i = 1; i < n; i++) {
        while (tail>0 && xuanzhuan(q[tail - 1], q[tail], p[i]) < 0)
            tail--;
        q[++tail] = p[i];
    }
}

int main()
{
    //freopen("txt.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> p[i].x >> p[i].y;

    int t = p[0].y, f = 1;
    for (int i = 0; i < n; i++)
        if (t != p[i].y) {
            f = 0;
            break;
        }
    if (!f) {
        int tail;
        Graham(tail);
        cout << (tail+1 == n) << endl;
        /*for (int i = 0; i <= tail; i++)
            cout << q[i].x+tp.x << ' ' << tp.y+q[i].y << endl;*/
    } else
        cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 3468
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  priority_queue<int, vector<int> > que;
  for (int i = 0; i < n; ++i) {
    que.push(a[i]);
  }
  for (int i = 0; i < m; ++i) {
    int p = que.top();
    que.pop();
    p /= 2;
    que.push(p);
  }
  ll ans = 0;
  while (!que.empty()) {
    int p = que.top();
    que.pop();
    ans += p;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  int a[3];
  rep(i, 3) {
    a[i] = -1;
  }
  rep(i, M) {
    int s, c;
    cin >> s >> c;
    s--;
    if(s == 0) {
      if(N != 1 && c == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    if(a[s] == -1) {
      a[s] = c;
    } else if(a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i, N) {
    if(i == 0) {
      if(a[i] == -1) {
        if(N == 1) a[i] = 0;
        else a[i] = 1;
      }
    } else {
      if(a[i] == -1) {
        a[i] = 0;
      }
    }
  }
  rep(i, N) {
    cout << a[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>H(N);
	for (int i = 0; i < N; i++)cin >> H[i];
	for (int i = 0; i < N - 1; i++)if (H[i + 1] - H[i] >= 1)H[i + 1]--;
	for (int i = 0; i < N - 1; i++)
	{
		if (H[i + 1] - H[i] < 0)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 1152
#define _GLIBCXX_DEBUG
#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()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  vector<ll> b;
  ll tmp = a[0];
  int c = 1;
  for (int i = 1; i < n; i++){
    if (a[i] == tmp){
      c++;
      if (c%2 == 0) b.push_back(tmp);
    } else {
      tmp  = a[i];
      c = 1;
    }
  }
  if (b.size() >= 2) {
    ll ans = b[b.size()-1] * b[b.size()- 2];
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1660
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,a[100010],pos;
vector <pii> ans;
bool po=false,ne=false,ze=false;

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
		if(a[i]>0) po=true;else
		if(a[i]<0) ne=true;else
		ze=true;
	}
	sort(a,a+n);
	repn(i,n-2)
	{
		if(a[i]>=0) 
		{
			ans.pb({a[0],a[i]});
			a[0]-=a[i];
		}
	}
	repn(i,n-2)
	{
		if(a[i]<0)
		{
			ans.pb({a[n-1],a[i]});
			a[n-1]-=a[i];
		}
	}
	cout<<a[n-1]-a[0]<<endl;
	ans.pb({a[n-1],a[0]});
	rep(i,ans.size()) cout<<ans[i].fi<<' '<<ans[i].se<<endl;
	rt0;
}

Measured memory_bytes: 4336
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

F = [[0]*3 for i in range(3)]
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        F[i][j] = 1
ans = 0
for i in range(3):
  f = 1
  for j in range(3):
    if F[i][j] != 1:
      f = 0
  if f ==1:
    ans = 1
for j in range(3):
  f = 1
  for i in range(3):
    if F[i][j] != 1:
      f = 0
  if f == 1:
    ans = 1
if F[0][0] and F[1][1] and F[2][2]:
  ans = 1
if F[0][2] and F[1][1] and F[2][0]:
  ans = 1
print("Yes" if ans else "No")
# print(F)

Measured memory_bytes: 38384
X,Y = map(int,input().split())
ans = 0
shokin = [-1,300000,200000,100000]
if X in (1,2,3):
    ans += shokin[X]
if Y in (1,2,3):
    ans += shokin[Y]
if X == 1 and Y == 1:
    ans += 400000
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


Measured memory_bytes: 2708
a,b = map(int,input().split(" "))

if a > b:
    small = b
    big = a
elif a == b:
    print(0)
    exit()
else:
    small = a
    big = b

if (big-small)%2 != 0:
    print("IMPOSSIBLE")
else:
    print(small+(big-small)//2)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,N,K,ans=0;
  cin>>N;N++;
  vec x(N+1,0);
  rep1(i,N){
    cin>>x[i];
    ans+=abs(x[i]-x[i-1]);
  }
  ans+=abs(x[N-1]);
  rep1(i,N){
    cout<<ans-abs(x[i]-x[i-1])-abs(x[i]-x[i+1])+abs(x[i+1]-x[i-1])<<endl;;
  }
  return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc061/tasks/abc061_b

int main() {
    int N, M;
    cin >> N >> M;

    int a, b;
    int arr[N]; REP(i, N) arr[i] = 0;
    REP(i, M) {
        cin >> a >> b;
        a--; b--;
        arr[a]++;
        arr[b]++;
    }

    REP(i, N) {
        cout << arr[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import numpy as np


def a():
    x, y = map(int, input().split())


def b():
    n = int(input())
    a = np.asarray(list(map(int, input().split())))
    b = np.asarray(list(map(int, input().split())))
    x = b.sum() - a.sum()
    d = b - a
    a_req = 0
    b_req = 0
    for i in d:
        if i <= 0:
            b_req += i // -1
        else:
            a_req += i // 2 + i % 2
            b_req += i % 2
    # total require
    if (a_req >= b_req and (0 < a_req + (a_req - b_req) == x)) or (a_req == 0 and b_req == 0):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    b()


Measured memory_bytes: 21504
#include <stdio.h>
int main() {
    int S;
    int h,m,s;
    scanf("%d",&S);
    h = S / 3600;
    m = (S -h*3600) / 60;
    s = S - 3600 * h - m * 60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 1812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 10000007

int main()
{
    Graf a(3,vector<int>(3));
    
    rep(i,3){
        rep(j,3){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n)cin >> b[i];

    rep(k,n){
        rep(i,3){
            rep(j,3){
                if(a[i][j]==b[k]){
                    a[i][j]=MAX;
                }
            }
        }
    }
    bool ans=false;

    rep(i,3){
        int num=0;
        rep(j,3){
            if(a[i][j]==MAX){
                num++;
            }
        }
        if(num==3){
            ans=true;
            Yes;return 0;
        }
        num=0;
    }
    rep(i,3){
        int num=0;
        rep(j,3){
            if(a[j][i]==MAX){
                num++;
            }
        }
        if(num==3){
            Yes;return 0;
        }
    }
    if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&a[0][0]==MAX){
        Yes;return 0;
    }
    if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]&&a[0][2]==MAX){
        Yes;return 0;
    }
    No;
}

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

int main()
{
    string s;
    int counter = 0;
    cin  >> s;
    if (s[0] == '1') ++counter;
    if (s[1] == '1') ++counter;
    if (s[2] == '1') ++counter;
    cout << counter << endl;
}

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

using namespace std;

int kei(int,int,int);

int main(void){
	int in[4],flag=0;
	int i,j,k;
	string s("+-*");
	
	while(1){
		cin>>in[0]>>in[1]>>in[2]>>in[3];
		if(in[0]==0 && in[1]==0 && in[2]==0 && in[3]==0)	break;
		sort(in,in+4);	//昇順
		
		do{
			for(i=0;i<3;i++){
				for(j=0;j<3;j++){
					for(k=0;k<3;k++){
						if(kei(kei(kei(in[0],in[1],i),in[2],j),in[3],k) == 10){
							cout<<"(("<<in[0]<<" "<<s[i]<<" "<<in[1]<<")"<<" "<<s[j]<<" "<<in[2]<<")"<<" "<<s[k]<<" "<<in[3]<<endl;
							flag=1;
							break;
						}
						if(kei(kei(in[0],in[1],i),kei(in[2],in[3],k),j) == 10){
							cout<<"("<<in[0]<<" "<<s[i]<<" "<<in[1]<<") "<<s[j]<<" ("<<in[2]<<" "<<s[k]<<" "<<in[3]<<")"<<endl;
							flag=1;
							break;
						}
						if(kei(kei(in[0],kei(in[1],in[2],j),i),in[3],k) == 10){
							cout<<"("<<in[0]<<" "<<s[i]<<" ("<<in[1]<<" "<<s[j]<<" "<<in[2]<<")) "<<s[k]<<" "<<in[3]<<endl;
							flag=1;
							break;
						}
						if(kei(in[0],kei(kei(in[1],in[2],j),in[3],k),i) == 10){
							cout<<in[0]<<" "<<s[i]<<" (("<<in[1]<<" "<<s[j]<<" "<<in[2]<<") "<<s[k]<<" "<<in[3]<<")"<<endl;
							flag=1;
							break;
						}
					}
					if(flag==1)	break;
				}
				if(flag==1)	break;
			}
		}while(next_permutation(in,in+4) && flag==0);
		if(flag==0)	cout<<0<<endl;
		flag=0;
	}
	return 0;
}

int kei(int x,int y,int ki){
	switch(ki){
		case 0:
			return x+y;
		case 1:
			return x-y;
		case 2:
			return x*y;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    REP(i, H) cin >> A[i];

    vector<vector<int> > dist(H, vector<int>(W, 1e9));
    queue<pair<int, int> > q;
    REP(i, H) REP(j, W) if(A[i][j] == '#') {
        q.push({i, j});
        dist[i][j] = 0;
    }
    while(!q.empty()) {
        auto s = q.front();
        q.pop();

        int i = s.first, j = s.second;
        for(int dx=-1; dx<=1; dx++)
            for(int dy=-1; dy<=1; dy++)
                if(i+dy >= 0 && i+dy < H && j+dx >=0 && j+dx < W && (dx==0 || dy==0)) {
                    dist[i+dy][j+dx] = min(dist[i+dy][j+dx], dist[i][j]+1);
                    if(A[i+dy][j+dx] == '.') {
                        A[i+dy][j+dx] = '#';
                        q.push({i+dy, j+dx});
                    }
                }
    }

    int ans = 0;
    REP(i, H) REP(j, W) if(ans < dist[i][j]) ans = dist[i][j];

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; ++i) {
    int from, to;
    cin >> from >> to;
    --from;
    --to;
    adj[from].push_back(to);
    adj[to].push_back(from);
  }
  int ans = 1 << 30;
  for (int i = 0; i < n; ++i) {
    vector<int> size(n);
    vector<int> foo(n);
    vector<int> bar(n);
    function<void(int, int)> dfs = [&](int x, int p) {
      size[x] = s[x] == '1';
      vector<int> son;
      for (auto y : adj[x]) {
        if (y != p) {
          son.push_back(y);
          dfs(y, x);
          size[x] += size[y];
          foo[x] += foo[y];
        }
      }
      if (!son.empty()) {
        sort(son.begin(), son.end(), [&](int u, int v) {
          return foo[u] < foo[v];
        });
        int other = 0;
        for (int i = 0; i < (int) son.size() - 1; ++i) {
          other += foo[son[i]];
        }
        bar[x] = max(0, bar[son.back()] - other);
      }
      foo[x] += size[x];
      bar[x] += size[x];
    };
    dfs(i, -1);
    if (bar[i] == size[i] && (foo[i] - size[i]) % 2 == 0) {
      ans = min(ans, (foo[i] - size[i]) / 2);
    }
  }
  if (ans == 1 << 30) {
    cout << -1 << "\n";
  } else {
    cout << ans << "\n";
  }
  return 0;
}


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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> v;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int a,b; cin >> a >> b;
    int ans = (a + b + 1) / 2;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define INF 0x3f3f3f3f
#define EXP 1e-9
#define MAXN 1000005
#define ltree 2*id,ll,mid
#define rtree 2*id+1,mid+1,rr
#define FO(i,n,m) for(LL i=n;i<=m;++i)
#define mem(a) memset(a,0,sizeof(a))
typedef long long LL;
using namespace std;


int main()
{

    LL x,y;
    cin>>x>>y;
    LL ans=1;
    LL temp=x*2;
    while(temp<=y&&temp>=x)
    {
        ans++;
        temp*=2;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define INF 1001001001
int min(int x, int y) {
	return x < y ? x : y;
}
int max(int x, int y) {
	return x > y ? x : y;
}
int dp[20100];
int main() {
	int h, n, hp[1000], mp[1000], maxHP = 0;
	scanf("%d%d", &h, &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &hp[i], &mp[i]);
		maxHP = max(maxHP, hp[i]);
	}
	for (int i = 0; i <= h + maxHP; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < n; j++) {
			dp[i + hp[j]] = min(dp[i + hp[j]], dp[i] + mp[j]);
		}
	}
	int ans = INF;
	for (int i = h; i <= h + maxHP; i++) {
		ans = min(ans, dp[i]);
	}
	printf("%d\n", ans);
	return 0;
}

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

int r;
int D;
int x[11];

int main(){
  cin >> r >> D >> x[0];
  for(int i = 1; i <= 10; i++){
    x[i] = (x[i - 1] * r) - D;
    cout << x[i] << "\n";
  }
}

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

int main(){
    int E,Y;
    cin >> E >> Y;
    if(E == 0){
        if(1868 <= Y && Y <= 1911){
            cout << 'M' << Y - 1867 << endl;
        }
        if(1912 <= Y && Y <= 1925){
            cout << 'T' << Y - 1911 << endl;
        }
        if(1926 <= Y && Y <= 1988){
            cout << 'S' << Y - 1925 << endl;
        }
        if(1989 <= Y && Y <= 2016){
            cout << 'H' << Y - 1988 << endl;
        }
    }
    else if(E == 1) cout << Y + 1867 << endl;
    else if(E == 2) cout << Y + 1911 << endl;
    else if(E == 3) cout << Y + 1925 << endl;
    else cout << Y + 1988 << endl;

}


Measured memory_bytes: 3088
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    int a[n];
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        ans^=a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cout<<(ans^a[i])<<" ";
    }

    printclock;
    return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	
	std::vector<int> dp(n, 1000000001);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j <= i + k && j < n; j++) dp[j] = std::min(dp[j], dp[i] + std::abs(a[i] - a[j]));
	std::cout << dp.back() << std::endl;
	return 0;
}


Measured memory_bytes: 1024
package main

import (
   "fmt"
)

func solution(t int, matrix [][]int) []int64 {
   out := make([]int64, 0)
   memo := make(map[int64]int64, 0)
   var a, b, c, d int64
   var helper func(n int64) int64
   helper = func(n int64) int64 {

        if n == 0 {
                return 0
        }
        if n == 1 {
                return d
        }

        if k, ok := memo[n]; ok {
                return k
        }

        var l2, r2, l3, r3, l5, r5 int64

        l2 = (n / 2) * 2
        r2 = ((n + 1) / 2) * 2
        l3 = (n / 3) * 3
        r3 = ((n + 2) / 3) * 3
        l5 = (n / 5) * 5
        r5 = ((n + 4) / 5) * 5

        var res int64 = 1e18
        if n < res/d {
                res = n * d
        }

        res = min(res, abs(l2-n)*d+a+helper(l2/2))
        res = min(res, abs(r2-n)*d+a+helper(r2/2))

        res = min(res, abs(l3-n)*d+b+helper(l3/3))
        res = min(res, abs(r3-n)*d+b+helper(r3/3))

        res = min(res, abs(l5-n)*d+c+helper(l5/5))
        res = min(res, abs(r5-n)*d+c+helper(r5/5))

        memo[n] = res
        return res
   }
   for i := range matrix {
        memo = make(map[int64]int64, 0)
        n := int64(matrix[i][0])
        a = int64(matrix[i][1])
        b = int64(matrix[i][2])
        c = int64(matrix[i][3])
        d = int64(matrix[i][4])
        out = append(out, helper(n))
   }

   return out
}

func abs(x int64) int64 {
   if x < 0 {
        return -x
   }
   return x
}

func min(x, y int64) int64 {
   if x < y {
        return x
   }
   return y
}

func main() {
   var t int
   fmt.Scan(&t)
   matrix := make([][]int, t)
   for i := range matrix {
        var n, a, b, c, d int
        fmt.Scan(&n, &a, &b, &c, &d)
        matrix[i] = make([]int, 5)
        matrix[i] = []int{n, a, b, c, d}
   }
   for _, a := range solution(t, matrix) {
        fmt.Println(a)
   }
}

Measured memory_bytes: 6440
# -*- coding: utf-8 -*-
import bisect
# import heapq
# import math
# import random
import sys
# from collections import Counter, defaultdict, deque
# from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
# from functools import lru_cache, reduce
# from itertools import combinations, combinations_with_replacement, product, permutations
# from operator import add, mul, sub

sys.setrecursionlimit(100000)
# input = sys.stdin.buffer.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


ans = [-1] * (2*10**5+1)

@mt
def slv(N, A, UV):
    A.insert(0, -1)
    g = [list() for _ in range(0, N+1)]
    for u, v in UV:
        g[u].append(v)
        g[v].append(u)


    def dfs(u, p, dp):
        global ans

        for v in g[u]:
            if v == p:
                continue

            i = bisect.bisect_left(dp, A[v])
            if len(dp) <= i:
                dp.append(A[v])
                ans[v] = len(dp)
                dfs(v, u, dp)
                dp.pop()
            else:
                b = dp[i]
                dp[i] = A[v]
                ans[v] = len(dp)
                dfs(v, u, dp)
                dp[i] = b
    dp = [A[1]]
    dfs(1, 0, dp)

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

    # return ans[:N]


def main():
    N = read_int()
    A = read_int_n()
    UV = [read_int_n() for _ in range(N-1)]
    (slv(N, A, UV))


if __name__ == '__main__':
    main()


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

const int ND = 112345;
int cost[ND], profit[ND];

void solve(){
	int n,t;
	cin >> n >> t;
	for(int i = 0; i < n; ++i)
		cin >> cost[i];
	
	int best = cost[n-1];
	int max_profit = 0;
	for(int i = n-2; i >= 0; --i){
		profit[i] = max(0,best-cost[i]);
		max_profit = max(max_profit,profit[i]);
		best = max(best,cost[i]);
	}
	
	int ans = 0;
	for(int i = 0; i < n-1; ++i)
		ans += (max_profit == profit[i]);
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * https://beta.atcoder.jp/contests/abc070/tasks/abc070_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		final int a = sc.nextInt();
		final int b = sc.nextInt();
		final int c = sc.nextInt();
		final int d = sc.nextInt();
		sc.close();
		
		int ans = 0;
		for(int i=0; i<=100; i++){
			if(a<=i && i<b && c<=i && i<d) ans++;
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int sum=0;
    string s = to_string(n);
    for(int i=0;i<s.length();i++)sum += (s[i]-'0');
    if(n%sum==0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  int N, D;
  cin >> N >> D;
  
  vector<vector<int>> vec(N, vector<int>(D));

  for (int i = 0; i < N; i++){
    for (int j = 0; j < D; j++){
      cin >> vec.at(i).at(j);
    }
  }

  int cnt = 0;
  double diff;
  for (int i = 0; i < N - 1; i++){
    for (int j = i + 1; j < N; j++){
      diff = 0;

      for (int k = 0; k < D; k++){
        diff += pow(vec.at(i).at(k) - vec.at(j).at(k), 2);
      }
      diff = sqrt(diff);
      if (floor(diff) == diff) cnt += 1;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3676
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) begin(x),end(x)
#define msi map<string,int>
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define sh short int
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const ll inf = 1e18;
const ll mod = 1e9+7;
const int shift = 50;
int dp[3009][3009];
string s,s1,s2;
int bt(int id1,int id2){
    if(id1 == s1.size() || id2 == s2.size()) return 0;
    int &ret = dp[id1][id2];
    if(ret != -1) return ret;
    ret = max(bt(id1+1,id2),bt(id1,id2+1));
    if(s1[id1] == s2[id2]){
        ret = max(ret,bt(id1+1,id2+1)+1);
    }
    return ret;
}
void path(int id1,int id2){
    if(id1 == s1.size() || id2 == s2.size()) return;
    int ret = dp[id1][id2];
    if(ret == bt(id1+1,id2)){
        path(id1+1,id2);
        return;
    }
    if(ret == bt(id1,id2+1)){
        path(id1,id2+1);
        return;
    }
    s += s1[id1],path(id1+1,id2+1);
}
int main(){
    fast,cin>>s1>>s2;
    memset(dp,-1,sizeof(dp));
    int x = bt(0,0); path(0,0);
    cout<<s<<endl; return 0;
}


Measured memory_bytes: 36224
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
ll a,b,c;
int main(void){
    scanf("%lld%lld%lld",&a,&b,&c);
    if(c>a+b)printf("%lld\n",a+b+b+1);
    else printf("%lld\n",b+c);
    return 0;
}


Measured memory_bytes: 256
n=int(input())
count=0
ans=0
for j in range(1,n+1,2):
  count=0
  for i in range(1,int(j**0.5)+1):
    if j%i==0:
      if j//i!=i:
        count+=2
      else:
        count+=1
  if count==8:
    ans+=1
print(ans)



Measured memory_bytes: 3060
def answer(arr):
    n = len(arr)
    count = 0
    INC = 'INCREASING'
    DEC = 'DECREASING'
    STATE = None
    if n == 1 or n == 2:
        return 1
    for i in range(n-1):
        diff = arr[i+1] - arr[i]
        if diff == 0:
            continue
        if STATE is None:
            if diff > 0:
                STATE = INC
            if diff < 0:
                STATE = DEC
            count += 1
        elif STATE is INC:
            if diff < 0:
                STATE = None
        elif STATE is DEC:
            if diff > 0:
                STATE = None
        if STATE is None and i == n-2:
            count += 1
            
    return count

n = int(input())
arr = list(map(int, input().split()))
print(answer(arr))

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

int main(){
  std::string str;
  bool n = false, e = false, w = false, s = false;
  std::cin >> str;
  for(int i = 0; str.c_str()[i] != '\0'; i++){
    switch(str.c_str()[i]){
    case 'N':
       n = true;break;
    case 'E':
      e = true;break;
    case 'W':
       w = true;break;
    case 'S':
       s = true;break;
    }
}
    if(n != s || e != w){
       std::cout << "No" << std::endl;
   }else{
        std::cout << "Yes" << std::endl;
   }
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	string s;
	cin >> s;
	int ans = INF;
	rep(i, s.size() - 2) {
		string num = s.substr(i, 3);
		int n = stoi(num);
		ans = min(ans, abs(753 - n));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    int now = 0, sum = 0, num = 0;
    sort(a.begin(), a.end());
    repi(i, a){
        if(*i != now){
            //cout <<  << " " << now << endl;
            sum += (now <= num ? num - now : num);
            now = *i;
            num = 1;
        }else{
            num++;
        }
    }
    sum += (now <= num ? num - now : num);
    //cout << num << " " << now << endl;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  int n,m;
  cin >>n >> m;
  cout <<n*(n-1)/2+m*(m-1)/2 << endl;
}


Measured memory_bytes: 256
/*
    AOJ Volume0 0003

    Simultaneous Equation

    Write a program which solve a simultaneous equation:
        ax+by=c
        dx+ey=f

    The program should print x and y for given 
    a, b, c, d, e and f (-1,000 ≤ a,b,c,d,e,f ≤ 1,000).
    You can suppose that given equation has a unique solution.
    
    Input
        The input consists of several data sets, 1 line for each data set.
        In a data set, there will be a,b,c,d,e,f separated by a single space.
        The input terminates with EOF.

    Output
        For each data set, print x and y separated by a single space.
        Print the solution to three places of decimals. Round off the solution to three decimal places.

    Sample Input 1
        1 2 3 4 5 6
        2 -1 -2 -1 -1 -5

    Output for the Sample Input 1
        -1.000 2.000
        1.000 4.000

    Sample Input 2
        2 -1 -3 1 -1 -3
        2 -1 -3 -9 9 27

    Output for the Sample Input 2
        0.000 3.000
        0.000 3.000


*/

#include <iostream>
#include <iomanip>

int main(void)
{

    while(true)
    {
        double a,b,c,d,e,f;
        if(std::cin >> a >> b >> c >> d >> e >> f)
        {
            double rate = d / a; 
            double 
                a2 = a * rate,
                b2 = b * rate,
                c2 = c * rate;

            double
                d2 = d - a2,  // defintly 0
                e2 = e - b2,
                f2 = f - c2;

            double y = f2 / e2;
            double x = (c - b*y) / a;

            std::cout << std::setprecision(3) << std::fixed << x << " " << y << std::endl;
        }

        else break;
    }

    return 0;

}


Measured memory_bytes: 3260
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
cnt = 0
past = []
while True:
    n = prime_factorize(N)
    if not n:
        break
    m = set(n)
    nn = []
    for i in m:
        for j in range(1, n.count(i)+1):
            nn.append(pow(i, j))
    for i in nn:
        if not (i in past):
            N = int(N / i)
            past.append(i)
            cnt+=1
            break
    else:
        break
print(cnt)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    cout << (N + 2 - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int M;
  cin >> M;
  vector<int> d(M);
  vector<long long> c(M);
  for (int i = 0; i < M; i++){
    cin >> d[i] >> c[i];
  }
  long long cnt = 0;
  long long sum = 0;
  for (int i = 0; i < M; i++){
    cnt += c[i];
    sum += c[i] * d[i];
  }
  cout << cnt + (sum - 1) / 9 - 1 << endl;
}

Measured memory_bytes: 5632