akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n;
	while(scanf("%d", &n),n){
		int cnt = 0;
		for(int i = 1; i < 200; i++){
			if(i*i == n) cnt++;
		}
		for(int i = 1; i < 200; i++){
			for(int j = i; j < 200; j++){
				if(i*i+j*j==n) cnt++;
			}
		}
		for(int i = 1; i < 200; i++){
			for(int j = i; j < 200; j++){
				for(int k = j; k < 200; k++){
					if(i*i+j*j+k*k == n) cnt++;
				}
			}
		}
		for(int i = 1; i < 200; i++){
			if(i*i*4 > n) break;
			for(int j = i; j < 200; j++){
				if(i*i+j*j*3 > n) break;
				for(int k = j; k < 200; k++){
					if(i*i+j*j+k*k*2 > n) break;
					for(int l = k; l < 200; l++){
						if(i*i+j*j+k*k+l*l==n) cnt++;
						if(i*i+j*j+k*k+l*l > n) break;
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int r = input(), D = input(), x = input();
  range(i, 0, 10) {
    x = r * x - D;
    cout << x << endl;
  }
}

signed main(int argc, char *argv[]) {
  solver();
}


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

int main(){
    int N,M;
    cin >> N >> M;
    
    int L[100001];
    int R[100001];
    for(int i = 0;i < M;i++){
        cin >> L[i] >> R[i];
    }
    
    sort(L,L + M);
    sort(R,R + M);
    
    if(R[0] - L[M - 1] >= 0) cout << R[0] - L[M - 1] + 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 1024
X, N=map(int, input().split())
p = list(map(int, input().split()))
ans=X


min= 100

p.sort()

for i in range(-200, 201):
  if (i not in p ) and len(p) > 0:
    a = abs(i-X)
    if a<min:
      min=a
      ans = i
print(ans)

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto&& x:a)cin>>x;
  vector<int> b(n+1, 0);
  a.insert(a.begin(), 0);
  for(int i=n;i>=1;--i){
    int f = 0;
    for(int j=2;i*j<=n;j++){
       f ^= b[i*j];
    }
    b[i] = f ^ a[i];
  }
  int k = 0;
  for(auto&& x:b)k += x;
  cout << k << endl;
  for(int i=1;i<=n;i++)if(b[i] == 1)cout << i << " ";
  cout << endl;
}

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e10+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}


void solve() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    map<int, int> M;
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += M[i-a[i]];
        M[i+a[i]]++;
    }
    cout << ans << endl;
}


signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;

    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}


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

int main()
{
  int x, y;
  cin >> x >> y;
  if (x < y)
  {
    swap(x, y);
  }
  int d;
  while (y != 0)
  {
    d = y;
    y = x % d;
    x = d;
  }
  cout << d << endl;
}


Measured memory_bytes: 3088
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define N 100100
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(x, a, b) for(int x=a; x<=b; x++)
#define drp(x, a, b) for(int x=a; x>=b; x--)
int st[N<<1], deg[N], d[N], n, vis[N], a[N], tot, num[N], l[N], ans=1, fac[N], inv[N];
typedef long long LL;

int power(int x, int y){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % mod) if(y & 1) an = (LL)an * x % mod;
	return an;
}

int C(int x, int y){
	if(x < 0 || y < 0 || x < y) return 0;
	return (LL)fac[x] * inv[y] % mod * inv[x - y] % mod;
}

void renew(int &x, const int y){
	x += y;
	if(x < 0) x += mod;
	if(x >= mod) x -= mod;
}

void init(){
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	rep(i, 2, n){
		fac[i] = (LL)fac[i - 1] * i % mod;
		inv[i] = power(fac[i], mod - 2);
	}
}

int getdp(){
	int fr = 0;
	rep(i, 1, tot) st[i + tot] = st[i];
	rep(i, 1, tot) if(l[st[i]]){
		fr = i;
		break;
	}
	reverse(st + fr + 1, st + fr + tot);
	int a = fr + l[st[fr]] - 1, b = a + 1, c = 1;
	rep(i, fr + 1, fr + tot - 1)if(l[st[i]]){
		int na = i + l[st[i]] - 1, nb = na + 1, cc = 0;
		if(a < i) renew(cc, c);
		if(b < i) renew(cc, c);
		a = na;
		b = nb;
		c = cc;
	}
	int ans = 0;
	if(a < fr + tot) renew(ans, c);
	if(b < fr + tot) renew(ans, c);
	return ans;
}

