akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

ll dp[3005][3005][4];
vector<ll> grid[3005][3005];

int main()
{
	fastInp;

	ll r, c, k;
	cin >> r >> c >> k;

	for (int i = 0; i < k; i++) {
		ll r, c, v;
		cin >> r >> c >> v;
		grid[r][c].push_back(v);
	}

	for (int i = 1; i <= r; i++) {
		for (int j = 1; j <= c; j++) {
			ll curAdd = 0;
			sort(grid[i][j].rbegin(), grid[i][j].rend());
			for (int k = 0; k < 4; k++) {
				curAdd = 0;
				for (int t = 0; t < k; t++) {
					if (t < grid[i][j].size() && grid[i][j][t] > 0) curAdd += grid[i][j][t];
				}

				ll vl = 0;
				if (k > 0) vl = dp[i][j][k - 1];
				dp[i][j][k] = max(dp[i - 1][j][3] + curAdd, vl);
				for (int t = 0; t <= k; t++) {
					curAdd = 0;
					for (int f = 0; f < k - t; f++) {
						if (f < grid[i][j].size() && grid[i][j][f] > 0) curAdd += grid[i][j][f];
					}
					dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][t] + curAdd);
				}
			}
		}
	}

	cout << dp[r][c][3];
	return 0;
}

Measured memory_bytes: 502992
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MOD = 1000000000 + 7;

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

  int n;
  cin >> n;
  long power = 1;
  for(int i = 1; i <= n; i++){
    power = (power * i) % MOD;
  }
  cout << power << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, C;
  cin >> N >> C;
  vector<vector<long long>> D(C, vector<long long>(C, 0));
  rep(i, C) rep(j, C)
  {
    cin >> D[i][j];
  }
  vector<vector<int>> Color(3), c(N, vector<int>(N, 0)), ColorCount(3, vector<int>(C, 0));
  rep(i, N) rep(j, N)
  {
    cin >> c[i][j];
    c[i][j]--;
    ColorCount[(i + j) % 3][c[i][j]]++;
  }
  rep(i, C)
  {
    Color[i % 3].push_back(i);
  }
  long long ans = INT64_MAX;
  rep(i0, C) rep(i1, C) rep(i2, C)
  {
    int C0 = i0;
    int C1 = i1;
    int C2 = i2;
    if (C0 == C1 || C1 == C2 || C2 == C0)
      continue;
    long long cost = 0;
    rep(iC, C)
    {
      long long iCcount0 = ColorCount[0][iC];
      long long iCcount1 = ColorCount[1][iC];
      long long iCcount2 = ColorCount[2][iC];
      cost += D[iC][C0] * iCcount0;
      cost += D[iC][C1] * iCcount1;
      cost += D[iC][C2] * iCcount2;
    }
    ans = min({ans, cost});
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1280
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
ans = "No"

for i in range(n - m + 1):
    for j in range(n - m + 1):
        if a[i][j] == b[0][0]:
            c = []
            for k in range(m):
                c.append(a[i + k][j:j + m])
            if c == b:
                ans = "Yes"
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
  int N,K; cin>>N>>K;
  cout<<max((int)0,(int)(N-2*K))<<endl;
}


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

struct card{
  char suit,value;
};

void bubble (struct card A[],int N){
  int i,j;
  for(i=0;i<N;i++){
    for(j = N-1;j>=i+1;j--){
      if(A[j].value < A[j-1].value){
        card t=A[j-1]; A[j-1] = A[j];A[j] = t;
      }
    }
  }
}

void selection(struct card A[],int N){
  int i,j;
  for(i=0;i<N;i++){
    int minj = i;
    for(j=i;j<N;j++){
      if(A[minj].value > A[j].value)
      minj = j;
    }
    card t = A[minj] ; A[minj] = A[i] ; A[i] = t;
  }
}

bool isStable(struct card C1[],struct card C2[],int N){
  for(int i =0;i<N;i++)
  if(C1[i].suit != C2[i].suit)return false;
  return true;
}

