akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M;
	cin >> N >> M;
	vector<pair<long long, long long>>A(M);
	vector<long long>Tree(N, 0);
	for (long long i = 0; i < M; i++) {
		cin >> A.at(i).first >> A.at(i).second;
		Tree.at(A.at(i).first - 1) += 1;
		Tree.at(A.at(i).second - 1) += -1;
	}
	if (M == 1) {
		cout << "NO" << endl;
		return 0;
	}
	long long ans = Tree.at(0);
	for (long long i = 1; i < N; i++) {
		ans += Tree.at(i);
		if (ans != 0 && ans % 2 != 0) { 
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var ret = 0
var N = 0
var M = 0
var G = [10][10]int{}
var v = [10]int{}

func dfs(n int) {
	cnt := 0
	for i := 0; i < N; i++ {
		if v[i] == 0 && G[n][i] == 1 {
			v[i] = 1
			dfs(i)
			v[i] = 0
		}
		if v[i] == 1 {
			cnt++
		}
	}
	if cnt == N {
		ret++
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	scanner.Scan()
	M, _ = strconv.Atoi(scanner.Text())

	for i := 0; i < M; i++ {
		scanner.Scan()
		A, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		B, _ := strconv.Atoi(scanner.Text())

		G[A-1][B-1] = 1
		G[B-1][A-1] = 1
	}

	v[0] = 1
	dfs(0)
	fmt.Println(ret)
}

Measured memory_bytes: 640
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
signed main(void)
{
	string s,t;
	cin>>s>>t;
	if(t.length()!=s.length()+1)
	{
		puts("No");
		return 0;
	}
	for(int i=0;i<(int)s.length();++i)
		if(s[i]!=t[i])
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}




Measured memory_bytes: 3624
/*
                    author         : TAPAN SAVANI 
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

#include <bits/stdc++.h>
using namespace std;

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

    string s;
    cin >> s;

    int n = s.length();

    if(s[n-1] == 's')
    {
        s.push_back('e');
        s.push_back('s');
    }
    else 
    {
        s.push_back('s');
    }

    cout << s << "\n";

    return 0;
}


Measured memory_bytes: 3636
n=int(input())
string_list=[int(input()) for i in range(n)]
int_list=sorted(string_list,reverse=True)
ix=0
res=0
for il in int_list:
    if ix == 0:
        res=int(il/2)
        ix=1
    else:
        res=res+il
print(res)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	int x,y,tmp,i;
	for (i=1;;i++){
		scanf("%d%d",&x,&y);
		if (x==0&&y==0)break;
		else if (x<=y){
			printf("%d %d\n",x,y);
		}
		else if (x>=y){
			tmp=x;
			x=y;
			y=tmp;
			printf("%d %d\n",x,y);
		}
	}
	return 0;}

Measured memory_bytes: 600
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
 
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int A[100000];
int maxi[100000], mini[100000];

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

    int N, T;
    cin >> N >> T;
    for(int i = 0; i < N; ++i) cin >> A[i];
    maxi[N - 1] = A[N - 1];
    for(int i = N - 2; i >= 0; --i) maxi[i] = max(maxi[i + 1], A[i]);
    int latte = 0;
    for(int i = 0; i < N; ++i) chmax(latte, maxi[i] - A[i]);
    int res = 0;
    for(int i = 0; i < N; ++i) if(latte == maxi[i] - A[i]) ++res;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;

    int intlist[200]={0};
    // N個の整数を入力
    for(int i=0;i<n;i++) {
	    cin >> intlist[i];
    }
    
    // 入力結果から操作回数を算出
    int action_cnt = 0;
    bool act_check = true;
    while(act_check) {
        for(int j=0;j<n;j++) {
            if(intlist[j] % 2 != 0) {
                act_check = false;
                break;
            }
    	    intlist[j] = intlist[j] / 2;
        }
        if(act_check) action_cnt++;
    }

    cout << action_cnt << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
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);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 55;

//head

int h, w;
string s[N];
int black;
int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};
inline bool able(int i, int j) {return i >= 0 and j >= 0 and i < h and j < w;}
int dist[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  rep(i, h) cin >> s[i];
  rep(i, h) rep(j, w) if(s[i][j] == '#') black++;

  queue<P> q;
  q.emplace(0, 0);
  s[0][0] = '$';
  dist[0][0] = 1;
  while(!q.empty()) {
    int i, j;
    tie(i, j) = q.front();
    q.pop();
    rep(k, 4) {
      int ni = i+di[k];
      int nj = j+dj[k];
      if(able(ni, nj) and s[ni][nj] == '.') {
        s[ni][nj] = '$';
        dist[ni][nj] = dist[i][j] + 1;
        q.emplace(ni, nj);
      }
    }
  }
  if(s[h-1][w-1] == '.') cout << -1 << endl;
  else {
    cout << h*w-dist[h-1][w-1]-black << endl;
  }
}

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(ll x, ll y) {
  return (x / y);
}

int main() {
  int n; read(n);
  int ans = 1e9;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    int cur = 0;
    while(x % 2 == 0) x /= 2, cur++;
    ans = min(ans, cur);
  }
  print(ans);
}

Measured memory_bytes: 256
N = int(input())
A_B = [[int(i) for i in input().split()] for _ in range(N)]
A_B.sort(key=lambda x:x[1])

time = 0
for i in A_B:
  time += i[0]
  if time > i[1]:
    print('No')
    exit()

print('Yes')

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


string S;
int N, L, a[1000], b[1000], sub1, sub2, j, i, Ans = 0;

int main() {
	cin >> N >> L;
	for (i = 0; i < N; i++) {
		a[i] = i + L;
		b[i] = i + L;
		Ans += a[i];
		if (a[i] < 0)
			a[i] *= -1;
	}

	for (i = 0; i < N - 1; i++) {
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]){
				sub1 = a[i];
				a[i] = a[j];
				a[j] = sub1;
				sub2 = b[i];
				b[i] = b[j];
				b[j] = sub2;
			}
		}
	}
	

	Ans = Ans - b[0];
	cout << Ans;
	return 0;
}


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

int N, dist[209][209], dp[209]; bool flag = false;
char c[209][209];
vector<int> X[209];

void dfs(int pos, int dep) {
	if (dp[pos] >= 0) {
		if (dp[pos] != dep) flag = true;
		return;
	}
	dp[pos] = dep;
	for (int i = 0; i < X[pos].size(); i++) dfs(X[pos][i], dep ^ 1);
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) dist[i][j] = (1 << 29);
		dist[i][i] = 0;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> c[i][j];
			if (c[i][j] == '1') { X[i].push_back(j); dist[i][j] = 1; }
		}
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	}

	// 二部グラフ判定
	for (int i = 0; i < N; i++) dp[i] = -1;
	dfs(0, 0);

	if (flag == true) {
		cout << "-1" << endl;
	}
	else {
		int maxn = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) maxn = max(maxn, dist[i][j]);
		}
		cout << maxn + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 640
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var S = lines[1].split("");
    var K = Number(lines[2]);

    for (var i = 0; i < N; i++) {
        if (S[K - 1] !== S[i]) { S[i] = "*"; }
    }
    var result ="";
    for (var i = 0; i < N; i++) {
        result = result + S[i];
    }
    console.log(result);
});

Measured memory_bytes: 7500
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

vector<long long int> getNearestPoint(long long int x, vector<long long int> &y) {
  vector<long long int> res;
  if (x < y[0]) {
    res.push_back(y[0]);
  } else if (x > y[y.size() - 1]) {
    res.push_back(y[y.size() - 1]);
  } else {
    int a = 0;
    int b = y.size() - 1;
    int c;
    while (a < b) {
      c = (a + b) / 2;
      if (y[c] <= x && y[c + 1] >= x) {
        break;
      } else if (y[c] > x) {
        b = c;
      } else {
        a = c;
      }
    }
    res.push_back(y[c]);
    res.push_back(y[c + 1]);
  }
  return res;
}

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;

  vector<long long int> s(A), t(B);
  for (int i = 0; i < A; i++) {
    cin >> s[i];
  }
  for(int i = 0; i < B; i++) {
    cin >> t[i];
  }

  for (int i = 0; i < Q; i++) {
    long long int x;
    cin >> x;

    long long int best = -1;
    vector<long long int> v1 = getNearestPoint(x, s);
    vector<long long int> v2;
    for (int j = 0; j < v1.size(); j++) {
      v2 = getNearestPoint(v1[j], t);
      for (int k = 0; k < v2.size(); k++) {
        if (best == -1 || best > abs(v1[j] - x) + abs(v2[k] - v1[j])) {
          best = abs(v1[j] - x) + abs(v2[k] - v1[j]);
        }
      }
    }

    v1 = getNearestPoint(x, t);
    for (int j = 0; j < v1.size(); j++) {
      v2 = getNearestPoint(v1[j], s);
      for (int k = 0; k < v2.size(); k++) {
        if (best > abs(v1[j] - x) + abs(v2[k] - v1[j])) {
          best = abs(v1[j] - x) + abs(v2[k] - v1[j]);
        }
      }
    }

    cout << best << endl;
  }

  return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>
long long int dp[100000]={0},m;
long long int pow(long long int n){
    if(n==1)return m;
    long long int mid=n/2;
    if(n>=100000)return pow(n-mid)*pow(mid)%1000000007;
    if(dp[n]!=0)return dp[n];
    return dp[n]=(pow(n-mid)*pow(mid))%1000000007;
}
int main(){
    int n;
    scanf("%lld%d",&m,&n);
    printf("%lld\n",pow(n));
}

Measured memory_bytes: 2764
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

ll a[1000005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,0,3*n-1)cin>>a[i];
sort(a,a+3*n);
ll ans=0;
for(int i=3*n-2,j=1;i>=0&&j<=n;i-=2,j++)
ans+=a[i];
ol(ans);
return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    double A[N];
    double inv_sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        inv_sum += 1 / A[i];
    }
    cout << setprecision(10) << fixed << 1 / inv_sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    long long t[n],a[n];
    for(int i=0; i<n; i++){ cin >> t[i] >> a[i]; }
    
    long long T=t[0], A=a[0];
    for(int i=0; i<n; i++){
        long long s=max(((T+t[i]-1)/t[i]),((A+a[i]-1)/a[i]));
        T = s * t[i];
        A = s * a[i];
    }
    cout << T+A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n,k;
  cin>>n>>k;
  ll ans=1;
  ans*=k;
  for(ll i=1;i<n;i++){
    ans*=(k-1);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3512
def fib_loop(a, t, n):
    if a < n:
        return fib_loop(a+1, (t[0]+t[1],t[0]), n)
    else:
        return t[0] + t[1]

def fib(n):
    if n < 2:
        return 1
    else:
        return fib_loop(2, (1,1), n)

n = int(input())
print(fib(n))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int long long

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

int num_1(int n) {
    int a = 0;

    while (n) {
        if (n & 1) a++;
        n >>= 1;
    }

    return a;
}

void out(int i, int j) {
    cout << i << " " << j << endl;
}

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

    if (num_1(N) == 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;

        out(1, 2);
        out(1, 3);
        out(2, 3+N);
        out(3, 2+N);
        out(2+N, 1+N);

        // out(2, 3+N);
        // out(3+N, 1+N);
        // out(1+N, 2+N);
        // out(2+N, 3+N);
        // cout << "1 2" << endl;
        // cout << "2 3" << endl;
        // cout << "3 " << (1+N) << endl;
        // cout << (1+N) << " " << (2+N) << endl;
        // cout << (2+N) << " " << (3+N) << endl;

        if (N % 2 == 1) {
            REPS(i, N/2-1) {
                int j = i * 2 + 2;
                out(1, j);
                out(1, j+1);
                out(j+1+N, j);
                out(j+N, j+1);
                // cout << 1 << " " << j << endl;
                // cout << 1 << " " << (j+1) << endl;
                // cout << (j+1+N) << " " << j << endl;
                // cout << (j+N) << " " << (j+1) << endl;
            }
        } else {
            REPS(i, N/2-3) {
                int j = i * 2 + 2;
                out(1, j);
                out(1, j+1);
                out(j+1+N, j);
                out(j+N, j+1);
            }

            int a = (N-2) ^ N;
            out(a, N-2);
            out(N-2, N);
            out(a, N+N);
            out(N+N, N-2+N);

            out(1, N-1);
            out(N+N, N-1+N);
        }
    }

    return 0;
}

Measured memory_bytes: 2304
#define LOCAL

#include<bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 123456789LL;
const double PI = acos(-1);

int main() {
	IOS;
	llong ll = 0, rr = INF;
	llong ans = -1;
	llong a, b; cin >> a >> b;
	for (int i = 1; i <= 10000; i++) {
		if (i * 8 / 100 == a && i * 10 / 100 == b) {
			cout << i << "\n";
			return 0;
		}
	}
	cout << ans;
}

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

int main()
{
    string S;
    cin >> S;

    queue<vector<long long>> q;
    q.push(vector<long long>{0, 0, (long long)(S[0] - '0')});
    long long ans = 0;
    while (!q.empty())
    {
        long long next_idx = q.front()[0] + 1;
        long long sum = q.front()[1];
        long long current = q.front()[2];
        if (next_idx < S.size())
        {
            q.push(vector<long long>{next_idx, sum + current, (long long)(S[next_idx] - '0')});
            q.push(vector<long long>{next_idx, sum, current * 10 + (long long)(S[next_idx] - '0')});
        }
        else
        {
            ans += sum + current;
        }
        q.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()
	n := bs.IntScan()

	if n == 2 {
		bw.Printf("1")
		return
	}

	count := 2
	var k int64
	for k = 2; k <= int64(math.Sqrt(float64(n))); k++ {
		if isOne(n, k) {
			count++
		}

		t := n / k
		if t <= k {
			continue
		}
		if isOne(n, t) {
			count++
		}
	}

	bw.Printf("%v", count)
}

func isOne(n, k int64) bool {
	x := n
	for x >= k && x % k == 0 {
		x /= k
	}
	// 割ったあまりが１、もしくはx=１の場合、対象
	if x % k == 1 {
		return true
	}
	return false
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int64 {
	v, err := strconv.ParseInt(b.Scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 640
// AOJ ALDS1_13_A 8 Queens Problem
// 2018.5.4 bal4u

#include <stdio.h>

char q[8];
char a[8], b[8], u[16], v[16];  // 衝突検出用 a:縦上下、b:横左右、u,v: 斜め方向

void found()
{
	int r, c;

	for (r = 0; r < 8; r++) {
		for (c = 0; c < 8; c++) {
			if (q[r] == c) putchar('Q');
			else           putchar('.');
		}
		putchar('\n');
	}
}

int check(int r)
{
	int c;

	if (r == 8) { found(); return 1; }
	if (b[r]) {	if (check(r+1)) return 1; }
	for (c = 0; c < 8; c++) {
		if (b[r] || a[c] || u[r+c] || v[r-c+7]) continue;
		a[c] = u[r+c] = v[r-c+7] = 1;
		q[r] = c;
		if (check(r+1)) return 1;
		a[c] = u[r+c] = v[r-c+7] = 0;
	}
	return 0;
}

int main()
{
	int k, r, c;

	scanf("%d", &k);
	while (k--) {
		scanf("%d%d", &r, &c);
		q[r] = c;
		a[c] = b[r] = u[r+c] = v[r-c+7] = 1;
	}
	check(0);
	return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
signed main() {
    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; i + j <= N; j++) {
            int k = N - i - j;
            if(Y == 10000 * i + 5000 * j + 1000 * k) {
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 256
//----------------------------------------------------------------
//B

#include <iostream>
using namespace std;

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}



Measured memory_bytes: 5216
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int N;
	cin >> N;
	int x[N];
	long long sum=0;
	for(int i=0;i<N;i++){
		cin >> x[i];
		sum+=x[i];
	}
	int ave=round((double)sum/N);
	int score=0;
	for(int i=0;i<N;i++){
		int tmp=x[i]-ave;
		score+=tmp*tmp;
	}
	cout << score << endl ;
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<cmath>
int main()
{
  int N,A,B;
  std::cin>>N>>A>>B;
  int minNum{};
  if (!(A+B<=N))
    minNum=(A+B)-N;
  std::cout<<std::min(A,B)<<' '<<minNum;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

void rec(int c, const vector<vi> &e, vi &v, vector<ll> &w){
	v[c] = 1;
	for(int i: e[c]){
		rec(i, e, v, w);
		v[c] += v[i];
		w[c] += w[i];
	}
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, x, d; cin >> n >> x >> d;
	vector<vi> e(n);
	vi v(n), rem(n);
	vector<ll> w(n);
	rep(i, n){
		cin >> w[i];
		if(i){
			int p; cin >> p; p--;
			e[p].pb(i);
		}
	}
	rec(0, e, v, w);
	
	//dbg(v); dbg(w);
	
	const int N = 65000;
	vector<ll> dp(N, (ll)1e18);
	dp[0] = 0;
	rep(i, n) for(int j = N - 1; j >= 0; j--) if(dp[j] < 1e18){
		int cnt = i == 0 ? inf : d, use = min(cnt, 50);
		rem[i] = cnt - use;
		
		for(int k = 1; k <= use; k++){
			int nj = j + k * v[i];
			if(nj >= N || dp[j] + k * w[i] > x) break;
			dp[nj] = min(dp[nj], dp[j] + k * w[i]);
		}
	}
	
	vector<tuple<int, ll, int>> u;
	rep(i, n) u.emplace_back(v[i], w[i], rem[i]);
	
	sort(all(u), [](tuple<int, ll, int> a, tuple<int, ll, int> b)
			{ return get<1>(a) * get<0>(b) < get<1>(b) * get<0>(a); }
	);
	
	ll ans = 0;
	rep(i, N) if(dp[i] <= x){
		ll cnt = i;
		ll cost = dp[i];
		for(auto j : u) if(cost < x){
			ll k = min((ll)get<2>(j), (x - cost) / get<1>(j));
			cnt += k * get<0>(j);
			cost += k * get<1>(j);
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;

static const int MAX = 4;

int main() {
	ll n; cin >> n;
	ll minV = INF;
	rep(i, 0, 5) {
		ll x; cin >> x;
		minV = min(minV, x);
	}

	cout << (minV + n - 1) / minV + 4 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1000

int min(int ,int );

int P[MAX];
int M[MAX][MAX];

int main(){
  int i, l, j, k;
  int n;

  scanf("%d", &n);
  for(i = 1; i <= n; i++){
    scanf("%d%d", &P[i - 1], &P[i]);
  }

  for(l = 2; l <= n; l++){
    for(i = 1; i < n; i++){
      j = i + l -1;
      M[i][j] = 20000000;
      for(k = i; k < j; k++){
	M[i][j] = min(M[i][j],M[i][k] + M[k+1][j] + P[i-1]*P[k]*P[j]); 
      }
    }
  }

  printf("%d\n", M[1][n]);
  
  return 0;
}

int min(int a,int b){
  return a < b ? a : b;
}



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

const ll MOD = 1e9+7;

int main() {
  int N, a;
  vector<int> A;
  ll ans = 1;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  if (N%2) {
    for (int i=0; i<N; i++) {
      if (A[i] != (i+1)/2 * 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    for (int i=0; i<N; i++) {
      if (A[i] != i/2 * 2 + 1) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  for (int i=0; i<N/2; i++) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    set<int> A;
    
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        A.insert(a);
    }
    
    if (A.size() == N)
    {
        cout << "YES" << endl;
    } else
    {
        cout << "NO" << endl;
    }
    
    
    
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}

void solve()
{
    string S;
    cin >> S;
    int N = S.length() - 1;

    LL ans = 0;

    REP0(bit, 1 << N)
    {
        LL num = 0;
        REP0(i, N)
        {
            char s = S[i];
            num *= 10LL;
            num += (LL)(s - '0');
            if ((bit & (1 << i)))
            {
                ans += num;
                num = 0LL;
            }
            if (i == N - 1)
            {
                s = S[i + 1];
                num *= 10LL;
                num += (LL)(s - '0');
                ans += num;
            }
        }
    }

    if (N)
        cout << ans << endl;
    else
        cout << S << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll MOD=1000000007;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
ll n,ans1=1,ans2=1,ans3=1;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	while(n--)
	{
		ans1*=10ll;
		ans2*=9ll;
		ans3*=8ll;
		ans1%=MOD;
		ans2%=MOD;
		ans3%=MOD;
	}
	ll ans=ans1-2*ans2+ans3;
	if(ans<0ll)ans+=MOD;
	if(ans<0ll)ans+=MOD;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
#include<ctime>
#include<complex>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

int main(){
    int dp[1<<15+1][5]={{0}};
    dp[0][0]=1;

    for(int i=1;i*i<=1<<15;i++){
        for(int j=i*i;j<=1<<15;j++){
            for(int k=1;k<=4;k++){
                dp[j][k]+=dp[j-i*i][k-1];
            }
        }
    }

    int N;
    while(scanf("%d",&N),N){
        int ret=0;
        for(int i=0;i<5;i++)ret+=dp[N][i];
        printf("%d\n",ret);
    }

    return 0;
}

Measured memory_bytes: 2472
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <string>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){

    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j+=i){
            ans += j;
        }
    }

    p(ans);

    return 0;
}


Measured memory_bytes: 3184
#!/usr/bin/env python3
#ABC43 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

s = input()
n = len(s)
for i in range(n-1):
    if s[i] == s[i+1]:
        print(i+1,i+2)
        break
    if i < n-2:
        if s[i] != s[i+1] and s[i] == s[i+2]:
            print(i+1,i+3)
            break
else:
    print(-1,-1)


Measured memory_bytes: 39440
#include <iostream>
#include <array>
#include <string>

using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		bool l = false,r = false;
		bool t = true;
		int ret = 0;
		for(int i=0;i<n;i++){
			string s;
			cin >> s;
			if(s == "ru") r = true;
			if(s == "rd") r = false;
			if(s == "lu") l = true;
			if(s == "ld") l = false;
			if(r == t && l == t){
				ret++;
				t = !t;
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

void solve()
{
	int N, L;
	cin >> N >> L;
	vector<string> s(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	string ans = "";
	for (int i = 0; i < N; ++i)
	{
		ans += s[i];
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int gozen,gogo;
	int kazu[5];
	int maxmise;
	int maxkazu;
	int i;
	while(1) {
		scanf("%d %d",&gozen,&gogo);
		if(gozen==0 && gogo==0)break;
		kazu[0]=gozen+gogo;
		for(i=1;i<5;i++) {
			scanf("%d %d",&gozen,&gogo);
			kazu[i]=gozen+gogo;
		}
		maxmise=0;
		maxkazu=kazu[0];
		for(i=0;i<5;i++) {
			if(kazu[i]>maxkazu) {
				maxkazu=kazu[i];
				maxmise=i;
			}
		}
		printf("%c %d\n",'A'+maxmise,maxkazu);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[122121];
ll a[122211];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		if(i>=2) dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1792
# 2019-11-15 00:35:39(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def nCr(n, r):
    r = min(r, n - r)
    upper = reduce(op.mul, range(n, n-r, -1), 1)
    lower = reduce(op.mul, range(r, 0, -1), 1)
    return upper // lower

mod = 10 ** 9 + 7

def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]

    for i in range(1, k+1):
        if i <= n - k + 1:
            print(nCr(n-k+1, i) * nCr(k-1, i-1) % mod)
        else:
            print(0) # k > n - k + 1 のとき、 i > n - k - 1 となる並べ方は存在しない

if __name__ == "__main__":
    main() 


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

int main() {
 int n,d;
  cin >> n >>d;
  
    double a[n][2];
    for(int i = 0;i<n;i++) {
        for(int j =0;j<2;j++){
     cin>>a[i][j];
        }
    }
   double dist = 0;
    int count = 0;
    
    for(int i = 0;i<n;i++) {
    dist = sqrt(a[i][0]*a[i][0]+a[i][1]*a[i][1]);
     if(dist<=d){
      count++;
     }       
        }
    
    cout << count;
}

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

using namespace std;

int main(){
int N;  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){ cin >> A[i];}
  sort(A.begin(),A.end());
  int c = lower_bound(A.begin(),A.end(), 0) - A.begin();
  //
 if( c <= 0){
   // all of components are positive
   c = 1;}
  else if( c >= N){
    // all of components are negative
  
   c = N - 1;}
  
   
  vector<int> vec1(c); vector<int> vec2( N - c);
  
  vector<pair<int,int>> B;
  for(int i = 0; i < c; i++){  vec1[i] = A[i];}
  for(int j = c; j < N; j++){  vec2[j - c] = A[j];}
  
 if((int) vec2.size() >= 2){
  for( int i = 0; i <= N - 2 - c; i++){
    
    B.push_back(make_pair(vec1[0],vec2[i]));
    vec1[0] -= vec2[i];}}
  
 if((int) vec1.size() >= 2){
   for(int j = 1; j <= c - 1; j++){
    B.push_back(make_pair(vec2[N - 1 - c],vec1[j]));
    vec2[N - 1 - c] -= vec1[j]; }}
  
  B.push_back(make_pair(vec2[N - 1 - c] , vec1[0])) ;
  
  int  M = vec2[N - 1 - c] - vec1[0];
  
  cout << M << endl;
  
  for(int i = 0; i < (int) B.size(); i++){
    cout << B[i].first << " " << B[i].second << endl; }
  
    
  
  return 0;}
    

Measured memory_bytes: 3572
def solve():
    N=n=int(input())
    q=int(n**0.5)
    ans=0
    for d in range(2,q+1) :
        a=0
        while n % d == 0 :
            a+=1
            n//=d
        if a>0 :
            ans+=int(((a*8+1)**0.5-1)/2)
    if n > 1 :
        ans+=1
    return ans

print(solve())


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

const int INF = 1e9;

signed main() {
  string s;
  cin >> s;

  s = '0' + s;
  int n = (int)s.size();

  vector<vector<int>> dp(n + 1, vector<int> (2, INF));

  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    int current = s[i] - '0';
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + current);
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + (10 - current));
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + current + 1);
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + (9 - current));
  }
  cout << dp[n][0] << '\n';
}


Measured memory_bytes: 58876
#include <iostream>
using namespace std;
int main()
{
    int n,k,count=0;
    cin>>n>>k;
    int a[100000];
    char temp;
    for(int i=0;i!=n;i++)
    {
        cin>>temp;
        if(temp=='L')
        {
            a[i]=-1;
        }
        else a[i]=1;
    }
    temp=a[0];
    for(int i=0;i<n&&k!=0;)
    {
        while(a[i]==temp&&i<n)
        {
            if(count%2)
            {
                a[i]*=(-1);
            }
            i++;
        }
        if(count%2)
        {
            k--;
        }
        count++;
        if(i<n) temp=a[i];
    }
    count=0;
    for(int i=0;i<n;i++)
    {
        if(i==0&&a[i]==-1) continue;
        if(i==n-1&&a[i]==1) continue;
        count+=int(a[i+a[i]]==a[i]);
    }
    cout<<count;
}


Measured memory_bytes: 3996
n, m = map(int, input().split())
x = list(map(int, input().split()))

x.sort()
diffs = [0]
for i in range(len(x) - 1):
    diffs.append(abs(x[i] - x[i + 1]))
diffs.sort()
for i in range(n - 1):
    if len(diffs) <= 0:
        break
    diffs.pop()
print(sum(diffs))

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

const int AMAX = 1000000;
int ans = 0;
map<int, int> arr;

int main(void)
{
    vector<bool> vec(AMAX, false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int k = 0; k < N; k++)
    {
        cin >> A[k];
        arr[A[k]] = arr[A[k]] + 1;
    }
    auto yakusuu = [&](int a, vector<int> &y) {
        int pw = sqrt(a);
        //cout << pw<<endl;
        y.push_back(1);
        for (int j = 2; j <= pw; j++)
        {
            if (a % j == 0)
            {
                int v = a / j;
                y.push_back(j);
                y.push_back(v);
                //cout <<j <<"  "<<v<<endl;
                //pw=v;
            }
            //vec[a]=false;
        }
    };
    sort(A.begin(), A.end());
    //for(int m=0;m<N;m++){
    //    yakusuu(A[m]);
    //}
    ans = N;
    for (int m = 0; m < N; m++)
    {
        if (arr.at(A[m]) == 1)
        {
            vector<int> yk;
            //vec[A[m]] = true;
            yakusuu(A[m], yk);
            for (int k = 0; k < yk.size(); k++)
            {
                if (vec[yk[k]] == true)
                {
                    ans--;
                    vec[A[m]] = true;
                    break;
                }
            }
            vec[A[m]] = true;
        }else{
            vec[A[m]] = true;
            ans--;
        }
        //if(vec[A[m]]==true && arr.at(A[m])==1){
        //    ans++;
        //    cout << A[m]<<endl;
        //}
    }
    cout << ans << endl;
}

Measured memory_bytes: 13300
A, B, M = map(int, input().split())

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

m_list = []
for _ in range(M):
	x, y, c = map(int, input().split())
	m_list.append((x, y, c))

total = min(a_list) + min(b_list)

for x, y, c in m_list:
	pay = a_list[x - 1] + b_list[y - 1] - c
	if pay < total:
		total = pay

print(total)


Measured memory_bytes: 29024
#D問題

#warshall_floyd法
def warshall_floyd(dist):
    #dist[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])
    return dist

##############################

dist = [[float("inf") for i in range(10)] for i in range(10)] 


H,W=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
A=[list(map(int,input().split())) for i in range(H)]

#dist[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(10):
    j=0
    for j in range(10):
        dist[i][j]=c[i][j]

warshall_floyd(dist)
count=0
for h in range(H):
    for w in range(W):
        a=A[h][w]
        if a != -1:
            count+=dist[A[h][w]][1]
print(count)

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long N){
  ll ans=LLONG_MAX;
  for(ll i=1;i*i<=N;i++){
    if(N%i==0){
      ans=min(ans,N/i+i-2);
    }
  }
  op(ans)
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#define ll long long 

using namespace std;

int main(){
	
	ll n;
	cin >> n;
	vector<ll> v(n);

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

	vector<ll> dp(n);

	dp[0] = 0;
	dp[1] = abs(v[0] - v[1]);

	for(int i = 2; i < n; i++){
		dp[i] = min(dp[i-1] + abs(v[i-1] - v[i]), dp[i-2] + abs(v[i-2] - v[i]));
	}

	cout << dp[n-1] << "\n";

	return 0;
}

Measured memory_bytes: 4820
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REP(n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)

int main() {
    int num,a, b, c, d;
    a = b = c = d = 0;
    string s,t;
    cin >> s>> t;
    num = s.length();

    REP(num) {
        if (s[i] != t[i]) {
            s[i] = t[i];
            a++;
        }
    }

    cout << a << endl;
}
 

Measured memory_bytes: 3884
#include <iostream>
#include <vector>

using std::vector;

void fail() {
    std::cout << -1 << std::endl;
    std::exit(0);
}

int main() {
    int n;
    std::cin >> n;
    int m = (1 << n);

    vector<int> a(m);
    for (auto& x : a) std::cin >> x;

    int ans = 0;
    for (int b = 0; b < m; ++b) {
        bool base = true;
        for (int i = 0; i < n; ++i) {
            if (!((b >> i) & 1)) continue;
            if (!a[b] && a[b ^ (1 << i)]) fail();
            if (a[b] && a[b ^ (1 << i)]) base = false;
        }
        if (a[b] && base) ++ans;
    }

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



Measured memory_bytes: 7180
n = int(input())
mount = list(map(int, input().split()))
count =1
for i in range(1,n):
    for j in range(0,i):
        if mount[i] >= mount[j] and j != i-1:
            continue
        elif mount[i] >= mount[j] and j == i-1:
            count+=1
        else:    
            break
print(count)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int n;
	static int[] a;
	static long[] b;
	static long[][] dp;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		b = new long[n + 1];
		for (int i = 1; i <= n; i++) {
			b[i] = b[i - 1] + a[i];
		}

		dp = new long[n + 1][n + 1];
		for (int i = 1; i <= n; i++) {
			Arrays.fill(dp[i], Long.MAX_VALUE);
		}
		System.out.println(dfs(1, n));
	}

	static long dfs(int l, int r) {
		if (dp[l][r] < Long.MAX_VALUE) {
			return dp[l][r];
		}
		if (l == r) {
			return dp[l][r] = 0;
		}

		long sum = b[r] - b[l - 1];
		long ret = Long.MAX_VALUE;
		for (int i = l; i < r; i++) {
			long s1 = dfs(l, i);
			long s2 = dfs(i + 1, r);
			long val = s1 + s2 + sum;
			ret = Math.min(ret, val);
		}
		return dp[l][r] = ret;
	}
}


Measured memory_bytes: 38772
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    vector<i64> A(N);
    i64 S = 0;
    for(auto &x : A) {
        cin >> x;
        S ^= x;
    }
    const int MAX_BIT = 60;
    int j = 0;
    for(int b = MAX_BIT; b >= 0; b--) {
        i64 p = 1ll << b;
        bool reduction = false;
        if (S & p || j < 0) continue;
        for(int i = j; i < N; i++) {
            if(A[i] & p) {
                swap(A[i], A[j]);
                reduction = true;
                break;
            }
        }
        if (!reduction) continue;
        for(int i = 0; i < N; i++) {
            if(i != j && (A[i] & p)) {
                A[i] ^= A[j];
            }
        }
        j++;
    }
    i64 X = 0;
    for(int i = 0; i < N; i++) {
        X ^= A[i];
    }
    i64 ans = X + (S ^ X);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024