akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long 
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define N ((ll)(2e6+100))
#define MAX ((ll)(1e16+100))
#define ARRS ((ll)(3e5+100))
#define MOD ((ll)(1e9+7))
#define M1 ((ll)(1001783))
#define M2 ((ll)(1001941))
#define M3 ((ll)(1002073))
#define pb push_back

ll dp[ARRS];
ll f[ARRS];
ll c[ARRS];


ll go(ll x){
	if(x&1)x^=1;
	if(!x)return 0;
	if(dp[x])return dp[x];
	ll a[18];
	ll b[18];
	for(int i=0; i<16; i++)a[i]=(x>>i)&1;
	dp[x]=MAX;
	for(int i=1; i<16; i++){
		for(int j=i+1; j<16; j++){
			if(a[i]&&a[j]){
				for(int t=1; t<16; t++){
					for(int i=0; i<16; i++)b[i]=a[i];
					b[i]--;
					b[j]--;
					b[i^t]++;
					b[j^t]++;
					ll k=0;
					ll r=0;
					for(int i=0; i<16; i++){
						if(i)
						k+=b[i]/2;
						b[i]&=1;
						r=r|(b[i]<<i);
					}
					//cout<<bitset<16>(x)<<endl;
					//cout<<i<<" "<<j<<" "<<t<<" "<<k<<endl;
					//cout<<bitset<16>(r)<<endl;
					//cout<<endl;
					if(x==r)continue;
					dp[x]=min(dp[x],go(r)+k+1);
				}
			}
		}
	}
	return dp[x];
}


int main(){

	ll n;
	cin>>n;
	for(int i=0; i<n-1; i++){
		ll k,p,c;
		cin>>k>>p>>c;
		f[k]^=c;
		f[p]^=c;
	}
	for(int i=0; i<n; i++)
		c[f[i]]++;

	ll t=0;
	ll pas=0;
	for(int i=0; i<16; i++){
		if(i)
		pas+=c[i]/2;
		c[i]&=1;
		t=t|(c[i]<<(i));
	}

	pas+=go(t);

	cout<<pas;
}


Measured memory_bytes: 4608
def prime_factor(n):#素因数分解
    factors = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0:
            factors.append(i)
            n = n//i
    if n!=1:
        factors.append(n)
    return factors

N = int(input())
P = [0]*(N+1)
ans = 1
mod = 10**9+7
for i in range(2,N+1):
    a = prime_factor(i)#iについて素因数分解でリストが帰ってくる
    for j in a:
        P[j] += 1#各素数の数がカウントされる 10であれば2*5なのでp[1]とp[4]に加算される
for k in P:
    ans = ans*(k+1)%mod
print(ans)

Measured memory_bytes: 3064
S = list(str(input()))
T = str(input())
s = len(S)
ss = " "
for x in S:
  ss+=x
flag = 0
for i in range(s):
  if ss == T:
    print("Yes")
    flag = 1
    break
  else:
    j = s-1
    while j > 0:
      S[j] , S[j-1] = S[j-1] , S[j]
      j-=1
    st =""
    for y in S:
      st+=y
    if st == T:
      print("Yes")
      flag = 1
      break
if flag == 0:
  print("No")    
   


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	char str[256];
	while(scanf("%s", str) != EOF){
		int dp[128] = {0};
		bool increasing = true;
		int num = 0;
		do{
			int tmp[128];
			int tmp_size = 0;

			sscanf(str, "%d,", &tmp[0]);
			++tmp_size;
			rep(i, strlen(str)){
				if(str[i] == ','){
					sscanf(str+i+1, "%d,", &tmp[tmp_size]);
					++tmp_size;
				}
			}

			if(tmp_size < num)
				increasing = false;
			num = tmp_size;

			rep(i, num){
				if(increasing)
					tmp[i] += max(dp[i], i ? dp[i-1] : 0);
				else
					tmp[i] += max(dp[i], dp[i+1]);
			}

			rep(i, num){
				dp[i] = tmp[i];
			}
			if(!increasing && num == 1)
				break;
		}while(scanf("%s", str) != EOF);
		printf("%d\n", dp[0]);
	}
	return 0;
}

Measured memory_bytes: 0
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const ll bound = 1e18;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding

	ll n;
	cin>>n;
	ll a[n];
	bool zero = false;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0)zero= true;
	}

	if(zero){
		cout<<0<<endl;
		return 0;
	}
	ll x = 1;
	bool f = false;
	for(int i=0;i<n;i++){
		if(x>bound/a[i]){
			f=  true;
		}
		x*=a[i];
	}
	if(f){
		cout<<-1<<endl;
	}else{
		cout<<x<<endl;
	}

	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 4400
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func checkVertical(s [][]byte, i int) bool {
	return s[0][i] == s[1][i]
}