int que[N], h, t;
int main(){
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", a + i);
	rep(i, 1, n){
		deg[a[i]] ++;
		if(deg[a[i]] > 2){ puts("0"); exit(0); }
	}
	rep(i, 1, n) d[i] = deg[i];
	rep(i, 1, n) if(!d[i]) que[++t] = i;
	rep(h, 1, t){
		int u = que[h];
		--d[a[u]];
		vis[u] = 1;
		if(!d[a[u]]) que[++t] = a[u];
	}
	rep(i, 1, n) if(vis[i] && deg[i] >= 2){
		puts("0");
		exit(0);
	}
	rep(i, 1, n) if(vis[i] && !deg[i]){
		int x = i, cnt = 0;
		for(x = i; vis[x]; x = a[x])cnt++;
		l[x] = cnt;
	}
	init();
	ans=1;
	rep(i, 1, n)if(!vis[i])
	{
		int u = i, cu = 1;
		tot = 0;
		int res = 0;
		do{
			st[++tot] = u;
			cu &= !l[u];
			vis[u] = 1;
			u = a[u];
		}while(u != i);
		if(cu){
			num[tot] ++;
			res = 1;
		}else{
			res = getdp();		
		}
		ans = (LL)ans * res % mod;
	}
	rep(i, 1, n) if(num[i])
	{
		int tot = num[i];
		int res = 0;
		for(int x = 0; x <= tot; x += 2){
			int cb = 1;
			cb = (LL)cb * power(i, (x >> 1)) % mod;
			cb = (LL)cb * C(tot, x) % mod;
			cb = (LL)cb * fac[x] % mod;
			cb = (LL)cb * inv[x >> 1] % mod;
			cb = (LL)cb * power((mod + 1) >> 1, x >> 1) % mod;
			if((i > 1) && (i & 1)){
				cb = (LL)cb * power(2, tot - x) % mod;
			}
			renew(res, cb);
		}
		ans = (LL)ans * res % mod;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3584
from fractions import gcd
from functools import reduce
n = int(input())
A = list(map(int,input().split()))

mod = 10 ** 9 + 7
lcm = reduce(lambda x,y: x*y//gcd(x,y), A)
# print(lcm)
ans = sum(lcm//x for x in A)
ans %= mod
print(ans)

Measured memory_bytes: 6140
/* DELAPAN.3gp */
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;

#ifdef DEBUG
	#define debug(...) printf(__VA_ARGS__)
	#define GetTime() fprintf(stderr,"Running time: %.3lf second\n",((double)clock())/CLOCKS_PER_SEC)
#else
	#define debug(...) 
	#define GetTime() 
#endif

//type definitions
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vint;

//abbreviations
#define A first
#define B second
#define MP make_pair
#define PB push_back

//macros
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n)-1; 0 <= i; --i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); (b) <= i; --i)
#define FORIT(it,c) for (__typeof ((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define RESET(a,x) memset(a,x,sizeof(a))
#define EXIST(a,s) ((s).find(a) != (s).end())
#define MX(a,b) a = max((a),(b));
#define MN(a,b) a = min((a),(b));

inline void OPEN(const string &s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

/* -------------- end of DELAPAN.3gp's template -------------- */

int n, a[100100];

int main(){
	scanf("%d", &n);
	FOR(i, 1, n) {
		scanf("%d", &a[i]);
	}
	ll ans = 0;
	ll temp = 0;
	FOR(i, 1, n) {
		if (a[i] == 0) {
			ans += temp / 2LL;
			temp = 0;
		} else {
			temp += a[i];
		}
	}
	ans += temp / 2LL;

	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(a); sll(b); sll(c);
	LL res = a * (100*b + c);
	pll((res/100)); nl;
}


Measured memory_bytes: 3752
N=int(input())
arr=[]
for i in range(N-1):
    arr.append(list(map(int,input().split())))

for i in range(N-1):
    t=arr[i][0]+arr[i][1]
    #print('station No',i)
    for j in range(N-1-i-1):
        #print('arrive',t)
        c,s,f=arr[i+j+1][0],arr[i+j+1][1],arr[i+j+1][2]
        t=max(s,((t-s-1)//f+1)*f+s)
        #print(c,s,f)
        #print(t)
        #print('deperture',t)
        t+=c
        #print('arrive next',t)
    print(t)
print(0)

Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>

#define rep(i, n) for (int i = 0; i < n; i++) 
#define rrep(i, n) for(int i = n-1; i>=0; i--)
#define range(i, n, m) for (int i = n; i < m; i++) 
#define rrange(i, n, m) for (int i = n - 1; i => m; i--) 
#define MOD 1000000007
#define MAX 20000000000

typedef long long int ll;
typedef unsigned long long int ull;


using namespace std;

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


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

	ll N, M;

	cin >> N;
	vector<ll> H(150, 0);

	rep(i, N) {
		cin >> H[i];
	}


	ll count = 0;
	bool flg = false;
	rep(i, N) {
		flg = true;
		rep(k, i) {
			if (H[k] > H[i]) {
				flg = false;
			}
		}
		if (flg)count++;
	}


	cout << count << endl;

	
	return 0;
}


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

static const int N = 3;
static const char dir[4] = {'r', 'l', 'u', 'd'};

class Puzzle {
 public:
  int v[N*N];
  string path;
  int space_pos;

  bool operator < (const Puzzle &p) const {
    for (int i = 0; i < N*N; i++) {
      if (v[i] == p.v[i]) continue;
      return v[i] < p.v[i];
    }
    return false;
  }
};

bool isTarget(Puzzle& p) {
  for (int i = 0; i < N*N; i++) {
    if (p.v[i] != ((i+1) % (N*N))) {
      return false;
    }
  }
  return true;
}

string bfs(Puzzle& p) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  p.path = "";
  Q.push(p);
  V[p] = true;
  Puzzle new_u;
  while(!Q.empty()) {
    Puzzle u = Q.front();
    Q.pop();
    if (isTarget(u)) {
      return u.path;
    }
    if (u.space_pos % 3 != 2) {
      new_u = u;
      swap(new_u.v[u.space_pos], new_u.v[u.space_pos+1]);
      new_u.space_pos = u.space_pos+1;
      if (!V[new_u]) {
        V[new_u] = true;
        new_u.path += dir[0];
        Q.push(new_u);
      }
    }
    if (u.space_pos % 3 != 0) {
      new_u = u;
      swap(new_u.v[u.space_pos], new_u.v[u.space_pos-1]);
      new_u.space_pos = u.space_pos-1;
      if (!V[new_u]) {
        V[new_u] = true;
        new_u.path += dir[1];
        Q.push(new_u);
      }
    }
    if (u.space_pos / 3 != 0) {
      new_u = u;
      swap(new_u.v[u.space_pos], new_u.v[u.space_pos-N]);
      new_u.space_pos = u.space_pos-N;
      if (!V[new_u]) {
        V[new_u] = true;
        new_u.path += dir[2];
        Q.push(new_u);
      }
    }
    if (u.space_pos / 3 != 2) {
      new_u = u;
      swap(new_u.v[u.space_pos], new_u.v[u.space_pos+N]);
      new_u.space_pos = u.space_pos+N;
      if (!V[new_u]) {
        V[new_u] = true;
        new_u.path += dir[3];
        Q.push(new_u);
      }
    }
  }
}


int main() {
  Puzzle p;
  for (int i = 0; i < N*N; i++) {
    cin >> p.v[i];
    if (!p.v[i]) p.space_pos = i;
  }
  cout << bfs(p).size() << endl;
  return 0;
}



Measured memory_bytes: 33508
// I need some holiday
// But I don't wish that everyday is holiday
// Because I didn't bear the pain
// Because it wasn't a true freedom
//         ——『イヤホンと蝉時雨』·Orangestar

#include <bits/stdc++.h>

using namespace std;

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

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return cur == ed && (ed = (cur = buffer) + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur == ed) ? EOF : *cur++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

inline char *read_str(char *s)
{
	register char ch(getc());
	while(!isgraph(ch)) ch = getc();
	for(; isgraph(ch); ch = getc()) *s++ = ch;
	*s = '\0';
	return s;
}

// END tpl.

const int MAXN = (int) 5e3;

int n;

char s[MAXN + 5], t[MAXN + 5];

inline void input()
{
	n = read<int>();
	read_str(s + 1);
	read_str(t + 1);
}

inline void solve()
{
	if(n <= 2)
	{
		int ans = 0;
		for(int i = 1; i <= n; ++i) ans += s[i] != t[i];
		printf("%d\n", ans);
		return;
	}

	static int a[MAXN + 5], b[MAXN + 5];

	int cnta[2] = {0, 0}, cntb[2] = {0, 0};
	for(int i = 1; i < n; ++i)
	{
		if(s[i] != s[i + 1]) ++cnta[a[i] = s[i] == '0' ? 0 : 1]; else a[i] = -1;
		if(t[i] != t[i + 1]) ++cntb[b[i] = t[i] == '0' ? 0 : 1]; else b[i] = -1;
	}

	auto calc = [cnta, cntb] (int d)
	{
		static vector<int> A, B;
		A.clear();
		B.clear();

		for(int i = 1; i < n; ++i) if(a[i] == d) A.push_back(i);

		for(int i = 1; i <= n; ++i) B.push_back(0);
		for(int i = 1; i < n; ++i) if(b[i] == d) B.push_back(i);
		for(int i = 1; i <= n; ++i) B.push_back(n);

		int ans = INT_MAX;
		for(int i = 0; i + SZ(A) < SZ(B); ++i)
		{
			int res = 0;
			for(int j = 0; j < i; ++j) res += B[j];
			for(int j = 0; j < SZ(A); ++j) res += abs(A[j] - B[i + j]);
			for(int j = i + SZ(A); j < SZ(B); ++j) res += abs(n - B[j]);
			chkmin(ans, res);
		}
		return ans;
	};

	printf("%d\n", calc(0) + calc(1));
}

int main()
{
#ifdef K_ON
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
string S;
cin >> S ;
int n = S.size();
string ans = "AC";
if(S[0] != 'A') ans = "WA";
int cnt = 0;
for(int i = 1; i < n ; i++){
    if(isupper(S[i])){
        if(i == 1 || i == n-1 || S[i] !='C'){
            ans = "WA";
        }
        ++cnt;
    }
    
}
if(cnt !=1){
    ans = "WA";
}
cout << ans << endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
as = Array.new(n+10, 1)
m.times do
  a = gets.to_i
  as[a] = 0
end
ss = []
cur = 0
(0..n).each do |i|
  if as[i] == 0 && as[i+1] == 0
    puts 0
    exit
  end

  if as[i] == 1
    cur += 1
  else
    ss << cur unless cur == 0
    cur = 0
  end
end
ss << cur

dp = Array.new(n+10)
dp[0] = 0
dp[1] = 1
(2..n+2).each do |i|
  dp[i] = dp[i-1] + dp[i-2]
end

ans = 1
# puts ss.inspect
# puts dp.inspect
ss.each do |s|
  ans = ans * dp[s] % (10 ** 9 + 7)
end
puts ans


Measured memory_bytes: 434228
#include <bits/stdc++.h>
//#include "Header.h"

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}}
    return C[n][k];
 }

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

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}


