akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const int INF = 1 << 30;

struct Edge
{
	int to, cost;
	Edge(int to, int cost) 
		: to(to), cost(cost)
	{ }
};

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	
	vint d(n, INF);
	priority_queue<pint, vector<pint>, greater<pint> > que;
	vector<vector<Edge> > edges(n, vector<Edge>());
	
	rep(i, m)
	{
		int a, b, c;
		cin >> a >> b >> c;
		
		edges[a - 1].push_back(Edge(b - 1, c));
		edges[b - 1].push_back(Edge(a - 1, c));
	}
	
	rep(i, k)
	{
		int f;
		cin >> f;
		
		d[f - 1] = 0;
		
		que.push(mp(0, f - 1));
	}
	
	
	// ショッピングモールがある街を距離０として他の街へダイクストラで最短路探索
	for(; !que.empty(); que.pop())
	{
		int cost = que.top().first;
		int v = que.top().second;
		
		if(d[v] < cost) continue;
		
		rep(i, edges[v].size())
		{
			Edge e(edges[v][i]);
			
			if(d[v] + e.cost < d[e.to])
			{
				d[e.to] = d[v] + e.cost;
				
				que.push(mp(d[e.to], e.to));
			}
		}
	}
	
	
	// 辺上の最大値を探すO(m)
	double res = 0;
	rep(i, n) 
	{
		rep(j, edges[i].size())
		{
			Edge &e = edges[i][j];
			int diff = d[e.to] - d[i];
			
			if(d[i] <= d[e.to]) chmax(res, d[i] + diff + (e.cost - diff) / 2.0);
		}
		
		chmax(res, d[i]);
	}
	
	cout << round(res) << endl;
}