func main() {
	defer stdout.Flush()

	n := readInt()
	s := make([][]byte, 2)
	s[0] = []byte(readString())
	s[1] = []byte(readString())

	var ans int
	var prevVertical bool
	p := 1000000007
	i := 0
	if checkVertical(s, i) {
		ans = 3
		i++
		prevVertical = true
	} else {
		ans = 6
		i += 2
		prevVertical = false
	}
	for i < n {
		curVertical := checkVertical(s, i)
		if prevVertical {
			ans = ans * 2 % p
		} else {
			if !curVertical {
				ans = ans * 3 % p
			}
		}

		if curVertical {
			i++
		} else {
			i += 2
		}
		prevVertical = curVertical
	}

	println(ans)
}


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

int main()
{
    int n, k, tmp;
    string s;
    while(cin >> n >> k >> s)
    {
        tmp = 0;
        for(int i = 1; i != n; ++i)
        {
            tmp += (s[i] != s[i - 1]);
        }
        cout << n - 1  - max(0, tmp - 2 * k);
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  string s; cin >> s;
  cout << "2018" + s.substr(4) << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < n - 2; ++i) {
		string cur = s.substr(i, 3);
		cnt += cur == "ABC";
	}
	cout << cnt;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

int N;
vi x[16], y[16];
void input(){
	cin>>N;
	rep(i, N){
		int A;
		cin>>A;
		rep(_, A){
			int xt, yt;
			cin>>xt>>yt;
			x[i].pb(xt-1);
			y[i].pb(yt);
		}
	}
}

void solve(){
	int ans=0;
	rep(bit, 1<<N){
		vi st(N);
		rep(i, N)st[i]=(bit>>i)& 1;
		bool allok=true;
		int ct=0;
		rep(i, N){
			if(st[i]==0)continue;
			else{
				ct++;
				rep(j, sz(x[i]))if(st[x[i][j]]!=y[i][j])allok=false;
			}
		}
		if(allok){
          ans=max(ans, ct);
        }
	}
	cout<<ans<<endl;

}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

inline ll sol(ll s, ll t, ll x){
	ll ret = LLONG_MAX;
	SML(ret, abs(x-s)+abs(s-t));
	SML(ret, abs(x-t)+abs(t-s));
	return ret;
}

#define N 100'005
ll *s=new ll[N], *t=new ll[N], *x=new ll[N];

int main(){
	int a, b, q; scanf("%d%d%d", &a, &b, &q);
	s[0]=t[0]=-100'000'000'000;
	s++; t++;
	REP(i, a) scanf("%lld", s+i);
	REP(i, b) scanf("%lld", t+i);
	REP(i, q) scanf("%lld", x+i);
	s[a]=t[b]=+100'000'000'000;
	REP(i, q){
		ll *f=lower_bound(s, s+a, x[i]);
		ll *g=lower_bound(t, t+b, x[i]);
		ll ans=LLONG_MAX;
		SML(ans, sol(*f, *g, x[i]));
		SML(ans, sol(*f, *(g-1), x[i]));
		SML(ans, sol(*(f-1), *g, x[i]));
		SML(ans, sol(*(f-1), *(g-1), x[i]));
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 3712
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;


int main()   {
    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, 1000);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n);
        vector<ll> a;
        forr(i,0,n) {
            readint(kk);
            a.push_back(kk);
        }

        ll tot_sum = 0;
        forr(i,0,n/2) {
            ll temp = a[2*i] ^ a[2*i+1];
            tot_sum = tot_sum ^ temp;
        }

        for(auto x : a) {
            cout << (x^tot_sum) << " ";
        }
        cout << endl;


    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 5336
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main(void)
{
	int n,k;
	scanf("%d %d",&n,&k);
	int arr[n];
	for(int i=0;i<n;i++)
		scanf("%d",&arr[i]);
	sort(arr,arr+n);
	if(k>arr[n-1])
	{
		printf("IMPOSSIBLE\n");
		return 0;
	}
	int gcdd=arr[0];
	for(int i=1;i<n;i++)
	{
		gcdd=gcd(gcdd,arr[i]);
	}
	if(k%gcdd==0)
		printf("POSSIBLE\n");
	else
		printf("IMPOSSIBLE\n");
	return 0;
}

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

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

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    string ans = "Yes";
    for(ll i=1;i<n;++i){
        if(h[i] > h[i-1]){
            h[i]--;
        }else if(h[i] < h[i-1]){
            ans = "No";
            break;
        }
    }
    cout<<ans<<endl;

    return 0;
}

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


int main() {
    int A,B,X;
    cin >>A>>B>>X;
    if(B-A+1<=2*X){
        for(int i=A;i<=B;i++){
            cout <<i <<endl;
        }
    }
    else{
    rep(i,X){
        cout<<A+i<<endl;
    }
    for(int i=X-1;0<=i;i--){
        cout << B-i<<endl;
    }
    }
}

Measured memory_bytes: 256
allEatCache = {}
lenBurgerCache = {}


def nOfPatty(level, eat):
    if level == 0:
        return 1
    else:
        if level in allEatCache and eat >= lenBurger(level):
            return allEatCache[level]
        else:
            lenOfLowerLevel = lenBurger(level - 1)
            if eat <= 1:
                return 0
            if 2 <= eat <= 1 + lenOfLowerLevel:
                return nOfPatty(level - 1, eat - 1)
            if eat == 1 + lenOfLowerLevel + 1:
                return nOfPatty(level - 1, eat - 1) + 1
            else:
                tmp = nOfPatty(level - 1, eat - 1) + 1
                tmp += nOfPatty(level - 1, eat - 1 - lenOfLowerLevel - 1)
                allEatCache[level] = tmp
                return tmp


def lenBurger(level):
    if level == 0:
        return 1
    else:
        if level in lenBurgerCache:
            return lenBurgerCache[level]
        else:
            tmp = 3 + lenBurger(level - 1) * 2
            lenBurgerCache[level] = tmp
            return tmp


str = input().split()
n = int(str[0])
x = int(str[1])

print(nOfPatty(n, x))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=200010;
int n,fa[MAXN],f[MAXN],a[MAXN],siz[2][MAXN];
ll ans;
struct cmp {
	bool operator () (int a,int b) {return (1ll*siz[1][a]*siz[0][b]<1ll*siz[0][a]*siz[1][b])||
										   ((1ll*siz[1][a]*siz[0][b]==1ll*siz[0][a]*siz[1][b])&&(a>b));}
};
int findr (int x) {return (f[x]==x?x:f[x]=findr(f[x]));}
set <int,cmp> s;
int main () {
	scanf("%d",&n);
	for (int i=2;i<=n;i++) {scanf("%d",&fa[i]);}
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		f[i]=i,siz[a[i]][i]++;
	}
	for (int i=2;i<=n;i++) {s.insert(i);}
	for (int i=1;i<=n-1;i++) {
		int v=*s.begin();
		int p=findr(fa[v]);
		if (p!=1) {s.erase(p);}
		s.erase(v);
		ans+=1ll*siz[1][p]*siz[0][v];
		//cout << v << "  " << siz[0][v] << "  " << siz[1][v] << "    " << p << "  " << siz[0][p] << "  " << siz[1][p] << endl; 
		siz[0][p]+=siz[0][v],siz[1][p]+=siz[1][v],f[v]=p;
		//cout << v << "  " << siz[0][v] << "  " << siz[1][v] << "    " << p << "  " << siz[0][p] << "  " << siz[1][p] << endl; 
		if (p!=1) {s.insert(p);} 
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15616
r = 0
a,b,c = map(int,input().split())
moto = list(map(int,input().split()))
for i in range(a):
    if r == 0:
        sosu =0
    else:
        if f+c<=0:
            sosu += 0
        else:
            sosu +=1
    tasu = list(map(int,input().split()))
    r +=1
    for q in range(b):
        if q == 0:
            f = moto[q]*tasu[q]
        else :
            f +=moto[q]*tasu[q]
if f+c<=0:
    sosu += 0
else:
     sosu +=1
print(sosu)            

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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n, m, k;
    cin >> n >> m >> k;
    vector<string> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int res = INT_MAX;
    for (int x = 0; x < (1 << (n - 1)); x++) {
        vector<int> gr(n);
        for (int i = 0; i < (n - 1); i++) {
            if (x & (1 << i)) {
                gr[i + 1] = gr[i] + 1;
            } else {
                gr[i + 1] = gr[i];
            }
        }
        int s = __builtin_popcount(x);
        vector<int> cnt(n);
        bool ok = true;
        for (int j = 0; j < m; j++) {
            vector<int> cnt2(n);
            for (int i = 0; i < n; i++) {
                cnt2[gr[i]] += a[i][j] - '0';
            }
            for (int i = 0; i < n; i++) {
                if (cnt2[i] > k) ok = false;
            }
            bool cut = false;
            for (int i = 0; i < n; i++) {
                if (cnt[i] + cnt2[i] > k) cut = true;
            }
            if (cut) {
                s++;
                cnt = cnt2;
            } else {
                for (int i = 0; i < n; i++) cnt[i] += cnt2[i];
            }
        }
        if (ok) {
            res = min(res, s);
        }
    }
    cout << res;

    return 0;
}

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

int main(){
  int n, k, cnt = 0;
  cin >> n >> k;
  int h[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
    if(h[i] >= k) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = scan.nextInt();
			//????????¶??\???
			if(a>b){
				int x = a;
				a = b;
				b = x;
			}
			if(b>c){
				int x = b;
				b = c;
				c = x;
			}
			if(a>b){
				int x = a;
				a = b;
				b = x;
			}
			System.out.print(a);
			System.out.print(" ");
			System.out.print(b);
			System.out.print(" ");
			System.out.println(c);
	}

}

Measured memory_bytes: 26076
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
using namespace std;

int main(){
	string S;
	cin >> S;
	int n = S.length();
	int a = 0;
	if (S[0] == 'A') {
		a++;
		S[0] = 'a';
	}
	int z = 0;
	for (int i = 2; i < n-1; i++) {
		if (S[i] == 'C') {
			a++;
			S[i] = 'c';
			z++;
		}
	}
	int t=1;
	for (int i = 0; i < n; i++) {
		if (('a' > S[i]) || ('z' < S[i])) {
			t *= 0;
		}
	}
	if (t == 1)a++;
	if (a == 3 && z == 1)cout << "AC" << endl;
	else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b,x;
	int c,d;
	while(cin>>a>>b){
		c=a;
		d=b;
		if(a<b){
			x=a;
			a=b;
			b=x;
		}
		while(b!=0){
			x=b;
			b=a%b;
			a=x;
		}
		cout<<a<<" "<<c/a*d<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1160
def solve():
    N = input()
    if len(N) == 1:
        print(int(N))
    elif all(i == '9' for i in N[1:]):
        print(int(N[0]) + 9 * (len(N) - 1))
    else:
        print((int(N[0]) - 1) + 9 * (len(N) - 1))

if __name__ == "__main__":
    solve()

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

int dp[30];

void makedp(){
  dp[0]=1;
  dp[1]=2;
  dp[2]=4;
  for(int i=3;i<30;i++)
    dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
}

int solve(int n){
  n--;
  int day = dp[n]/10;
  if(dp[n]%10) day++;

  int year = day/365;
  if(day%365) year++;

  return year;
}

int main(){
  makedp();
  for(;;){
    int n;
    cin >> n;
    if(!n) break;
    cout << solve(n) << endl;
  }
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string read = Console.ReadLine();
            int D = int.Parse(read.Split(' ')[0]);
            int X = int.Parse(read.Split(' ')[1]);
            int[] a = new int[N];
            for (int i = 0; i < N; i++)
            {
                read = Console.ReadLine();
                a[i] = int.Parse(read);
            }
            ;

            int chocolate = 0;
            for (int i = 1; i <= D; i++)
            {
                for (int member = 0; member < N; member++)
                {
                    if (((i - 1) % a[member]) == 0) chocolate++;
                }
            }
            Console.WriteLine(chocolate+X);
            ;
        }

    }
}


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

#define Bye return 0
#define ll long long
const ll MAX = 1e9+7;

void solve(){
    int n; cin>>n;
    ll fat = 1;
    for (ll i=2; i<=n; i++)
        fat = (fat * i)%MAX;
    cout<<fat<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3596
/**
 * B - Bitter Alchemy
 */

#include <iostream>

using namespace std;

int main() {
    int N, X, ans = 0;
    int m[100];
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> m[i];
        X -= m[i];
        ans++;
    }
    sort(m, m + N);
    cout << ans + (X / m[0]) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// use gp_hash_table<int,int,custom_hash> m;
// in place of map
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
// This custom_hash is for unordered_map 
// use map<int, int, custom_hash> mp;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int win(char x){
	if(x == 'p')return 1;
	if(x == 's')return 0;
	return 2;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	#ifndef ONLINE_JUDGE
  //  	freopen("input.txt", "r", stdin);
    //	freopen("output.txt", "w", stdout);
//	#endif
	int n,k;
	cin>>n>>k;
	int r,s,p;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	int dp[n][3];
	int val[3];
	val[0] = r;val[1]=s;val[2]=p;
	vi v[3];
	rep(i,3){
		rep(j,3){
			if(i!=j)v[i].pb(j);
		}
	}
	rep(i,k){
		rep(j,3){
			if(j == win(t[i]))dp[i][j] = val[j];
			else dp[i][j] = 0;
		}
	}
	repa(i,k,n){
		rep(j,3){
			if(j == win(t[i])){
				dp[i][j] = val[j] + max(dp[i-k][v[j][0]],dp[i-k][v[j][1]]);
			}
			else{
				dp[i][j] = max(dp[i-k][v[j][0]],dp[i-k][v[j][1]]);
			}
		}
	}
	ll ans=0;
	repr(i,k){
		ans += max(dp[n-i-1][0],max(dp[n-i-1][1],dp[n-i-1][2]));
	}
	cout<<ans;
	return 0;
}

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

int H,W;
char grid[1000][1000];
ll dp[1000][1000];
ll solve(int i,int j){
	
	if(i>=H || i<0 ||j>=W || j<0 ||grid[i][j]=='#')
		return 0;
	if(i==H-1 && j==W-1)
		return 1;
	if(dp[i][j]!=-1)
		return dp[i][j];
	
	return dp[i][j]=(solve(i+1,j)%MOD+solve(i,j+1)%MOD)%MOD;
}


int main(){
	ios_base::sync_with_stdio(0);
  	cin.tie(NULL);
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>grid[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0)<<endl;
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
#define PB push_back
#define MP make_pair
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  vector<int> A(n+1);
  for(int i=0;i<n;++i)cin>>A[i];
  int64_t cur=1000;
  for(int i=0;i<n;++i){
    if(A[i]<=A[i+1]){
      cur=cur%A[i]+cur/A[i]*A[i+1];
    }
  }
  cout<<cur<<'\n';
  
  return 0;
}
//2020.07.25 20:14:29


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

int main(){
    string s;
    cin >> s;
    int n = s.size()+1;
    vector<int> from_left(n),from_right(n);
    rep(i,n-1){
        if(s.at(i) == '>') from_left.at(i+1) = 0;
        else from_left.at(i+1) = from_left.at(i)+1;
    }

    reverse(s.begin(),s.end());
    rep(i,n-1){
        if(s.at(i) == '<') from_right.at(i+1) = 0;
        else from_right.at(i+1) = from_right.at(i)+1;
    }
    reverse(from_right.begin(),from_right.end());
    ll tot=0;
    rep(i,n){
        tot += max(from_right.at(i),from_left.at(i));
    }
    cout << tot << endl;
    return 0;
}

Measured memory_bytes: 4740
#include <stdio.h>
int main(void) {
    int r, c, cell, row_sum, total, i, j;
    const char *fmt;
 
    scanf("%d %d", &r, &c);
    int col_sum[c];
 
    for (i = 0; i < c; i++)
        col_sum[i] = 0;
    for (total = i = 0; i < r; i++) {
        for (fmt = "%d", row_sum = j = 0; j < c; j++) {
            scanf("%d", &cell);
            printf(fmt, cell);
            row_sum += cell;
            col_sum[j] += cell;
            fmt = " %d";
        }
        printf(" %d\n", row_sum);
        total += row_sum;
    }
    for (fmt = "%d", i = 0; i < c; i++) {
        printf(fmt, col_sum[i]);
        fmt = " %d";
    }
    printf(" %d\n", total);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll  long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair

using namespace std;

const ll MOD = 1000000007LL;

ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];

ll ar[100056];
ll br[100056];
ll cr[100056];
vector<int> adj[100005];
set<ll> st;

int vis[100005];


bool prime[10000006];

vector<int> primes;



ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;

}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}

inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}

ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}

void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {

      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 

      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}

void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}

map<int,int> has[100008],occur[1000005];
bool flag;

map<ll,ll> hav;


void dfs(int s, int sum)
{
	
	vis[s]=1;
	vector<int>::iterator it;
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
			ar[*it]=sum+has[s][*it];
			dfs(*it,ar[*it]);
		}
		else if(vis[*it])
		{
			int p=sum+has[s][*it];
			
			//cout<<"vis p="<<p<<"\n";
			
			if(p!=ar[*it])
			{
			flag=1;
			}
		}
	}
}




int main() 
{
    ll n,m,t,p,q,s,a,b,c,d,e,f,g,h,sum=0,res,u,v,i,j,l,k,len,ans=0,tot,rad,ds,rs,x,y,r,z,maxm,minm;
    
    string str,ptr="";
    
    
    cin>>n;
    
    for(i=1;i<=n;i++)
    {
    cin>>ar[i];
    }
    
    for(i=1;i<=n;i++)
    {
    	if(ar[i]==i)
    	{
    		swap(ar[i],ar[i+1]);
    		ans++;
		}
	}
     cout<<ans;
    
    return 0;
    
}

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

const long long INIT = LLONG_MIN;

class segment_tree {
private:
  int n;
  vector<long long> dat;

