akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long read(){
	long long f=1,x=0;
	char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return f*x;
}
#define MAXN 100000
struct node{
	int x,y;
	bool color;//0 White 1 Black
}wish[MAXN+5];
int fit[MAXN+5],unfit[MAXN+5];
int main(){
	char c;
	int n=read(),k=read(),tmp,ans=0;
	for(int i=1;i<=n;i++)
	{
		wish[i].x=read()%(2*k),wish[i].y=read()%(2*k),c=getchar();
		if(c=='W')
			wish[i].color=1;
		else
			wish[i].color=0;
	}
	for(int x=0;x<=k;x++)
	{
		tmp=0;
		memset(fit,0,sizeof fit);
		memset(unfit,0,sizeof unfit);
		for(int i=1;i<=n;i++)
		{
			int p=(x<=wish[i].x&&wish[i].x<x+k),
				q=(0<=wish[i].y&&wish[i].y<k);
			if((p^q)==wish[i].color)
			{
				tmp++;
				fit[wish[i].y]++;
			}
			else
				unfit[wish[i].y]++;
		}
		for(int i=0;i<=k;i++)
		{
			if(tmp>ans) ans=tmp;
			if(n-tmp>ans) ans=n-tmp;
			if(i!=k)
				tmp=tmp-fit[i]+unfit[i]-fit[i+k]+unfit[i+k];		
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2176
from itertools import permutations
# 3*5*5
# (2, 4, 4) (14, 4) (2, 24) (74)
n = int(input())
d = [0] * (n + 1)
for i in range(2, n + 1):
    for p in range(2, n + 1):
        while i % p == 0:
            i //= p
            d[p] += 1
d = list(filter(int, d))
ans = 0
for i, j, k in permutations(d, 3):
    ans += min(i - 2, j - 4, k - 4) >= 0
ans //= 2
for i, j in permutations(d, 2):
    ans += min(i - 14, j - 4) >= 0
    ans += min(i - 2, j - 24) >= 0
for i in d:
    ans += i - 74 >= 0
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef pair<int, pair<int, int>> State;

const int INF = 1 << 30;
vector<vector<int>> bfs(vector<vector<int>> &g, int h, int w, int sy, int sx)
{
    assert(g[sy][sx] == 0);
    vector<vector<int>> ret(h, vector<int>(w, INF));
    priority_queue<State, vector<State>, greater<State>> pque;

    map<pair<int, int>, bool> mp;
    mp.clear();
    pque.push({0, {sy, sx}});
    while (!pque.empty())
    {
        auto cur = pque.top();
        pque.pop();
        if (mp[cur.second] == true)
        {
            continue;
        }
        ret[cur.second.first][cur.second.second] = cur.first;
        mp[cur.second] = true;
        int y = cur.second.first;
        int x = cur.second.second;
        if (y + 1 < h && g[y + 1][x] == 0)
        {
            pque.push({cur.first + 1, {y + 1, x}});
        }
        if (y - 1 >= 0 && g[y - 1][x] == 0)
        {
            pque.push({cur.first + 1, {y - 1, x}});
        }
        if (x + 1 < w && g[y][x + 1] == 0)
        {
            pque.push({cur.first + 1, {y, x + 1}});
        }
        if (x - 1 >= 0 && g[y][x - 1] == 0)
        {
            pque.push({cur.first + 1, {y, x - 1}});
        }
    }
    return ret;
}

int check(vector<vector<int>> &g, int h, int w, int sy, int sx)
{
    auto cost = bfs(g, h, w, sy, sx);
    int mcost = -1;
    rep(i, h) rep(j, w)
    {
        if (cost[i][j] == INF)
            continue;
        if (mcost < cost[i][j])
        {
            sy = i;
            sx = j;
            mcost = cost[i][j];
        }
    }
    return mcost;
}

int main()
{
    int h, w;
    cin >> h >> w;

    vector<vector<int>> g(h, vector<int>(w, 0));
    int sy, sx;
    rep(i, h) rep(j, w)
    {
        char s;
        cin >> s;
        if (s == '.')
        {
            g[i][j] = 0;
            sy = i;
            sx = j;
        }
        else
        {
            g[i][j] = 1;
        }
    }

    int ans = -1;
    rep(i, h)
    {
        rep(j, w)
        {
            if (g[i][j] == 0)
            {
                ans = max(ans, check(g, h, w, i, j));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int a, b, c, count;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) count++;
    }

    cout << count << endl;
/**
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if (x + r > W || y + r > H) {
        printf("No");
    } else if (x - r < 0 || y - r < 0) {
        printf("No");
    } else {
        printf("Yes");
    }
    printf("\n");

    return 0;
    **/
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vi bells(3);
  while(cin >> bells[0] >> bells[1] >> bells[2]){
    TSTART();
    sort(ALL(bells));
    cout << bells[0] + bells[1] << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int K, o, e, x;
            cin >> K;
                if(K % 2 == 0){
                    o = K/2;
                    e = K/2;
                }else{
                    o = (K/2) + 1;
                    e = K/2;
                }
                    for(int i = 0; i < o; i++){
                        for(int j = 0; j < e; j++){
                            x += 1;
                        }
                    }
                        cout << x << endl;
    return 0;}

Measured memory_bytes: 256
#include<stdio.h>
int a[200010];
int ans[200010];
int main(void)
{
  int n,i;


  scanf("%d",&n);

  for(i=2;i<=n;i++)
    scanf("%d",&a[i]);

  for(i=2;i<=n;i++)
    ans[a[i]]++;

  for(i=1;i<=n;i++)
  printf("%d\n",ans[i]);

  return 0;
}


Measured memory_bytes: 3232
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
x=list(t)
ans=0
for i in range(n):
  if x[i]=="r":x[i]="p"
  elif x[i]=="p":x[i]="s"
  else:x[i]="r"
for i in range(k):
  if x[i]=="r":ans+=r
  elif x[i]=="p":ans+=p
  else:ans+=s
for i in range(k,n):
  if x[i]==x[i-k]:
    x[i]="-"
    continue
  if x[i]=="r":ans+=r
  elif x[i]=="p":ans+=p
  else:ans+=s
print(ans)

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

int main(){
  int A,B;
  cin >> hex >> A >> B;
  if(A>B){
    cout << ">" << endl;
  }else if(A<B){
    cout << "<" << endl;
  }else{
    cout << "=" << endl;
  }
}

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

#define ELEMENT_CNT_MIN 1
#define ELEMENT_CNT_MAX 100
#define ELEMENT_MIN 0
#define ELEMENT_MAX 100

int selection_sort(int *p_arr, int size);
void swap(int *px, int *py);
void put_arr(int *p_arr, int size);
int get_int_sequence(int *p_num, int min, int max, int size);
int get_int(int *p_num, int min, int max);
int judge_constraint(int test_num, int min, int max);


int main(void){
    
    int element_num;
    int element[ELEMENT_CNT_MAX];
    int cnt_exchange;
    
    if(get_int(&element_num, ELEMENT_CNT_MIN, ELEMENT_CNT_MAX) == -1)
    {
        return -1;
    }
    
    if(get_int_sequence(&element[0], ELEMENT_MIN, ELEMENT_MAX, element_num) == -1)
    {
        return -1;
    }
    
    cnt_exchange = selection_sort(&element[0], element_num);
    
    put_arr(&element[0], element_num);
    printf("%d\n", cnt_exchange);
    
    return 0;
}

int selection_sort(int *p_arr, int size)
{
    int i;
    int j;
    int min_idx;
    int cnt = 0;    /* exchange count */
    
    for(i = 0; i < size - 1; i++)
    {
        min_idx = i;
        for(j = i + 1; j < size; j++)
        {
            if(p_arr[j] < p_arr[min_idx])   
            {
                min_idx = j;        /* minimum value [i,size - 1] */
            }
        }
        if(p_arr[i] != p_arr[min_idx])
        {
            swap(&p_arr[i], &p_arr[min_idx]);
            cnt++;
        }
    }
    
    return cnt;
}

void swap(int *px, int *py)
{
    int tmp = *px;
    *px = *py;
    *py = tmp;
    
    return;
}

void put_arr(int *p_arr, int size)
{
	int i;
	
	for(i = 0; i < size - 1; i++)
	{
	    printf("%d ", p_arr[i]);
	}
	printf("%d\n", p_arr[size - 1]);
}

int get_int_sequence(int *p_num, int min, int max, int size)
{
    int i;
    
    for(i = 0; i < size; i++)
    {
        if(get_int(&p_num[i], min, max) == -1)
        {
            return -1;
        }
    }
    
    return 0;
}

int get_int(int *p_num, int min, int max)
{
	scanf("%d", p_num);
	
	if(judge_constraint(*p_num, min, max) == -1)
    {
        return -1;
    }
	
	return 0;
}
int judge_constraint(int test_num, int min, int max)
{
    if(test_num < min || test_num > max)
    {
        return -1;
    }
    
    return 0;
}

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

int calc_factor(int num, int div) {
  int res = 0;
  while (num % div == 0) {
    num /= div;
    res++;
  }

  return res;
}

int main() {
  int N;
  cin >> N;
  bool is_prime[N+1];
  for (int i=0 ; i<=N ; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i=2 ; i<=N ; i++) {
    if (is_prime[i]) {
      for (int j=2*i ; j<=N ; j += i) is_prime[j] = false;
    }
  }

  long long cnt[N+1];
  for (int i=0 ; i<=N ; i++) cnt[i] = 0;

  for (int i=1 ; i<=N ; i++) {
    for (int j=1 ; j<=i ; j++) {
      if (is_prime[j]) {
        cnt[j] += calc_factor(i, j);
      }
    }
  }
  long long ans = 1;
  for (int i=1 ; i<=N ; i++) {
    if (is_prime[i]) {
      ans = ans * (cnt[i]+1) % 1000000007;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m, x, y;
	cin>>n>>m>>x>>y;
	vector<int> xi(n), yi(m);
	for(int i = 0; i < n; ++i)cin>>xi[i];
	for(int i = 0; i < m; ++i)cin>>yi[i];
	sort(xi.begin(),xi.end());
	sort(yi.begin(),yi.end());
	int l = xi[n - 1];
	int r = yi[0];
	bool ok = false;
	for(int i = x + 1; i <= y; ++i){
		if(i > l && i <= r)ok=true;
	}
	if(ok)cout<<"No War"<<endl;
	else cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
import heapq


def solve():
    X, Y, Z, K = map(int, input().split())
    a_ls = sorted(map(lambda x: -int(x), input().split()))
    b_ls = sorted(map(lambda x: -int(x), input().split()))
    c_ls = sorted(map(lambda x: -int(x), input().split()))
    hq = []
    heapq.heappush(hq, (a_ls[0]+b_ls[0]+c_ls[0], 0, 0, 0))
    hq_hash = {(0, 0, 0)}
    
    for _ in range(K):
        ans, i, j, k = heapq.heappop(hq)
        
        if i+1 < X and not((i+1, j, k) in hq_hash):
            hq_hash.add((i+1, j, k))
            heapq.heappush(hq, (a_ls[i+1]+b_ls[j]+c_ls[k], i+1, j, k))
        if j+1 < Y and not((i, j+1, k) in hq_hash):
            hq_hash.add((i, j+1, k))
            heapq.heappush(hq, (a_ls[i]+b_ls[j+1]+c_ls[k], i, j+1, k))
        if k+1 < Z and not((i, j, k+1) in hq_hash):
            hq_hash.add((i, j, k+1))
            heapq.heappush(hq, (a_ls[i]+b_ls[j]+c_ls[k+1], i, j, k+1))
        
        print(-ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 4980
// A Dynamic Programming based
// solution for 0-1 Knapsack problem
#include <iostream>
 using namespace std;
// A utility function that returns
// maximum of two integers
int max(int a, int b)
{
    return (a > b) ? a : b;
}
 
// Returns the maximum value that
// can be put in a knapsack of capacity W
long long knapSack(int W, int wt[], int val[], int n)
{
    int i, w;
    long long K[n + 1][W + 1];
 
    // Build table K[][] in bottom up manner
    for (i = 0; i <= n; i++) {
        for (w = 0; w <= W; w++) {
            if (i == 0 || w == 0)
                K[i][w] = 0;
            else if (wt[i - 1] <= w)
                K[i][w] = max(
                    val[i - 1] + K[i - 1][w - wt[i - 1]],
                    K[i - 1][w]);
            else
                K[i][w] = K[i - 1][w];
        }
    }
 
    return K[n][W];
}
 
int main()
{
    int W,N;
    cin>>N>>W;
     int val[N];
    int wt[N];
  for(int i=0;i<N;i++){
    int w,v;
    cin>>w>>v;
    val[i] = v;
    wt[i] = w;
  }
 
    cout<<knapSack(W, wt, val, N);
    return 0;
}

Measured memory_bytes: 82288
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string s;
int main()
{
	cin >> s;
	int n=s.length();
	int flag=0;
	for(int i=0;i<(n-1)/2;i++)
	{
	//	cout << s[i] << " " << s[n-1-i] << endl;
		if(s[i]!=s[n-1-i])
		{
			flag=1;
		//	cout << 1 << endl;
			break;
		}
	}
	string s1=s.substr(0,(n-1)/2);
	string s2=s.substr((n+1)/2,n);
//	cout << s1 << endl << s2 << endl;
	int n1=s1.length(),n2=s2.length();
	if(!flag)
	for(int i=0;i<=(n1-1)/2;i++)
	{
	//	cout << s1[i] << " " << s1[n1-1-i] << endl;
		if(s1[i]!=s1[n1-1-i])
		{
			flag=1;
	//		cout << 2 << endl;
			break;
		}
	}
	if(!flag)
	for(int i=0;i<=(n2-1)/2;i++)
	{
	//	cout << s2[i] << " " << s2[n2-1-i] << endl;
		if(s2[i]!=s2[n2-1-i])
		{
			flag=1;
	//		cout << 3 << endl;
			break;
		}
	}
	if(flag) cout <<"No";
	else cout <<"Yes";
	return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >>B;
  
  if(A%K!=0){
  if((A/K+1)*K<B+1){
    cout << "OK" << endl;
  }
  
  else{
    cout << "NG" << endl;
  }
  }
  
  else{
    cout << "OK" << endl;
  }
  
}



Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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; }

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

	ll N, K;
	cin >> N >> K;

	vl A(N);
	rep(i, N) {
		cin >> A[i];
	}

	ll cnt = 0;
	ll bcnt = 0;

	rep(i, N) {
		range(k, i+1, N) {
			if (A[i] > A[k])cnt++;
		}

		rep(k, i) {
			if (A[i] > A[k])bcnt++;
		}
	}

	cnt %= MOD;
	cnt *= (K * (K + 1) / 2) % MOD;
	cnt %= MOD;

	bcnt *= (K * (K - 1) / 2) % MOD;
	bcnt %= MOD;

	cout << (cnt+bcnt)%MOD << endl;



	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0;
  int flag = 0;
  cin >> N;
  int cmax = N/4;
  int dmax = N/7;
  for(int i = 0;i<=cmax;i++){
    for(int j = 0;j<=dmax;j++){
      int total = i * 4 + j * 7;
      if(total == N){
        flag = true;
      }
    }
  }
  if(flag==1){
  cout << "Yes" << endl; // h
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
int main(){
    int K, S;
    cin >> K >> S;
    int c = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if(S - (i + j) >= 0 && S - (i + j) <= K)
            c++;
        }
    }
    cout << c << endl;
    return 0; 
}

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

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n+1);
  rep(i,n){
    ll ai; cin>>ai;
    a[i+1]=ai;
  }
  for(int i=k+1; i<=n; i++){
    int left=a[i-k], right=a[i];
    if(left < right) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}



Measured memory_bytes: 4776
local mod = 1000000007
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local s = io.read()
local n = #s
local a, b, c = {}, {0}, {0}
local sstr = s:sub(1, 1)
local z = 1
if sstr == "A" then
  a[1] = 1
elseif sstr == "?" then
  a[1] = 1
  z = 3
else
  a[1] = 0
end
for i = 2, n do
  sstr = s:sub(i, i)
  if sstr == "A" then
    a[i] = badd(a[i - 1], z)
    b[i] = b[i - 1]
    c[i] = c[i - 1]
  elseif sstr == "B" then
    a[i] = a[i - 1]
    b[i] = badd(b[i - 1], a[i - 1])
    c[i] = c[i - 1]
  elseif sstr == "C" then
    a[i] = a[i - 1]
    b[i] = b[i - 1]
    c[i] = badd(c[i - 1], b[i - 1])
  elseif sstr == "?" then
    a[i] = badd(bmul(3, a[i - 1]), z)
    b[i] = badd(bmul(3, b[i - 1]), a[i - 1])
    c[i] = badd(bmul(3, c[i - 1]), b[i - 1])
    z = bmul(z, 3)
  end
end
print(c[n])


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

ll N, A;

ll check (ll m, ll eat){
    
    ll cnt = 0;
    ll num = 1;
    REP(i,eat) {
        num*=m;
    }
    REP(i,eat) {
        // *mを*(m-1)に
        num/=m;
        num*=m-1;
        if (num>=N) {
            cnt+=1;
        } else {
            break;
        }
    }
    
    return cnt;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> N >> A;
    
    ll ans = N;
    FOR(eat,1,50) {
        // double lt = 0; double bt=INF*INF;
        double m = pow(N,1/(double)(eat+1));
        ll mi = m;
        if (m>=mi) mi+=1;
        ll dec = check(mi, eat+1);
        //cout << A*eat+mi*(eat+1-dec)+(mi-1)*dec << endl;
        ans = min(ans, A*eat+mi*(eat+1-dec)+(mi-1)*dec);
    }
    
    cout << ans << endl;
    return 0;
}

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

INF = float('inf')


def main():
    A = int(input())  # 500 Yen
    B = int(input())  # 100 Yen
    C = int(input())  # 50 Yen
    X = int(input())

    counter = 0

    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                total = 500 * a + 100 * b + 50 * c
                if total == X:
                    counter += 1

    print(counter)


if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n; cin>>n;
  ll ans = 1000010000010;
  
  rep(i,1000010) {
    if(i==0) continue;
    
    if(n%i==0) chmin(ans, i+n/i-2);
  }
  cout<<ans;
}

Measured memory_bytes: 3688
#include <iostream>

using namespace std;

void solve()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		int pos;
		cin >> pos;
		int up = 0, down = 0;
		for(int i = 1; i < n; ++i)
		{
			int a;
			cin >> a;
			if(pos > a && pos - a > down)
			{
				down = pos - a;
			}
			else if(pos < a && a - pos > up)
			{
				up = a - pos;
			}
			pos = a;
		}
		cout << up << " " << down << endl;
	}
}

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

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int p[30];

int n;
int main (){
    cin >> n;
    int ans = 0;
    for(int i=0;i<n;i++) cin >> p[i];
    for(int i=1;i<n-1;i++) {
        vector<int> v;
        for(int j=0;j<3;j++) v.push_back(p[i-1+j]);
        sort(v.begin(),v.end());
        if(v[1] == p[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int n;
  cin>>n;
  int dp[n][3];
  
  for(int i=0;i<n;i++)
  {   
     cin>>dp[i][0]>>dp[i][1]>>dp[i][2];
    
  }
  for(int i=1;i<n;i++)
  {
    dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]+=max(dp[i-1][0],dp[i-1][1]);
  }
  cout<< max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  
}

Measured memory_bytes: 1408
n=int(input())
x=list(map(int,input().split()))
x.insert(0,0) #x[0]に0を挿入
sorted_x = sorted(x[:])

l,r=sorted_x[n//2],sorted_x[n//2+1]

for i in range(1,n+1):
    print(r if x[i]<=l else l)

Measured memory_bytes: 95188
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;
#define NNN_MAX 100010
typedef pair<int,int> P;

int max(int a,int b){
	if (a>b) return a;
	return b;
}

int min(int a,int b){
	if (a>b) return b;
	return a;
}

int main (){
	int HHH,WWW;
	cin >> HHH >>WWW;
	string temp;
	int sh=1,sw=1,gh=HHH,gw=WWW;
	bool map[HHH+2][WWW+2];
	int kyori[HHH+2][WWW+2];
	int counter=0;
	//入力受取
	rep(i,HHH){
		cin >> temp;
		rep(j,WWW){
			if(temp[j]=='.'){
				map[i+1][j+1]=true;
				counter ++;
			}
			else {
				map[i+1][j+1]=false;
			}
			kyori[i+1][j+1]=INF;
		}
	}
	rep(i,HHH+2){
		map[i][0]=false;
		map[i][WWW+1]=false;
		kyori[i][0]=INF;
		kyori[i][WWW+1]=INF;
	}
	rep(i,WWW+1){
		map[0][i]=false;
		map[HHH+1][i]=false;
		kyori[0][i]=INF;
		kyori[HHH+1][i]=INF;
	}

	map[sh][sw]=false;
	kyori[sh][sw]=0;

	queue <int> hque;
	queue <int> wque;
	hque.push(1);
	wque.push(1);
	int h,w;
	int dh[4]={0,0,1,-1};
	int dw[4]={1,-1,0,0};

	while(hque.size()>0){
		h = hque.front();
		w = wque.front();
		hque.pop();
		wque.pop();

		if(h==gh && w==gw) break;

		rep(i,4){
			if(map[h+dh[i]][w+dw[i]] && kyori[h+dh[i]][w+dw[i]]==INF ){
				map[h+dh[i]][w+dw[i]]=false;
				kyori[h+dh[i]][w+dw[i]] = kyori[h][w]+1;
				hque.push(h+dh[i]);
				wque.push(w+dw[i]);
			}
		}

	}
	if(kyori[HHH][WWW]==INF){
		cout << -1 << endl;
		return 0;
	}
	//counter = まだ塗れるマス kyori = 使うますの最小値 counter - kyori =score
	cout << counter - kyori[HHH][WWW] - 1<< endl;

	return 0;
}


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

using namespace std;

int main(void)
{
	int h[10];
	for (int i = 0; i < 10; i++){
		cin >> h[i];
	}
	sort(h, h + 10);
	cout << h[9] << endl << h[8] << endl << h[7] << endl;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>a>>b>>c;
      Yes(a+b==c or a+c==b or b+c==a);
     

       
return 0;
}


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

int main() {
	int i,N, D;
	vector<int> d;
	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> D;
		d.emplace_back(D);
	}
	sort(d.begin(), d.end());
	d.erase(unique(d.begin(), d.end()), d.end());

	cout << d.size() << endl;

	return 0;
}

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

enum DIE {TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};
enum DIR {E, N, S, W, CLOCKWISE};

void rotate(vector<int>& die, DIR dir) {
  if(dir == E) {
    swap(die[TOP], die[RIGHT]);
    swap(die[TOP], die[BOTTOM]);
    swap(die[TOP], die[LEFT]);
  }
  if(dir == N) {
    swap(die[TOP], die[BACK]);
    swap(die[TOP], die[BOTTOM]);
    swap(die[TOP], die[FRONT]);
  }
  if(dir == S) {
    swap(die[TOP], die[FRONT]);
    swap(die[TOP], die[BOTTOM]);
    swap(die[TOP], die[BACK]);
  }
  if(dir == W) {
    swap(die[TOP], die[LEFT]);
    swap(die[TOP], die[BOTTOM]);
    swap(die[TOP], die[RIGHT]);
  }
  --die[BOTTOM];
}

bool possible(vector<int> die, DIR dir, int sum) {
  rotate(die, dir);
  --sum;
  if(die[BOTTOM] < 0) return false;
  if(sum == 1) return die[TOP] == 0 && die[BOTTOM] == 0;
  int fb = die[FRONT] + die[BACK];
  int tb = die[TOP] + die[BOTTOM];
  int lr = die[LEFT] + die[RIGHT];
  return fb <= sum - fb + 1 && lr <= sum - lr + 1 && tb <= sum - tb;
}

void greedy(char res[30000 + 1], vector<int> die) {
  res[0] = 'X';
  res[1] = '\0';
  int size = 0;
  int sum = accumulate(begin(die), end(die), 0);
  if(!possible(die, E, sum)) {
    res[0] = 'X';
    res[1] = '\0';
    return;
  }
  while(0 < sum) {
    for(auto dir: {E, N, S, W}) if(possible(die, dir, sum)) {
      rotate(die, dir);
      --sum;
      if(dir == E)      res[size++] = 'E';
      else if(dir == N) res[size++] = 'N';
      else if(dir == S) res[size++] = 'S';
      else if(dir == W) res[size++] = 'W';
      break;
    }
  }
  res[size] = '\0';
}

int main() {
  while(true) {
    vector<int> t(6);
    for(auto& i: t) cin >> i;
    if(all_of(begin(t), end(t), [](int i){return i == 0;})) break;

    char ans[30000 + 1], res[30000 + 1];
    ans[0] = 'X';
    ans[1] = '\0';
    sort(begin(t), end(t));
    do {
      greedy(res, t);
      if(strcmp(res, ans) < 0) swap(ans, res);
    } while(next_permutation(begin(t), end(t)));

    int p, q;
    cin >> p >> q;
    if(ans[0] == 'X') printf("impossible\n");
    else              {for(int i = p - 1; i < q; ++i) putchar(ans[i]); puts("");}
  }
}

Measured memory_bytes: 1220
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int base_val = sc.nextInt();
		int tp_val = sc.nextInt();
		int base_cal = sc.nextInt();;
		int tp_cal[] = new int[n];
		for(int i=0; i<n; ++i) tp_cal[i]=sc.nextInt();
		int temp;
		int index=0;
		for(int i=0; i<n; ++i){
			int max=0;
			for(int j=i+1; j<n; ++j){
				if(max<tp_cal[j]){
					max=tp_cal[j];
					index=j;
				}
			}
			temp=tp_cal[i];
			tp_cal[i]=max;
			tp_cal[index]=temp;
		}
		int best = base_cal / base_val;
		int sum=0;
		for(int i=0; i<n; ++i){
			sum+=tp_cal[i];
			temp=(base_cal+sum)/(base_val+(i+1)*tp_val);
			if(best < temp){
				best=temp;
			}
		}
		System.out.println(best);
	}
}

Measured memory_bytes: 18236
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<numeric>
using namespace std;

int main(void)
{
	int N;
	cin >> N;

	vector<int> a(N);
	for(int i=0; i<N; i++)
		cin >> a[i];

	int ret = accumulate(a.begin(), a.end(), 0);
	ret -= a.size();

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,a,b,i,j;cin>>n>>a>>b;
	//すべての数をxor aすれば 0beginにできる
	int dif=0;
	b^=a;
	for(i=0;i<n;i++){
		if(b&(1<<i)){dif++;}
	}
	if(dif%2==0){cout<<"NO"<<endl;return 0;}
	cout<<"YES"<<endl;
	//通常のグレイコードだと最上位のみ1になるのでうまいことswapする
	vector<int>cha;
	for(i=0;i<n;i++){
		if((b^(1<<(n-1)))&(1<<i)){cha.pub(i);}
	}
	//chaの中身がchangeしたい内容
	int m=cha.size();//ソート済み
	int mae=-1;
	int c=0;
	for(i=0;i<(1<<n);i++){
		if(i!=0){
			int kaz=-1;
			for(j=0;j<n;j++){
				if(i&(1<<j)){kaz=j;break;}
			}
			for(j=0;j<m;j++){
				if(cha[j]!=kaz){continue;}
				int tai=max(cha[j],cha[j^1])+1;
				if(i+(1<<tai)>=(1<<n)){kaz=cha[j^1];break;}
				
			}
			c^=(1<<kaz);
		}
		cout<<(c^a)<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
loc = [0] + list(map(int, input().split())) + [0]
total_distance = 0
for i in range(len(loc)-1):
    total_distance += abs(loc[i+1] - loc[i])
for i in range(1, len(loc)-1):
    dist = total_distance
    dist -= abs(loc[i] - loc[i-1])
    dist -= abs(loc[i+1] - loc[i])
    dist += abs(loc[i+1] - loc[i-1])
    print(dist)

Measured memory_bytes: 14048
//標準入力
//int getchar(void); EOFまで1文字ずつ返す
//char *gets(char *str); EOFまで1行ずつ取得。文字列の先頭アドレスを引数のchar型ポインタに・戻り値として返す
//char *fgets(const char *str,int n,FILE  *stream); *streamで示されるストリームからn-1文字を取得、\0を付加して先頭アドレスを引数のchar型ポインタに返すとともに戻り値としても返す。標準入力では、*stream=stdin
//int scanf(char *format,変換指定子)
#include <stdio.h>
int main(){
	int n,a,b;
	if(scanf("%d%d%d",&n,&a,&b)==-1){
		return 1;
	};
	if(n*a>=b){
		printf("%d",b);
		}
	else{
		printf("%d",n*a);
	}
	return 0;
}

Measured memory_bytes: 128
n=int(input())
b=list(map(int,input().split()))

a=[0]*n
if n>2:
  
  for x in range(1,n-1):
    c=min(b[x-1],b[x])
    a[x]+=c
  
  a[0]+=b[0]
  a[n-1]+=b[n-2]

  ans=0

  for y in range(len(a)):
    ans+=a[y]
  print(ans)

else:
  print(b[0]*2)

Measured memory_bytes: 61972
n = int(input())
num = list(map(int,input().split()))
mini=num[0]
max=num[0]
sum=0

for i in range(n):
    if num[i]<mini:
        mini=num[i]
    if num[i]>max:
        max=num[i]
    sum+=num[i]
print(mini,max,sum)



Measured memory_bytes: 6592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;

int main(int argc,char const* argv[])
{
  int a,b;
  cin >> a >> b;
  if(a+b==15) cout << '+' << endl;
  else if(a*b==15) cout << '*' << endl;
  else cout << 'x' << endl;
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   vec<int> c(n);
   for (int &x : c) cin >> x;
   int q;
   cin >> q;
   vec<ll> A(n);

   int ans = 0;
   bool ok = false;
   rep (i, q) {
      int t, x, d;
      cin >> t >> x >> d;
      x--;
      if (t == 1) { // 収穫
         A[x] += d;
      } else { // 出荷
         A[x] -= d;
      }
      
      if (A[x] < 0 || A[x] > c[x]) {
         if (!ok) ans = x + 1;
         ok = true;
      }
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	vector<int> b=a;
	sort(b.begin(),b.end());
	rep(i,n){
		if(a.at(i)==b.at(n-1)) cout << b.at(n-2) << endl;
		else cout << b.at(n-1) << endl;
	}
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
	int n, k; cin >> n >> k;
	vector<pair<int,int>> dt(n);
	for (int i = 0; i < n; i++) {
		int t, d; cin >> t >> d;
		dt.at(i) = make_pair(d, t);
	}
	sort(dt.rbegin(), dt.rend());
	vector<int> v1, v2;
	set<int> s;
	vector<long long> f(n + 1, 0);
	long long sum = 0;
	int cur;
	for (int i = 0; i < n; i++) {
		if (i < k) sum += dt.at(i).first;
		if (s.count(dt.at(i).second)) {
			if (i < k) v1.push_back(dt.at(i).first);
		} else {
			s.insert(dt.at(i).second);
			if (i >= k) v2.push_back(dt.at(i).first);
		}
		if (i == k - 1) {
			f.at(s.size()) = sum;
			cur = s.size();
		}
	}
	reverse(v1.begin(), v1.end());
	int cur1 = 0, cur2 = 0;
	while (cur1 < v1.size() && cur2 < v2.size()) {
		f.at(cur + 1) = f.at(cur) - v1.at(cur1) + v2.at(cur2);
		cur++; cur1++; cur2++;
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (f.at(i) > 0) ans = max(ans, f.at(i) + (long long)i * i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6780
# Ford-Fulkerson algorithm
class FordFulkerson:
  def __init__(self, N):
    self.N = N
    self.G = [[] for i in range(N)]

  def add_edge(self, fr, to, cap):
    forward = [to, cap, None]
    forward[2] = backward = [fr, 0, forward]
    self.G[fr].append(forward)
    self.G[to].append(backward)

  def add_multi_edge(self, v1, v2, cap1, cap2):
    edge1 = [v2, cap1, None]
    edge1[2] = edge2 = [v1, cap2, edge1]
    self.G[v1].append(edge1)
    self.G[v2].append(edge2)

  def dfs(self, v, t, f):
    if v == t:
      return f
    used = self.used
    used[v] = 1
    for e in self.G[v]:
      w, cap, rev = e
      if cap and not used[w]:
        d = self.dfs(w, t, min(f, cap))
        if d:
          e[1] -= d
          rev[1] += d
          return d
    return 0

  def flow(self, s, t):
    flow = 0
    f = INF = 10**9 + 7
    N = self.N 
    while f:
      self.used = [0]*N
      f = self.dfs(s, t, INF)
      flow += f
    return flow

N=int(input())

red_list=[]
for i in range(N):
  a,b=map(int,input().split())
  red_list.append((a,b,N+i+1))
  
blue_list=[]
for i in range(N):
  c,d=map(int,input().split())
  blue_list.append((c,d,i+1))
    
#print(blue_list)
#print(red_list)

#[s=0]->[blue:1..N]->[red:N+1..2N]->[t=2N+1]
ff = FordFulkerson(2*N+2)
for i in range(N):
  #print(0,i+1)
  ff.add_edge(0,i+1,1)
for c,d,ind1 in blue_list:
  for a,b,ind2 in red_list:
    if a<c and b<d:
      #print(ind1,ind2)
      ff.add_edge(ind1,ind2,1)  
for i in range(N):
  #print(N+i+1,2*N+1)
  ff.add_edge(N+i+1,2*N+1,1)

answer=ff.flow(0,2*N+1)
print(answer)

Measured memory_bytes: 3700
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

//#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int N, K; cin >> N >> K;
	cout << K * (int)pow(K - 1, N - 1) << endl;
	system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	char c[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> c[i][j];
		}
	}

	for(int i=0 ; i<2*h; i++){
		for(int j=0; j<w; j++){
			cout << c[i/2][j];
		}
		cout << endl;
	}

	return 0;
}

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

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

int main(){
  int n;
  cin>>n;
  ll a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  ll ans=0;
  rep(i,n){
    ans=(ans+(n+1-i)*a[i]%mod)%mod;
  }
  cout<<ans*power(4,n-1)%mod<<endl;
}



Measured memory_bytes: 1792
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, q;
  scanf("%lld%lld", &n, &q);
  ll a[n], x;
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < q; ++i) {
    scanf("%lld", &x);
    ll ans = 0, now = a[0], t = 0;
    for(j = 0; j < n; ++j) {
      int s = 0;
      while(x >= now && t <= n - 1) {
        t++;
        now += a[t];
      }
      if(a[j] <= x) ans += t - j;
      now -= a[j];
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 3388
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, h[20];

    cin >> n;

    for (int i=0; i<n; i++) {
        cin >> h[i];
    }

    int big = h[0], ans = 1;
    for (int i=1; i<n; i++) {
        if (h[i] >= big) {
            ans++;
            big = h[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

const int dh[] = {-1, 0, 1, 0};
const int dw[] = {0, 1, 0, -1};

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

    while (true) {
        int w, h; cin >> w >> h;
        if (w+h==0) break;
        vector<vector<vector<int>>> mat(h, vector<vector<int>>(w, vector<int>(4, 1)));
        // up right down left

        rep(i, h) {
            rep(j, w-1) {
                int x; cin >> x;
                if (x==1) {
                    mat[i][j][1] = 0;
                    mat[i][j+1][3] = 0;
                }
            }
            if (i==h-1) break;
            rep(j, w) {
                int x; cin >> x;
                if (x==1) {
                    mat[i][j][2] = 0;
                    mat[i+1][j][0] = 0;
                }
            }
        }

        queue<P> que;
        que.push(P(0, 0));
        vector<vector<int>> dist(h, vector<int>(w, -1));
        dist[0][0] = 1;
        while(!que.empty()) {
            P p = que.front(); que.pop();
            int ch = p.fi, cw = p.se;
            rep(i, 4) {
                if (!mat[ch][cw][i]) continue;
                int nh = ch+dh[i], nw = cw+dw[i];
                if (nh<0||nh>h-1||nw<0||nw>w-1) continue;
                if (dist[nh][nw]!=-1) continue;
                dist[nh][nw] = dist[ch][cw]+1;
                que.push(P(nh, nw));
            }
        }

        int ans = dist[h-1][w-1];
        if (ans<0) ans = 0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3208
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;


int main(void) {

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


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

#define pb push_back
#define fst first
#define snd second
#define ALL(s) s.begin(),s.end()
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define SZ(x) ((int)(x).size())
#define PI acos(-1)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

int main() {FIN;
    string s,t; cin>>s>>t;
    int n = SZ(s), m = SZ(t);
    int dp[n][m];
    fore(i,0,n){
        fore(j,0,m){
            dp[i][j] = 0;
            if(i-1>=0) dp[i][j] = max(dp[i][j],dp[i-1][j]);
            if(j-1>=0) dp[i][j] = max(dp[i][j],dp[i][j-1]);
            if(s[i]==t[j]) dp[i][j] = max(dp[i][j],(i-1>=0&&j-1>=0?dp[i-1][j-1]:0)+1);
        }
    }
    int res = dp[n-1][m-1], i = n-1, j = m-1;
    vector<char> ans;
    while(res){
        if(i-1>=0 && dp[i][j] == dp[i-1][j]) i--;
        else if(j-1>=0 && dp[i][j] == dp[i][j-1]) j--;
        else if(s[i]==t[j] && dp[i][j] == (i-1>=0&&j-1>=0?dp[i-1][j-1]:0)+1){ ans.pb(s[i]); res--; i--; j--;}
    }
    reverse(ALL(ans));
    for(auto x: ans) cout<<x; cout<<"\n";
    return 0;
}


Measured memory_bytes: 38748
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
//////////
vector<int> gr[100001];
int vis[100001];
int de[100001];
vector<int> tt[100001];
stack<int> s;
void dfs(int i,int d)
{
    vis[i]=1;
    for(auto r:gr[i])
    {
        tt[r].push_back(i);
        if(vis[r]==0)
        {
            dfs(r,d+1);
        }
    }
    s.push(i);
}
signed main()
{
    fastio;
    int n;
    cin>>n;
    int m;
    cin>>m;
    int f[n+1]={};
    for(int i=0;i<n-1+m;++i)
    {
        int x,y;
        cin>>x>>y;
        gr[x].push_back(y);
        f[y]++;
    }
    int ro;
    for(int i=1;i<=n;++i)
    {
        if(f[i]==0)
            ro=i;
    }
    dfs(ro,1);
    int y=0;
    while(!s.empty())
    {
        ++y;
        de[s.top()]=y;
        s.pop();
    }
    for(int i=1;i<=n;++i)
    {
        if(i==ro)
        {
            cout<<"0\n";
        }
        else
        {
            int po=0;
            int dep=de[tt[i][0]];
            for(int j=1;j<tt[i].size();++j)
            {
                if(de[tt[i][j]]>dep)
                {
                    po=j;
                    dep=de[tt[i][j]];
                }
            }
            cout<<tt[i][po]<<"\n";
        }
    }
}

Measured memory_bytes: 21020
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int K, A, B;
    cin >> K >> A >> B;
    
    ll cnt = 1;
    for(int i = 0; i < K; i++) {
        if (cnt < A || B-A <= 2 || K-i <= 1) {
            cnt++;
        } else {
            cnt += B-A;
            i++;
        }
    }
    
    cout << cnt << endl;

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

Measured memory_bytes: 256
function main(lines) {
    const n = lines.split('\n')[0]
    const An = lines.split('\n')[1].split(' ').map(Number)
    
    //配列末尾の要素を対象にする
    let swap = 0
    for(let i=0; i<n; i++){
    for(let j=n -2; j>=0; j--){
    // 右の数値が左の数値より大きければ、交換する
        if(An[j+1]<An[j]){
            tmp = An[j]
            An[j] = An[j+1]
            An[j+1] = tmp
            swap++
        }
    }
    }
    console.log(An.join(' '))
    console.log(swap)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15412
// Author: Wenxing Mei
//   File: d.cpp
//   Date: 2019-03-11 22:14
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b - 1; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE

int get(ll l, ll r) {
    ll n = (r - l + 1) / 2ll;
    return n % 2;
}

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    ll A, B;
    cin >> A >> B;

    ll ans;
    if (A % 2 == 0) {
        if (B % 2 == 0)
            ans = B ^ get(A, B - 1);
        else
            ans = get(A, B);
    } else {
        if (B % 2 == 0)
            ans = B ^ get(A + 1, B - 1) ^ A;
        else
            ans = get(A + 1, B) ^ A;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256