akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

map<int, int> pos;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
       
    int n;
    cin >> n;
    vi a(n);
    fi(0, n) 
        cin >> a[i];
    vi s = a;
    sort(all(s));
    fi(0, n)
        pos[s[i]] = i % 2;
    int cnt = 0;
    int sum = 0;
    fi(0, n) {
        if (i % 2 != pos[a[i]]) {
            ++cnt;
            if (i % 2)
                --sum;
            else
                ++sum;
        }
    }
    assert(sum == 0);
    cout << cnt / 2 << '\n';
}

Measured memory_bytes: 11152
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;

int n, k;
int a[N];

void solv()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n - k; ++i)
    {
        if (a[i] < a[i + k])
            printf("Yes\n");
        else
            printf("No\n");
    }
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


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

int main() {
  int n;cin>>n;
  int ans=0;
  rep(i,n){
    int a;cin>>a;
    while(1){
      if(a%2==0){
        ans++;
        a/=2;
      }
      else break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 105000000000

const int maxn = 1e5 + 10;
ll fa[maxn];

void init() {
	rep(i, maxn) fa[i] = i;
}

int Find(int x) {
	return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

void Union(int x, int y) {
	int fx = Find(x), fy = Find(y);
	if (fx == fy) return;
	fa[fy] = fx;
	}

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

	init();
	int n;
	cin >> n;
	vector<P> v(n);
	vector<P> fx,fy;
	rep(i, n) {
		cin >> v[i].F >> v[i].S;
		fx.pb(mp(v[i].F, i));
		fy.pb(mp(v[i].second, i));
	}

	vsort(fx);
	vsort(fy);

	set<pair<pair<int, int>, pair<int,int>>> st;

	for (int i = 0; i + 1 < n; i++)
	{
		st.insert(mp(mp(abs(fx[i].first - fx[i + 1].first), 0), mp(fx[i].second, fx[i + 1].second)));
		st.insert(mp(mp(abs(fy[i].first - fy[i + 1].first), 1), mp(fy[i].second, fy[i + 1].second)));
	}

	ll ans = 0;

	while (!st.empty())
	{
		auto it = (*(st.begin()));
		st.erase(st.begin());
		if (Find(it.second.first) != Find(it.second.second))
		{
			Union(it.second.first, it.second.second);
			ans += it.first.first;
		}
	}


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

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

int main(void){
    string s;
    cin >> s;
    int ocount = 0, ecount = 0;
    
    for(int i = 0; i < s.size(); i++){
        if(i % 2){
            if(s[i] == '0') ecount++;
            else if(s[i] == '1') ocount++;
        }  
        else{
            if(s[i] == '0') ocount++;
            else if(s[i] == '1') ecount++;
        }  
    }
    cout << ((ecount > ocount)? ocount:ecount) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define sort(ss) sort(ss.begin(), ss.end())
#define rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return acos(-1.0);
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int a,ac[30]={},win=0,ss,qq=10,i;
	cin>>ss;
	for(int e=0;e<ss;e++){
		cin>>a;
		cin>>ac[e];
		if(ac[e]>=win){
			if(ac[e]==win){
				if(qq>a) qq=a;
			}
			else{
				win=ac[e];
				qq=a;
			}
		}
	}
	cout<<qq<<" "<<win<<endl;
}

Measured memory_bytes: 1164
def check(lst, n):
    i = 0
    j = 1

    while j < n:
        if lst[i] > lst[j]:
            return False
        i += 1
        j += 1

    return True


def swap(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp


def submit():
    n = int(input())
    plist = list(map(int, input().split()))

    if check(plist, n):
        print('YES')
        return

    for i in range(0, n - 1):
        for j in range(i + 1, n):
            swap(plist, i, j)
            if check(plist, n):
                print('YES')
                return
            swap(plist, j, i)

    print('NO')


if __name__ == '__main__':
    submit()


Measured memory_bytes: 40176
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <queue>
#include <numeric>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s;
  cin >> s;
  int r;
  for(auto c : s) r += c=='+' ? 1 : -1;
  cout << r << endl;

  return 0;
}








Measured memory_bytes: 888
fun main(args: Array<String>){
    val n = readLine()!!.toLong()
    val l = readLine()!!.split(' ').map{ it.toLong()}
    var ans = l[0]
    for (i in 1 until l.size){
        ans = gcd(ans, l[i])
    }
    println(ans)
}

fun gcd(a: Long, b:Long): Long{
    return if(b >   0L){
        gcd(b, a%b.toLong())
    } else{
        a
    }
}

Measured memory_bytes: 52012
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN(n);
  OUT(48-n);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	b := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		fmt.Scan(&b[i])
	}
	a := make([]int, n)
	for i := 0; i < n; i++ {
		if i == 0 {
			a[i] = b[i]
		} else if i == n-1 {
			a[i] = b[i-1]
		} else {
			a[i] = min(b[i], b[i-1])
		}
	}
	fmt.Println(sum(a))
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)

const int INF = 1001001001;

void solve(){
  double L;  cin >> L;
  double ans = pow(L/3, 3);
  printf("%.6f\n", ans);
}

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


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def selection_sort(A, N):
    cnt = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    return cnt


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    cnt = selection_sort(A, N)
    print(*A)
    print(cnt)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7296
#include <iostream>
using namespace std;
int main() {
	int r, c, n, num[101][101] = {}, row[101] = {}, line[101] = {};
	cin >> r >> c;
	for (int i = 0; i<r; i++){
		for (int j = 0; j<c; j++){
			cin >> n;
			num[i][j] = n;
			row[i] += n;
		}
		num[i][c] = row[i];
	}
	for (int i = 0; i <= c; i++){
		for (int j = 0; j<r; j++){
			line[i] += num[j][i];
		}
		num[r][i] = line[i];
	}
	for (int i = 0; i <= r; i++){
		for (int j = 0; j <= c; j++){
			if (j<c){
				cout << num[i][j] << " ";
			}
			else{ cout << num[i][j] << endl; }
		}
	}
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int H, W;
    cin >> H >> W;
    char S[H+2][W+2] = {};
    REP(i,H){
        REP(j,W){
            cin >> S[i+1][j+1];
        }
    }
    REP(i,H){
        REP(j,W){
            int c = 0;
            if(S[i+1][j+1] == '#'){
                cout << "#" ;
                continue;
            }
            REP(k,3){
                REP(l,3){
                    if(S[i+k][j+l] == '#'){
                        c++;
                    }
                }
            }
            cout << c ;
        }
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int MAXN = 200000;
const int MAXM = 8*MAXN;

struct edge{
	int to; bool tag;
	edge *nxt, *rev;
}edges[MAXM + 5], *adj[MAXN + 5], *ecnt = edges;

void addedge(int u, int v) {
	edge *p = (++ecnt), *q = (++ecnt);
	p->to = v, p->tag = false, p->nxt = adj[u], adj[u] = p;
	q->to = u, q->tag = false, q->nxt = adj[v], adj[v] = q;
	p->rev = q, q->rev = p;
}

int X[MAXN + 5], N;
void dfs(int x) {
	for(;adj[x];) {
		edge *p = adj[x]; adj[x] = adj[x]->nxt;
		if( p->tag ) continue;
		p->tag = p->rev->tag = true;
		dfs(p->to);
		if( x - p->to == -N ) X[x] = -1;
		else if( x - p->to == N ) X[p->to] = 1;
	}
}

int cnt[2][MAXN + 5];
int main() {
	scanf("%d", &N);
	int rt1;
	for(int i=1;i<=N;i++) {
		int x; scanf("%d", &x);
		if( x != -1 ) {
			addedge(x, i);
			cnt[0][x]++;
		}
		else rt1 = i;
	}
	for(int i=1;i<=N;i++) {
		int x; scanf("%d", &x);
		if( x != -1 ) {
			addedge(x + N, i + N);
			cnt[1][x]++;
		} 
	}
	for(int i=1;i<=N;i++) {
		if( (cnt[0][i] - cnt[1][i]) & 1 ) {
			puts("IMPOSSIBLE");
			return 0;
		}
		if( !(cnt[0][i] & 1) )
			addedge(i, N + i);
	}
	dfs(rt1);
	puts("POSSIBLE");
	for(int i=1;i<=N;i++)
		printf("%d%c", X[i], (i == N ? '\n' : ' '));
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX (1<<16)

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	static int sq[MAX];
	
	for(int i = 1; i*i < MAX; i++){
		sq[i*i] = i;
	}
	while(true){
		int N;
		int ans = 0;
		
		cin>>N;
		
		if(!N) break;
		
		for(int i = 1; i*i <= N; i++){
			if(i*i == N){ans++;break;}
			for(int j = i; i*i + j*j <= N; j++){
				if(j*j + i*i == N){ans++;break;}
				for(int k = j; k*k + i*i + j*j <= N; k++){
					int l = N - (k*k + i*i + j*j);
					int l2 = sq[l];
					if(!l || l2 >= k) ans++;
				}
			}
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

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


int main(){
  string o, e;
  cin >> o >> e;
  rep(i,max(o.size(), e.size())){
    cout << o[i];
    if(i < e.size()) cout << e[i];
  }
  cout << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long list[n+1];
  for (long i = 0; i <= n; i++) {
    list[i] = 0;
  }
  long value;
  for (long x = 1; x <= 100; x++) {
    for (long y = 1; y <= 100; y++) {
      for (long z = 1; z <= 100; z++) {
        value = x*x+y*y+z*z;
        value += x*y+y*z+z*x;
        if (value > n) {
          continue;
        }
        list[value]++;
      }
    }
  }
  for (long i = 1; i <= n; i++) {
    printf("%ld\n", list[i]);
  }

  return 0;
}

Measured memory_bytes: 1760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e5+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
int a[M];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin>>n;
  	for(int i=1;i<=n;i++)cin>>a[i];
  	sort(a+1,a+1+n);
  	ll ans=a[n];
  	int nm=n-2;
  	for(int i=n-1;i>=1;i--)
  	{
  		if(nm>1)nm-=2,ans+=a[i]*2;
  		else if(nm==1)nm=0,ans+=a[i];
  		else break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4444
a = []
for i in range(3):
    c = list(map(int, input().split()))
    a.append(c)
n = int(input())

for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == a[i][j]:
                a[i][j] = '#'

flag = 0

if a[0][0] == a[0][1] and a[0][1] == a[0][2]:
    flag = 1
if a[1][0] == a[1][1] and a[1][1] == a[1][2]:
    flag = 1
if a[2][0] == a[2][1] and a[2][1] == a[2][2]:
    flag = 1
if a[0][0] == a[1][0] and a[1][0] == a[2][0]:
    flag = 1
if a[0][1] == a[1][1] and a[1][1] == a[2][1]:
    flag = 1
if a[0][2] == a[1][2] and a[1][2] == a[2][2]:
    flag = 1
if a[0][0] == a[1][1] and a[1][1] == a[2][2]:
    flag = 1
if a[0][2] == a[1][1] and a[1][1] == a[2][0]:
    flag = 1

if flag == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
#!/usr/bin/env python
# coding: utf-8
#

def main(n, x, m):
    print(int((x - sum(m)) / min(m)) + len(m))


if __name__ == '__main__':
    try:
        n, x = list(map(int, input().strip().split(' ')))
        m = []
        for i in range(n):
            m.append(int(input().strip()))
        
        main(n, x, m)
    except EOFError:
        pass


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

int main() {
  int A,B,C,K,ans;
  cin>>A>>B>>C>>K;
  if (K<=A) ans=K;
  else if (K<=A+B) ans=A;
  else ans=2*A+B-K;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3152
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {
	
	printf("square1001\n");

	Please AC;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  string s;cin>>s;lint ans=0;
  //caricurate
  lint i,sz;sz=s.size();vint ps(sz,0);vector<bool> wht(sz,false);
  for(i=0;i<sz;i++){
  if(s.at(i) =='B'){ps[i]=1;}else{wht[i]=true;}
  }
  for(i=0;i<sz-1;i++){
    ps[i+1]+=ps[i];
  }
  for(i=0;i<sz;i++){
    if(wht[i]){ans+=ps[i];}
  }
  //output
  cout<<ans<<endl;
}

Measured memory_bytes: 1936
package main

import "fmt"

type edge struct {
	to, weight int
}

func dfs(g [][]edge, node int, colors []int) {
	for _, e := range g[node] {
		if colors[e.to] != 2 {
			continue
		}
		if e.weight%2 == 0 {
			colors[e.to] = colors[node]
		} else {
			colors[e.to] = (colors[node] + 1) % 2
		}
		dfs(g, e.to, colors)
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	us := make([]int, n-1)
	vs := make([]int, n-1)
	ws := make([]int, n-1)
	for i := range us {
		fmt.Scan(&us[i], &vs[i], &ws[i])
	}

	g := make([][]edge, n)
	for i := range us {
		g[i] = make([]edge, 0)
	}
	for i, u := range us {
		v := vs[i]
		g[u-1] = append(g[u-1], edge{to: v - 1, weight: ws[i]})
		g[v-1] = append(g[v-1], edge{to: u - 1, weight: ws[i]})
	}

	colors := make([]int, n)
	for i := range colors {
		colors[i] = 2
	}
	colors[0] = 0
	dfs(g, 0, colors)

	for _, c := range colors {
		fmt.Println(c)
	}
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int K, S;
void func()
{
    cin >> K >> S;
    int ans(0);
    rep(i, 0, K + 1)
    {
        rep(j, 0, K + 1)
        {
            if (S - i - j >= 0 && S - i - j <= K)
                ++ans;
        }
    }
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <string.h>

int main() {
    char s[5];
    gets(s);
    
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
        printf("Yes");
    }
    else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[2]){
        printf("Yes");
    }
    else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){
        printf("Yes");
    }
    else if(s[1] == s[2] && s[0] == s[3] && s[0] != s[1]){
        printf("Yes");
    }
    else{printf("No");}
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define rep(i,n) for(long long i = n-1;i>=0;i--)
#define repp(i,m,n) for(long long i = n-1; i >= m; i--)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N],b[N],c[N];
    int dp[N+1][3] = {};
    REPP(i,1,N+1){
        cin >> a[i] >> b[i] >> c[i];
        dp[i][0] = max(dp[i-1][1]+b[i],dp[i-1][2]+c[i]);
        dp[i][1] = max(dp[i-1][0]+a[i],dp[i-1][2]+c[i]);
        dp[i][2] = max(dp[i-1][0]+a[i],dp[i-1][1]+b[i]);
    }
    cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;
}

Measured memory_bytes: 2560
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
min_nk = min(n, k)
for l in range(min_nk+1):
    for r in range(min_nk-l+1):
        hand = []
        for i in range(l):
            hand.append(v[i])
        for i in range(r):
            hand.append(v[n-1-i])
        hand.sort()
        
        for i in range(min(k-l-r, len(hand))):
            if hand[i] < 0:
                hand[i] = 0
        ans = max(ans, sum(hand))
print(ans)

Measured memory_bytes: 42844
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

n,m = map(int,input().split())

coor = [[False for _ in range(n)] for _ in range(n)]
for i in range(n):
    coor[i][i] = True
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    coor[a][b] = True
    coor[b][a] = True

# n-1頂点のperm
l = range(2,n+1)

res = 0
for p in perm(l):
    p = [1] + list(p)
    for s,g in zip(p,p[1:]):
        if not coor[s-1][g-1]:
            break
    else:
        res += 1
print(res)


Measured memory_bytes: 5076
/*
TASK: ditch
LANG: C++11
 */
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 3, M = 2 * 3e4 + 3;

int arr[N];
long long mem[N][2];
int n;
long long solve(int i,int isPos){
    int s=isPos*2-1;
    if(i==n-1)return arr[i]*s;
    auto &ret=mem[i][isPos];
    if(ret!=0x3f3f3f3f3f3f3f3f)return ret;
    ret=arr[i]*s+solve(i+1,1);
    ret=max(ret,arr[i]*s*-1+solve(i+1,0));
    return ret;
}
int main() {
    //freopen("test.in", "r", stdin);

    while (cin >> n) {

        for (int i = 0; i < n; i++)cin >> arr[i];
        memset(mem,'?',sizeof mem);
        cout <<solve(0,1) << endl;
    }
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific

using namespace std;

int main(void) {
    size_t hello[101];
    for(size_t i = 0; i < 101; ++i)
        hello[i] = 0;
    size_t a, b, c;
    cin >> a >> b >> c;
    ++hello[a];
    ++hello[b];
    ++hello[c];
    size_t count = 0;
    for(size_t i = 0; i < 101; ++i)
        if(hello[i]) ++count;
    cout << count << endl;
    
    return 0;
}


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

const int MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  int64_t ans = 1;
  for(int i = 1; i <= n;i++){
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll pre1[maxn],pre2[maxn];
int main()
{
    int n,m,k,x,pos;
    int ans=0;
    cin>>n>>m>>k;
    For(i,1,n)cin>>x,pre1[i]=pre1[i-1]+x;
    For(i,1,m)cin>>x,pre2[i]=pre2[i-1]+x;
    For(i,0,n)
    {
        if(pre1[i]<=k)
        {
            x=k-pre1[i];
            pos=lower_bound(pre2+1,pre2+1+m,x)-pre2;
            if(pre2[pos]!=x&&pos>0)pos--;
            ans=max(i+pos,ans);
        }
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

		for (int i = 0; i < n; i++) {
			if (a[i] < min) {
				min = a[i];
			}
			if (a[i] > max) {
				max = a[i];
			}
		}

		System.out.println(max - min);
	}

}


Measured memory_bytes: 23124
use proconio::*;
use proconio::marker::Bytes;

fn run() {
    input! {
        a: u64,
        s: Bytes,
    }
    let mut val = 0;
    for s in s.iter() {
        if b'0' <= *s && *s <= b'9' {
            val = 10 * val + (*s - b'0') as u64;
        }
    }
    let ans = val * a / 100;
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 2116
#三井住友2019_D
n=int(input())
s=input()

cnt=0
for i in range(0,1000):
    t='0'*(3-len(str(i)))+str(i)
    flg1,flg2,flg3=[False]*3
    for j in range(n):
        if flg1:
            if flg2:
                if s[j]==t[2]:
                    flg3=True
                    break
            else:
                if s[j]==t[1]:
                    flg2=True
        else:
            if s[j]==t[0]:
                flg1=True
    cnt+=1 if flg3 else 0
    
print(cnt)



Measured memory_bytes: 42588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n, m, k; cin >> n >> m >> k;
  vector <ll> a(n+1, 0), b(m+1, 0);
  rep(i, n) cin >> a.at(i+1);
  rep(i, m) cin >> b.at(i+1);
  rep(i, n) a.at(i+1) += a.at(i);
  rep(i, m) b.at(i+1) += b.at(i);
  ll res = 0;
  rep(i, n+1) {
    auto itr = upper_bound(b.begin(), b.end(), k-a.at(i));
    if (itr == b.begin()) continue;
    itr--;
    if (a.at(i)+*itr <= k) {
      res = max(res, i+distance(b.begin(), itr));
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 6420
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <istream>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define vec vector<int>a(n)
#define soot(a) sort(a.begin(),a.end())
/*int n;
cin >> n;
vector<int>a(n);
rep0(i, n - 1)cin >> a[i];*/
using namespace std;
int main() {
	int a,b;
  cin>>a>>b;
  cout<<(a+b+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import count
while 1:
    a,p=map(int,input().split())
    if not a and not p:break
    a=str(a).zfill(p)
    b=[a]
    f=lambda l:int("".join(l))
    i=0
    for j in count(1):
        m=sorted(a)
        a=str(f(m[::-1])-f(m)).zfill(p)
        if a in b:
            i=b.index(a)
            break
        b.append(a)
    print(i,int(a),j-i)



Measured memory_bytes: 5640
a = [0,0,0,0,0]

a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

ans = 10000000

def is_unique(seq):
   return len(seq) == len(set(seq))

for o in range(5):
	for p in range(5):
		if is_unique([o,p]):
			for q in range(5):
				if is_unique([o,p,q]):
					for r in range(5):
						if is_unique([o,p,q,r]):
							for s in range(5):
								if is_unique([o,p,q,r,s]):
									tmp = int(a[o]/10)*10+int(a[p]/10)*10+int(a[q]/10)*10+int(a[r]/10)*10+int(a[s])
									tmp += (bool(a[o]%10)+bool(a[p]%10)+bool(a[q]%10)+bool(a[r]%10))*10
									ans = min(tmp, ans)

print(ans)

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

all=0

for i in range(1,N+1):
    all+=i

S=0

for i in range(1,N+1):
    if i%3==0:
        S+=i
    elif i%5==0:
        S+=i
    elif i%15==0:
        S-=i
        
print(all-S)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;

    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }

    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }

    //日程を乱数で初期化
    int t[D] = {};
    srand(time(NULL));
    rep(i, 0, D) {
        t[i] = rand() % 26;
    }

    ll mx_score = -1e18;
    int cnt = 100000;
    while (cnt--) {
        //d日目のコンテストをqに置き換えてスコアを計算し、改善しなければ元に戻す
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        //スコアを計算する
        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            //増加分
            score[i] += s[i][t[i]];

            last_day[t[i]] = i;

            //減少分
            ll decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        //cout << "score[D - 1]: " << score[D - 1] << endl;
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }

    rep(i, 0, D) cout << t[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

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

    int ans = 0;
    if(B >= C){
        cout << B+C << endl;
    }else{
        ans = B*2;
        if(A < (C-B)){
            ans += A;
        }else{
            ans = B+C; 
        }
        if((C - B - A) >= 1){
            ans += 1;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Asum = sum(A) % (10**9 + 7)
ans = 0

for i in range(N):
  ans += A[i] * (Asum-A[i]) % (10**9 + 7)
  Asum -= A[i]

print(ans % (10**9 + 7))

Measured memory_bytes: 31612
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner (System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] c = new int[N];
		int[] t = new int[N];
		int p = 1001;
		for (int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			if ((t[i] <= T) && (c[i] < p)) {
				p = c[i];
			}
		}
		if (p == 1001) {
			System.out.println("TLE");
		}else{
			System.out.println(p);
		}
	}
}

Measured memory_bytes: 23508
X,N = map(int,input().split( ))
p = set(list(map(int,input().split( ))))
all_num_plus = {i for i in range(1,501)}
all_num_minus = {-i for i in range(0,501)}
all_num = all_num_plus | all_num_minus
ans = 1000
ans_num = 1000
for i in list(all_num - p):
    if abs(X - i) < ans_num:
        ans_num = abs(X-i)
        ans = i
    elif abs(X-i) == ans_num and i < ans :
        ans_num = abs(X-i)
        ans = i
print(ans)

Measured memory_bytes: 9320
#include <stdio.h>

int main(void)
{
	
	int t[5], ja[3];
	int i;
	
	while (1){
		
		for (i = 0; i < 3; i++){
			ja[i] = 0;
		}
		
		for (i = 0; i < 5; i++){
			scanf("%d", &t[i]);
			if (t[i] == 0){
				break;
			}
			ja[t[i] - 1]++;
		}
		
		if (t[i] == 0){
			break;
		}
		
		
		
		if ( (ja[0] == 5 || ja[1] == 5 || ja[2] == 5) || (ja[0] > 0 && ja[1] > 0 && ja[2] > 0) ){
			for (i = 0; i < 5; i++){
				t[i] = 3;
			}
		}
		else if (ja[0] > 0 && ja[1] > 0){
			for (i = 0; i < 5; i++){
				
				if (t[i] == 1) t[i] = 1;
				
				else t[i] = 2;
			}
			
		}
		else if (ja[1] > 0 && ja[2] > 0){
			for (i = 0; i < 5; i++){
				
				if (t[i] == 2) t[i] = 1;
				
				else t[i] = 2;
			}
		}
		else{
			for (i = 0; i < 5; i++){
				
				if (t[i] == 3) t[i] = 1;
				
				else t[i] = 2;
			}
		}
		
		printf("%d\n%d\n%d\n%d\n%d\n", t[0], t[1], t[2], t[3], t[4]);
		
	}
	
	return (0);
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> v(N);
  for(ll i = 0LL; i < N; i++){
    ll x;
    cin>>x;
    v[i]=x-1LL;
  }
  ll ans = 0LL;
  vector<ll> B(M*2LL,0LL);
  for(ll i = 0; i < N-1LL; i++){
    if(v[i]<v[i+1]) {
      ans+=v[i+1]-v[i];
      if(v[i+1]-v[i]<2LL) continue;
      B[v[i]+2]++;
      B[v[i+1]+1]--;
    }
    if(v[i]>v[i+1]){
      ans+=v[i+1]+M-v[i];
      if(v[i+1]+M-v[i]<2LL) continue;
      B[v[i]+2LL]++;
      B[v[i+1]+M+1]--;
    }
  }
  for(ll i = 1LL; i < M*2LL; i++){
    B[i]=B[i-1]+B[i];
  }
  for(ll i = 0; i < N-1LL; i++){
    if(v[i]<v[i+1]) {
      if(v[i+1]-v[i]<2LL) continue;
      B[v[i+1]+1]-=v[i+1]-v[i]-1;
    }
    if(v[i]>v[i+1]){
      if(v[i+1]+M-v[i]<2LL) continue;
      B[v[i+1]+M+1]-=v[i+1]+M-v[i]-1;
    }
  }
  for(ll i = 1LL; i<M*2LL; i++){
    B[i]=B[i-1]+B[i];
  }
  vector<ll> A(M);
  for(ll i = 0LL; i < M;i++){
    A[i]=B[i]+B[i+M];
  }
  ll t = 0LL;
  for(auto x:A) {
    chmax(t,x);
  }
  ans-=t;
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
long long f[45]={2};
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1]*2+2;
	}
	cout<<f[n];
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;
typedef map<string,int> dict;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}


double EPS = 1e-10;
double add(double a, double b){
  if(abs(a+b) < EPS* (abs(a) + abs(b))) return 0;
  return a+b;
}

struct P{
  double x,y;
  P(){}
  P(double _x,double _y):x(_x),y(_y){}
  P operator + (P p){
    return P(add(x,p.x) ,add(y,p.y));
  }
  P operator - (P p){
    return P(add(x,-p.x) ,add(y,-p.y));
  }
  P operator * (double d){
    return P(x * d,y * d);
  }
  double dot(P p){
    return add(x * p.x,y*p.y);
  }
  double det(P p){
    return add(x*p.y,-y*p.x);
  }
};
//???????????????????????¨?????????
bool on_seg(P p1,P p2,P q){
  return (p1-q).det(p2-q) == 0 && (p1-q).dot(p2-q) <= 0;
}
//???????°????
P intersection(P p1, P p2, P q1,P q2){
  return p1 + (p2-p1) * ((q2 - q1).det(q1-p1) / (q2 - q1).det(p2-p1)) ;
}

bool cmp_x(const P& p, const P& q){
  if(p.x != q.x) return p.x < q.x;
  return p.y < q.y;
}
void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
vector<P> convex_hull(P *ps,int n){
  sort(ps,ps+n,cmp_x);
  int k = 0;
  vector<P> qs(n*2);
  rep(i,n){
    while(k > 1 && (qs[k-1] -qs[k-2]).det(ps[i] - qs[k-1]) <= 0){
      k--;
    }
    qs[k++] = ps[i];
  }
  for(int i = n-2,t = k; i >= 0; i--){
    while(k>t && (qs[k-1] - qs[k-2]).det(ps[i]-qs[k-1]) <= 0){
      k--;
    }
    qs[k++] = ps[i] ;
  }
  qs.resize(k-1);
//   cout << n-qs.size() << endl;
  Ans(n-qs.size() == 0);
  return qs;
}

double dist(P p,P q){
  return (p - q).dot(p - q);
}

constexpr int MAX_N = 5;
P ps[MAX_N];
void Solve(){
  vector<P> qs = convex_hull(ps,4);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c;
  while(cin >> ps[0].x >>c >> ps[0].y >> c >> ps[1].x >> c >> ps[1].y >>c >> ps[2].x >> c >> ps[2].y >> c >>ps[3].x>>c>>ps[3].y){
    Solve();
    }
  return 0;
}

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

using namespace std; 


int main(){
	
	int a,b,k;
	
	cin >> a >> b >> k;
	vector<int> v;
	
	for(int i=100; i>=1;i--){
			if(a%i==0 && b%i==0){
				v.push_back(i);
			}
	}
	
	cout << v[k-1] << endl;
	
	
	
		
    return 0;
}


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


int main(){
   
    string S;
    int N;
    char tmp;
    int sum = 0;
    cin >> S;
    N = S.size();
    sum = 1;
    tmp = S[0];
    for(int i = 1; i < N; ++i){
        if(S[i] != tmp){
            sum ++;
            if(tmp == '#'){
                tmp = '.' ;
            }else{
                tmp = S[i];
            }
        }else{
            tmp = '#';
        }
        
    }
    cout <<sum<<endl;
    return 0;
    

}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
	int i,n,k,m,a[100010];
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	if((n-1)%(k-1)==0){
		cout << (n-1)/(k-1) << endl;
	}else{
		cout << (n-1)/(k-1) + 1 << endl;
}}

Measured memory_bytes: 640
def main():
    n, k, s = map(int, input().split())

    ans = [(10 ** 9 if s != 10 ** 9 else 10 ** 9 - 1) for _ in range(n)]
    for i in range(k):
        ans[i] = s

    print(' '.join([str(x) for x in ans]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 12056
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin>>n;
	vector<lint> v(n);
	lint s=0;
	for(lint &x:v){cin>>x;s+=x;}
	
	lint s2=0;
	lint ans = s;
	for(int i=0;i<n;i++){
		s2 += v[i];
		s -= v[i];
		cerr<<s-s2<<"\n";
		ans = min(ans, abs(s-s2));
	
	}	
	cout<<ans<<"\n";

	return 0;	
}


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

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

const LL INF=300000000;
const LL MOD=1000000007;



int main(){
    int n,m;
    cin>>n>>m;
    LL a[50],b[50],c[50],d[50];
    for(int i=0;i<n;++i){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<m;++i){
        cin>>c[i]>>d[i];
    }
    
    for(int i=0;i<n;++i){
        LL ans=INF; int p=-11;
        for(int j=0;j<m;++j){
            if(abs(a[i]-c[j])+abs(b[i]-d[j])<ans){
                ans=abs(a[i]-c[j])+abs(b[i]-d[j]);
                p=j+1;
            }
        }
        cout<<p<<"\n";
    }

    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string s,s1="AAA",s2="BBB";
    cin>>s;
    if(s==s1){
        cout<<"No"<<endl;
    }
    else if(s==s2){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    let mut r = 0;
    let mut b = 0;
    for i in 0..n {
        if s[i] == 'R' {
            r += 1;
        } else {
            b += 1;
        }
    }
    println!("{}", if r > b {"Yes"} else {"No"});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  int p;
  double n, m;
  std::vector<int> vec;
  std::cin >> n >> m;

  for(int i = 0; i<n; i++){
    std::cin >> p;
    vec.push_back(p);
  }

  int sum = std::accumulate(vec.begin(), vec.end(), 0);
  double thr = sum / (4 * m);
  std::sort(vec.begin(), vec.end(), std::greater<int>() );
  int count = 0;

  for(int i = 0; i<m; i++){
    if(thr <= vec[i]){
      count += 1;
    }
  }
  if(count >= m){
    std::cout << "Yes" <<std::endl;
  }else{
    std::cout << "No" <<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
/**
 *      AGC 6 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-11 04:03:17
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int64 long long
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    string s, t; cin >> s >> t;

    for (auto i = 0; i < N; ++i) {
        string temps = s.substr(i, N - i);
        string tempt = t.substr(0, N - i);
        if (temps == tempt){
            cout << 2 * N - (N - i) << endl; return 0;
        }
    }
    cout << 2 * N << endl; 
    
    return 0;
}

Measured memory_bytes: 256