void print(struct card C[],int N){
  for(int i= 0;i<N;i++){
    if(i)cout << " ";
    cout << C[i].suit << C[i].value;
  }
  cout << endl;
}

int main() {
  int N,i;
  card card1[100],card2[100];
  cin >> N;

  for(i=0;i<N;i++){
    cin >> card1[i].suit >> card1[i].value;
  }

  for(i=0;i<N;i++)card2[i]=card1[i];

  bubble(card1,N);
  selection(card2,N);

  print(card1,N);
  cout << "Stable" << endl;
  print(card2,N);
  if(isStable(card1,card2,N)){
    cout << "Stable" << endl;
  }
  else{
    cout << "Not stable" << endl;
  }

  return 0;
}



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll ans = n / 2;
  if (n % 2 != 0) {
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int N;
int A[200000];

int main(void){
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];

	ll res = 0, sum = 0;
	int l = 0, r = 0;
	while(l < N){
		while(r < N and (sum ^ A[r]) == sum + A[r]) sum += A[r++];

		res += r - l;
		sum -= A[l++];
	}

	cout << res << '\n';

	return 0;
}


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

using ll = long long;

int H, W, K;
vector<string> v;
vector<int> mass;
vector<int> massb;
int ans;
int check(){
    int cnt = 00;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(mass[i] == 0 && massb[j] == 0 && v[i][j] == '#'){
                cnt++;
            }
        }
    }
    if(cnt == K)ans++;
    return 0;
}

int zrk(){
    for(int i = 0;i < (1<<H);i++){
        for(int j = 0;j < H;j++){
            mass[j] = i & (1<<j);
        }
        for(int k = 0;k < (1<<W);k++){
            for(int l = 0;l < W;l++){
                massb[l] = k & (1<<l);
            }
            check();
        }
    }
    return 0;
}


int main(){
    cin >> H >> W >> K;
    mass = vector<int>(H);
    massb = vector<int>(W);
    for(int i = 0;i < H;i++){
        string s;cin >> s;
        v.push_back(s);
    }
    zrk();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int  n; cin >> n;
    vector<int>v;
    rep(i,n+1){
        if(i == 0)continue;
        if(i % 3 == 0)v.push_back(i);
        else {
            string s = to_string(i);
            rep(j,s.size()){
                if(s[j] == '3'){v.push_back(i);break;}
            }
        }
    }
    rep(i,v.size()){
        cout << " ";
        cout << v[i];
    }
    cout << endl;
}





Measured memory_bytes: 3312
#include <stdio.h>

int main(void) {
  int l[10];
  while(scanf("%d", &l[0]) != EOF) {
  int sum, v1, v2, vs, now = 0, i, j;
  sum = l[0];
  for(i = 1; i < 10; ++i) {
    scanf(",%d", &l[i]);
    sum += l[i];
  }
  scanf(",%d,%d", &v1, &v2);
  vs = v1 + v2;
  double t = (double)sum / (double)vs;
  //printf("sum%d vs%d t%f\n", sum, vs, t);
  for(i = 0; i <= 10; ++i) {
    if(now >= t * v1) {
      printf("%d\n", i);
      break;
    }
    now += l[i];
  }
  }
  return 0;
}


Measured memory_bytes: 2548
# Setup
import sys
import collections
sys.setrecursionlimit(4100000)

n, k = [int(i) for i in input().split()]
s = input()

ans = 0
lblocks = 0
# if s[0] == "L":
#     lblocks += 1
flag = False
if s[0] == "L":
    flag = True
for i,v in enumerate(s):
    if i == 0:
        continue
    if s[i] == s[i-1]:
        ans += 1
    if s[i] == "L":
        if not flag:
            lblocks += 1
            flag = True
    else:
        flag = False
if lblocks == 0:
    print(n-1)
else:
    if lblocks < k:
        print(n-1)
    else:
        print(ans+k+k)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;cin >> n;