  static inline long long func(long long a, long long b) {
    return max(a, b);
  }

  long long query(int a, int b, int k, int l, int r) const {
    if(r <= a || b <= l) return INIT;
    if(a <= l && r <= b) return dat[k];

    const auto vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    const auto vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return func(vl, vr);
  }

public:
  segment_tree(int n_):n(1) {
    while(n < n_) n <<= 1;
    dat.resize(2 * n - 1, INIT);
  }

  void update(int k, long long a) {
    k += n - 1;
    dat[k] = a;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  long long query(int a, int b) const {
    return query(a, b, 0, 0, n);
  }
};

inline segment_tree make_segment_tree(const vector<long long> &a, const vector<long long> &weight) {
  const int n = a.size();
  segment_tree res(n);

  for(int i = 0; i < n; ++i) {
    res.update(i, a[i] - weight[i]);
  }

  return res;
}

inline bool ok(int r, long long m, const vector<long long> &vl, const vector<long long> &vr,
	       const segment_tree &left, const segment_tree &right) {

  const int n = vl.size();
  vector<long long> value(n);

  for(int i = 0; i < n; ++i) {
    value[i] = max(vl[i] + left.query(max(0, i - r), i + 1),
		   vr[i] + right.query(i, min(n, i + r + 1)));
  }

  return accumulate(value.begin(), value.end(), 0ll) >= m;
}

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

