akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
 
long long int n,p,j[65000],psum,j2[65000],money,jsum;
 
int main(){
    while(1){
        psum=0;
        jsum=0;
        cin>>n;
        if(n==0){break;}
        for(int i=0;i<n;i++){
            cin>>p;
            psum+=p;
        }
        for(int i=0;i<n-1;i++){
            cin>>j2[i];
        }
        sort(j2,j2+n-1);
        for(int i=0;i<n-1;i++){j[i]=j2[n-1-1-i];}
        money=psum*n;
        for(int i=0;i<n-1;i++){
            jsum+=j[i];
            if((psum+jsum)*(n-i-1)>money){
                money=(psum+jsum)*(n-i-1);
            }
        }
        cout<<money<<endl;
    }
     
    return 0;

}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int array[2][2];
    int n; cin >> n;
    REPI(i, 2) REPJ(j, 2) array[i][j] = 0;
    REPI(i, n){
        int x; cin >> x;
        if(array[0][0] < x){
            array[0][0] = x;
            array[1][0] = i;
        }else if(array[0][1] < x){
            array[0][1] = x;
            array[1][1] = i;
        }
    }

    REPI(i, n){
        if(i != array[1][0]) cout << array[0][0];
        else cout << array[0][1];
        cout << '\n';
    }
}


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