int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
// code now
   
    ll n,k;
    cin>>n>>k;
    if(n==0){cout<<binomialCoeff(k, 2);return 0;}
    if(k==0){cout<<binomialCoeff(n, 2);return 0;}
    if(n==1&&k==1){cout<<0;return 0;}
    if(n>1&&k==1){cout<<binomialCoeff(n, 2);return 0;}
    if(n==1&&k>1){cout<<binomialCoeff(k, 2);return 0;}
    ll j=binomialCoeff(n, 2)+binomialCoeff(k, 2);
    cout<<j;
    
    
    
//code ends
    return 0;
}


Measured memory_bytes: 256
//
// Created by mustafa on 17/07/19.
//
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std ;

#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define all(v)  v.begin() , v.end()
#define Start while(TCF--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define FastInputOutput ios_base :: sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ;
#define ReadFromFile(x)  freopen( x, "rt" , stdin ) ;
#define WriteToFile(x)  freopen( "in.txt", "wt" , stdout ) ;
#define D(x) scanf("%d",&x);
#define LLD(X) scanf("%lld",&x);
#define in(x,...) scanf(x,__VA_ARGS__)
#define out(x,...) printf(x,__VA_ARGS__)
/// for debugging
string to_string(string s) {return '"' + s + '"';}string to_string(const char* s) {return to_string((string) s);}string to_string(bool b) {return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) {}
#endif
/// start driven program
int mod(int k, int n){
    return ((k %= n) < 0) ? k+n : k;
}

