akhauriyash/Code-Regression huggingface dataset:
n,p=map(int,input().split())
from collections import Counter
a=[]
while p%2==0:
  a.append(2)
  p//=2
f=3
while f<=p:
  if p%f==0:
    a.append(f)
    p//=f
  elif f*f>p:
    a.append(p)
    break
  else:
      f+=2
c=Counter(a)
ans=1
for k,v in c.items():
  if v>=n:
    ans*=k**(v//n)
print(ans)

Measured memory_bytes: 9436
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,j,n) for(int i = (int)(j); i < (int)(n); i++)
#define mrep(i,n) for (int i = (int)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll modn = 998244353;

int main() {
	ll x,y; cin >> x >> y;
	int ans=0;
	while(x<=y) {
		ans++;
		x*=2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3620
const int N = 400005;
const int LG = 21;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<int> t(n), f(n);
    forn(i, m)
    {
        int a, b;
        cin >> a >> b, a--, b--;
        if (a == 0) t[b] = 1;
        if (b == n - 1) f[a] = 1;
    }
    forn(i, n) if (t[i] && f[i]) cout << "POSSIBLE", exit(0);
    cout << "IMPOSSIBLE";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

using namespace std;

const int maxn = 1e4;
struct node
{
    int x, y;
} point[maxn];

bool cmp(node a, node b)
{
    return atan2(a.x, a.y) < atan2(b.x, b.y);
}
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> point[i].x >> point[i].y;
    }
    long long ans = 0;
    int tx, ty;
    sort(point, point + n, cmp);
    for (int i = 0; i < n; i++)
    {
        tx = point[i].x;
        ty = point[i].y;
        ans = max(ans, 1LL * tx * tx + 1LL * ty * ty);
        for (int j = (i + 1) % n; j != i; j = (j + 1) % n)
        {
            tx += point[j].x;
            ty += point[j].y;
            ans = max(ans, 1LL * tx * tx + 1LL * ty * ty);
        }
    }
    double res = sqrt(ans);
    printf("%.13f\n", res);
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;

int main()
{
	int n, m, cost[36][36];
	for (int i = 0;i < 36; ++i)
		for (int j = 0; j < 36; ++j)
			cost[i][j] = 9999999;
	for (int i = 0; i < 36; ++i)
		cost[i][i] = 0;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i)
	{
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		cost[a][b] = c;
		cost[b][a] = d;
	}
	int start, end, given, pay;
	scanf("%d,%d,%d,%d", &start, &end, &given, &pay);

	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

	printf("%d\n", given - (cost[start][end] + cost[end][start] + pay));

	return 0;
}

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

using namespace std;

const int N = 1e3 + 7;
const int mod = 1e9 + 7;

char a[N][N];
int f[N][N], n, m;

int main()
{
    cin >> n >> m;

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            if(i == 1 && j == 1) f[i][j] = 1;
            else if(a[i][j] != '#') f[i][j] = (f[i - 1][j] + f[i][j - 1]) % mod;
        }

    cout << f[n][m];
}


Measured memory_bytes: 5248
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <map>
#define ull unsigned long long
using namespace std;