int main(){
	int x;
	int ans = 1;
	vector<int> v;
        v.push_back(1);
	cin >> x;
	int root = sqrt(x);
	for(int i = 2; i <= root; i++){
		ans = 1;
		while(ans * i <= x){
			ans *= i;
		}
		v.push_back(ans);
	}
	cout << *max_element(v.begin(), v.end()) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void bubble_sort(vector<string> &arr, int num) {
    for (int i = 0; i < num; i++) {
        for (int j = num - 1; j > i; j--) {
            if (arr[j][1] < arr[j - 1][1]) {
                string v = arr[j];
                arr[j] = arr[j - 1];
                arr[j - 1] = v;
            }
        }
    }
}

void selection_sort(vector<string> &arr, int num) {
    for (int i = 0; i < num; i++) {
        int min_j = i;
        for (int j = i; j < num; j++) {
            if (arr[min_j][1] > arr[j][1]) {
                min_j = j;
            }
        }
        if (min_j != i) {
            string v = arr[min_j];
            arr[min_j] = arr[i];
            arr[i] = v;
        }
    }
}

bool is_stable(vector<string> &ori, vector<string> &arr, int num) {
    for (int i = 0; i < num; i++) {
       if (ori[i][0] != arr[i][0]) {
           return false;
       }
    }
    return true;
}

int main() {

    int num;
    cin >> num;

    vector<string> ori(num);
    for (int i = 0; i < num; i++) {
        cin >> ori[i];
    }
    vector<string> arr1(ori);
    vector<string> arr2(ori);

    bubble_sort(arr1, num);
    for (int i = 0; i < num; i++) {
        cout << arr1[i];
        if (i != num - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    cout << "Stable" << endl;

    selection_sort(arr2, num);
    for (int i = 0; i < num; i++) {
        cout << arr2[i];
        if (i != num - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    cout << (is_stable(arr1, arr2, num) ? "Stable" : "Not stable");
    cout << endl;

    return 0;
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,mod=1e9+7;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
int dp[2][55][2510],n,k;

int main(){
    scanf("%d%d",&n,&k);
    dp[0][0][0]=1;
    int x=0;
    /**
    This is the most weird dp problem I've seen so far
    But require some good insight
    dp[i][j][k] is the number of ways to match 
    from 1,..i-th such that there is j elements pending to be matched with i+1 or later
    until it's paired with something it will increase the oddness 1 in each step
    One key is: the number of unmatched left side and right side is equal
    */
    for(int i=1;i<=n;i++){
        x^=1;
        memset(dp[x],0,sizeof(dp[x]));
        for(int j=0;j<=n;j++){
            for(int l=2*j;l<=k;l++){
                plusle(dp[x][j][l],mul(2*j+1,dp[x^1][j][l-2*j]));
                if(j<=n)
                plusle(dp[x][j][l],mul((j+1)*(j+1),dp[x^1][j+1][l-2*j]));
                if(j>0)
                plusle(dp[x][j][l],dp[x^1][j-1][l-2*j]);
            }
        }
    }
    printf("%d\n",dp[x][0][k]);
/*
|i-p[i]|
*/
}
/*
    Good Luck
        -Lucina
*/



Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,m,x;
  cin >> n >> m >> x;

  ll a[n+1]={};
  for(ll i=0;i<m;i++){
    ll b;
    cin >> b;
    a[b]=1;
  }
  ll p=0,q=0;
  for(ll i=x;i<n;i++)if(a[i])p++;
  for(ll i=x;i>=0;i--)if(a[i])q++;
  cout << min(p,q) << endl;

}

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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve()
{
	ll n;
	cin >> n;

	if (n % 1000 == 0)
		cout << 0;
	else

		cout << ( 1000 - n % 1000);

}



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

#ifndef ONLINE_JUDGE
	freopen("1input.txt", "r", stdin);
	freopen("1output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

vector<vi> v(10, vi(10));

int gen(string s)
{
	int res = 0;		
	REP(i, s.size())
	{
		res = v[res][s[i] - '0'];
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> v;
	vs ids;
	REP(i, 10)REP(j, 10)REP(k, 10)REP(l, 10)
	{
		string tmp;
		tmp += to_string(i);
		tmp += to_string(j);
		tmp += to_string(k);
		tmp += to_string(l);
		ids.push_back(tmp);
	}
	int ans = 0;
	for (auto id : ids)
	{
		int cd = gen(id);
		id += char(cd + '0');
		bool f = false;
		REP(i, 5)REP(j, 10)
		{
			string s = id;
			s[i] = j + '0';
			if (s == id) continue;
			int a = gen(s);
			if (a == 0) f = true;
		}
		REP(i, 4)
		{
			string s = id;
			swap(s[i], s[i + 1]);
			if (s == id) continue;
			int a = gen(s);
			if (a == 0) f = true;
		}
		if (f) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3784
/*
 * AGC024_B.cpp
 *
 *  Created on: May 20, 2018
 *      Author: 13743
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int p[200001];
int rev[200010];
int memo[200010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	REP(i, N) {
		cin >> p[i];
		rev[p[i]] = i;
	}

	memo[N] = 1;
	FORD(i, N-1, 1) {
		if(rev[i+1] < rev[i]) {
			memo[i] = 1;
		}
		else {
			memo[i] = memo[i+1]+1;
		}
	}

	int maxS = 0;
	FOR(i, 1, N) {
		maxS = max(maxS, memo[i]);
	}

	cout << N-maxS << endl;
}






Measured memory_bytes: 2560
/*
   Author : tarang
*/
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
int a[106];
int main(){
	fastio ;
    ll n ; cin >> n ;
    vector<ll> v(n);
    map<ll ,ll> mp;
    ll sum = 0 ;
    for(ll i =  0 ; i < n ; i++){
    	  cin >> v[i];
    	  mp[v[i]]++;
    	  sum += v[i];
	}
	ll q ; cin >> q ;
	while(q--){
		ll a,b;
		cin >> a >> b ;
		ll z = mp[a];
		mp[a] = 0 ;
		mp[b] += z ;
		ll ans = (sum - a*z + b*z);
		sum = ans ;
		cout << ans << endl;
	}
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;
string s;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  cin >> s;

  int cnt = 0;
  int min_left = 100 + 5;

  for (int i = 0; i < s.size(); ++i) {
    cnt += (s[i] == '(') ? 1 : -1;
    min_left = min(min_left, cnt);
  }

  if (min_left < 0) {
    for (int i = 0; i < (-1) * min_left; ++i) {
      s.insert(0, "(");
    }
  }

  cnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    cnt += (s[i] == '(') ? 1 : -1;
  }

  for (int i = 0; i < cnt; ++i) {
    s.push_back(')');
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			double pi = Math.Atan(1) * 4;
			double r = double.Parse(Console.ReadLine());
			double surface = pi * r * r;
			double shu = 2 * pi * r;
			Console.WriteLine("{0} {1}", surface.ToString("F10"), shu.ToString("F10"));
		}
	}
}

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

signed main(){
	string S; cin>>S;
	int ans;
	while(S.size()>0){
		S.erase(S.end()-1);
		if(S.size()%2==0){
			int N=S.size()/2;
			string fir=S.substr(0,N);
			string sec=S.substr(N,N);
			if(fir==sec){
				ans=S.size();
				break;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

string s;

struct node{
    int step;
    int cst;
    int lr;
    bool operator<(const node &o) const{
	return cst > o.cst;
    }
};
bool done[100005][2];
int main()
{
    while(cin >> s, s != "#") {
	vector<int> v;
	rep(i, s.size()) v.pb(s[i]-'0'-1);
	priority_queue<node> pq;
	pq.push((node){0, 0, 0});
	pq.push((node){0, 0, 1});
	memset(done, 0, sizeof(done));
	int ans = 10000000;
	while(!pq.empty()) {
	    int step = pq.top().step;
	    int cst = pq.top().cst;
	    int lr = pq.top().lr;
	    pq.pop();
	    if(done[step][lr]) continue;
	    done[step][lr] = true;
	    if(step == s.size()-1) {
		ans = min(ans, cst);
		continue;
	    }
	    if(v[step]%3 < v[step+1]%3) {
		if(lr == 1) pq.push((node){step+1, cst+1 ,1});
		else pq.push((node){step+1, cst ,1});
	    } else if(v[step]%3 > v[step+1]%3) {
		if(lr == 0) pq.push((node){step+1, cst+1 ,0});
		else pq.push((node){step+1, cst ,0});
	    } else {
		if(lr == 0) {
		    pq.push((node){step+1, cst+1 ,0});
		    pq.push((node){step+1, cst ,1});
		} else {
		    pq.push((node){step+1, cst ,0});
		    pq.push((node){step+1, cst+1 ,1});
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2280
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    vector<vector<int>> indices(n + 1);
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        indices[a].push_back(i);
    }
    int x = 0;
    int i = 1;
    while (i <= n) {
        auto it = lower_bound(indices[i].begin(), indices[i].end(), x);
        if (it == indices[i].end()) break;

        x = *it + 1;
        ++i;
    }
    
    if (i == 1) cout << -1 << endl;
    else cout << n - i + 1 << endl;
    return 0;
}

Measured memory_bytes: 11136
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	c := getNextInt(scanner)
	x := getNextInt(scanner)
	y := getNextInt(scanner)

	var ans int
	ans = math.MaxInt32
	for i := 0; i <= maxint(x, y)<<1; i += 2 {
		sum := c*i + maxint(0, (x-(i>>1))*a) + maxint(0, (y-(i>>1))*b)
		if ans > sum {
			ans = sum
		}
	}
	fmt.Fprintln(writer, ans)
}

func maxint(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
  int64_t A;
  string B;
  cin>>A>>B;
  int c=(B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0');
  cout<<A*c/100<<endl;

  return 0;}

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

int main(){
    int N,K; cin >> N >> K;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    
    //等差数列の方程式
    auto f=[&](int x){//xは項数
        return 1+(x-1)*(K-1);
    };
    
    int ans=0;
    int x=1;//初項
    while(1){
        if(f(x)>=N) break;//末項超えたら終了
        ans++;
        x++;
    }
    cout << ans;
}

Measured memory_bytes: 640
#include <iostream>

int main()
{

    int a, b;
    int cunt[20000];
    char c;
    int x = 0;

    while (1){
        std::cin >> a >> c >> b;

    if(c == '+'){
        cunt[x] = a + b;
    }else if (c == '-'){
        cunt[x] = a - b;
    }else if (c == '*'){
        cunt[x] = a * b;
    }else if (c == '/'){
        cunt[x] = a / b;
    }else if (c == '?'){
        break;
    }
    ++x;

    }

    for (int i = 0 ; i < x; ++i){
        std::cout << cunt[i] << "\n";
    }



    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 100003

using namespace std;

int main() {
	int n;
	sfd(n);
 	vector<double> value;
 	double v;
	for( int i=0; i<n; i++ ) {
		sflf(v);
		value.push_back(v);
	}
	sort(value.begin(), value.end());
	v = value[0];
	for( int i=1; i<n; i++ ) {
		v = (v+value[i])/2;
	}
	pf("%.5lf", v);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

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

enum Status {
    Not = 0,
    Now,
    End,
};

template<typename T>
struct Edge {
    int to;
    int from;
    T weight;
    Edge(int from, int to, T weight) : from(from), to(to), weight(weight) {}
};

template<typename T, typename D>
struct Graph {
    int n;
    vector<vector<Edge<T>>> g;
    vector<D> data;
    vector<Status> s;
    
    Graph(int N) : n(N), g(N+1), data(N+1), s(N+1) {}
    
    void add_edge(int from, Edge<T> e) {
        g[from].push_back(e);
    }
    void set_data(int node, D value) {
        data[node] = value;
    }
    
    //あるノードに到達できるか
    //逆方向はグラフ自体逆で構成することで可能
    vector<bool> can_reach_from(int start, vector<bool> &reached) {
        //vector<bool> reached(n+1, false);
        dfs_reach_from(start, reached);
        return reached;
    }
    void dfs_reach_from(int now, vector<bool> &reached) {
        if (reached[now]) return;
        reached[now] = true;
        for (auto e: g[now]) {
            dfs_reach_from(e.to, reached);
        }
    }
    
    //出力
    void print() {
        for (auto v: g) {
            for (auto e: v) {
                std::cout << e.from << "-(" << e.weight << ")->" << e.to << ", ";
            }
            std::cout << std::endl;
        }
    }
};

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

int main() {
    
    int N, M;
    cin >> N >> M;
    Graph<ll, ll> g(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        g.add_edge(x, Edge<ll>(x, y, 1));
        g.add_edge(y, Edge<ll>(y, x, 1));
    }
    vector<bool> reached(N+1);
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (reached[i] == false) {
            ans++;
            auto res = g.can_reach_from(i, reached);
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 10880
INF = 10**11


def binary_search(array, value):
    start = 0
    end = len(array) - 1
    while end - start >= 2:
        tmp = (start + end) // 2
        # print(start, end, tmp)
        if array[tmp] <= value:
            start = tmp
        else:
            end = tmp
        # print(start, end, tmp)
    return start


A, B, Q = map(int, input().split())
s_array = [int(input()) if i != 0 else -INF for i in range(A + 1)]
s_array.append(INF)
t_array = [int(input()) if i != 0 else -INF for i in range(B + 1)]
t_array.append(INF)
q_array = [int(input()) for i in range(Q)]

# print(s_array, t_array, q_array)

ans_array = []
for q in q_array:
    s_index = binary_search(s_array, q)
    t_index = binary_search(t_array, q)
    method_a = q - min(s_array[s_index], t_array[t_index])
    method_b = max(s_array[s_index + 1], t_array[t_index + 1]) - q
    method_c = (q - s_array[s_index]) + (t_array[t_index + 1] - q) + min(
        (q - s_array[s_index]), (t_array[t_index + 1] - q))
    method_d = (q - t_array[t_index]) + (s_array[s_index + 1] - q) + min(
        (q - t_array[t_index]), (s_array[s_index + 1] - q))
    ans_array.append(min(method_a, method_b, method_c, method_d))

for ans in ans_array:
    print(ans)

Measured memory_bytes: 20340
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
const ll mod = 1e9 + 7;
#define REP(i, o, n) for (ll i = o; i < n; i++)
#define rep(i, n) REP(i, 0, n)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(b, a % b) * b; }

void actual() {
    // Resolve the problem.
    ll n, k, q;
    cin >> n >> k >> q;
    vector <ll> ps(n);
    rep(i, ps.size()) {
        ps[i] = k - q;
    }
    int w;
    rep(i, q) {
        cin >> w;
        ps[w - 1] += 1;
    }

    rep(i, ps.size()) {
        if (ps[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    actual();
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define maxn 100000+5
#define P 998244353
#define pi  3.1415926535
#define eps 0.00000001
#define pb  push_back
#define mkp make_pair
#define fi first
#define se second
#define pii  pair<int,int>
#define mii  map<int,int>
#define vi  vector<int>
#define dbg(i)  cout<<i<<endl;
#define Max(a,b) (((a)>(b))?(a):(b))
#define Min(a,b) (((a)<(b))?(a):(b))
#define me(a,b) memset(a,b,sizeof(a))
using ll=long long;
using ull=unsigned long long;
using namespace std;
inline void up(int&x,int y){x=x+y<P?x+y:x+y-P;}
inline char emm(int q,int w){return q==w?'\n':' ';}
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int niyuan[1000000];
void ni()
{
    niyuan[1]=1;
    for (int i=2;i<300001;i++) niyuan[i]=ll(P-P/i)*niyuan[P%i]%P;
}
ll n,a,b,k,ans,c[1000000],d[1000000];
int main()
{
    //freopen("stdin.txt","r",stdin);
    //freopen("1.txt","w",stdout);
    //clock_t time=clock();
    //srand(time(0));
    cin>>n>>a>>b>>k;ni();c[n]=n;d[1]=d[0]=c[n+1]=1;
    for (int i=2;i<=n;i++)
        d[i]=d[i-1]*niyuan[i]%P;
    for (int i=n-1;i;i--)
        c[i]=c[i+1]*i%P;
    for (int i=0;i<=n;i++)
        if (k-i*a>=0&&(k-i*a)%b==0&&(k-i*a)/b<=n)
            ans=(ans+c[n-i+1]*d[i]%P*c[n+1-(k-i*a)/b]%P*d[(k-i*a)/b]%P)%P;
    cout<<ans;
    //printf("程序运行的时间为%f\n",(double)(clock()-time)/CLOCKS_PER_SEC);
    //fclose(stdin);fclose(stdout);
    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// UnionFind 解説：https://youtu.be/TdR816rqc3s?t=8424
struct UnionFind {
	vi d;
	UnionFind(int n = 0) : d(n, -1) {}

	int find(int x) {
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);

		if (x == y) return false;

		if (d[x] > d[x]) swap(d[x], d[x]);
		d[x] += d[y];
		d[y] = x;
		return true;
	}

	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d[find(x)]; }
};

// ──────────────────────────────────────────────────────────────────

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

	vl x(n), y(n);

	rep(i, n) cin >> x[i] >> y[i];

	using pint = pair<int, int>;
	using Edge = pair<ll, pint>;
	vector<Edge> edges;

	vi ids(n);
	iota(ASC(ids), 0);
	sort(ASC(ids), [&](int i, int j) {return x[i] < x[j]; });
	for (int i = 0; i + 1 < ids.size(); ++i) {
		int u = ids[i], v = ids[i + 1];
		edges.push_back(Edge(x[v] - x[u], pint(u, v)));
	}

	sort(ASC(ids), [&](int i, int j) {return y[i] < y[j]; });
	for (int i = 0; i + 1 < ids.size(); ++i) {
		int u = ids[i], v = ids[i + 1];
		edges.push_back(Edge(y[v] - y[u], pint(u, v)));
	}

	sort(ASC(edges));

	UnionFind uf(n);
	ll res = 0;
	for (auto e : edges) {
		int u = e.second.first, v = e.second.second;
		ll cost = e.first;
		if (uf.same(u, v)) continue;
		uf.unite(u, v);
		res += cost;
	}
	cout << res << endl;
}

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

int main() {
	char c; cin >> c;
	if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'o' || c == 'u') {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
}


Measured memory_bytes: 256
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, A, B, C = in_nn()
    l = list(map(int, read().rstrip().split()))

    comb = list(itertools.product(range(4), repeat=N))
    abc_p = list(itertools.permutations([A, B, C], 3))

    ans = 10**9 + 7
    for abc in abc_p:
        for c in comb:
            if (0 in c) and (1 in c) and (2 in c):
                t = [0] * 3
                m = [-10] * 3
                for i in range(N):
                    if c[i] == 3:
                        continue
                    t[c[i]] += l[i]
                    m[c[i]] += 10

                for i in range(3):
                    m[i] += abs(t[i] - abc[i])

                ans = min(ans, sum(m))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13044
#include<iostream>
using namespace std;
#include<queue>
#include<cstdio>
#include<map>
#include<set> 
typedef long long LL;
LL ans[100];
int main()
{
	LL k;
	while(cin>>k)
	{
		for (int i=1;i<=50;i++)  ans[i]=k/50+i-1;
		k=k%50;
		for(int i=1;i<=k;i++)
    	{
        for(int j=1;j<=50;j++)
        {
            ans[j]--;
        }
        ans[i]+=51;
   		 }
    printf("50\n");
    for(int i=1;i<=50;i++)
    {
        if(i!=1) printf(" ");
        printf("%lld",ans[i]);
    }
    cout<<endl;
    return 0;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(M)]

    AB = [list(map(lambda x: x - 1, ab)) for ab in AB]

    ma = [0] * N
    for key, ab in enumerate(AB):
        a = ab[0]
        b = ab[1]
        ma[a] = max(ma[a], H[b])
        ma[b] = max(ma[b], H[a])
    ans = 0
    for h, ma_ in zip(H, ma):
        if h > ma_:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 49380
#include <bits/stdc++.h>
#define ll long long
#define FASTIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mo 1000000007
using namespace std;
int main(){
	FASTIO
	string str;
	cin>>str;
	bool flag = true;
	for(int i=0;i<str.size();i++){
		if(str[i]=='L'){
			if(!(i&1)){
				flag=false;
			}
		}else if(str[i]=='R'){
			if(i&1){
				flag=false;
			}
		}
	}
	if(flag){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[1001][1001];
ll   dp[1001][1001];

int main(int argc, char* argv[])
{
    int h,w;
    scanf("%d%d", &h, &w);
    int i,j;
    for(i=0; i<h; i++) {
        scanf("%s", str[i]);
    }

    dp[0][0]=1;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(i==0 && j==0) continue;
            dp[i][j]=0;
            if(str[i][j]!='#') {
                if(i>0) dp[i][j] = (dp[i][j] + dp[i-1][j])%MOD;
                if(j>0) dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
            }
        }
    }
    printf("%lld\n", dp[h-1][w-1]);

    return 0;
}


Measured memory_bytes: 8960
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/

void build(){

}
int n , k;
map<int,int> M;
void init(){
  cin >> n >> k;
  while( n -- )
    M[ getint() ] ++;
}
void solve(){
  vector<int> v;
  for( auto i : M )
    v.push_back( i.second );
  sort( v.begin() , v.end() );
  reverse( v.begin() , v.end() );
  int ans = 0;
  for( size_t i = k ; i < v.size() ; i ++ )
    ans += v[ i ];
  cout << ans << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 10748
#include<stdio.h>
#include<stdlib.h>

struct abc{
		int fr;
		int to;
		int c;
};

int compare_int(const void *a,const void *b){
		struct abc A=*(struct abc*)a;
		struct abc B=*(struct abc*)b;
		return A.fr-B.fr;
}

long long ans[200000];
struct abc ab[400000];
int list[200000],m;
int f[200000]={0};

int dfs(int now,int co){
		int i;
		for(i=list[now];i<list[now+1];i++){
				if(f[ab[i].to]==0){
						f[ab[i].to]=1;
						ans[ab[i].to]+=co;
						dfs(ab[i].to,ans[ab[i].to]);
				}
		}return 0;
}

int main(){
		int n,q,i,j;
		scanf("%d%d",&n,&q);m=2*n-2;
		for(i=0;i<n-1;i++){
				int a,b;
				scanf("%d%d",&a,&b);
				a--,b--;
				ab[i*2].fr=a;
				ab[i*2].to=b;
				ab[i*2].c=0;
				ab[i*2+1].fr=b;
				ab[i*2+1].to=a;
				ab[i*2+1].c=0;
		}
		for(i=0;i<q;i++){
				int x,p;
				scanf("%d%d",&p,&x);
				p--;
				ans[p]+=x;
		}
		qsort(ab,m,sizeof(struct abc),compare_int);
		list[0]=0;
		list[n]=m;
		for(i=1;i<m;i++){
				if(ab[i-1].fr!=ab[i].fr){
						list[ab[i].fr]=i;
				}
		}
		f[0]=1;
		dfs(0,ans[0]);
		for(i=0;i<n;i++)printf("%lld ",ans[i]);
		puts("");
		return 0;
}


Measured memory_bytes: 16428
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String S = sc.next();
		int fh = Integer.parseInt(S.substring(0, 2));
		int lh = Integer.parseInt(S.substring(2));
		String ans = null;
		if ((fh >= 13 || fh == 0) && (lh >= 13 || lh == 0)) {
			ans = "NA";
		} else if ((fh < 13 && fh != 0) && (lh < 13 && lh != 0)) {
			ans = "AMBIGUOUS";
		} else if (fh < 13 && fh != 0) {
			ans = "MMYY";
		} else {
			ans = "YYMM";
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define deb(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<double>p(n+1);
    for(int i=1;i<=n;i++)
        cin>>p[i];
    
    double dp[n+1][n+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(j>i)
                dp[i][j]=0;
            else if(i==0 && j==0)
                dp[0][0]=1;
            else if(j==0)
                dp[i][0]=(dp[i-1][0])*(1-p[i]);
            else
                dp[i][j]=(1-p[i])*dp[i-1][j] + p[i]*dp[i-1][j-1];
            
            // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[n][i];

    cout<<fixed<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 74044
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define ll 				long long
#define int             long long int
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define modp            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }


void solve()
{
	int h, w, k;
	cin >> h >> w >> k;
	char c[h][w];
	int total = 0;
	int row[h] = {}, col[w] = {};
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cin >> c[i][j];
			if(c[i][j] == '#')
			{
				row[i]++;
				col[j]++;
				total++;
			}
		}
	}
	int cnt = 0;
	int curr = 0, curr1, curr2;
	vector<int> rr;
	vector<int> cc;
	for(int i = 0; i < (int)pow(2, h); i++)
	{
		curr = 0;
		curr1 = 0;
		rr.clear();
		for(int j = 0; j < h; j++)
		{
			if ((i & (1 << j)) != 0) 
			{
				curr1 += row[j];
				rr.push_back(j);
			}
		}
		for(int j = 0; j < (int)pow(2, w); j++)
		{
			cc.clear();
			curr2 = 0;
			for(int k = 0; k < w; k++)
			{
				if ((j & (1 << k)) != 0) 
				{
					curr2 += col[k];
					cc.push_back(k);
				}
			}
			int x = rr.size();
			int y = cc.size();
			curr = curr1+curr2;
			for(int l = 0; l < x; l++)
			{
				for(int m = 0; m < y; m++)
					if(c[rr[l]][cc[m]] == '#')
						curr--;
			}
			if((total-curr) == k)
			{
				cnt++;
			}

		}
	}
	cout << cnt;	

}
 
int32_t main()
{
	FIO
    //aks();
    // w(t)
    {
    	solve();
    }	
    return 0;
}
	

	

Measured memory_bytes: 4064
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
  int A;
  cin >> A;
  if(A < 1200){
    cout << "ABC" << endl;
  }
  else if(A < 2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
from math import factorial

N,M=map(int,input().split())
MOD = 10**9 + 7

if abs(N-M) >= 2:
  print(0)
  exit()

print(2*factorial(N)*factorial(M)%MOD if abs(N-M) == 0 else factorial(N)*factorial(M)%MOD)

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

class Point {
  public:
    double x;
    double y;
    
    Point(double x1 = 0, double y1 = 0) {
      x = x1;
      y = y1;
    }

};

Point middle(Point p1, Point p2) {
  Point p(p1.x, p1.y);
  double theta = M_PI/3;
  p.x += cos(theta)*(p2.x-p1.x)-sin(theta)*(p2.y-p1.y);
  p.y += sin(theta)*(p2.x-p1.x)+cos(theta)*(p2.y-p1.y);
  return p; 
}

Point left(Point p1, Point p2) {
  Point p(p1.x, p1.y);
  p.x += (p2.x - p1.x)/3;
  p.y += (p2.y - p1.y)/3;
  return p;
}

Point right(Point p1, Point p2) {
  Point p(p1.x, p1.y);
  p.x += (p2.x - p1.x)*2/3;
  p.y += (p2.y - p1.y)*2/3;
  return p;
}

void Print(Point p) {
  cout << fixed << p.x << " " << p.y << endl;
}

void solve(int n, Point p1, Point p2) {
  if (n == 0) return;
  n--;
  Point s = left(p1, p2);
  Point t = right(p1, p2);
  Point u = middle(s, t);
  solve(n, p1, s);
  Print(s);
  solve(n, s, u);
  Print(u);
  solve(n, u, t);
  Print(t);
  solve(n, t, p2);
}

int main() {
  int n;
  cin >> n;
  Point p1(0, 0), p2(100, 0);
  Print(p1);
  solve(n, p1, p2);
  Print(p2);
}




Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <stack>
#include <unordered_set>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 3e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n, m;

int main() {
    int i, j;
    ll a, b;
    cin >> a >> b;
    ll c = b / a;
    i = 0;
    while (c) {
        c >>= 1;
        ++i;
    }
    cout << i << endl;
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length();
	int ans = 0;

	int i = 0, j = n-1;
	while(i < j) {
		ans += s[i++] != s[j--];
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

void solve() {
  ll n, k;
  cin >> n >> k;
  ll ret = n;
  for(int a = 1; a <= 1000000; a++) {
    ll curr = 2;
    while(curr <= 1e6) {
      ll p = 1;
      bool bad = false;
      for(int i = 0; i < a; i++) {
        p *= curr;
        if(p > n) bad = true;
      }
      if(bad) break;
      ret = min(ret, (n+p-1)/p + a*curr + a*k);
      for(int i = 0; i < a; i++) {
        p /= curr;
        p *= curr + 1;
        ret = min(ret, (n+p-1)/p + (a*curr+i+1) + a*k);
        if(p > n) bad = true;
      }
      if(bad) break;
      curr++;
    }
    if(curr == 2) break;
  }
  cout << ret << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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

using namespace std;

const int maxN = 1e5+5;
const int INF = 1e9;

int A[maxN], DP[maxN];

void solve() {
    int n, k; cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        DP[i] = INF;
    }
    DP[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(i - j < 0) break;
            DP[i] = min(DP[i], abs(A[i]-A[i-j])+DP[i-j]);
        }
    }
    cout << DP[n-1] << "\n";

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    bool multitest = false;
    //multitest = true;
    if (multitest) {
        int t; cin >> t;
        while (t--)
            solve();
    }
    else
        solve();
}


Measured memory_bytes: 4316
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,A[100001],K,mo=0;
  cin >> N >> K;
  REP(i,N)cin >> A[i];
  sort(A,A+N);
  REP(i,N){
    if(A[i] == K){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  if(N == 1){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  mo = A[0];
  REP(i,N-1){
    mo = __gcd(mo,A[i+1]);
  }
  if(A[N-1] >= K && K%mo==0){
    cout << "POSSIBLE" << endl;
  }else
    cout << "IMPOSSIBLE" << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 1024