string ans = "";
while(n){
    int k = n%26;
    if(!k){ans += 'z';n--;}
    else ans += char(k+96);
    n = n/26;
}
reverse(ans.begin(),ans.end());
cout << ans;
return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007
#define MAX 100000
//bitset<MAX> bit1, bit2, bit3;
bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________


	int n;
	cin >> n;
	pp a[n];
	pp b[n];
	map<pp, pp>m;
	for (pp i = 1; i <= n; i++)

	{
		pp x;
		cin >> x;
		a[i] = i + x;
		b[i] = i - x;
		m[b[i]]++;
	}
	pp cnt = 0;
	for (pp i = 1; i <= n; i++)
	{
		if (m[a[i]] > 0)
		{
			cnt += m[a[i]];
		}
	}
	cout << cnt << en;

	return 0;

}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll x;
    cin >> x;
    for(ll l = -4000; l<=4000; l++){
        for(ll r = 4000; r>=-4000; r--){
            if((l*l*l*l*l)-(r*r*r*r*r)==x){
                cout << l << " " << r;
                return 0;
            }
        }
    }
    return 0;
}
/*

*/


Measured memory_bytes: 3604
r,c = map(int,input().split())

A = [list(map(int,input().split(" "))) for i in range(r)]
B = []
x = 0
y = 0
for i in range(r):
    for j in range(c):
        x += A[i][j]
    A[i].append(x)
    x = 0

for j in range(c+1):
    for i in range(r):
        y += A[i][j]
    B.append(y)
    y = 0

A.append(B)

for a in A:
    print(*a)



Measured memory_bytes: 6200
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	An := make([]int, N)
	ans := 0
	for i := range An {
		An[i] = nextInt()
	}
	for i := 0; i < N; i++ {
		if An[An[i]-1]-1 == i {
			ans++
		}
	}
	fmt.Println(ans / 2)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 2560
s=[s for s in input()]
k=int(input())
for i,j in enumerate(s):
  if j=='a':continue
  if ord('z')-ord(j)+1<=k:
    s[i]='a'
    k-=ord('z')-ord(j)+1
  if k==0:break
if k>0:s[-1]=chr(k%26+ord(s[-1]))
print(''.join(s))

Measured memory_bytes: 80696
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
    int n;
    
    scanf("%d", &n);
    
    vector<long long> dp(n + 1);
    
    dp[1] = dp[0] = 1;
    
    for(int i = 2; i <= n ;i++)
    {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    
    printf("%lld\n", dp[n]);
    
    return 0;
}

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