const int N=1e6+7  , MOD= 1e9+7;
int n,k,v;
bool ok(int val){
    ll sum=(1ll*val*(val+1))/2;
    if(val+(sum-k) == n){
        return true;
    }
    return false;
}
int frq[1000+7];
int main(){
    submitStage Start {
        char arr[5][5];
        scanf(" %s",arr[0]);
        scanf(" %s",arr[1]);
        scanf(" %s",arr[2]);
        printf("%c%c%c",arr[0][0],arr[1][1],arr[2][2]);
    }
}

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

const int MAX = 1e5+5;

const int MOD = 1e9 + 7;

int  n , k;

ll ans;

vector<int>edg[MAX];


void dfs(int node,  int par) {

    
    int tmp = k-1;
    
    
    if(par != 0 ) tmp--;
    
    
    for(auto x : edg[node]) {
        
        if( x == par)  continue;
        
        ans = (ans * tmp ) %MOD;
        
        tmp--;
        
        dfs(x , node);
    }
    
}


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

    cin>>n>>k;
    
    for(int i =0 ; i < n -1 ; i++) {
        int u , v;
        cin>>u>>v;
        edg[u].push_back(v);
        edg[v].push_back(u);
    }
    
    ans = k;
    dfs(1 , 0);
    cout<<ans<<endl;
    return 0;
}

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