  int n, c;
  long long m;
  cin >> n >> m >> c;

  vector<long long> a(n);
  for(auto &e : a) cin >> e;

  vector<long long> vr(n);
  vr.front() = 0;
  for(int i = 1; i < n; ++i) {
    vr[i] = vr[i - 1] + c;
  }

  vector<long long> vl(vr);
  reverse(vl.begin(), vl.end());

  const auto left = make_segment_tree(a, vl);
  const auto right = make_segment_tree(a, vr);

  int low = -1, high = n;
  while(low + 1 < high) {
    const int middle = (low + high) / 2;
    if(ok(middle, m, vl, vr, left, right)) {
      high = middle;
    }
    else {
      low = middle;
    }
  }

  cout << (high == n ? -1 : high) << endl;

  return 0;
}


Measured memory_bytes: 8408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k[100],t[52];
  string s;
  for(int i=0;i<26;i++)t[i]='a'+i;
  for(int i=0;i<26;i++)t[i+26]='A'+i;
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>k[i];
    cin>>s;
    for(int i=0;i<s.size();i++){
      if('A'<=s[i]&&s[i]<='Z')s[i]=s[i]-'A'+26;
      else s[i]=s[i]-'a';
      s[i]=t[(52+s[i]-k[i%n])%52];
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
import java.util.*;
import java.io.*;

public class Main {

	public static final int mod = 1000000007;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		int k = Integer.parseInt(s[1]);
		int[] arr = new int[n + 1];
		int[][] dp = new int[n + 1][k + 1];
		int[] prefix = new int[k+1];
		s = br.readLine().split(" ");

		dp[0][0] = 1;
		for (int i = 1; i <= n; i++) {
			arr[i] = Integer.parseInt(s[i - 1]);
			dp[i][0] = 1;
		}

		int max = 0;
		for (int i = 1; i <= n; i++) {
			prefix[0] = dp[i-1][0];
			max += arr[i];
//			System.out.println(max);
			for (int j = 1; j <= max && j <=k; j++) {
				prefix[j] = (dp[i-1][j]+ prefix[j-1]) % mod;
//				System.out.println(i + " " + j+ " " + prefix[j]);
				if (j-arr[i]-1 < 0) {
					dp[i][j] = prefix[j];
				} else {
					dp[i][j] = (prefix[j]-prefix[j-arr[i]-1]+mod)%mod;
				}
			}
		}
		System.out.println(dp[n][k]);
//		for (int j = 0; j <= k; j++) {
//			for (int i = 0; i <= n; i++) {
//				System.out.print(dp[i][j] + " ");
//			}
//			System.out.println();
//		}

	}

}