Measured memory_bytes: 3628
#coding: utf-8
H, W, K = map(int, input().split())
g = [list(input()) for _ in range(H)]
# print(*g, sep="\n")
ans = 0
for h in range(2**H):
    for w in range(2**W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (h >> i) & 1 == 0 and (w >> j) & 1 == 0 and g[i][j] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


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

using namespace std;

int main()
{
  int64_t x, k, d;

  cin >> x >> k >> d;

  int64_t ans = 0;

  int64_t p = abs(x / d);

  int sign = 1;
  if (x < 0)
  {
    sign = -1;
  }

  if (k < p)
  {
    cout << abs(x - sign * k * d) << endl;
  }
  else
  {
    if ((k - p) % 2 == 0)
    {
      cout << abs(x - sign * p * d) << endl;
    }
    else
    {
      cout << abs(x - sign * (p + 1) * d) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3628
import collections as cl
import math


def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

cnt = cl.Counter(A)
cnt_l = [0] * 200000
for a in A:
    cnt_l[a] += 1

ans = 0
for v in cnt_l:
    ans += combinations_count(v, 2)

for a in A:
    print(ans - cnt_l[a] + 1)


Measured memory_bytes: 26780
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define no_of_test(x)        int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	no_of_test(x)
	{
       int n,k;
       cin>>n>>k;
       int a[n];
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
       }	  
       sort(a,a+n);
        int sum=0;
       for(int i=0;i<n-k;i++)
       {
           sum+=a[i];
       }
       cout<<sum<<'\n';
	}
	return 0;
}

Measured memory_bytes: 5176
from collections import Counter
n = int(input())
li = list(map(int,input().split()))
counter_li = Counter(li)
ans = 0
for i in range(1,10**5):
    dum = counter_li[i-1] + counter_li[i] + counter_li[i+1]
    ans = max(dum,ans)
print(ans)

Measured memory_bytes: 58156
import heapq

N = int(input())
tasks = []
for _ in range(N):
  a,b = map(int,input().split())
  if b-a < 0:
    print('No')
    exit()
  else:
    heapq.heappush(tasks,[b,-a])
    
day = 0
while len(tasks) != 0:
  b, neg_a = heapq.heappop(tasks)
  if day - neg_a > b:
    print('No')
    exit()
  else: day -= neg_a
print('Yes')

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

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

    for (int i = 0; i < 50000; i++) {
        int x = 1.08 * i;

        if (x == N) {
            printf("%d\n", i);
            return 0;
        }
    }

    printf(":(\n");
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;


int main() {
	int a, b, c, x, y;
	int ans;
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	ans = a * x + b * y;
	for (int i = 0; i <= max(x, y) * 2; i += 2) {
		ans = min(max((x-i/2),0) * a + max((y-i/2),0) * b+i*c, ans);
	}
	printf("%d", ans);
}



Measured memory_bytes: 3828
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

def many_lcm(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = tmp * l[i]//gcd(tmp, l[i])
    return tmp



# B % C
# B - 
total = B - (A - 1)
# print(total)
A = A - 1
lc = many_lcm([C, D])
# print(lc)

a = A - (A // C + A // D - A // (lc))
b = B - (B // C + B // D - B // (lc))
print(b - a)


# (A - 1) % C
# B % C
# (A - 1) % D
# B % D


Measured memory_bytes: 10716
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MD=998244353;
const int N=2e5+5;
pair<int,int> p[N];
stack<pair<int,int> > st;
int main() {
	//freopen("in.txt","r",stdin);
	int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d%d",&p[i].first,&p[i].second);
    }
    sort(p,p+n);
    int ans=1;
    st.push({1e9,ans});
    for(int i=n-1;i>=0;i--) {
        int t=p[i].first+p[i].second;
        while(t>st.top().first) st.pop();
        ans=(ans+st.top().second)%MD;
        st.push({p[i].first,ans});
    }
    printf("%d\n",ans);
	return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<ll> x(N),y(N),z(N);
    rep(i,N){
        cin >> x[i] >> y[i] >> z[i];
    }
    vector<vector<Pll>> a(8,vector<Pll>(N));
    rep(i,N){
        a[0][i]=Pll(x[i]+y[i]+z[i],i);
        a[1][i]=Pll(x[i]+y[i]-z[i],i);
        a[2][i]=Pll(x[i]-y[i]+z[i],i);
        a[3][i]=Pll(x[i]-y[i]-z[i],i);
        a[4][i]=Pll(-x[i]+y[i]+z[i],i);
        a[5][i]=Pll(-x[i]+y[i]-z[i],i);
        a[6][i]=Pll(-x[i]-y[i]+z[i],i);
        a[7][i]=Pll(-x[i]-y[i]-z[i],i);
    }
    rep(i,8){
        sort(a[i].begin(),a[i].end());
        reverse(a[i].begin(),a[i].end());
    }
    vector<vector<ll>> ans(8,vector<ll>(3,0));
    rep(i,8){
        rep(j,M){
            ll k=a[i][j].second;
            ans[i][0]+=x[k];
            ans[i][1]+=y[k];
            ans[i][2]+=z[k];
        }
    }
    ll sum=0;
    rep(i,8){
        sum=max(sum,abs(ans[i][0])+abs(ans[i][1])+abs(ans[i][2]));
    }
    cout << sum << endl;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll n;
    ll ans=1;
    cin>>n;
    rep(i,n){
        ans*=i+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve();


    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  st s;
  cin >> s;
  vst ans(s.size(), "x");
  vrep(i, ans) cout << i;
  cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

const int MAX_V = 10010;
const int INF = 1000000000;
struct edge {
	int to;//行先
	int capacity;//容量
	int reverse;//逆辺
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void AddEdge(int from, int to, int capacity) {
	G[from].push_back(edge{ to, capacity, (int)G[to].size() });
	G[to].push_back(edge{ from,0,(int)G[from].size() - 1 });
}

int dfs(int v, int t, int f) {
	if (v == t) {
		return f;
	}
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.capacity > 0) {//使える辺を見つけたら
			int d = dfs(e.to, t, min(f, e.capacity));
			if (d>0) {
				e.capacity -= d;
				G[e.to][e.reverse].capacity += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0) {
			return flow;
		}
		else {
			flow += f;
		}
	}
}

int H,W = 0;
char a[105][105];
bool checked[105][105];
int s, t;

int main() {
	cin >> H >> W ;
	for (int i = 0; i < H;i++) {
		cin >> a[i];
	}
	s = 0;
	t = H + W + 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j]=='S') {
				AddEdge(s, i+1, INF);
				AddEdge(s, H + j+1,INF);
			}
			else if (a[i][j] == 'T') {
				AddEdge(i+1, t, INF);
				AddEdge(H+j+1, t, INF);
			}
			else if(a[i][j]=='o'){
				AddEdge(i+1, H+j+1, 1);
				AddEdge(H+j+1, i+1, 1);
			}
		}
	}
	int ans= max_flow(s, t);
	if (ans >= INF) {
		cout << "-1" << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 503, mod = 998244353;
typedef long long LL;
int n, sa, sb, ans, a[N], b[N], fac[N], ifac[N], inv[N], dp[2][N][N], cur, pw[N];
inline void upd(int &a, int b){a += b; if(a >= mod) a -= mod;}
inline int kasumi(int a, int b){
	int res = 1;
	while(b){
		if(b & 1) res = (LL) res * a % mod;
		a = (LL) a * a % mod; b >>= 1;
	}
	return res;
}
inline void init(int m){
	fac[0] = 1;
	for(Rint i = 1;i <= m;++ i) fac[i] = (LL) fac[i - 1] * i % mod;
	ifac[m] = kasumi(fac[m], mod - 2);
	for(Rint i = m;i;-- i){
		ifac[i - 1] = (LL) ifac[i] * i % mod;
		inv[i] = (LL) ifac[i] * fac[i - 1] % mod;
	}
}
inline int C(int n, int m){
	if(n < 0 || m < 0 || n < m) return 0;
	return (LL) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i <= n;++ i){
		scanf("%d%d", a + i, b + i);
		sa += a[i]; sb += b[i];
	}
	init(max(sa, sb) + 10);
	dp[0][0][0] = mod - 1;
	for(Rint i = 1;i <= n;cur ^= 1, ++ i){
		memcpy(dp[cur ^ 1], dp[cur], sizeof dp[cur]);
		int v = (LL) a[i] * inv[sa] % mod; pw[0] = 1;
		for(Rint j = 1;j <= sb - n;++ j) pw[j] = (LL) pw[j - 1] * v % mod;
		for(Rint j = 0;j <= sb - n;++ j)
			for(Rint k = a[i];k <= sa;++ k)
				for(Rint t = 0;t <= j && t < b[i];++ t)
					upd(dp[cur ^ 1][j][k], mod - (LL) C(j, t) * dp[cur][j - t][k - a[i]] % mod * pw[t] % mod);
	}
	for(Rint i = 0;i <= sb - n;++ i)
		for(Rint j = 1;j <= sa;++ j)
			upd(ans, (LL) dp[cur][i][j] * kasumi((LL) sa * inv[j] % mod, i + 1) % mod);
	printf("%d\n", ans);
}

Measured memory_bytes: 2176
import itertools
import copy

H, W, k = map(int, input().split())
matrix = []

for h in range(H):
    matrix.append(list(input()))

def count_black(mat):
    flat = list(itertools.chain.from_iterable(mat))
    b_sum = flat.count('#')
    return b_sum

ans = 0
for h in range(2 ** H):
    for w in range(2 ** W):
        tmp_matrix = copy.deepcopy(matrix)
        for i in range(H):
            if (h >> i) & 1:
                tmp_matrix[i][:] = ['.'] * W
        for j in range(W):
            if (w >> j) & 1:
                for i in range(H):
                    tmp_matrix[i][j] = '.'
        c = count_black(tmp_matrix)
        if c == k:
            ans += 1

print(ans)


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

string s;
int K;
set<string> st;

int main() {
	cin >> s >> K;
	int n = s.size();
	for (char c = 'a'; c <= 'z'; c++) {
		for (int i = 0; i < n; i++) {
			if (s[i] == c) {
				for (int j = 1; j <= min(K, n - i); j++) {
					st.insert(s.substr(i, j));
				}
			}
		}
		if (st.size() >= K) break;
	}

	auto pos = st.begin();
	for (int i = 0; i < K - 1; i++) pos++;

	cout << *pos << endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,ans,a[100005];
int main()
{
	re(n);
	for(int i=1;i<=n;++i)re(a[i]);
	sort(a+1,a+n+1,greater<int>());
	for(int i=1;i<=n;++i)
		if(i+1>a[i+1])
		{
			for(int j=i+1;a[j]==i;++j)ans^=1;
			ans|=(a[i]-i)&1;
			if(ans)puts("First");else puts("Second");
			return 0;
		}
}

Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B; cin >> A >> B;

	string S; cin >> S;
	REP(i, S.size()) {
		if (i == A) {
			if (S[i] != '-') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (S[i] < '0'|| S[i] > '9') {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}



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

int main() {
    lint n, s;
    cin >> n >> s;
    vector<lint> a(n);
    lint mod = 998244353;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    // dp[i][j]:0~iまでで和がjの答え
    vector<vector<lint>> dp(n + 1, vector<lint>(3001, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 3000; j++) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 2 % mod) % mod;
            if (j + a[i] <= 3000) {
                dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % mod;
            }
        }
    }
    if (dp[n][s] < 0) {
        dp[n][s] = (dp[n][s] + mod) % mod;
    }
    cout << dp[n][s] << endl;
}

Measured memory_bytes: 73676
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	map<ll, ll> M;
	rep(i, N) {
		map<ll, ll>::iterator it = M.lower_bound(A[i]);
		if(M.size() == 0 || it == M.begin()) {
			M[A[i]]++;
		} else {
			it--;
			(*it).second--;
			if((*it).second == 0) {
				M.erase(it);
			}
			M[A[i]]++;
		}
	}

	ll ans = 0;
	for(pair<ll, ll> item: M) {
		ans += item.second;
	}
	cout << ans  << endl;
	

}


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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for(int i = 1; i < n - 1; i++) {
        if((p[i - 1] < p[i] & p[i] < p[i+1]) | 
            p[i + 1] < p[i] & p[i] < p[i-1]) {
                ans++;
            }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		char[] c = S.toCharArray();
		
		int r1 = 0;
		int r2 = 0;
		for(int i=0; i<c.length; i++) {
			if(i%2==1) {
				//奇数 0
				if(c[i]=='1') {
					r1++;
				} else {
					r2++;
				}
			} else {
				//偶数 1
				if(c[i]=='0') {
					r1++;
				} else {
					r2++;
				}
			}
		}
		if(r1<r2) {
			System.out.println(r1);
		} else {
			System.out.println(r2);
		}
		

	}

}


Measured memory_bytes: 27476
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

int a[100005];

int main(){
	int n,m,v,p;
	scanf("%d%d%d%d", &n, &m, &v, &p);

	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	sort(a, a+n, greater<int>());

	int ans = p;
	ll cur = 0;

	for(int i = p; i < n; i++) {
		if(a[p-1] - a[i] > m) break;
		ll aux = cur + a[p-1] - a[i];
		if(n-i + (p-1) >= v) {
			ans++;
			cur = aux;
			continue;
		}

		int me = a[i] + m;
		int chosen = (n-i + (p-1));
		int lft = ((ll)v - chosen);
		ll votes = (ll)lft*m;

		int nchosen = n - chosen;
		
		ll tmp = ((ll)me - a[p-1])*((ll)nchosen);
		if(tmp+cur >= votes) ans++;

		cur = aux;
	}

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

Measured memory_bytes: 640
def main():
    N = int(raw_input())
    s= raw_input()
    ans = ["SS", "SW", "WS", "WW"]
    for n in range(4):
          for i in range(N-2):
              ans[n] += pred(ans[n][i], ans[n][i+1], s[i+1])
          if check(ans[n] ,s, 0, N)  and check(ans[n] , s , N-1, N) :
              return ans[n]
    return -1

def pred(a_a, a_b, s_b):
    if((a_b == 'S' and s_b == 'o' ) or (a_b == 'W' and s_b == 'x')):
        return a_a
    else:
        if(a_a == 'S'):
            return 'W'
        else:
            return 'S'

def check(ans, s, i, N):
    if((ans[i] == 'S' and s[i] == 'o') or (ans[i] == 'W' and s[i] == 'x')):
            if ans[(i-1)%N] != ans[(i+1)%N]:
                return False
    else:
            if ans[(i-1)%N] == ans[(i+1)%N]:
                return False
    return True
print main()


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    REP(i, 0, n +1) {
        if(int(i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

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

int main() {
    int N; string S;
    cin >> N >> S;
    map<char, int> cnt;
    for(int i=0; i<N; ++i) cnt[S[i]] += 1;

    const long long MOD = 1000000007;
    long long res = 1;
    for(auto p : cnt) res = (res * (p.second + 1)) % MOD;
    cout << res - 1 << endl;
}

Measured memory_bytes: 512
module Main where
    import Data.List
    import Control.Monad
    
    main = do
        inputs<-getLine
        putStrLn ([head inputs]++(show $ length (inputs)-2)++[last inputs])
        
        
    read' s = read s ::Integer

    getInputs = do
        line <- getLine
        let inputs = map read' (words line)
        return inputs

    getLines n = do
        lines <- (replicateM n getLine)
        return lines

    getGCD::Integer->Integer->Integer
    getGCD m n 
        | m < n = (getGCD n m)
        | n == 0 = m
        | otherwise = getGCD (mod m n) n

    getLCM::Integer->Integer->Integer
    getLCM m n = div (m * n) (getGCD m n)
   

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	if(n % 1000 == 0) cout << 0 << endl;
	else{
		cout << (n/1000+1)*1000-n << endl;
	}
	
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const int maxn = 500050;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const ll linf = 7e18;
ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

ll gcd(ll x, ll y)
{
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

bool pa(ll a, ll b)
{
    __int128 x = a, y = b, z = 1e18;
    return x * y <= z;
}

ll a[maxn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i, j, k;
    ll n, m, ans = 1;
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + 1 + n);
    for (i = 1; i <= n; i++)
    {
        m = a[i];
        if (ans >= 0 && pa(ans, m))
            ans *= m;
        else
        {
            ans = -1;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4440
#include<stdio.h>
int main(void){
int n, i, q;
int p[11];
int t, m;
q=0;

scanf("%d", &n);
for(i=0; i<n; i++){
 scanf("%d", &p[i]);
 q+=p[i];
}
t=p[1];
for(i=1; i<n; i++){
 if(t<p[i])
  t=p[i];
}
 m=t/2;
 q=q-m;
printf("%d\n", q);

return 0;
}

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

int main() {
  char s;
  cin >> s;
  if(s >= 'a' && s <= 'z'){
    cout << "a" << endl;
  }else{
    cout << "A" << endl;
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)


void Main()
{
	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;

	bool isMatch = true;
	rep(i, S.size())
	{
		if (i == A)
		{
			if (S[i] == '-') continue;
			else {
				isMatch = false;
				break;
			}
		}
		else
		{
			if (!('0' <= S[i] && S[i] <= '9'))
			{
				isMatch = false;
				break;
			}
		}
	}

	cout << (isMatch ? "Yes" : "No") << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int calc(int p, int x)
{
	return p * (100 + x) / 100;
}
int main()
{
	while (true)
	{
		int x, y, s;
		cin >> x >> y >> s;
		if (!x && !y && !s)
			break;
		int maxv = -1;
		for (int i = 1; i < s; i++)
			for (int j = 1; j < s; j++)
			{
				if (calc(i, x) + calc(j, x) != s)
					continue;
				maxv = max(maxv, calc(i, y) + calc(j, y));
			}
		cout << maxv << endl;
	}
}


Measured memory_bytes: 3092
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    N = int(readline())
    if N == 0:
        return False
    if N == 1:
        return True
    *S, = set(i**2 % N for i in range(1, N))
    S.sort()
    L = len(S)
    C = [0]*N
    D = [0]*((N-1)//2)
    for i in range(L):
        a = S[i]
        for b in S[:i]:
            C[a - b] += 2
    for i in range(1, N):
        D[min(i, N-i)-1] += C[i]
    write("\n".join(map(str, D)))
    write("\n")
    return True
while solve():
    ...



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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 20000005, P = 998244353;

int n, A, B;

int qpow(int a, int b) {
	int s = 1;
	for (; b; b >>= 1) {
		if (b & 1) {
			s = 1ll * s * a % P;
		}
		a = 1ll * a * a % P;
	}
	return s;
}

int fac[N], inv[N];

void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % P;
	}
	inv[n] = qpow(fac[n], P - 2);
	for (int i = n; i; --i) {
		inv[i - 1] = 1ll * inv[i] * i % P;
	}
}

int C(int n, int m) {
	if (m < 0 || m > n) {
		return 0;
	}
	return 1ll * fac[n] * inv[m] % P * inv[n - m] % P;
}

int main() {
	read(n), read(A), read(B);
	if (!B) {
		print(1);
		return 0;
	}
	init(n << 1);
	int ans = 0;
	for (int k = 0; k <= n - B && k <= A; ++k) {
		int t = (C(B + k - 1, k) + P - C(B + k - 1, k - 1)) % P;
		if (k + B == n) {
			if (k == A) {
				ans = (ans + t) % P;
			}
		} else {
			ans = (ans + 1ll * t * C(n - k - B - 1 + A - k, A - k)) % P;
		}
	}
	print(ans);
}


Measured memory_bytes: 159840
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <set>
#include <cmath>
#include <algorithm>
#include <locale>

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int (i)=0;(i)<(n);(i)++)
//#define ForJ(n) for(int j=0;j<n;j++)
//#define ForK(n) for(int k=0;k<n;k++)
#define Pr(n) cout<<n<<endl;
#define INS(v,n) for(int i=0;i<n;i++){cin >>v.at(i);}//vector 代入
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;

signed  main(){
    int n,x;
    cin >>n>>x;
    vector<int> l(n);
    For(n, i){
        cin>>l.at(i);
    }
    int _x = 0;
    int c=0;
    For(n, i){
        _x+=l[i];
        if(_x>x){
            break;
        }
        c++;
    }
    cout<<c+1<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int n,m,Q;
vi a,b,c,d;
vi nums;

int dfs(int depth, int ni){
    if(depth == n){
        int sum = 0;
        rep(i,Q){
            if(nums[b[i]] - nums[a[i]] == c[i]) sum += d[i];
        }
        return sum;
    }
    int ret = 0;
    for(int i=ni;i<=m;++i){
        nums[depth] = i;
        chmax(ret, dfs(depth+1, i));
    }
    return ret;
}

int main(){
    cin >> n >> m >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    nums.resize(n);

    rep(i,Q) cin >> a[i] >> b[i] >> c[i] >> d[i], a[i]--, b[i]--;
    
    cout << dfs(0, 1) << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, X;
    int L[100];

    cin >> N >> X;
    rep(i, N) {
        cin >> L[i];
    }
    int D = 0, ans = 1;
    rep(i, N) {
        D = D + L[i];
        if(D <= X) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 0
    now = 1
    for i in a:
        if now == i:
            now = now +1
        else:
            ans = ans +1
    if ans == n:
        print(-1)
    else:
        print(ans)



Measured memory_bytes: 26268
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int printkigou(int, char);

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	int H, W;
	char kigou = '#';
	char a[100][100];
	int i,j;

	scanf("%d %d", &H, &W);
	for (i = 0; i < H; i++) {
		scanf("%s", &a[i]);
	}
	
	printkigou(W+2, kigou);
	for (i = 0; i < H; i++){
		printf("%c", kigou);
		for(j = 0; j < W; j++) {
			printf("%c", a[i][j]);
		}
		printf("%c\n", kigou);
	}
	printkigou(W+2, kigou);

	return 0;
}

printkigou(int weight, char kigou) {
	int i;
	for (i = 0; i < weight; i++) {
		printf("%c", kigou);
	}
	printf("\n");
}



Measured memory_bytes: 128
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;

int main() 
{
	LL a,b;
	scanf("%lld %lld",&a,&b);
	if(a==b)
	{
		printf("1\n");
		return 0;
	}
	LL l=(1ll<<60);	
	while((l&a)==(l&b))
	{
		l>>=1;
	}
	LL q=l-(a&(l-1));
	LL k=l;
	l/=2;
	LL bi;
	while(l)
	{
		if((b&l)!=0)
		{
			bi=2*l;
			break;
		}
		l/=2;
	}
	if(l==0)
	{
		bi=1;
	}
	printf("%lld\n",2*q+min(bi,a&(k-1)));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a,a + n,greater<int>());
    int ans_a = 0;
    int ans_b = 0;
    for(int i = 0;i < n;i++)
    {
        if(i % 2 == 0)
        {
            ans_a += a[i];
        }
        else
        {
            ans_b += a[i];
        }
    }
    cout << ans_a - ans_b << "\n";

    return 0;
}

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: Allen
 *
 * Created on January 12, 2019, 5:08 PM
 */

#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    int n;
    cin>>n;
    int a,b,c;
    int dp[n+1][3];
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for(int i=1;i<=n;i++){
        cin>>a>>b>>c;
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c;
    }
    printf("%d",max(dp[n][0],max(dp[n][1],dp[n][2])));
    return 0;
}



Measured memory_bytes: 1408
/*********************
*                    *
* Nothing Impossible *
*                    *
*********************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld; 
using namespace std;

int main()
{
	char img[3];
	cin >> img;
	char cor[3];
	cin >> cor;
	int ans = 0;
	Rep(i,0,3)
	{
		if(img[i] == cor[i])
		{
			ans += 1;
		}
	}
	cout << ans;
	return 0;
}





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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  ll sum=0, prev=0;
  rep(i,n){
    cin>>a[i];
    sum+=abs(a[i]-prev);
    prev=a[i];
  }
  sum+=abs(a[n-1]);
  prev=0;
  rep(i,n){
    ll nxt;
    if(i==n-1) nxt=0;
    else nxt=a[i+1];
    cout<<sum-abs(a[i]-prev)-abs(a[i]-nxt)+abs(prev-nxt)<<endl;
    prev=a[i];
  }
}

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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll n;
      cin>>n;
      ll arr[n];
      loop(i,0,n){cin>>arr[i];}

      ll sum=0;
      for(int i=1; i<n; i++){
            if(arr[i-1]<=arr[i]){continue;}
            ll dif=(arr[i-1]-arr[i]);
            sum+=dif;
            arr[i]+=dif;
      }
      cout<<sum<<endl;


      bye;
}


Measured memory_bytes: 5212
def main():
    N, M = (int(i) for i in input().split())
    edge = [[] for _ in range(N)]
    edge_list = []
    for i in range(M):
        a, b = (int(i) for i in input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        edge_list.append((a-1, b-1))

    def dfs(G, v, e):
        seen = [False]*N
        todo = []
        seen[v] = True
        todo.append(v)
        while todo:
            u = todo.pop()
            for next_v in G[u]:
                if seen[next_v]:
                    continue
                if (u, next_v) == e or (next_v, u) == e:
                    continue
                seen[next_v] = True
                todo.append(next_v)
        return all(seen)

    ans = 0
    for e in edge_list:
        if dfs(edge, 0, e):
            pass
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;
char s[1005][1005];
int vis[1005][1005];
int cnt[1005][1005];
int h,w;
int sx,sy,ex,ey;
int xx[5]={58,0,0,1,-1};
int yy[5]={58,1,-1,0,0};
int min1=1e9;

struct ac
{
    int x,y,step,num;
};


void bfs()
{
    deque<ac>q;
    q.push_front({sx,sy,0,cnt[sx][sy]});
    s[sx][sy]='#';
    while(!q.empty())
    {
        ac u=q.front();
        q.pop_front();
        if(u.num==cnt[ex][ey])
        {
            min1=u.step;
            return;
        }
        int x=u.x,y=u.y;
        s[x][y]='#';
        for(int i=x-2;i<=x+2;i++)
        {
            for(int j=y-2;j<=y+2;j++)
            {
                if(i<1||j<1||i>h||j>w||s[i][j]=='#')
                    continue;
                if(u.num==cnt[i][j])
                q.push_front({i,j,u.step,cnt[i][j]});
                else
                q.push_back({i,j,u.step+1,cnt[i][j]});
            }
        }
    }
}


void dfs222(int x,int y,int num)
{
    cnt[x][y]=num;
    vis[x][y]=1;
    for(int i=1;i<=4;i++)
    {
        int tx=xx[i]+x;
        int ty=yy[i]+y;
        if(tx<1||ty<1||tx>h||ty>w||vis[tx][ty]||s[tx][ty]=='#')
            continue;
        dfs222(tx,ty,num);
    }

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w;
    cin>>sx>>sy>>ex>>ey;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>s[i][j];
        }
    }
    int tot=0;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(vis[i][j]||s[i][j]=='#')
                continue;
            dfs222(i,j,++tot);
        }
    }
    bfs();
    if(min1==1e9)
        cout<<-1<<'\n';
    else
        cout<<min1<<'\n';



}


Measured memory_bytes: 18440
N = int(input())
S = []
for i in range(N):
  S.append(input())

cnt_ac = S.count('AC')
cnt_wa = S.count('WA')
cnt_tle = S.count('TLE')
cnt_re = S.count('RE')

print(f'AC x {cnt_ac}')
print(f'WA x {cnt_wa}')
print(f'TLE x {cnt_tle}')
print(f'RE x {cnt_re}')

Measured memory_bytes: 16160
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    
    int A,B;
    
    // 入力
    cin >> A >> B;
    
    cout << A*B << endl;
    
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    int ans = String.valueOf(n).length();

    for (long i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        ans = Math.min(String.valueOf(n / i).length(), ans);
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
//                 _                      
//                (_)                     
// _ __ ___   __ _ _  ___  _ __ _ __ ___  
//| '_ ` _ \ / _` | |/ _ \| '__| '__/ _ \ 
//| | | | | | (_| | | (_) | |  | | | (_) |
//|_| |_| |_|\__,_| |\___/|_|  |_|  \___/ 
//               _/ |                     
//              |__/                      
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
  
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vbl;
typedef tree<
    pll,
    null_type,
    less<pll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;

#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size();\
                                    forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define printarr(arr, length, delimeter) {forn(elementarr, length){cout << arr[elementarr] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
  
struct pair_hash
{
    template <class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& pair) const
    {
        return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
    }
};
 
const ldbl EPS = 1e-6;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const ll MOD = 3037000499;
// const ull MOD = 1000000000000000003;
const ll INF = 1e18;
const ldbl pi = 2 * acos(0.0);
ll n, m, k, p, q, t, sum = 0, cnt= 0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
str s = "", s1, s2;
char c;
 
void bad_solve(){}

void solve() //set.merge() -> c++17
//DELET DEBUG OUTPUT!11!1
//"YES"/"NO" OUTPUT!!!!
//__builtin_popcountll() -> __popcnt64() from <intrin.h>
{
    cin >> n;
    cout << n+n*n+n*n*n;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("F:\\repos\\projects\\contests_vsc\\in.txt", "r", stdin);
    freopen("F:\\repos\\projects\\contests_vsc\\out.txt", "w", stdout);
#endif
    majorro
    
    solve();
  
    // freopen("test.txt", "w", stdout);
    // bad_solve();
  
//  memset(v, INT_MAX, 1000*2000*sizeof(int));
  
    return 0;
}

Measured memory_bytes: 3604
n=int(input())
a=list(map(int,input().split()))
for i in range(n):a[i]-=i+1
a.sort()
if n%2==1:
    ans=0
    for i in a:ans+=abs(i-a[n//2])
else:
    ans,ans2=0,0
    for i in a:
        ans+=abs(i-a[n//2])
        ans2+=abs(i-a[n//2+1])
    ans=min(ans,ans2)
print(ans)

Measured memory_bytes: 26708
#include <bits/stdc++.h>
using namespace std;
 
 
int main()
{
 
    int n;
    cin>>n;

    bool flg=true;
    for(int i=0;i<n;i++){
        int t,x,y;
        cin>>t>>x>>y;

        if(t%2==(x+y)%2 && t>=x+y)
            ;
        else
            flg=false;
    }
 

    if(flg)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
    return 0;
}   

Measured memory_bytes: 256
# N = int(input())
a, b, k = map(int, input().split())
# l = [int(x) for x in input().split()]
if a <= k:
    k -= a
    a = 0
    
    if b <= k:
        b = 0
    else:
        b -= k
else:
    a -= k
    
print(a, b)


Measured memory_bytes: 2940