long long ways(int n) {
   return (n * 1LL * (n - 1)) / 2;
}

int main() {

   ios_base::sync_with_stdio(0);
   cin.tie(0); 

   int n;
   cin >> n;

   vector <int> col(n);
   map <int, int> colCount;
   for(int i = 0; i < n; i++) {
      cin >> col[i];
      colCount[col[i]]++;
   }

   long long ans = 0;
   for(auto e: colCount) {
      ans += ways(e.second);
   }

   for(int i = 0; i < n; i++) {
      long long cur = ans;
      cur += ways(colCount[col[i]] - 1) - ways(colCount[col[i]]);
      cout << cur << endl;
   }
   
   return 0;
}

Measured memory_bytes: 8320
m = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
    m[i] = list(map(int, input().split()))

a1 = a2 = a3 = 0
b1, b2, b3 = m[0]
a2 = m[1][0] - b1
a3 = m[2][0] - b1

if ((m[1][1] != a2 + b2) or
    (m[1][2] != a2 + b3) or
    (m[2][1] != a3 + b2) or
    (m[2][2] != a3 + b3)):
    print('No')
else:
    print('Yes')

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    vector<ll> dp(k+1,2);
    vector<ll> V(n);
    for(ll i=0;i<n;i++){
        cin>>V[i];
    }
    for(ll i=1;i<=k;i++){
        for(ll j=0;j<n;j++){
            if(V[j] > i){
                break;
            }
            if(dp[i-V[j]] == 2){
                dp[i] = 1;
                break;
            }
        }
    }
    if(dp[k] == 2){
        cout<<"Second"<<endl;
    }
    else{
        cout<<"First"<<endl;
    }
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void) {
	int i=0;
	int j = 0;
	char ID[99];
	char T[99];
	scanf("%s", ID);
	scanf("%s",T);
	while (ID[i] != '\0') {
		if (ID[i]==T[i]) {
			j++;
	}
		i++;
	}
	if (j == i) {
		printf("Yes");
	}
	else {
		printf("No");

	}
return 0;
}

Measured memory_bytes: 2152
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,m = LI()
        if n == 0 and m == 0:
            break
        a = [LI() for _ in range(m)]
        a.sort()
        u = set([1])
        for t,s,d in a:
            if s in u:
                u.add(d)

        rr.append(len(u))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 17788
#include <stdio.h>