const int MOD=1000000007;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
vector<int>v[200000];
int main(){
	Fact fact(200000);
	int n,x,y;scanf("%d%d%d",&n,&x,&y);
	set<int>se;
	rep(i,n){
		int c,w;scanf("%d%d",&c,&w);c--;
		v[c].push_back(w);
		se.insert(c);
	}
	if(se.size()==1){
		puts("1");return 0;
	}
	set<P>S;
	rep(i,n){
		if(v[i].empty())continue;
		sort(v[i].begin(),v[i].end());
		S.insert(P(v[i][0],i));
	}
	vector<P>vs;
	rep(i,n){
		if(v[i].empty())continue;
		while(v[i].size()>1&&v[i].front()+v[i].back()>x
		&&v[i].back()+(S.begin()->second==i?(++S.begin())->first:S.begin()->first)>y){
			v[i].pop_back();
		}
		vs.push_back(P(v[i][0],v[i].size()));
	}
	sort(vs.begin(),vs.end());
	while(vs.size()>1&&vs.front().first+vs.back().first>y)vs.pop_back();
	int cnt=0;
	for(auto p:vs)cnt+=p.second;
	ll ans=fact.get(cnt);
	for(auto p:vs)(ans*=fact.get_inv(p.second))%=MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 30840
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC111C_VVV();

int main()
{
	ABC111C_VVV();
	fflush(stdout);
	return 0;
}

class ABC111C_data {
public:
	int num = 0;
	int cnt = 0;
	static bool dsc_cnt(const ABC111C_data& a, const ABC111C_data& b) {
		return a.cnt > b.cnt;
	}
};

static void ABC111C_VVV()
{
	int N;
	get1int(N);

	std::vector<ABC111C_data> even(100001);
	std::vector<ABC111C_data> odd(100001);

	for (int i = 0; i < N; i++) {
		int v;
		get1int(v);
		if (i % 2) {
			odd[v].num = v;
			odd[v].cnt++;
		}
		else {
			even[v].num = v;
			even[v].cnt++;
		}
	}

	std::sort(even.begin(), even.end(), ABC111C_data::dsc_cnt);
	std::sort(odd.begin(), odd.end(), ABC111C_data::dsc_cnt);

	int ans = 0;
	if (even[0].num == odd[0].num) {
		int tmp1 = N - even[0].cnt - odd[1].cnt;
		int tmp2 = N - odd[0].cnt - even[1].cnt;
		ans = tp_min(tmp1, tmp2);
	}
	else {
		ans = N - even[0].cnt - odd[0].cnt;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
S = [0]*N
S[N-1] = A[N-1]
for i in range(N-2,0,-1):
    S[i] = int((S[i+1] + A[i])%mod)

sum = 0
for i in range(N-1):
    sum += int(A[i]*S[i+1]%mod)
    

sum = int(sum%mod)    
print(sum)

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int R, C, K;
    cin >> R >> C >> K;

    vector< map<int, ll> > a(R);
    for (int i = 0; i < K; i++) {
        int r, c;
        ll v;
        cin >> r >> c >> v;
        --r; --c;
        a[r][c] = v;
    }

    vector< vector<ll> > dp(4, vector<ll>(C, 0));
    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            bool f = (a[i].find(j) != a[i].end());
            {
                ll dp0 = 0, dp1 = 0;
                for (int k = 0; k < 4; k++) {
                    dp0 = max(dp0, dp[k][j]);
                    if (f) dp1 = max(dp1, dp[k][j] + a[i][j]);
                    dp[k][j] = 0;
                }
                dp[0][j] = dp0;
                dp[1][j] = dp1;
            }
            if (j == 0) continue;
            for (int k = 3; k >= 0; --k) {
                dp[k][j] = max(dp[k][j], dp[k][j - 1]);
                if (k > 0 && f) dp[k][j] = max(dp[k][j], dp[k - 1][j - 1] + a[i][j]);
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 4; i++) {
        ans = max(ans, dp[i][C - 1]);
    }
    cout << ans << newl;

    return 0;
}

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

class Dice
{
public:
	int n[6];
	
	void Input()
	{
		cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4] >> n[5];
	}
	
	void Set(int a, int b, int c, int d, int e, int f)
	{
		n[0] = a;
		n[1] = b;
		n[2] = c;
		n[3] = d;
		n[4] = e;
		n[5] = f;
	}
	
	void Roll(char c)
	{
		switch(c)
		{
			case 'N':
				Set(n[1], n[5], n[2], n[3], n[0], n[4]);
				break;
			case 'W':
				Set(n[2], n[1], n[5], n[0], n[4], n[3]);
				break;
			case 'S':
				Set(n[4], n[0], n[2], n[3], n[5], n[1]);
				break;
			case 'E': 
				Set(n[3], n[1], n[0], n[5], n[4], n[2]);
				break;
		};
	}
	
	bool operator==(Dice d)
	{
		for(int i = 0; i < 6; ++i)
		{
			if(n[i] != d.n[i])
			{
				return false;
			}
		}
		
		return true;
	}
	
	bool Equal(Dice d)
	{
		string cmd = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < cmd.length(); ++i)
		{
			d.Roll(cmd[i]);
			if(*this == d)
			{
				return true;
			}
		}
		
		return false;
	}
	
	int Find(int t, int f)
	{
		string cmd = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < cmd.length(); ++i)
		{
			Roll(cmd[i]);
			if(n[0] == t && n[1] == f)
			{
				return n[2];
			}
		}
		
		return 0;
	}
};

int main()
{
	Dice a, b;
	a.Input();
	b.Input();
	
	cout << (a.Equal(b) ? "Yes" : "No") << endl;
	
	return 0;
} 