Measured memory_bytes: 78292
// 2020-08-02 21:09:52
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> sum(n+1, 0);
  rep(i, n) {
    sum[i+1] = sum[i] + (s[i] == 'R');
  }
  cout << sum[n] - sum[sum[n]] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	string s1, s2;
	cin >> s1 >> s2;
	cout << s2 << s1 << "\n";

	return 0;
}



Measured memory_bytes: 256
from fractions import gcd
from math import ceil,floor
 
A,B,C,D=map(int, input().split())
 
Cans = B//C - (A-1)//C
Dans = B//D - (A-1)//D
 
CD = C * D // gcd(C,D)
CDans = B//CD - (A-1)//CD
 
ans = (B-A+1) - (Cans + Dans - CDans)
 
print(ans)


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

template <class T>
class SegmentTree {
private:

    T n;
    vector<T> node;
    const ll inf;

public:

    SegmentTree(vector<T> v) : inf((1LL<<31)-1) {
        n = 1;
        while (n < v.size()) n *= 2;
        node.resize(2*n-1, inf);
        for (int i=0; i<v.size(); ++i) node[i+n-1] = v[i];
        for (int i=n-2; i>=0; --i) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    SegmentTree(T N) : inf((1LL<<31)-1) {
        n = 1;
        while (n < N) n *= 2;
        node.resize(2*n-1, inf);
    }

    void update(T x, T val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    // [a, b)
    T query(T a, T b, T k=0, T l=0, T r=-1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return inf;
        if (a <= l and r <= b) return node[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    ll n, q;
    cin >> n >> q;
    SegmentTree<ll> tree(n);
    rep(i, q) {
        ll c, x, y;
        cin >> c >> x >> y;
        if (c) cout << tree.query(x, y+1) << endl;
        else tree.update(x, y);
    }
    return 0;
}



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

using namespace std;

int main() {
    int a, b, c;

    cin >> a >> b >> c;

    for (int i = 1; i <= b; i++) {
        if ( ((a*i) % b) == c) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


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

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i =0; i < N; i++) {
        cin >> L[i];
    }

    vector<int> D(N+1);
    D[0] = 0;
    int bounce = 1;

    for (int i = 0; i < N; i++) {
        D[i+1] = D[i] + L[i];
        if (D[i+1] <= X) {
            ++bounce;
        }
    }
    cout << bounce << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

typedef long long ll;
#define rep(i, n) for(int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
using namespace std;
vector<int> vec;
int main() {
    string s;
    int N, K, answer = 0;
    cin >> N >> K;
    vec.resize(N);
    rep(i, N) {
        cin >> vec[i];
    }
    rep(i, N) {
        answer += 2 * min(K - vec[i], vec[i]);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
# include <cstdio>
# include <iostream>
# include <algorithm>
# define R register int
# define ll long long 

using namespace std;

int a,b;

int main()
{
    scanf("%d%d",&a,&b);
    if(a<=0&&b>=0) printf("Zero");
    else if(b<0)
    {
        if((b-a+1)&1) printf("Negative");
        else printf("Positive");
    }
    else if(a>0) printf("Positive");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 5e5; int n;
char s[maxN];
int a[maxN];

int main()
{
  scanf("%s", s);

  n = strlen(s);
  for (int i = n - 1; i >= 0; i --)
  {
    if (s[i] == '>')
    {
      a[i + 1] = 0;
      int j = i, v = 1;
      while (j - 1 >= 0 && s[j - 1] == '>')
        a[j --] = v ++;
      a[j --] = v;
      i = j + 1;
    }
  }
  for (int i = 0; i < n; i ++)
  {
    if (s[i] == '<')
    {
      int j = i;
      while (j + 1 < n && s[j + 1] == '<')
        j ++;
      j ++;
      int k = j;
      int v = max(a[j], j - i);
      while (j != i)
        a[j --] = v --;
      a[j] = v;
      i = k - 1;
    }
  }
  if (s[0] == '<')
  {
    int j = 0;
    while (j + 1 < n && s[j + 1] == '<') j ++;
    for (int i = 0; i <= j; i ++)
      a[i] = i;
  }
  if (s[n - 1] == '>')
  {
    int j = n - 1;
    while (j - 1 >= 0 && s[j - 1] == '>') j --;
    for (int i = n, v = 0; i > j; i --)
      a[i] = v ++;
  }
  for (int i = 0; i < n - 1; i ++)
  {
    if (s[i] == '>' && s[i + 1] == '<')
    {
      int j = i + 1;
      while (j + 1 < n && s[j + 1] == '<') j ++;
      for (int k = i + 1, v = 0; k <= j; k ++)
        a[k] = v ++;
      i = j;
    }
  }
  DEBUG {
    for (int i = 0; i <= n; i ++)
      printf("%d %c ", a[i], i < n ? s[i] : '\n');
    bool valid = true;
    for (int i = 0; i < n; i ++)
      if ((s[i] == '>' && a[i] <= a[i + 1]) || (s[i] == '<' && a[i] >= a[i + 1]))
      {
        printf("Wrong at %d %c\n", i, s[i]);
        valid = false;
      }
    printf("valid: %d\n", valid);
  }

  lli ans = 0;
  for (int i = 0; i <= n; i ++)
    ans += a[i];
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll h,w,m;
    cin >> h >> w >> m;
    vector<P> hmwm;

    vector<ll> row(w,0);
    vector<ll> column(h,0);

    ll hm,wm;

    rep(i,m){
        cin >> hm >> wm;
        hmwm.push_back(make_pair(hm,wm));
        column[hmwm[i].first-1]++;
        row[hmwm[i].second-1]++;
    }

    ll result = 0;
    ll max_column = 0;
    vector<ll> max_column_list;
    ll max_row = 0;
    vector<ll> max_row_list;
    rep(i,h){
        if(max_column < column[i]){
            max_column = column[i];
            max_column_list = {i};
        }
        else if(max_column == column[i]){
            max_column_list.push_back(i);
        }
    }
    rep(i,w){
        if(max_row < row[i]){
            max_row = row[i];
            max_row_list = {i};
        }
        else if(max_row == row[i]){
            max_row_list.push_back(i);
        }
    }
    ll temp = 0;
    // rep(i,m){
    //     if(find(all(max_column_list),hmwm[i].first-1)!=max_column_list.end() and find(all(max_row_list),hmwm[i].second-1)!=max_row_list.end()){
    //         temp++;
    //     }
    // }

    // rep(i,max_column_list.size())rep(j,max_row_list.size()){
    //     if(find(all(hmwm),make_pair(max_column_list[i]+1,max_row_list[j]+1)) == hmwm.end()) {
    //         cout << max_column + max_row;
    //         return 0;
    //     }
    // }

    // cout << max_column + max_row - 1;

    // cout << "max_col: " << max_column << "\n";
    // cout << "max_row: " << max_row << "\n";
    // cout << "temp: " << temp << "\n";

    // if(temp == max_column_list.size() * max_row_list.size()) cout << max_column + max_row -1;
    // else cout << max_column + max_row;

    result = max_column + max_row;

    rep(i,m){
        if(column[hmwm[i].first-1] == max_column && row[hmwm[i].second-1] == max_row){
            temp++;
        }
    }

    if(max_column_list.size() * max_row_list.size() == temp){
        result--;
    }

    cout << result;
    
    return 0;
}

Measured memory_bytes: 21460
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int N;
string s, g;
int dp[1<<16][16];
int dfs(int S, int u){
  if(S == (1<<N) - 1) return 0;
  if(dp[S][u] != -1) return dp[S][u];
  int res = INF;
  REP(i, N)REP(j, N) if(i != j && (S >> i & 1) == 0 && (S >> j & 1) == 0 && g[i] != g[j]){
    res = min(res, abs(u - i) + abs(i - j) + dfs(S | 1 << i | 1 << j, j));
  }
  return dp[S][u] = res;
}
int main(){
  while(cin>>N && N){
    cin>>s>>g;
    REP(S, 1<<N) REP(p, N) dp[S][p] = -1;
    int S = 0;
    REP(i, N) if(s[i] == g[i]) S |= 1<<i;
    int ans = INF;
    REP(i, N) ans = min(ans, dfs(S, i));
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 7176
N, K, C = map(int, input().split())
S = input()
S_reverse = S[::-1]

left_justified = [-1 for _ in range(N)]
right_justified = [-2 for _ in range(N)]

for i_justified in (left_justified, right_justified):
    if i_justified == left_justified:
        i_S = S
        nearest_position = 1
        positioning = 1
    else:
        i_S = S_reverse
        nearest_position = K
        positioning = -1
    
    i_K = 0
    
    while i_K <= N-1:
        if i_S[i_K] == 'o':
            i_justified[i_K] = nearest_position
            i_K += C
            nearest_position += positioning
        i_K += 1

for i_N in range(N):
    if left_justified[i_N] == right_justified[N - i_N - 1]:
        print(i_N + 1)

Measured memory_bytes: 58216
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

int n , a[100005], b[100005], c[100005] ;
int dp[100005][3] ;

void runDP(){
	dp[0][0] = a[0] ;
	dp[0][1] = b[0] ;
	dp[0][2] = c[0] ;
	
	for(int i = 1 ; i< n; i++){
		dp[i][0] = a[i] + max(dp[i-1][1] , dp[i-1][2]) ;
		dp[i][1] = b[i] + max(dp[i-1][0] , dp[i-1][2]) ;
		dp[i][2] = c[i] + max(dp[i-1][1] , dp[i-1][0]) ;
	}
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n ;
	for(int i = 0 ; i< n ;i++){
		cin >> a[i] >> b[i] >> c[i] ;
	}

	runDP() ;

	cout << max( dp[n-1][0] , max( dp[n-1][1] , dp[n-1][2] ) ) << endl ;

	return 0;
}

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

int main(){
  int N;
  double A, ans = 0.0;
  
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> A;
    ans += 1.0 / A;
  }
  
  cout << 1.0 / ans << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
try (Scanner sc = new Scanner(System.in)) {
int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for (int i = 0; i < values.length; i++) {
values[i] = i + 1;
}
for (int i = 0; i < n; i++) {
String str = sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) - 1;
int b = Integer.parseInt(ab[1]) - 1;
int j;
j = values[a];
values[a] = values[b];
values[b] = j;
}
for (int i = 0; i < w; i++){
    System.out.println(values[i]);
}
}
}
}


Measured memory_bytes: 25880
package main
 
import (
    "fmt"
)
 
func main() {
	var N,M,A,i int
    fmt.Scan(&N)
  	fmt.Scan(&M)
  	i=0
  	for i<M {
      	fmt.Scan(&A)
      	N=N-A
      	i++
  	}
  	if N >= 0 {
  		fmt.Print(N)
    }else{
      	fmt.Print("-1")
    }
}

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

int main() {
    vector<int> A(3);
    for (int i = 0; i < 3; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    cout << A.size() << endl;
}


Measured memory_bytes: 256