int main(){
    char op;
    int a, b;
    
    while(scanf("%d %c %d", &a, &op, &b), op != '?'){
        
        switch(op){
        case '+':
            printf("%d\n", a + b);
            break;
        
        case '-':
            printf("%d\n", a - b);
            break;
        
        case '*':
            printf("%d\n", a * b);
            break;
        
        case '/':
            printf("%d\n", a / b);
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 2752
/*
  ????????±????\????????±???????
 */

#include <iostream>
#include <vector>

using namespace std;

#define MAX_V 100000
#define MAX_LOG_V 100

vector<int> G[MAX_V];
int root;
int deg[MAX_V];

int parent[MAX_LOG_V][MAX_V];  
int depth[MAX_V];

void dfs(int v, int p, int d)
{
    parent[0][v] = p;
    depth[v] = d;
    for (int i = 0; i < (int)G[v].size(); i++) { 
	if(G[v][i] != p) {
	    dfs(G[v][i], v, d+1);
	}
    }
}

int getRoot(int V)
{
    for (int i = 0; i < V; i++) {
	if (deg[i] == 0) {
	    return i;
	}
    }
    return -1;
}

void init(int V)
{
    root = getRoot(V);
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
	for (int v = 0; v < V; v++) {
	    if (parent[k][v] < 0) {
		parent[k+1][v] = -1;
	    } else {
		parent[k+1][v] = parent[k][parent[k][v]];
	    }
	}
    }
}

int lca(int u, int v)
{
    if(depth[u] > depth[v]){
	swap(u, v);
    }
    for (int k = 0; k < MAX_LOG_V; k++) {
	if ((depth[v] - depth[u]) >> k & 1) {
	    v = parent[k][v];
	}
    }
    if (u == v) {
        return u;
    }
    for (int k = MAX_LOG_V-1; k >= 0; k--) {
	if (parent[k][u] != parent[k][v]) {
	    u = parent[k][u];
	    v = parent[k][v];
	}
    }
    return parent[0][u];
}

int main()
{
    int N, K, x;
    cin >> N;
    for (int i = 0; i < N; i++) {
	cin >> K;
	for (int j = 0; j < K; j++) {
	    cin >> x;
	    G[i].push_back(x);
	}
    }
    init(N);
    int Q, a, b;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
	cin >> a >> b;
	cout << lca(a, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 52604
#include <stdio.h>
#include <math.h>

int main(void){

  int a,b;
  scanf("%d%d",&a,&b);
  
  int n=0;
  int e=b;
  while(e!=0){
  	e = e/10;
    ++n;
  //  printf("%d,%d",e,n);
  }
  
  int c = a*pow(10,n)+b;
  
  int d = sqrt(c);
 // printf("%d,%d,%d,%d\n",a,b,c,d);
  
  if(c==pow(d,2))
    printf("Yes");
  else
    printf("No");
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll max_sum(vector<ll>& a, int n, vector<vector<ll>>& b, int m) 
{ 
    sort(a.begin(), a.end()); 
    vector<pair<int, int> > B; 
    for (int i = 0; i < m; i++) 
        B.push_back({ b[i][1], b[i][0] }); 
  
    sort(B.rbegin(), B.rend()); 
  
    int left = 0; 
  
    for (int i = 0; i < m; i++) { 
        ll x = B[i].first, y = B[i].second; 
  
        for (int j = 0; j < y; j++) { 
            if (a[left] < x) { 
                a[left] = x; 
                left++; 
  
                if (left == n) 
                    break; 
            } 
            else
                break; 
        } 
    } 
  
    ll ans = 0; 
    for (int i = 0; i < n; i++) 
        ans += a[i]; 
  
    return ans; 
} 
int main() {
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n);
	vector<vector<ll>> b(m, vector<ll>(2));
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<m; i++) cin>>b[i][0] >> b[i][1];
	cout<<max_sum(a,n,b,m);
	return 0;
}

Measured memory_bytes: 7800
import java.io.*;
        import java.math.BigDecimal;
        import java.math.BigInteger;
        import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] A = new int[N];
        Integer[] index = new Integer[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
            index[i] = i;
        }
        Arrays.sort(index, Comparator.comparingInt(i -> -A[i]));
        long[][] dp = new long[N + 1][N + 1];
        for (int n = 0; n < N; n++) {
            for (int i = 0; i <= n; i++) {
                dp[n + 1][i] = Math.max(dp[n + 1][i], dp[n][i] + ((long)A[index[n]]) * Math.abs(N - 1 - n + i - index[n]));
                dp[n + 1][i + 1] = dp[n][i] + ((long)A[index[n]]) * (index[n] - i);
            }
        }
        long max = 0;
        for (int n = 0; n <= N; n++) {
            max = Math.max(max, dp[N][n]);
        }
        out.println(max);
        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}

Measured memory_bytes: 84200
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


#include <math.h>  /* M_PI */

int main(){

    double r;
    cin >> r;


    printf("%.5f\n", 2* r * M_PI);
}

Measured memory_bytes: 3784
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

const int MAX = 11;

int H,W;
char m[MAX][MAX];

string res;

class P{
public:
  int x,y,d;
  P(int x,int y,int d):x(x),y(y),d(d){};
  P(){};
  bool operator==(const P &p)const{
    return p.x == x && p.y == y && p.d == d;
  }
};

char conv[4] = {'U','R','D','L'};
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};


P no(-1,-1,-1);
bool f;

P func(P s){
  
  while(1){
    if(m[s.y][s.x] == 'o')return s;
    if(!(0 <= s.x && s.x < W))return no;
    if(!(0 <= s.y && s.y < H))return no;
    
    s.x = s.x + dx[s.d];
    s.y = s.y + dy[s.d];
  }
}


void dfs(P s,int cnt){
  P np;

  if(cnt == 0){
    f = true;
    return;
  }
  
  for(int i = 0 ; i < 4 ; i++){
    if((s.d + 2)%4 == i)continue;
    np = func(P(s.x + dx[i],s.y + dy[i],i));
    if(np == no)continue;
    m[np.y][np.x] = '.';
    dfs(np,cnt-1);
    m[np.y][np.x] = 'o';
    if(f){
      res += conv[np.d];
      return;
    }
  }
}