Measured memory_bytes: 3216
#include <stdio.h>

int main(){

  int n,max,min,i,a;
  long long int sum=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d%",&a);

    if(i==0){ max=a; min=a; }

    if(max<a) max = a;
    if(min>a) min = a;

    sum+=a;
  }

  printf("%d %d %lld\n",min,max,sum);

  return 0;
}


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

public class Program
{

    public void Proc()
    {
        int len = int.Parse(Reader.ReadLine());

        string inpt = Reader.ReadLine();

        int ans = 0;
        for (int i = 1; i < len - 1; i++) {
            string tmp1 = inpt.Substring(0, i);
            string tmp2 = inpt.Substring(i);

            int cnt = tmp1.Where(a => tmp2.Contains(a)).Distinct().Count();
            ans = Math.Max(ans, cnt);
        }
        Console.WriteLine(ans);
        



    }


	public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13280
fn main() {
    // cells[j][i] == a[i] + b[j]
    let c = read_lines(3);
    let mut a = vec![0, 0, 0];
    let mut b = vec![0, 0, 0];

    a[0] = 0;
    b[0] = c[0][0] - a[0];
    b[1] = c[1][0] - a[0];
    b[2] = c[2][0] - a[0];
    a[1] = c[0][1] - b[0];
    a[2] = c[0][2] - b[0];

    for j in 0..3 {
        for i in 0..3 {
            if c[j][i] != a[i] + b[j] {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}

fn read_lines(n: i32) -> Vec<Vec<i32>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap())
            .collect();
        v2.push(v);
    }
    v2
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
    int n,x;cin>>n>>x;
    
    
    if(x == 1 || x == 2*n-1){
        cout<<"No"<<endl;
        return 0;
    }else{
        cout<<"Yes"<<endl;
    }
    
    vint ans(2*n-1);
    rep(i,ans.size()) ans[i]=i+1;
    /// xを1, 2*n-1で挟む
    swap(ans[x-1],ans[n-1]);
    swap(ans[0],ans[n-2]);
    swap(ans.back(),ans[n]);
    rep(i,n*2-1){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 2304
//https://ideone.com/x8zpRc
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)
const int N=100000,M=100000;

int n;
pair<int,int>a[200010];
 main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
//printf("%s, ",name[k[i]].c_str());  printf of string
//priority_queue<ll,vector<ll>,greater<ll>>y;
input;

cin>>n;
forr(i,1,n)
{
    cin>>a[i].S>>a[i].F;
}
sort(a+1,a+1+n);
ll sum=0;
forr(i,1,n)
{
    sum+=a[i].S;
    if(a[i].F<sum)
    {
        cout<<"No";
        return 0;
    }
}

cout<<"Yes";
return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

int main() {
  int K;
  cin >> K;
  int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

  cout << a[K-1] << endl;
};


Measured memory_bytes: 256
#include <stdio.h>

int pre[100005],in[100005],post[100005];
int n,x=0,y=0;

int f(int a){
  int i;
  for(i=0;i<n;i++){
    if(a==in[i])return i;
  }
  return 0;
}

void R(int l, int r){
  int a,m;
  if(l>=r) return;
  a=pre[x];
  x++;
  m=f(a);
  R(l,m);
  R(m+1,r);
  post[y]=a;
  y++;
}

int main(){
  int i;
  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d%",&pre[i]);
  for(i=0;i<n;i++) scanf("%d%",&in[i]);
  R(0,n);
  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    printf("%d",post[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = (b % a == 0) ? a + b : b - a;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll int  
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define fi first
#define se second
#define mp make_pair
int main() {
ll n;
string s;
cin>>s;
n=s.length();
ll res=0,temp=0;
for(ll i=0;i<n;i++)
{
  if(s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G')
  {
temp++;
  }
  else
  {
    res=max(res,temp);
    temp=0;
  }
}
res=max(res,temp);
cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int res = 0;
		for (int i = 0; i < N - 2; i++) {
			if (S.charAt(i) == 'A' && S.charAt(i + 1) == 'B' && S.charAt(i + 2) == 'C') {
				res++;
			}
		}
		System.out.print(res);
	}
}

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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> ps(n+1, 1);
    for(int i=2; i<=n; ++i){
        int t=i;
        for(int j=2; j<=i; ++j){
            while(t%j==0){
                t/=j;
                ++ps[j];
            }
        }
    }
    long long ans=1;
    for(int i=0; i<=n; ++i){
        ans=(long long)ans*(long long)ps[i]%(1000*1000*1000+7);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int c[200010][2];

signed main()
{
    int N,M; cin>>N>>M;
    REP(i,M){
        int a,b; cin>>a>>b;
        if(a==1) c[b][0]=1;
        if(b==N) c[a][1]=1;

    }
    for(int i=2;i<=N-1;i++){
        if(c[i][0] and c[i][1]){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;

}


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

int main() {
	string s;
	cin >> s;
	if (s == "ooo") cout << 1000;
	if (s == "oox") cout << 900;
	if (s == "oxo") cout << 900;
	if (s == "xoo") cout << 900;
	if (s == "oxx") cout << 800;
	if (s == "xox") cout << 800;
	if (s == "xxo") cout << 800;
	if (s == "xxx") cout << 700;
}

Measured memory_bytes: 256
d = {"S":[1,2,3,4,5,6,7,8,9,10,11,12,13],
     "H":[1,2,3,4,5,6,7,8,9,10,11,12,13],
     "C":[1,2,3,4,5,6,7,8,9,10,11,12,13],
     "D":[1,2,3,4,5,6,7,8,9,10,11,12,13]}
n = int(input())
for i in range(n):
    N, M = map(str,input().split())
    d[N][int(M)-1] ="None"

for j in range(len(d)):
    if j==0:
        list_d = d["S"]
        c = "S"
    elif j == 1:
        list_d = d["H"]
        c = "H"
    elif j == 2:
        list_d = d["C"]
        c = "C"
    else:
        list_d = d["D"]
        c = "D"
    for i in range(len(list_d)):
        if(list_d[i] != "None"):
            print(c , list_d[i])


Measured memory_bytes: 5616
#include<stdio.h>
int main(void)
{
  long int a,b,sum;
  sum = 0;
  scanf("%ld",&a);
  scanf("%ld",&b);
  do{
    a = a-b;
    sum++;
  }while(0<a);
  printf("%ld",sum);
  return 0;
}


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

read = sys.stdin.buffer.read

n, *A = map(int, read().split())

now = 1000
for i in range(n-1):
    if A[i+1] > A[i]:
        now += (A[i+1] - A[i])*(now // A[i])
print(now)

Measured memory_bytes: 65600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

int main(){
	int N;cin>>N;
	vl P(N);
	vl Q(N);
	vl K(N);
	rep(i,0,N){
		ll M;cin>>M;
		P[i]=M;
		K[i]=M;
	}
	rep(i,0,N){
		ll M;cin>>M;
		Q[i]=M;
	}
	sort(all(K));
	ll cnt=1;
	ll a,b;
	do{
		bool ok=true;
		rep(i,0,N){
			if(P[i]!=K[i]){
				ok=false;
				break;
			}
		}
		if(ok){
			a=cnt;
			break;
		}
		cnt++;
	}while (n_p(K));
	sort(all(K));
	ll cnts=1;	
	do{
		bool ok=true;
		rep(i,0,N){
			if(Q[i]!=K[i]){
				ok=false;
				break;
			}
		}
		if(ok){
			b=cnts;
			break;
		}
		cnts++;
	}while (n_p(K));
	cout<<max(a,b)-min(a,b);
}

Measured memory_bytes: 256
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd<T>(a: T, b: T) -> T
where
    T: Copy + std::cmp::PartialEq + std::ops::Rem<Output = T> + std::convert::From<u8>,
{
    if b == T::from(0u8) {
        a
    } else {
        gcd(b, a % b)
    }
}

fn lcm<T>(a: T, b: T) -> T
where
    T: Copy
        + std::cmp::PartialEq
        + std::ops::Rem<Output = T>
        + std::ops::Mul<Output = T>
        + std::ops::Div<Output = T>
        + std::convert::From<u8>,
{
    a / gcd(a, b) * b
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    let ans = lcm(a, b);
    println!("{}", ans);
}


Measured memory_bytes: 4352
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,m = MAP()

graph = defaultdict(list)

for _ in range(m):
    u,v = MAP()
    graph[u].append(v)
    graph[v].append(u)

comp = 0
vis = [False]*(n+1)
for i in range(1,n+1):
    if(vis[i]==False):
        comp+=1
        stack = [i]
        while(stack):
            node = stack.pop()
            vis[node] = True
            for adj in graph[node]:
                if(vis[adj]==False):
                    stack.append(adj)



print(comp - 1)

Measured memory_bytes: 94664
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int go(int n,int size,vector<int>&v,vector<int>&memo,int k)
{
    if(n<0)
    {
        return INT_MAX;
    }
    if(n==0)
    {
       return 0;
    }
    if(n==1)
    {
        return abs(v[1]-v[0]);
    }
    if(memo[n]!=-1)
    {
        return memo[n];
    }
    // int m=go(n-1,size,v,memo)+abs(v[n]-v[n-1]);
    // int l=go(n-2,size,v,memo)+abs(v[n]-v[n-2]);
    int output=INT_MAX;
    int dif=n-k;
    for(int j=n-1;j>=dif;j--)
    {
        int m=go(j,size,v,memo,k);
        if(m!=INT_MAX)
        {
         output=min(output,m+abs(v[n]-v[j]));   
        }
        
    }
    return memo[n]=output;
}
main()
{
  int i,j;
  int n;
  cin>>n;
  int k;
  cin>>k;
  vector<int>v;
  for(i=0;i<n;i++)
  {
      int a;
      cin>>a;
      v.push_back(a);
  }
  vector<int>memo;
  for(i=0;i<n;i++)
  {
      memo.push_back(-1);
  }
  cout<<go(n-1,n,v,memo,k);
}

Measured memory_bytes: 12012
[A,B,C] = list(map(int,input().split()))
K = int(input())

cnt=0

while True:
    if A>=B:
        B=B*2
        cnt+=1
    else:
        break

while True:
    if B>=C:
        C=C*2
        cnt+=1
    else:
        break

if cnt<=K:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61624
//-----by LY02------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define M 1000000007
//------------------------------------------------

double a[3000],b[3000];
double dp[3000][3000];

//------------------------------------------------
int main() {
//------------------------------------------------
//	freopen("In.txt","r",stdin);
//	freopen("Out.txt","w",stdout);
//------------------------------------------------
	ios::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------

int n; cin>>n;
for(int i=0;i<n;i++)
{
	cin>>a[i];
	b[i]=1-a[i];
}
dp[0][0]=b[0];
dp[0][1]=a[0];
for(int i=1;i<n;i++)
{
	for(int j=0;j<=i;j++)
	{
		dp[i][j]+=dp[i-1][j]*b[i];
		dp[i][j+1]+=dp[i-1][j]*a[i];
	}
}
double ans=0;
for(int i=n/2+1;i<=n;i++)
{
	ans+=dp[n-1][i];
}
cout<<fixed<<setprecision(10)<<ans<<endl;


//------------------------------------------------
	return 0;
}





//-----by LY02------------------------------------


Measured memory_bytes: 68992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a > b)cout << 0 << endl;
    else if(n==1&&a!=b)cout << 0 << endl;
    else cout << (b * n - b + a) - (a * n - a + b) + 1 << endl;
}

Measured memory_bytes: 3620
/******************************************
* AUTHOR : Muhammed Shakir CK *

* INSTITUTION : Government Engineering College Wayanad *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long


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

string s;
cin >>s;
int count =0;
int i =0;
int j = s.size()-1;
while(i<=j){
	if(s[i]!=s[j]) count ++;
	++i;
	j--;
}
cout << count;
return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string c,d,u;
    int a,b;
    cin >> c >> d;
    cin >> a >> b;
    cin >> u;
    if(c == u){
        cout << a-1 << " " << b;
    }
    else{
        cout << a << " " << b-1;
    }
    return 0;
}



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

#define ll long long int
#define ff first
#define ss second
#define int long long int
#define pb push_back

#define N 500010
#define MOD 1000000007

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

    string s;
    cin >> s;  

    int ans = 0;

    if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5; 
    else if(s == "WED") ans = 4; 
    else if(s == "THU") ans = 3; 
    else if(s == "FRI") ans = 2; 
    else if(s == "SAT") ans = 1; 
    else ans = 7;

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    Deque<Integer> stack = new ArrayDeque<Integer>();
    String out = "";
    while (scanner.hasNext()) {
      int a = scanner.nextInt();
      if (a == 0) {
        out += stack.pop() + "\n";
        continue;
      }
      stack.push(a);
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 15384
import math
n=int(input())
xy=[input().split(" ") for i in range(n)]
#print(xy)
l=0
for i in range(n):
    for j in range(n):
        l+=math.sqrt((int(xy[i][0])-int(xy[j][0]))**2+(int(xy[i][1])-int(xy[j][1]))**2)
        #print(l)
print(l/n)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define ll long long
const int maxm=2e6+5;
int n,x;
int cal(int a,int b){
    if(b%a==0){
        return (b/a*2-1)*a;
    }
    int ans=0;
    ans+=cal(b%a,a);
    ans+=b/a*2*a;
    return ans;
}
signed main(){
    cin>>n>>x;
    int a=x,b=n-x;
    if(a>b)swap(a,b);
    int ans=cal(a,b)+n;//外面两条边的长度=x+(n-x)=n
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3556
n=gets.to_i
c=0
1.upto(n) do |i|
  if i/10==0 then c+=1
  elsif i/100==0 then next
  elsif i/1000==0 then c+=1
  elsif i/10000==0 then next
  elsif i/100000==0 then c+=1
  elsif i/1000000==0 then next
  elsif i==1000000 then c+=1
  end
end
puts c


Measured memory_bytes: 1788
import math
import heapq
N,M=map(int, input().split())
A=list(map(int, input().split())) #N個
for i,item in enumerate(A):
  A[i]=(-1)*item
  
heapq.heapify(A)

for m in range(M):
  tmp1=heapq.heappop(A)
  tmp2=(-1)*(math.floor((-1)*tmp1/2))
  heapq.heappush(A,tmp2)
  
print((-1)*sum(A))

Measured memory_bytes: 14508
//58
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int h,w,n;cin>>h>>w>>n,h|w|n;){
    static int g[1000][1000];
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	cin>>g[y][x];
      }
    }
    static int t[1001][1001];
    fill(t[0],t[1001],0);
    t[0][0]=n-1;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	t[y+1][x]+=t[y][x]/2+(g[y][x]==0&&t[y][x]%2);
	t[y][x+1]+=t[y][x]/2+(g[y][x]==1&&t[y][x]%2);
	g[y][x]^=t[y][x]%2;
      }
    }
    int y=0,x=0;
    while(y!=h&&x!=w){
      (g[y][x]?x:y)++;
    }
    cout<<y+1<<' '<<x+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 8980
N = int(input())

if N == 0:
    print(0)
    exit()

ans = []
x = N

while x != 1:
    if x % 2 == 0:
        ans.append('0')
    else:
        ans.append('1')
        x -= 1
    x /= -2
ans.append('1')

r = "".join(ans[::-1])
print(r)


Measured memory_bytes: 3060
import collections
import copy
N=int(input())
A=list(map(int,(input().split())))
ans=sum(A)
Q=int(input())
col = collections.Counter(A)

for i in range(Q):
  L, R = map(int,(input().split()))
  sa=(R-L)*col[L]
  col[R]+=copy.copy(col[L])
  col[L]=0
  ans= ans+sa
  print(ans)

Measured memory_bytes: 23928