int main()
{
    int n;
    cin>>n;

    double a[n];
    for (int i=0;i<n;i++) cin>>a[i];

    double sum = 0;
    for (int i=0;i<n;i++){
        sum+=(1/a[i]);
    }

    double d = 1 / sum;
    cout<<setprecision(10)<<fixed<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
namespace _0008
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input==null)
                {
                    break;
                }
                int now = int.Parse(input);
                int count = 0;
                for (int a = 0; a < 10; a++)
                {
                    for (int b = 0; b < 10; b++)
                    {
                        for (int c = 0; c < 10; c++)
                        {
                            for (int d = 0; d < 10; d++)
                            {
                                if (a + b + c + d == now)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  for(int i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


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

int main() {
  int n, m, a, b;
  int ans = 0;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> bad(n);
  rep(i, n) cin >> h.at(i);
  rep(i, m){
    cin >> a >> b;
    a--;
    b--;
    if(h[a] == h[b]) bad.at(a) = bad.at(b) = true;
    else if(h[a] < h[b]) bad.at(a) = true;
    else bad.at(b) = true;
  }
  rep(i, n){
    if(!bad.at(i)) ans++;
  }
  cout << ans << endl;
}
  
  

Measured memory_bytes: 3788
from bisect import*
class SquareSkipList:
    def __init__(self,values=None,sorted_=False,square=1000,seed=42):
        inf=float("inf")
        self.square=square
        if values is None:
            self.rand_y=seed
            self.layer1=[inf]
            self.layer0=[[]]
        else:
            self.layer1=layer1=[]
            self.layer0=layer0=[]
            if not sorted_:values.sort()
            y=seed
            l0=[]
            for v in values:
                y^=(y&0x7ffff)<<13
                y^=y>>17
                y^=(y&0x7ffffff)<<5
                if y%square<1:
                    layer0.append(l0)
                    l0=[]
                    layer1.append(v)
                else:l0.append(v)
            layer1.append(inf)
            layer0.append(l0)
            self.rand_y=y
    def add(self,x):
        y=self.rand_y
        y^=(y&0x7ffff)<<13
        y^=y>>17
        y^=(y&0x7ffffff)<<5
        self.rand_y=y
        if y%self.square<1:
            layer1,layer0=self.layer1,self.layer0
            idx1=bisect(layer1,x)
            layer1.insert(idx1,x)
            layer0_idx1=layer0[idx1]
            idx0=bisect(layer0_idx1,x)
            layer0.insert(idx1+1,layer0_idx1[idx0:])
            del layer0_idx1[idx0:]
        else:
            idx1=bisect(self.layer1,x)
            insort(self.layer0[idx1],x)
    def remove(self,x):
        idx1=bisect_left(self.layer1,x)
        layer0_idx1=self.layer0[idx1]
        idx0=bisect_left(layer0_idx1,x)
        if idx0==len(layer0_idx1):
            del self.layer1[idx1]
            self.layer0[idx1]+=self.layer0.pop(idx1+1)
        else:del layer0_idx1[idx0]
    def search_higher_equal(self,x):
        idx1=bisect_left(self.layer1,x)
        layer0_idx1=self.layer0[idx1]
        idx0=bisect_left(layer0_idx1,x)
        if idx0==len(layer0_idx1):return self.layer1[idx1]
        return layer0_idx1[idx0]
    def search_higher(self,x):
        idx1=bisect(self.layer1,x)
        layer0_idx1=self.layer0[idx1]
        idx0=bisect_right(layer0_idx1,x)
        if idx0==len(layer0_idx1):return self.layer1[idx1]
        return layer0_idx1[idx0]
    def search_lower(self,x):
        idx1=bisect_left(self.layer1,x)
        layer0_idx1=self.layer0[idx1]
        idx0=bisect_left(layer0_idx1,x)
        if idx0==0:return self.layer1[idx1-1]
        return layer0_idx1[idx0-1]
    def pop(self, idx):
        layer0=self.layer0
        s=-1
        for i,l0 in enumerate(layer0):
            s+=len(l0)+1
            if s>=idx:break
        if s==idx:
            layer0[i]+=layer0.pop(i+1)
            return self.layer1.pop(i)
        else:return layer0[i].pop(idx-s)
    def print(self):
        print(self.layer1)
        print(self.layer0)
def main():
    n,*a=map(int,open(0).read().split())
    l=[0]*n
    for i,v in enumerate(a,1):l[v-1]=i
    t=SquareSkipList()
    t.add(0)
    t.add(n+1)
    c=0
    for i,v in enumerate(l,1):
        c+=(t.search_higher(v)-v)*(v-t.search_lower(v))*i
        t.add(v)
    print(c)
main()

Measured memory_bytes: 24564
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int MaxN = 100;
int a[MaxN + 5];
int n;

int main()
{
	int ans = 0;
	scanf("%d", &n);
	for(int i = 1; i <= 2*n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + 1 + 2*n);
	for(int i = 1; i <= 2 * n; i += 2)
	{
		ans += a[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
using namespace std;
struct node{
  int key;
  node *parent,*left,*right;
};
node *NIL,*root;
void insert(int x){
  node *n,*r=root,*m=NIL;
  n=(node *)malloc(sizeof(node));
  n->key=x; n->left=NIL; n->right=NIL;
  while(r!=NIL){
    m=r;
    if(n->key<r->key) r=r->left;
    else r=r->right;
  }
  n->parent=m;
  if(m==NIL) root=n;
  else{
    if(n->key<m->key) m->left=n;
    else m->right=n;
  }
}
void inorder(node *p){
  if(p!=NIL){
    inorder(p->left);
    cout<<" "<<p->key;
    inorder(p->right);
  }
}
void preorder(node *p){
  if(p!=NIL){
    cout<<" "<<p->key;
    preorder(p->left);
    preorder(p->right);
  }
}
int main(){
  int n,x;
  char s[7]; cin>>n;
  for(int i=0;i<n;++i){
    cin>>s;
    if(s[0]=='i'){
      cin>>x;
      insert(x);
    }else{
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 26456
i = input().split(" ")
x = int(i[0])
y = int(i[1])

xx = 2 * x + (-1) * y
yy = (-1) * x + 2 * y

if (xx % 3) != 0 or (yy % 3) != 0:
  res = 0
else:
  xx = xx / 3
  yy = yy / 3

  def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
  
  mod = 10**9+7 #出力の制限
  N = 10**6
  g1 = [1, 1] # 元テーブル
  g2 = [1, 1] #逆元テーブル
  inverse = [0, 1] #逆元テーブル計算用テーブル

  for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

  res = cmb(int(xx+yy),int(yy),mod)
  
print(int(res))

Measured memory_bytes: 122048
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
int main() {
	long long int n, m, h, w;
	long long int l, s,x,y;
	long long int ans[3],anss[4];
	long long int max, min;
	cin >> h >> w;
	if (h%3 == 0 || w%3 == 0) {
		cout << 0 << endl;
	}
	else {
		for (int j = 0; j < 8; j++) {

			
			n = h * w / 3;

			if (h > w) {
				l = h;
				s = w;
			}
			else {
				l =	w;
				s = h;
			}

			if (j < 4) {
				x = l;
			}
			else {
				x = s;
			}
		
			y = n/x;

			if (j == 1 || j == 5) {
				y++;
			}
			else if (j == 2 || j == 6) {
				y = (n + 1) / x;
			}
			else if (j == 3 || j == 7) {
				y++;
			}


			ans[0] = x * y;

			if (j < 4) {
				s -= y;
			}
			else {
				l -= y;
			}

			if (l % 2 == 0) {
				l/=2;
				ans[1] = l * s;
				if (ans[0] > ans[1]) {
					anss[j] = ans[0] - ans[1];
				}
				else {
					anss[j] = ans[1] - ans[0];
				}
			}
			else if (s % 2 == 0) {
				s /= 2;
				ans[1] = s * l;
				if (ans[0] > ans[1]) {
					anss[j] = ans[0] - ans[1];
				}
				else {
					anss[j] = ans[1] - ans[0];
				}
			}
			else if (l > s) {
				m =l / 2;
				ans[1] = m * s;
				l -= m;
				ans[2] = l * s;
				max = ans[0];
				min = ans[0];
				for (int i = 1; i < 3; i++) {
					if (ans[i] > max) {
						max = ans[i];
					}
					if (ans[i] < min) {
						min = ans[i];
					}
				}
				anss[j] = max - min;
			}
			else {
				m = s / 2;
				ans[1] = l * m;
				s -= m;
				ans[2] = l * s;
				max = ans[0];
				min = ans[0];
				for (int i = 1; i < 3; i++) {
					if (ans[i] > max) {
						max = ans[i];
					}
					if (ans[i] < min) {
						min = ans[i];
					}
				}
				anss[j] = max - min;
			}
		}
		min = anss[0];
		for (int i = 1; i < 8; i++) {
			if (min > anss[i]) {
				min = anss[i];
			}
		}
		cout << min << endl;
	}
	return 0;
}

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

int main(){
  int A,B;
  int ans;
  cin >> A >> B;
  for(int i = 10;i <= 1000;i++){
    int A_tax = i * 8 / 100;
    int B_tax = i * 10 /100;
    if(A == A_tax && B == B_tax){
      ans = i;
      break;
    }
    if(i == 1000){
      ans = -1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll dig(ll n) {
  ll keta = log10(n) + 1;
  ll ans = 0;
  ll x = n;
  for(int i = 0;i < (keta);i++) {
    ans += x % 10; x /= 10;
  }
  return ans;
}

int main(int argc, char const *argv[])
{
  ll n;cin >> n;
  if(n % dig(n) == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = sorted(list(map(int,input().split())))

cnt = 1
for i in range(N-1):
    if A[i]*2 < A[i+1]:
        cnt = 1
    else:
        cnt += 1
    A[i+1] += A[i]

print(cnt)


Measured memory_bytes: 20256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int x = s.nextInt();
        int hour = (int)Math.ceil(x / 3600);
        int minutes = (int)Math.ceil((x - hour * 3600 ) / 60);
        int second = (x - hour * 3600 - minutes * 60);

        System.out.println(hour + ":" + minutes + ":" +second);
    }

}

Measured memory_bytes: 17308
h, w = map(int, input().split())
ar = []
for _ in range(h):
    row = [c == "#" for c in input().rstrip()]
    ar.append(row)

count = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    for j in range(w):
        up = None
        right = None
        if i != 0:
            up = count[i - 1][j]
            if ar[i][j] and not ar[i - 1][j]:
                up += 1

        if j != 0:
            right = count[i][j - 1]
            if ar[i][j] and not ar[i][j - 1]:
                right += 1

        if up is None:
            if right is None:
                count[i][j] = int(ar[0][0])
            else:
                count[i][j] = right
        else:
            if right is None:
                count[i][j] = up
            else:
                count[i][j] = min(right, up)

print(count[-1][-1])


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

string str;
string ptn[5];
long long pattern(int s, int n)
{
	int x=1,y=1,yc=0,yz=0;
	for(int i=0; i<n*8; i++)
	{
		switch(str[s+i])
		{
			case 'x':
				if(ptn[n][i]=='x') x=(x*2)%1000000;
				if(ptn[n][i]=='y') y=(y*2)%1000000;
				break;
			
			case '1':
				if(ptn[n][i]=='0') return 0;
				if(ptn[n][i]=='y') yc++;
				break;
			
			case '0':
				if(ptn[n][i]=='1') return 0;
				if(ptn[n][i]=='y')
				{
					int t = (n==2?4:5);
					if(++yz == t) return 0;
				}
				break;
		}
	}

	if(y>1 && yc==0) y-=1;
		
	return (x*y)%1000000;
}

int main()
{
	ptn[1] = "0xxxxxxx";
	ptn[2] = "110yyyyx10xxxxxx";
	ptn[3] = "1110yyyy10yxxxxx10xxxxxx";
	ptn[4] = "11110yyy10yyxxxx10xxxxxx10xxxxxx";

/*
	str="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
	cout << pattern(0,1) << endl;
	cout << pattern(0,2) << endl;
	cout << pattern(0,3) << endl;
	cout << pattern(0,4) << endl;
*/

	int N;
	while(cin>>N, N)
	{
		str="";
		for(int i=0; i<N; i++)
		{
			string tmp;
			cin >> tmp;
			str += tmp;
		}
		
		long long dp[1024] = {0};
		dp[0] = 1;
		
		for(int i=1; i<=N; i++)
		{
			for(int n=1; n<=4; n++)
			{
				if(i-n < 0) break;    
				dp[i] = (dp[i] + dp[i-n]*pattern((i-n)*8, n))%1000000;
			}
		}
		
		cout << dp[N] << endl;
	}	
}

Measured memory_bytes: 0
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: u32 = buf.trim_right().parse().unwrap();
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.trim_right().split_whitespace();
    let mut v = iter.map(|x| x.parse().unwrap()).collect::<Vec<u32>>();

    let mut count: u32 = 0;
    let mut x: u32 = v.iter().map(|x| x % 2).sum();
    while x == 0 {
        count += 1;
        v = v.iter().map(|x| x / 2).collect::<Vec<u32>>();
        x = v.iter().map(|x| x % 2).sum();
    }
    println!("{}", count);
}  

Measured memory_bytes: 4352
N = list(map(int,input().split()))
A = [(a,idx+1) for idx,a in enumerate(list(map(int,input().split())))]
A = sorted(A)

color_set = set()
prev_sum = 0
prev_num = 0
for a,color in A:
  if prev_num == a or prev_sum*2 >=a :
    color_set |= {color}
  else:
    color_set = {color}
  prev_sum += a
  prev_num = a
  
print(len(color_set))

Measured memory_bytes: 71164
H, W, D = map(int, input().split())
A = [list(map(lambda s: int(s) - 1, input().split())) for i in range(H)]
Q = int(input())
queries = [tuple(map(lambda s: int(s) - 1, input().split())) for i in range(Q)]

T = {}
for i in range(H):
    for j in range(W):
        T[A[i][j]] = (i, j)
accum = [[0] for i in range(D)]
for i in range(D):
    for j in range(i + D, H * W, D):
        p = T[j - D]
        n = T[j]
        accum[i].append(accum[i][-1] + abs(p[0] - n[0]) + abs(p[1] - n[1]))

for query in queries:
    r = query[0] % D
    print(accum[r][query[1] // D] - accum[r][query[0] // D])


Measured memory_bytes: 42468
#include <iostream>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  int N, A, prev;
  cin >> N;
  cin >> prev;
  int ret = 1;
  int dir = 0;
  for( int i=1; i<N; i++ ){
    cin >> A;
    if( dir == 0 ){
      if( A > prev ){
        dir = 1;
      } else if( A < prev ){
        dir = -1;
      }
    } else if( dir == 1 ){
      if( A < prev ){
        ret++;
        dir = 0;
      }
    } else {
      if( A > prev ){
        ret++;
        dir = 0;
      }
    }
    prev = A;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn is_sym(b: usize, ss: &Vec<Vec<char>>) -> bool {
    let n = ss.len();

    for i in 0..n {
        for j in 0..n {
            if ss[i][(j+b)%n] != ss[j][(i+b)%n] {
                return false
            }
        }
    }

    true
}

fn solve(ss: Vec<Vec<char>>) -> usize {
    let mut acc = 0;
    let n = ss.len();

    for b in 0..n {
        if is_sym(b, &ss) {
            acc += 1;
        }
    }

    acc * n
}

fn main() {
    let n = parse_line!(usize);

    println!("{}", solve((0..n).map(|_| read_line!().chars().collect()).collect()));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![vec!['a', 'b'], vec!['c','a']]), 2);
}


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

  int main(){
  char s;cin>>s;
    int p=0;
    for(char moji='a'; moji<='z'; ++moji)
    {
        if(p==1)
      {
        cout<<moji;
        break;
      }
      if(s==moji)
      {
        p++;
      }
    
    }
    
  }
      
      



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T1, typename T2> 
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL a(n);
  VVI x(n), y(n);
  rep(i, n) {
    cin >> a[i];
    x[i].resize(a[i]);
    y[i].resize(a[i]);
    rep(j, a[i]) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }
  ll ans = 0;
  rep(bit, 1 << n) {
    ll tmp = 0;
    bool ok = true;
    rep(i, n) {
      if (((bit >> i) & 1) == 0) continue;
      tmp++;
      rep(j, a[i]) {
        if (((bit >> x[i][j]) & 1) != y[i][j]) ok = false;
      }
    }
    if (ok) chmax(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    if(k==1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(n<k)
    {
        cout<<min(n,k-n)<<endl;
        return 0;
    }
    if(n==k)
    {
        cout<<0<<endl;
        return 0;
    }
    if(n>k)
    {
        cout<<min(n%k,k-(n%k))<<endl;
        return 0;

    }
    return 0;
}


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

int main(){
  int n, k, h[100000], min = 1000000000;
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> h[i];
  sort(h, h + n);
  for(int i = k - 1; i < n; i++){
    int d = h[i] - h[i-k+1];
    if(min > d) min = d;
  }
  cout << min;
  return 0;
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> A >> B >> C;
	if (A <= C && B >= C) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

typedef long long ll;

ll N;
map<char, map<ll, set<double>>> Vs;
double R = 1e20;

void update(double t) {
  t = abs(t);
  double res = 1;
  for (char xy : {'x', 'y'}) {
    set<double> avs;
    for (const auto &d_vs : Vs[xy]) {
      ll d = d_vs.first;
      const auto &vs = d_vs.second;
      avs.insert(*vs.begin() + d * t);
      avs.insert(*vs.rbegin() + d * t);
    }
    res *= *avs.rbegin() - *avs.begin();
  }
  R = min(R, res);
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    double x, y;
    char d;
    cin >> x >> y >> d;
    Vs['x'][d == 'R' ? 1 : d == 'L' ? -1 : 0].insert(x);
    Vs['y'][d == 'U' ? 1 : d == 'D' ? -1 : 0].insert(y);
  }
  update(0);
  for (char xy : {'x', 'y'}) {
    for (ll d : {0, 1, -1}) {
      if (!Vs[xy].count(d)) continue;
      for (ll d2 : {0, 1, -1}) {
        if (d >= d2) continue;
        if (!Vs[xy].count(d2)) continue;
        const auto &vs = Vs[xy][d], &vs2 = Vs[xy][d2];
        update((*vs2.begin() - *vs.begin()) / (d - d2));
        update((*vs2.rbegin() - *vs.rbegin()) / (d - d2));
      }
    }
  }
  cout << setprecision(10) << R << endl;
  return 0;
}


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

const long long mod=1000000007LL;

long long dp[205][100005]={};

int main(int argc, char const *argv[])
{
	int n,x;
	cin>>n>>x;
	int s[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>s[i];
	}
	sort(s,s+n);
	for (int i = 0; i <= x; ++i)
	{
		dp[0][i]=(long long)i;
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= x; ++j)
		{
			dp[i+1][j]+=dp[i][j%s[i]]+(long long)i*dp[i][j];
			dp[i+1][j]%=mod;
		}
	}
	cout<<dp[n][x]<<endl;
	return 0;
}


Measured memory_bytes: 157952
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
const int mxn=1e7;
vll cnt(mxn+5,2);
void pre()
{
	int i,j;
	cnt[1]=1;
	for(i=2;i<=mxn;++i)
	{
		for(j=2*i;j<=mxn;j+=i)++cnt[j];
	}
	//rep(i,1,100)db1(cnt[i]);
}
int32_t main() {
    IOS;
    	pre();
        ll n,ans=0;
        cin>>n;
       	rep(i,1,n)ans+=(i*cnt[i]);
       	cout<<ans;


        cout<<'\n';
    return 0;
}

Measured memory_bytes: 81216
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W,D;
    cin >> H >> W >> D;
    vP plc(H*W);
    rep(i,H){
        rep(j,W){
            int x;
            cin >> x;
            x--;
            plc[x]={i,j};
        }
    }
    vl dp(H*W);
    rep(i,H*W){
        if(i<D){
            dp[i]=0;
        }
        else{
            dp[i]=dp[i-D]+abs(plc[i].first-plc[i-D].first)+abs(plc[i].second-plc[i-D].second);
        }
    }
    int Q;
    cin >> Q;
    while(Q--){
        int l,r;
        cin >> l >> r;
        l--,r--;
        cout << dp[r]-dp[l] << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


Measured memory_bytes: 5312
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <queue>

using namespace std;

static vector<uint64_t> items0;
static vector<uint64_t> items1;
static vector<uint64_t> items2;
static vector<uint64_t> items3;

int32_t main()
{
  uint64_t N, W;
  cin >> N >> W;

  uint64_t w0, v0;
  cin >> w0 >> v0;

  items0.push_back(v0);

  for (uint64_t i = 1; i < N; i++) {
    uint64_t w, v;
    cin >> w >> v;
    switch (w - w0) {
    case 0:
      items0.push_back(v);
      break;
    case 1:
      items1.push_back(v);
      break;
    case 2:
      items2.push_back(v);
      break;
    case 3:
      items3.push_back(v);
      break;
    }
  }

  sort(items0.begin(), items0.end(), std::greater<uint64_t>());
  sort(items1.begin(), items1.end(), std::greater<uint64_t>());
  sort(items2.begin(), items2.end(), std::greater<uint64_t>());
  sort(items3.begin(), items3.end(), std::greater<uint64_t>());
  items0.insert(items0.begin(), 0);
  for (uint32_t i = 1; i < items0.size(); i++) {
    items0[i] += items0[i - 1];
  }
  items1.insert(items1.begin(), 0);
  for (uint32_t i = 1; i < items1.size(); i++) {
    items1[i] += items1[i - 1];
  }
  items2.insert(items2.begin(), 0);
  for (uint32_t i = 1; i < items2.size(); i++) {
    items2[i] += items2[i - 1];
  }
  items3.insert(items3.begin(), 0);
  for (uint32_t i = 1; i < items3.size(); i++) {
    items3[i] += items3[i - 1];
  }

  uint64_t max_values = 0;
  for (uint32_t i0 = 0; i0 < items0.size(); i0++) {
    for (uint32_t i1 = 0; i1 < items1.size(); i1++) {
      for (uint32_t i2 = 0; i2 < items2.size(); i2++) {
        for (uint32_t i3 = 0; i3 < items3.size(); i3++) {
          uint64_t values = items0[i0] + items1[i1] + items2[i2] + items3[i3];
          uint64_t weights = i0 * w0 + i1 * (w0 + 1) + i2 * (w0 + 2) + i3 * (w0 + 3);
          if (weights <= W) {
            max_values = max(max_values, values);
          }
        }
      }
    }
  }

  cout << max_values << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();


        System.out.println(s.substring(0, k-1) + s.substring(k-1, k).toLowerCase() + s.substring(k));
    }
}


Measured memory_bytes: 21844
import java.io.FileInputStream;
import java.util.Scanner;


public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
        while(hasNext()){
            StringBuilder s = new StringBuilder(NLine());
            StringBuilder ans=new StringBuilder();
            if(s.length()==0)return;
            for (int i = 0; i < s.length(); i++) {
                if(s.charAt(i)=='@'){
                    i++;
                    int len = s.charAt(i)-'0';
                    i++;
                    for (int j = 0; j < len; j++) {
                        ans.append(s.charAt(i));
                    }
                } else {
                    ans.append(s.charAt(i));
                }
            }
            System.out.println(ans);
        }
    }

    
    static int c=0;
    static int NI(){
        return (int)NL();
    }
    
    static long NL(){
        try {
            long r = 0;
            skip();
            if(c=='-') return -NL();
            for(;'0'<=c&&c<='9';c=System.in.read())
                r = r * 10 + c - '0';
            return r;
        } catch (Exception e) {
            return -1;
        }
    }
    
    static char NC(){
        try {
            skip();
            return (char)c;
        } catch (Exception e) {
            return 0;
        }
    }
    
    static String NS(){
        StringBuilder sb=new StringBuilder();
        try {
            skip();
            for(;!isSkip();){
                sb.append((char)c);
                c=System.in.read();
            }
            return sb.toString();
        } catch (Exception e) {
            return "";
        }
    }
    
    static String NLine(){
        StringBuilder sb=new StringBuilder();
        try {
            for(;c!='\n'&&c!='\r';){
                sb.append((char)c);
                c=System.in.read();
//                System.out.println(c);
            }
            c=System.in.read();
            return sb.toString();
        } catch (Exception e) {
            return "";
        }
    }
    
    static void skip(){
        try{
            while(isSkip()){
                c=System.in.read();
            }
        } catch (Exception e){}
        
    }
    
    static boolean hasNext(){
        skip();
        return c!=-1;
    }
    
    static boolean isSkip(){
        return 0 <= c && c <= ' ';
    }
}

Measured memory_bytes: 17012
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int n;
    cin >> n;
    cout << n*800 - (int)(n/15)*200 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll n;
    cin >> n;
    vector <ll> a;
    ll tmp;
    ll sum = 0;
    for (ll i=0;i<n;i++){
        cin >> tmp;
        sum += tmp;
        a.push_back(tmp);
    }
    ll sumMemo = 0;
    ll sumMemoPre = 0;
    for (ll i=0;i<n;i++){
        sumMemoPre = sumMemo;
        sumMemo += a[i];
        if(sumMemo > sum / 2.0){
            cout << min(sum - 2 * sumMemoPre, 2*sumMemo - sum) << endl;
            break;
        }
    }
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
int main()
{
	char s[1000];
	char t[]="CODEFESTIVAL2016";
	gets(s);
	int flag=0;
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]!=t[i])
		flag++;
	}
	printf("%d",flag);
	return 0;
}

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

int main(){
  
  int A,B,X; cin >> A >> B >> X;
  
  
  if(X >= A && X <= A+B ){
    cout << "YES" << endl;
  }
  
  else{
    cout << "NO" << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    static String[] word = {"dream", "dreamer", "erase", "eraser"};
    static int[] wordlen = {5,7,5,6};
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        long k = sc.nextLong();
        System.out.println(50);
        long[] ans = new long[50];
        Arrays.fill(ans,49);
        long pow = k/50L;
        long rem = k%50L;
        for(int i = 0; i < 50; i++){
            ans[i] += pow;
        }
        for(int i = 0; i < rem; i++){
            ans[i] += 50;
            for(int j = 0; j < 50; j++){
                if(i == j) continue;
                ans[j]--;
            }
        }
        for(int i = 0; i < 50; i++){
            System.out.print(ans[i] + " ");
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25376
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int main(){
    int N,A,B,C;
    cin >> N >> A >> B >> C;
    cout << N - A - B + C << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <numeric>

using namespace std;

int n, k;
vector<int> v;

int calc(int nr, int nl) {
	// printf("-------- %d %d %d\n", nr, nl, n);
	vector<int> hand;

	for (int i = 0; i < nr; i++) {
		hand.push_back(v[i]);
	}

	for (int i = 0; i < nl; i++) {
		hand.push_back(v[n - 1 - i]);
	}

	sort(hand.begin(), hand.end(), greater<int>());
	int rest = k - nr - nl;

	for (int i = 0; i < rest; i++) {
		if (hand.empty() || hand.back() > 0) {
			break;
		} else {
			hand.pop_back();
		}
	}


	int ret = accumulate(hand.begin(), hand.end(), 0);

	// printf("nr %d nl %d, ret %d\n", nr, nl, ret);
	// for (auto x: hand) {
	// 	cout << x << " ";
	// }
	// cout << endl;

	return ret;
}

int main() {
	cin >> n >> k;

	v.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	int ans = 0;
	// 左からi, 右からj個
	for (int i = 0; i <= min(n, k); i++) {
		for (int j = 0; i + j <= min(n, k); j++) {
			int tmp = calc(i, j);
			ans = max(ans, tmp);
		}
	}

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


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

int main(){
  int A, B, C, X, Y;
  cin >> A  >> B >> C >> X >> Y;
  int price=0;

  int q;
  q = max(X, Y);

  int Z = min(X, Y);
  if (A+B>2*C) {
    price += 2*C*Z;
  } else {
    price += Z*(A+B);
  }

  if (q==X){
    if (A>2*C) price += 2*C*(q-Z);
    else price += A*(q-Z);
  } else if (q==Y){
    if (B>2*C) price += 2*C*(q-Z);
    else price += B*(q-Z);
  }

  cout << price << 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, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll N; cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    map<ll, ll> memo;
    vector<ll> memo2;
    ll tmp = 2;
    while (tmp*tmp <= N) {
        if (N%tmp == 0) {
            ll cnt = 0;
            while (N%tmp == 0) {
                N /= tmp;
                cnt++;
            }
            memo[tmp] = cnt;
            memo2.push_back(tmp);
        }
        else tmp++;
    }
    if (N > 1) {
        memo[tmp]++;
        memo2.push_back(tmp);
    }
    /*for (ll i:memo2){
        cout << i << " " << memo[i] << endl;
    }+*/
    for (ll i = 0; i < memo2.size(); i++) {
        ll j = 1;
        while (memo[memo2[i]] >= j) {
            ans++;
            memo[memo2[i]] -= j;
            j++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(abs(a-b)>abs(a-c))cout<<'B'<<endl;
	else cout<<"A"<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int n, x, mt;
  vector<int> m;

  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    cin >> mt;
    m.push_back(mt);
  }
  // for (auto l:m) {
  //   cout<<l<<endl;
  // }
  int s = accumulate(m.begin(), m.end(), 0);
  x = x - s;
  int minn = *min_element(m.begin(), m.end());
  int ans = x / minn;
  ans += n;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
   vector<int>v;
   vector<int>::iterator it;
	for(int i=0;i<5;i++)
		{
			int l;
			cin>>l;
			v.push_back(l);
		}

	it=find(v.begin(),v.end(),0);

	cout<<it-v.begin()+1<<endl;

	return 0;
}

Measured memory_bytes: 3548
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

string s, r, c[] = {"maerd", "remaerd", "esare", "resare"};

bool cut(string &s)
{
  bool r = false;
  REP(i, 4)
  {
    if (s.find(c[i]) == 0)
    {
      s = s.substr(c[i].length());
      r = true;
    }
  }
  return r;
}

int main()
{
  cin >> s;
  reverse(ALL(s));

  while (0 < s.length())
    if (!cut(s))
      break;

  r = s.length() == 0 ? "YES" : "NO";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 512
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int n, k;
	
	cin >> n >> k;

	//int h[n];

	int c = 0;
	rep(i, n)
	{
		int a;
		cin >> a;
		if (a >= k)
		{
			c++;
		}
	}

	cout << c << endl;

	
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N)], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for s in edge[i]:
        if H_ls[i] <= H_ls[s]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Measured memory_bytes: 29432
n,*z=`dd`.split.map &:to_i
t=(e=[*0...n]).dup
a=z.shift n+1
n.downto(1){|i|a[i]-=a[i-1]}
k,*z=z
z.map{|x|t[x-2],t[x-1]=t[x-1],t[x-2]}
(k%2>0&&e=t.map{|q|e[q]};t=t.map{|q|t[q]};k/=2)while k>0
k,*a=a
n.times{|i|p k;k+=a[e[i]]}

Measured memory_bytes: 74284
use std::io::*;

fn read() -> String {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
	b
}

fn main() {
	let s = read();
	//let nn = s.chars().map(|c| c.to_digit(10).unwrap()).collect::<Vec<u32>>();;
	let nn = s.chars().map(|c| c.to_digit(10).unwrap()).fold(0, |acc, i| acc + i);

	let n = s.parse::<f64>().unwrap();

	if n % nn as f64 == 0.0 {
		println!("Yes");
	} else {
		println!("No");
	}
}


Measured memory_bytes: 4352
use std::io::Read;
use std::io::{stdout, BufWriter, Write};

fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    
    let mut v : Vec<u64> = (0..n)
    	.map(|_|{iter.next().unwrap().parse().unwrap()})
        .collect();
        
    let mut c : Vec<u64> = (0..n)
    	.map(|_|{iter.next().unwrap().parse().unwrap()})
        .collect();
        
    let mut sum = 0;
    for i in 0..n {
    	if v[i] > c[i] {
        	sum += v[i] - c[i];
        }
    }
    
	writeln!(out, "{}", sum);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define ll long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%I64d",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(ll i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(ll i=s;i<n+s;i++){scll(a[i]);}
#define open(in,out) freopen(in,"r",stdin);freopen(out,"w",stdout);
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(ll i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace std;
const int N=1e5+10;
ll mem[N],n,a[N];
int main(){
scll(n);
read_arr(a,1,n);
mem[n]=0;
mem[n-1]=abs(a[n]-a[n-1]);
for(int i=n-2;i>=1;i--){
mem[i]=min(abs(a[i]-a[i+1])+mem[i+1],abs(a[i]-a[i+2])+mem[i+2]);
}
//err_arr(mem,1,n);
printf("%lld\n",mem[1]);
}
/**
n=0
n-1=20
n-2= 20 , 10
n-3=

**/


Measured memory_bytes: 1792