int main(){
  cin >> H >> W;
  P s;
  int cnt = 0;
  f = false;

  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> m[i][j];
      if(m[i][j] == 'U')s = P(j,i,0);
      else if(m[i][j] == 'R') s = P(j,i,1);
      else if(m[i][j] == 'D') s = P(j,i,2);
      else if(m[i][j] == 'L') s = P(j,i,3);
      else if(m[i][j] == 'o') cnt++;
    }
  }
  dfs(s,cnt);
  reverse(res.begin(),res.end());
  cout << res << endl;
  return 0;
}

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

#define endl '\n'

// #define int long long

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007; // 998244353

signed main() {  
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   int a, b;
   cin >> a >> b;
   string str_a = "";
   string str_b = "";
   for (int i = 0; i < b; i++)
      str_a += a + '0';
   for (int i = 0; i < a; i++)
      str_b += b + '0';
   if (str_a < str_b)
      cout << str_a << endl;
   else
      cout << str_b << endl;  
   return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N + 1];
        for (int i = 1; i <= N; ++i) {
            x[i] = sc.nextInt();
        }

        long[][][] dp = new long[N + 1][N + 1][N * A + 1];
        for (int i = 0; i < N; ++i) {
            dp[i][0][0] = 1;
        }

        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= i; ++j) {
                for (int k = 1; k <= N * A; ++k) {
                    if (k < x[i]) {
                        dp[i][j][k] = dp[i - 1][j][k];
                    } else {
                        dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
                    }
                }
            }
        }

        long ans = 0;
        for (int j = 1; j <= N; ++j) {
            ans += dp[N][j][j * A];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 84416
#include<iostream>
//#include<string>
//#include<stack>/*** LIFO *** stack<type> var;
//push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
//#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int X;
    cin >> X;
    int value[X] = {};
    if(X < 100){
        cout << 0 << endl;
        return 0;
    }else if(X <= 105){
        cout << 1 << endl;
        return 0;
    }else{
        Fp(i, 100 - 1, 105) value[i] = 1;
        Fp(i, 105, X){
            if(value[i - 100] || value[i - 101] || value[i - 102] || value[i - 103] || value[i - 104] || value[i - 105]) value[i] = 1;
        }
    }
    
    cout << value[X - 1] << endl;
    return 0;
}


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

const int mod = 1000000007;

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < 60; i++)
    {
        ll x = 0;
        for (int j = 0; j < n; j++)
        {
            if(((ll)1<<i & a[j] )){
                x++;
            }
        }
        ll now = x * (n - x)%mod;
        for (int j = 0; j < i; j++)
        {
            now = now * 2 % mod;
        }
        ans += now;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n = 0, flag = 1, a[100] = { 0 }, temp = 0, k = 0;

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	while (flag) {
		flag = 0;
		for (int j = n - 1; j > 0; j--) {
			if (a[j] < a[j - 1]) {
				temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
				k++;
				flag = 1;
			}
		}
	}

	for (int i = 0; i < n - 1; i++)
		cout << a[i] << " ";
	cout << a[n - 1] << endl;

	cout << k << endl;
		
	return 0;
}

Measured memory_bytes: 3080
import sys
input = sys.stdin.readline

N=int(input())
W=list(map(int,input().split()))

SUM=[0]
for w in W:
    SUM.append(SUM[-1]+w)

S=SUM[-1]

ANS=10**20

for i in range(N+1):
    ANS=min(ANS,abs((S-SUM[i])-SUM[i]))

print(ANS)

Measured memory_bytes: 3064
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll n;cin>>n;
  ll a,b;cin>>a>>b;
  ll ans=n/(a+b)*(a);
  n=n%(a+b);
  // cout<<n<<endl;
  
  ans+=min(n,a);
  cout<<ans<<endl;
  return false;
}


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[], int N){
    int i;
    for (i=0; i<N; i++){
        if( i>0 ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int j, i, v;
    for (i=1; i<N; i++){
        v = A[i];
        j = i - 1;
        while(j>=0 && A[j]>v){
            A[j+1] =A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, N);
    }
}

int main() {
    int N, i, j;
    int A[100];
    scanf("%d", &N);
    for (i=0; i<N; i++) scanf("%d", &A[i]);
    trace(A, N);
    insertionSort(A, N);
    return 0;
}





Measured memory_bytes: 2100
// https://atcoder.jp/contests/abc142/tasks/abc142_f

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 1500;
vector<int> path;
vector<pii> edges;
vector<vector<int>> cycles;
set<int> G[maxn];
int vis[maxn];
int N, M;

void dfs(int v) {
    // cerr << "currently on " << v << endl;
    vis[v] = 1;
    path.push_back(v);

    for(int to: G[v]) {
        if(vis[to] != 2) {
            if(vis[to] == 1) {
                // cerr << "hit cycle, back edge going to " << to << endl;
                cycles.emplace_back(vector<int>());
                int i = path.size()-1;
    
                while(path[i] != to) {
                    cycles.back().emplace_back(path[i]);
                    i--;
                }
                cycles.back().emplace_back(to);
            } else {
                dfs(to);
            }
        }
    }

    path.pop_back();
    vis[v] = 2;
}


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

    cin >> N >> M;

    for(int i = 1; i <= M; i++) {
        int a, b;
        cin >> a >> b;

        G[a].emplace(b);
        edges.emplace_back(a, b);
    }

    for(int i = 1; i <= N; i++) {
        if(!vis[i]) {
            dfs(i);
        }
    }

    // for(auto c: cycles) {
    //     for(int x: c) {
    //         cerr << x << " ";
    //     }
    //     cerr << endl;
    // }
    
    for(vector<int> c: cycles) {
        set<int> S;
        map<int, int> indeg, outdeg;

        for(int x: c) {
            S.emplace(x);
        }

        for(pii e: edges) {
            if(S.count(e.fi) and S.count(e.se)) {
                outdeg[e.fi]++;
                indeg[e.se]++;
            }
        }

        bool ok = true;
        for(int x: c) {
            if(!(outdeg[x] == 1 and indeg[x] == 1)) {
                ok = false;
            }
        }

        if(ok) {
            cout << c.size() << endl;
            for(int x: c) {
                cout << x << endl;
            }
            exit(0);
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 3976
import java.math.*;
import java.util.*;
class Main{
	public static void main(String[] args){
		String lis[]={"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok",
		"Ggs","Asg","Nyt","Fks","Mts"};
		BigInteger[] val=new BigInteger[18];
		val[0]=BigInteger.ONE;
		for(int i=1;i<18;i++)val[i]=val[i-1].multiply(new BigInteger("10000"));
		Scanner s=new Scanner(System.in);
		while(true){
			BigInteger a=s.nextBigInteger();
			int b=s.nextInt();
			if(b==0){
				break;
			}
			BigInteger ret=BigInteger.ONE;
			for(int i=0;i<b;i++)ret=ret.multiply(a);
			for(int i=17;i>=0;i--){
				BigInteger ks=ret.divide(val[i]);
				ret=ret.remainder(val[i]);
				if(!ks.equals(BigInteger.ZERO))System.out.print(ks.toString()+lis[i]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 20660
#include<cstdio>
using namespace std;
const int maxn=200005;
int n,a[maxn],L[maxn],R[maxn];
long long ans;
inline int read(){
	int ret=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return f?-ret:ret;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++)
	for (L[i]=i-1;a[L[i]]>a[i];L[i]=L[L[i]]);
	for (int i=n;i;i--)
	for (R[i]=i+1;a[R[i]]>a[i];R[i]=R[R[i]]);
	for (int i=1;i<=n;i++)
	ans+=1ll*a[i]*(i-L[i])*(R[i]-i);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    long N,K,Q,A,C;
    cin>>N>>K>>Q;
    long B[100000]={0};
    rep(0,i,Q){
        cin>>A;
        ++B[A-1];
    }
    rep(0,i,N){
        C=B[i]-Q+K;
        if(C>0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    res = 0
    for i in range(n):

        # A[i]の転倒数を求める
        x = 0
        for j in range(i + 1, n):
            if A[i] > A[j]:
                x += 1

        # A[i]より小さい数を求める
        y = 0
        for j in range(n):
            if A[i] > A[j]:
                y += 1

        res += x * k
        res %= mod
        res += y * (k - 1) * k // 2
        res %= mod

    print(res)


if __name__ == '__main__':
    resolve()


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<bool>v(8,false); int gm=0;
	for(int i=0;i<n;++i){
		int a; cin>>a;
		if(a<3200)v.at(a/400)=true;
		else ++gm;

	}
	int mn=count(v.begin(),v.end(),true);
	cout<<mn+(mn==0&&gm>0)<<" "s<<mn+gm<<"\n"s;
}

Measured memory_bytes: 3644