akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


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

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}

void solve()
{
    int n, k;
    cin>>n>>k;
    readv(a,n);
    //brute 


    for(int step = 1 ;step<=k;step++)
    {
        bool flag=false;
        for(int i=0;i<n;i++)
        {
            if(a[i]!=n)
            {
                flag=true;
            }
        } 
        if(!flag)
            break;

        vector<int> b(n+1);

        for(int i=0;i<n;i++)
        {
            int left = max((int)0,i-a[i]);
            int right = min(i+a[i]+1, n);
            b[left]++;
            b[right]--;
        }
        for(int i=1;i<n;i++)
        {
            b[i] = b[i-1]+b[i];
        }
        for(int i=0;i<n;i++)
        {
            a[i] = b[i];
        }

    }
    for(int i=0;i<n;i++)
    {
        cout<<a[i]<<" ";
    }

}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t = 1;
    // cin>>t;
    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 6420
a,b,c,x,y=map(int,input().split())
ans=0
m=min(x,y)
if a+b>=2*c: #Half and Half購入で安くなる可能性あるパターン
    # HaHをm枚買って残りHaH購入,または全部HaH購入,このいずれかしかあり得ない
    ans = min(2*c*m+a*(x-m)+b*(y-m), 2*c*max(x,y))
else:
    ans = a*x+b*y
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
const constexpr int MAX = 1e5;
const constexpr ll INF = 1LL<<32;
vi G[MAX], indeg(MAX, 0), out;
vb V(MAX, false);
int n;
inline void bfs(int s) {
	deque<int> dq;
	dq.eb(s);
	V[s] = true;
	int u, v;
	while(!dq.empty()) {
		u = dq.front(); dq.pop_front();
		out.eb(u);
		rep(i, 0, len(G[u])) {
			v = G[u][i];
			if(--indeg[v] == 0 && !V[v]) {
				V[v] = true;
				dq.eb(v);
			}
		}
	}
}
inline void tsort() {
	rep(u, 0, n) rep(i, 0, len(G[u])) ++indeg[G[u][i]];
	rep(u, 0, n) if(indeg[u] == 0 && !V[u]) bfs(u);
	rep(i, 0, len(out)) P(out[i]);
}
int main() {
	int m; cin >> n >> m;
	int s, t;
	rep(i, 0, m) {
		cin >> s >> t;
		G[s].eb(t);
	}
	tsort();
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9+7;

int main() {
	int n;
	cin >> n;
	long long ans=1;
	rep(i, n){
		ans *= i+1;
		ans %= INF;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
using pii = pair<int, int>;
using piii = pair<pii, int>;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;

#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<b; i++)
#define fi first
#define se second


int main() {
    vint cnt(31);

    int n, m;
    cin >> n >> m;
    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int t;
            cin >> t;
            cnt[t]++;
        }
    }

    int ans = 0;
    rep(i, 31) {
        if (cnt[i] == n) {
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main() {
	// your code goes here
	string s;
	cin>>s;
	
	if (s=="ABC")
	{
		cout<<"ARC"<<endl;
	}
	if (s=="ARC")
	{
		cout<<"ABC"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3580
N, K = map(int, raw_input().split())
tree = []
for i in range(0, N):
	tree.append(int(raw_input()))
tree.sort()
min = tree[N-1]
for i in range(0, N-K+1):
	if tree[i+K-1] - tree[i] < min: 
		min = tree[i+K-1] - tree[i]

print min

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
int r,D,x;
int i,a,b;
int main(){
    scanf("%d%d%d", &r, &D, &x);
    fornum(i,0,10){
        x = x * r - D;
        printf("%d\n", x);
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.append(0)
 
all = 0
last = 0
diff = []
 
for i in range(N):
  all += abs(A[i] - last)
  diff.append(abs(A[i+1] - last) - abs(A[i+1] - A[i]) - abs(A[i] - last))
  last = A[i]
all += abs(A[N-1])
 
for i in range(N):
  print(all + diff[i])

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

int main(){
    int N,L;
    cin >> N >> L;
    
    int a[201];
    int ans = 0;
    for(int i = 1;i <= N;i++){
        a[i] = L + i - 1;
        ans += a[i];
    }
    
    if(L > 0) ans -= a[1];
    else if(L < 1 - N) ans -= a[N];
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

n, m = map(int, input().split())
edges = []
graph = [ [] for _ in range(n) ]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1;
    edges.append( (a, b) )

    graph[a].append(b)
    graph[b].append(a)

def dfs(u, v):
    is_visited = [ False ]*n
    st = []
    st.append(0)
    while st:
        cur = st.pop()
        is_visited[cur] = True
        for adj in graph[cur]:
            if is_visited[adj]: continue
            if cur == u and adj == v: continue
            if cur == v and adj == u: continue

            st.append(adj)

    return all(is_visited)

ans = 0
for u, v in edges:
    if not dfs(u, v):
        ans += 1

print(ans)



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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll N; cin >> N;
    vll A(N), B(N), C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));

    ll ans = 0;
    REP(i, N)
    {
        ll b = B[i];
        ll less = lower_bound(ALL(A), b) - A.begin();
        ll more = C.end() - upper_bound(ALL(C), b);
        ans += less * more;
    }

    cout << ans << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
class dice{
public:
	int d1;
	int d2;
	int d3;
	int d4;
	int d5;
	int d6;
	int kaisi(int s1, int s2, int s3, int s4 ,int s5,int s6);
	string huru(string x);
	int kakunin(int x,int y);
};
int dice::kaisi(int s1,int s2,int s3,int s4,int s5,int s6){
  d1 = s1;
  d2 = s2;
  d3 = s3;
  d4 = s4;
  d5 = s5;
  d6 = s6;
}
/*string dice::huru(string x){
	int a,b,c,d,e,f;
	for(int i = 0;i<x.size();i++){
		if(x.at(i) == 'E'){
			a = d3;
			d3 = d1;
			d1 = d4;
			d4 = d6;
			d6 = a;
		}
		if(x.at(i) == 'S'){
			a = d2;
			d2 = d1;
			d1 = d5;
			d5 = d6; 
			d6 = a;
		}
		if(x.at(i) == 'W'){
			a = d4;
			d4 = d1;
			d1 = d3;
			d3 = d6;
			d6 = a;
		}
		if(x.at(i) == 'N'){
			a = d5;
			d5 = d1;
			b = d6;
			d6 = a;
			a = d2;
			d2 = b;
			d1  =  a;
		}
	}
} */
int dice::kakunin(int x,int y){
	int a1,a2,a3,a4,a5,a6;
	if(d1 == x){
        a1 = d1;
        a2 = d2;
        a3 = d3;
        a4 = d4;
        a5 = d5;
        a6 = d6;
        }
    else if(d2 == x){
		a1 = d2;
		a2 = d6;
		a6 = d5;
		a5 = d1;
		a4 = d4;
		a3 = d3;
		}
	else if(d3 == x){	
		a1 = d3;
		a2 = d2;
		a3 = d6;
		a4 = d1;
		a5 = d5;
		a6 = d4;
		}
	else if(d4 == x){	
		a1 = d4;
		a2 = d2;
		a3 = d1;
		a4 = d6;
		a5 = d5;
		a6 = d3;
		}
	else if(d5 == x){	
		a1 = d5;
		a2 = d1;
		a3 = d3;
		a4 = d4;
		a5 = d6;
		a6 = d2;
	}
	else if(d6 == x){	
		a1 = d6;
		a2 = d5;
		a3 = d3;
		a4 = d4;
		a5 = d2;
		a6 = d1;
	}

	if(y == a2)return a3;
	else if(y == a3)return a5;
	else if(y == a4)return a2;
	else if(y == a5)return a4;
	else return 0;
}
int main(){
	int s1,s2,s3,s4,s5,s6,huuta,x,y;
	cin>>s1>>s2>>s3>>s4>>s5>>s6;
	cin>>huuta;
	dice iti;
	iti.kaisi(s1,s2,s3,s4,s5,s6);
	for(int i = 0;i<huuta;i++){
		cin>>x>>y;
		cout<<iti.kakunin(x,y)<<endl;
	}
	return 0;
}


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


int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  
  vector<int> cnt(N, K);
  int A;
  for(int i=0; i<Q; i++){
    cin >> A;
    cnt.at(A-1)++;
  }
  for(int i=0; i<N; i++){
    if((cnt.at(i)-Q) > 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
    
  return 0;
  
}

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


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

    int R;
    cin >> R;


    cout << 2*R*3.14159<<endl;


}

Measured memory_bytes: 3764
n = int(input())
a = list(map(int, input().split()))

r = 0
ans = 0
sum_a = 0
for l in range(n):
    while r < n and sum_a&a[r] == 0:
        sum_a += a[r]
        ans += r-l+1
        r += 1
    sum_a -= a[l]
print(ans)


Measured memory_bytes: 24840
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < (i##_MACRO); i++)
#define RANGE(i, a, b) for(int i = (a), i < (b), i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MOD(x) ((x) % static_cast<int>(1e9 + 7))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int square(int x) {
	return x * x;
}

double distance(pair<int, int> a, pair<int, int> b) {
	return sqrt(square(a.first - b.first) + square(a.second - b.second));
}

void foreach_permutation(int n, std::function<void(int*)> f) {
	int indexes[n];
	for(int i = 0; i < n; i++)
		indexes[i] = i;
	do {
		f(indexes);
	} while(std::next_permutation(indexes, indexes + n));
}

int main() {
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> towns(n);
	EACH(e, towns) { scanf("%d %d", &e.first, &e.second); }
	vector<double> lengths;

	foreach_permutation(n, [&](int indexes[]) {
		double length = 0.0;
		REP(i, n - 1) {
			length += distance(towns[indexes[i]], towns[indexes[i + 1]]);
		}
		lengths.push_back(length);
	});

	printf("%0.10f", static_cast<double>(accumulate(ALL(lengths), 0.0)) /
						 static_cast<double>(lengths.size()));

	return 0;
}

Measured memory_bytes: 892
//不等,不问,不犹豫,不回头.
#include<bits/stdc++.h>
#define _ 0
#define db double
#define RE register
#define ll long long
#define P 1000000007
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define pb(x) push_back(x)
#define ull unsigned long long
#define getc(c) scanf("%s",c+1)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=2e5+10;
int n,a[N],vis[N],q[N],top,pre[N];
ll k; 

inline ll read()
{
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

inline void dfs(int x)
{
	vis[q[++top]=x]=1;pre[x]=top;
	if(!vis[a[x]]) dfs(a[x]);
}

int main()
{
	//freopen("1.in","r",stdin);
	get(n);get(k);
	rep(i,1,n) get(a[i]);
	dfs(1);
	if(k<=top) {printf("%d ",a[q[k]]);return 0;}
	k-=top;
	int s=a[q[top]];
	int cnt=top-pre[s]+1;
	k%=cnt;
	while(k) s=a[s],--k;
	printf("%d",s);
	return (0^_^0);
}
//以吾之血,祭吾最后的亡魂







Measured memory_bytes: 6696
#include <iostream>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  char A[50][50], B[50][50];
  auto cursor = [](int x){return [=](int &i, int &j){i++; if(i>=x){j+=1; i=0;}};};
  auto nextM = cursor(M), nextNM = cursor(N-M);  
  for(int i=0; i<N; ++i) scanf("%s", &A[i][0]);
  for(int i=0; i<M; ++i) scanf("%s", &B[i][0]);
  bool ok = false;
  for(int Ax=0, Ay=0; !ok && Ay<=N-M; nextNM(Ax, Ay))
  {
    ok = true;
    for(int i = 0, j = 0; j < M; nextM(i, j))
      if(A[Ax+i][Ay+j] != B[i][j])
      {
        ok = false;
        break;
      }
  }
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a<=0&&b>=0) cout<<"Zero"<<endl;
	else if(a>0&&b>0) cout<<"Positive"<<endl;
	else if(a<0&&b<0) {
		if((a-b+1)%2) cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int sumA, sumB;
		int[] data = new int[31];
		
		for(int i = 0; i < 28; i++){
			data[sc.nextInt()] = 1;
		}
		for(int i = 1; i < 31; i++){
			if(data[i] == 0){
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 12000
class DualSegmentTree():

    def __init__(self, n, op, e):
        """
        :param n: 配列の要素数
        :param op: 作用素（モノイド＝結合則＋単位元存在）
        :param e:  単位元
        """
        self.n = n
        self.op = op
        self.e = e
        self.depth = (self.n - 1).bit_length()
        self.size = 1 << self.depth
        self.lazy = [self.e] * ((self.size << 1) + 1)

    def built(self, array):
        """
        arrayを初期値とするセグメント木を構築
        """
        for i in range(self.n):
            self.lazy[self.size + i] = array[i]

    def update(self, l, r, x):
        """
        半開区間 [l, r) の各々の要素 a に op(x, a)を作用させる （ 0-indexed ）　（ O(logN) ）
        """
        l += self.size
        r += self.size
        l0 = l//(l&-l)
        r0 = r//(r&-r)
        self.propagate(l0)
        self.propagate(r0-1)
        while l < r:
            if r&1:
                r -= 1              # 半開区間なので先に引いてる
                self.lazy[r] = self.op(x, self.lazy[r])
            if l&1:
                self.lazy[l] = self.op(x, self.lazy[l])
                l += 1
            l >>= 1
            r >>= 1

    def propagate(self, i):
        """
        根から葉に伝搬させる。可換モノイドの場合は更新時の伝搬をサボれる。　（ O(logN) ）
        """
        for k in range(i.bit_length()-1, 0,-1):
            x = i>>k
            if self.lazy[x] == self.e:
                continue
            self.lazy[(x<<1)|1] = self.op(self.lazy[x], self.lazy[(x<<1)|1])
            self.lazy[x<<1] = self.op(self.lazy[x], self.lazy[x<<1])
            self.lazy[x] = self.e

    def get(self, i):
        """
        i 番目の値を取得（ 0-indexed ） ( O(logN) )
        """
        i += self.size
        self.propagate(i)
        return self.lazy[i]

    def __getitem__(self, i):
        return self.get(i)

    def __iter__(self):
        for x in range(1, self.size):
            if self.lazy[x] == self.e:
                continue
            self.lazy[(x<<1)|1] = self.op(self.lazy[x], self.lazy[(x<<1)|1])
            self.lazy[x<<1] = self.op(self.lazy[x], self.lazy[x<<1])
            self.lazy[x] = self.e
        for a in self.lazy[self.size:self.size+self.n]:
            yield a

    def __str__(self):
        for x in range(1, self.size):
            if self.lazy[x] == self.e:
                continue
            self.lazy[(x<<1)|1] = self.op(self.lazy[x], self.lazy[(x<<1)|1])
            self.lazy[x<<1] = self.op(self.lazy[x], self.lazy[x<<1])
            self.lazy[x] = self.e
        return str(self.lazy[self.size:self.size + self.n])

##################################################################################################################
import sys
from bisect import *
input = sys.stdin.readline

N, Q = map(int, input().split())

e = -1
op = lambda x, y: x if x != e else y
st = DualSegmentTree(Q, op, e)

Qu = [list(map(int, input().split())) for _ in range(N)]
Qu.sort(key=lambda x:x[2], reverse=True)

D = [int(input()) for _ in range(Q)]

for q in Qu:
    S, T, X = q
    L = bisect_left(D,S-X)
    R = bisect_left(D,T-X)
    st.update(L, R, X)
print(*st, sep="\n")

Measured memory_bytes: 146340
#include <iostream>
#include <cstring>
#include <algorithm>

const int maxn = 100009;

struct miao{
	int s, t, c;
}mi[maxn];

bool cmp(miao a, miao b) {
	return a.c < b.c;
}

int main(int argc, char *argv[]) {  
	int n, c;
	std::cin >> n >> c;
	int s, t, cc;
	int ch[maxn], ans[maxn];
	memset(ans, 0, sizeof(ans));
	memset(ch, 0, sizeof(ch));
	for(int i = 0; i < n; i++) {
		std::cin >> mi[i].s >> mi[i].t >> mi[i].c;
	}
	std::sort(mi, mi+n, cmp);
	int now = mi[0].c;
	for(int i = 0; i < n; i++) {
		if(mi[i].c == now) {
			for(int j = mi[i].s; j <= mi[i].t; j++) {
				ch[j] = 1;
			}
		} else {
			now = mi[i].c;
			for(int j = 0; j < maxn-1; j++) {
				ans[j] += ch[j];
			}
			memset(ch, 0, sizeof(ch));
			for(int j = mi[i].s; j <= mi[i].t; j++) {
				ch[j] = 1;
			}
		}		
	}
	for(int j = 0; j < maxn-1; j++) {
		ans[j] += ch[j];
	}
	int minn = 0;
	for(int i = 0; i < 100001; i++) {
		//std::cout << ans[i];
		minn = std::max(minn, ans[i]);
	}
	std::cout << minn << std::endl;
	return 0;
}

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

const string YES = "yes";
const string NO = "no";

void solve(std::string S){
    int lp = S.size();
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    int ln = S.size();
    if(lp == ln) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e4+10;
    static const ll MOD=1e9+7;
    ll qpow(ll a,ll k){
        ll r=1;
        while(k){
            if(k&1)r=(r*a)%MOD;
            a=(a*a)%MOD;
            k>>=1;
        }
        return r%MOD;
    }
    int N;
    ll A[MAXN];
    map<ll,ll>mp[MAXN];
    map<ll,ll>lcm;
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N;
        for(int i=0;i<N;i++){
            cin>>A[i];
            ll t=A[i];
            for(ll u=2;u*u<=t;u++){
                if(t%u)continue;
                ll cnt=0;
                while(t%u==0)cnt++,t/=u;
                mp[i].insert({u,cnt});
            }
            if(t>1)mp[i].insert({t,1});
            for(auto p:mp[i]){
                lcm[p.first]=max(lcm[p.first],p.second);
            }
            A[i]=qpow(A[i],MOD-2);
        }
        ll ans=0;
        ll vlcm=1;
        for(auto p:lcm){
            vlcm=(vlcm*qpow(p.first,p.second))%MOD;
        }
        for(int u=0;u<N;u++){
            ans=(ans+(vlcm*A[u])%MOD)%MOD;
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 3968
/**
  *  Worg
  */
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

int n;

bool get_verdict(std::vector<int>& a) {
    std::cout << "? ";
    for (auto& x: a) {
        std::cout << x << " ";
    }
    std::cout << std::endl;

    std::string verdict; std::cin >> verdict;
    return verdict == "Red";
}

bool ask(int start) {
    std::vector<int> a;
    for (int i = start; i < start + n; i++) {
        a.push_back(i);
    }
    return get_verdict(a);
}


int main() {
    std::cin >> n;
    int l = ask(1);

    int left = 1, right = n + 1, critical = 1;
    while (left <= right) {
        int mid = (left + right) >> 1;
        if (ask(mid) == l) {
            critical = mid; left = mid + 1;
        } else {
            right = mid - 1;
        }
    }

    std::vector<int> answer(2 * n + 1);
    for (int i = 1; i <= 2 * n; i++) {
        std::vector<int> a = {i};

        if (i < critical || i >= critical + n) {
            for (int j = critical + 1; j < critical + n; j++) {
                a.push_back(j);
            }

            answer[i] = get_verdict(a);
        } else {
            for (int j = 1; j < critical; j++) {
                a.push_back(j);
            }
            for (int j = critical + n + 1; j <= 2 * n; j++) {
                a.push_back(j);
            }

            answer[i] = get_verdict(a);
        }
    }

    std::cout << "! ";
    for (int i = 1; i <= 2 * n; i++) {
        if (answer[i]) {
            std::cout << "R";
        } else {
            std::cout << "B";
        }
    }
    std::cout << std::endl;
    return 0;
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld", &N);
    vector<ll> d(N);

    REP(ll,i,0,N) scanf("%lld",&d.at(i));
    sort(d.begin(),d.end());

    ans = d.at( N/2 ) - d.at( N/2 - 1 );
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    final int n = scanner.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = scanner.nextInt();
    }
    int[] b = Arrays.copyOf(a, a.length);
    Arrays.sort(b);
    int mid = b[n / 2 - 1];
    int mid1 = b[n / 2];
    for (int i = 0; i < n; i++) {
      if (a[i] <= mid) System.out.println(mid1);
      else System.out.println(mid);
    }
  }
}


Measured memory_bytes: 89668
#include <bits/stdc++.h>
/*
	Karya anak bangsa yang paling agung
	Author : Yohandi or... bukan..
*/

#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define endl "\n"

#define all(a) a.begin(),a.end()
#define lb(a,x) (lower_bound(all(a),x)-a.begin())
#define ub(a,x) (upper_bound(all(a),x)-a.begin())

#define rep(a,x,y) for(int a=(int)x;a<=(int)y;++a)
#define repd(a,x,y,d) for(int a=(int)x;a<=(int)y;a+=d)
#define res(a,x,y) for(int a=(int)x;a>=(int)y;--a)
#define resd(a,x,y,d) for(int a=(int)x;a>=(int)y;a-=d)

// Ordered Set, Ordered Multiset
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define o_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define o_multiset tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
// .order_of_key(x) -> Number of elements less than x
// * .find_by_order(k) -> Kth smallest element (0-based)
// .erase(x) -> Remove all elements equal to x

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using lint=long long;

mt19937 rng(time(NULL));

lint Power(lint A,lint B,lint C){
	if(!B) return 1LL;
	lint tmp=Power(A,B>>1,C);
	return tmp*tmp%C*(B&1?A:1)%C;
}

int T;

int main(){
//	ios_base::sync_with_stdio(0);
//	cin.tie(0); cout.tie(0);
	T=1;
//	cin>>T;
	rep(t,1,T){
        int K;
        string S;
        cin>>K>>S;
        for(int i=0;i<S.length();++i){
            if(i<K) cout<<S[i];
            else {
                cout<<"...";
                break;
            }
        }
        cout<<"\n";
	}
	return 0;
}




Measured memory_bytes: 3632
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
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...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a>>b>>c>>d;
  if(a==c)Cout(0);
  else Cout(1);
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    vbool seen(n, false);
    vint ans;

    rep(i, n){
        int t = -1;
        for(int j=a.size()-1;j>=0;j--){
            if(j+1==a[j]){
                t = j;
                ans.push_back(j+1);
                break;
            }
        }

        if(t==-1){
            pr(-1);
            break;
        }

        vint b;
        rep(j, a.size()){
            if(j==t) continue;
            b.push_back(a[j]);
        }

        a = b;
    }

    if(ans.size()==n) {
        reverse(ALL(ans));
        rep(i, n) pr(ans[i]);
    }
    return 0;}

Measured memory_bytes: 3640
n,m=gets.chomp.split.map(&:to_i)
eatTypes={}
n.times do
  temp = gets.chomp.split.map(&:to_i)
  temp.delete_at(0)
  temp.each do |number|
    eatTypes.key?(number) ? eatTypes[number] += 1 : eatTypes.store(number,1)
  end
end
count = 0
eatTypes.each do |key, value|
	count += 1 if value == n
end
puts count

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#define INF (2000000000)
#define MOD (1000000007)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;
typedef vector<long>::iterator VL;
typedef vector<long>::iterator VLI;
typedef pair<int, int> P;

bitset<100> s[100];
bitset<100> dp[100][100];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		memset(s, 0, sizeof(s));
		memset(dp, 0, sizeof(dp));
		
		for (int i = 0; i < n; i++){
			int f;
			scanf("%d", &f);
			for (int j = 0; j < f; j++){
				int d;
				scanf("%d", &d);
				s[d].set(i);
			}
		}
		
		for (int i = 0; i < n; i++){
			dp[0][i].set(i);
		}
		
		for (int i = 1; i <= 30; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] |= dp[i - 1][j];
				
				if (/*(1 << j) & s[i]*/ s[i][j]){
					for (int k = 0; k < n; k++){
						if (/*s[i] & (1 << k)*/ s[i][k]){
							dp[i][j] |= dp[i - 1][k];
						}
					}
				}
			}
		}
		
		int fast = -1;
		for (int i = 1; i <= 30 && fast == -1; i++){
			for (int j = 0; j < n && fast == -1; j++){
				bool f = true;
				for (int k = 0; k < n; k++){
					f &= dp[i][j][k];
				}
				if (f) fast = i;
			}
		}
		
		printf("%d\n", fast);
	}
	
	return 0;
}

Measured memory_bytes: 1356
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

typedef long long ll;
const ll MAXN=1e5+10;
bool cmp(ll m,ll n){
	return m>n;
}
int main()//所有的循环已改正 
{
	int n;
	cin>>n;
	ll a[MAXN]={0};
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n-3;i++){
		if(a[i]==a[i+1]){
			for(int j=i+2;j<=n-1;j++){
				if(a[j]==a[j+1]){
					cout<<a[i]*a[j]<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"0"<<endl;
	return 0;
}	 


Measured memory_bytes: 1024
/*
	       ^  ^
			--

	Hello there!   __________    ___  __
	                |       |     |   /
	                |       |     |  /
	                |       |     | /
	                |_______|     |/
	                | \           |\
	                |  \          | \
	                |   \         |  \
	              __|    \________|   \__
*/

#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define f(x, n)             for(int x = 0; x < n; ++ x)
#define fr(x,n)             for(int x=1;x<=n;x++)
#define mp                  make_pair
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define pb                  push_back
#define eb                  emplace_back
#define pii 				pair<int,int>
#define pll 				pair<ll,ll>
#define F 					first
#define S 					second
#define inf 				1e18
#define MOD 				1000000007
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)

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


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  vector<int> v(3);
  int K, ans = 0, ma = 0;
  rep(i, 0, 3) {
    cin >> v[i];
    ans += v[i];
    ma = max(ma, v[i]);
  }
  cin >> K;

  int x = ma;
  rep(i, 0, K) x *= 2;
  ans += x - ma;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3544
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  val H = Array.fill(N)(sc.nextInt())
  val flags = Array.ofDim[Boolean](N)
  for (_ <- 1.to(M)) {
    val A, B = sc.nextInt() - 1
    if (H(A) == H(B)) {
      flags(A) = true
      flags(B) = true
    } else if (H(A) < H(B)) {
      flags(A) = true
    } else {
      flags(B) = true
    }
  }
  println(flags.count(_ == false))
}


Measured memory_bytes: 59604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int n, m, a, b, c;
    string s, t;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b));
}


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> lr (m);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        lr.at(i).push_back(a);
        lr.at(i).push_back(b);
    }
    int s,e,ans;
    s = 0;
    e = 100010;
    for(int i=0; i<m; i++){
        s = max(lr.at(i).at(0),s);
        e = min(lr.at(i).at(1),e);
        if(s > e) break;
    }
    if(s > e) ans = 0;
    else ans = e-s+1;
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
typedef long long ll;

pair<ll,ll> func(ll h, ll w) {
    if (h % 2 == 0 || w % 2 == 0) {
        pair<ll,ll> p(h*w/2, h*w/2);
        return p;
    }

    pair<ll,ll> p(h/2*w, (h/2+1)*w), q(h*(w/2), h*(w/2+1));
    if (p.second - p.first < q.second - q.first)
        return p;
    else 
        return q;
}

int main() {
    ll h, w;    cin >> h >> w;

    ll ans = 1e15;
    for (int i = 1; i < h; i++) {
        pair<ll,ll> p = func(h-i, w);
        ans = min(ans, max(i*w, max(p.first, p.second))-min(i*w, min(p.first, p.second)));
    }
    for (int i = 1; i < w; i++) {
        pair<ll,ll> p = func(h, w-i);
        ans = min(ans, max(h*i, max(p.first, p.second))-min(h*i, min(p.first, p.second)));
    }

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

Measured memory_bytes: 3624
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

H, W = map(int, input().split())
white = 0
w = [None]*H
for i in range(H):
    w[i] = input()
    # print(w[i])
for i in range(H):
    for j in range(W):
        if w[i][j] == '.':
            white += 1
#print("white", white)
d = deque()
d.append((0, 0))
dist = [None]*H
for i in range(H):
    dist[i] = [None]*W
dist[0][0] = 0
cost = 100
while(len(d) != 0):
    g, r = d.popleft()
    #print(g, r, dist[g][r])
    if w[g][r] == '.':
        if g != 0 and dist[g-1][r] == None:
            dist[g-1][r] = dist[g][r]+1
            d.append((g-1, r))
        if g != H-1 and dist[g+1][r] == None:
            dist[g+1][r] = dist[g][r]+1
            d.append((g+1, r))
        if r != 0 and dist[g][r-1] == None:
            dist[g][r-1] = dist[g][r]+1
            d.append((g, r-1))
        if r != W-1 and dist[g][r+1] == None:
            dist[g][r+1] = dist[g][r]+1
            d.append((g, r+1))
    if H-1 == g and W-1 == r:
        cost = min(cost, dist[g][r])
        print(white-(cost+1))
        exit()
if dist[H-1][W-1] == None:
    print(-1)


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

int main(){ 
	int x,n,a,d = 0;
	map<int,bool> ok;
	cin >> x >> n;
	for(int i = 1;i <= n;++i){
		cin >> a;
		ok[a] = 1;
	}

	while(1){
		if(!ok[x-d]){
			cout << x-d;
			break;
		}
		if(!ok[x+d]){
			cout << x+d;
			break;
		}
		d++;
	}
}

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

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

    vector <int>multi_table(9);
    for (int i = 0; i < 9; i++){
        multi_table.at(i) = i + 1;
    }
    
    int res1 = -1;
    int res2 = -1;
    for (int i = 0; i < 9; i++){
        if (multi_table.at(i) == A) res1 = A;
    }
    for (int i = 0; i < 9; i++){
        if (multi_table.at(i) == B) res2 = B;
    }
    if (res1 == -1 || res2 == -1){
        cout << -1 << endl;
    }else cout << res1 * res2 << endl;
}

Measured memory_bytes: 3592
#include<cstdio>
struct node{
	int s,c;
} a[100];
int n,m,ans[100];
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i) scanf("%d%d",&a[i].s,&a[i].c);
	for (int i=1;i<=m;++i) if (!ans[a[i].s]) ans[a[i].s]=a[i].c; else if (ans[a[i].s]!=a[i].c) ans[0]=-1;
	if (n>1) for (int i=1;i<=m;++i) if (a[i].s==1&&a[i].c==0) ans[0]=-1;
	if (n>1&&!ans[1]) ans[1]=1;
	if (ans[0]==-1) {
		printf("-1");
		return 0;
	}
	for (int i=1;i<=n;++i) printf("%d",ans[i]);
	return 0;
} 

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007
//#define DEBUG

int plus[16];
char numbers[16];
long int sum;
int len;

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(array, 10, sizeof(int), compare_int)

void culc(int i)
{
	if(i == len-1){
		long int term;

		term = 0;
		for(int j=0; j<len-1; j++){
			term += numbers[j] - '0';
			if(plus[j] != -1){
				sum += term;
				//printf("term:%ld\n", term);
				term = 0;
			}
			else{
				term = term*10;
			}
		}
		term += numbers[len-1] - '0';
		//printf("term:%ld\n", term);
		sum += term;

		return;
	}
	
	plus[i] = -1;
	culc(i+1);
	plus[i] = 1;
	culc(i+1);

	return;
}

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

	len = strlen(numbers);
	for(int i=0; i<16; i++){
		plus[i] = -1;
	}

	sum = 0;
	culc(0);

	printf("%ld\n", sum);
	
	return 0;
}



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

using namespace std;

int main() {
	string s;
    cin >> s;
    int a[4];
    for(int i = 0; i < 4; i++){
        a[i] = s[i] - '0';
    }

    char op[3];
    bool flag = false;

    for(int bit = 0; bit < (1 << 3); bit++){
        int sum = a[0];
        for(int j = 0; j < 3; j++){
            if(bit & (1 << j)){
                op[j] = '+';
                sum += a[j+1];            
            }else{
                op[j] = '-';
                sum -= a[j+1];
            }
        }
        if(sum == 7){
            break;
        }
    }

    cout << a[0];
    for(int i = 1; i < 4; i++){
        cout << op[i-1] << a[i];
    }
    cout <<"=" << "7" << endl;
}

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

ll INF = 1e+18;
int iINF = 1e9;
int MAXI = 1e8 + 1;

bool
comp(pair<ll, ll> a, pair<ll, ll> b)
{
  return a.first < b.first;
}

int 
main()
{
  ll N, D, A; cin >> N >> D >> A;
  vector<pair<ll, ll>> enmy(N);
  ll a = 0;
  rep(i, 0, N){
    ll x, h; cin >> x >> h;
    if(a < h) a= h;
    enmy[i].first = x;
    if(h % A != 0) enmy[i].second = (h / A) + 1;
    else enmy[i].second = h / A;
  }

  sort(enmy.begin(), enmy.end(), comp);
  
  vector<ll> range(N + 1, 0);
  rep(i, 0, N){
    ll dis = enmy[i].first + D * 2;
    auto itr = upper_bound(enmy.begin(), enmy.end(), make_pair(dis, 0), comp);
    if((itr - enmy.begin())<= N - 1){
      if(dis < enmy[i + 1].first){ range[i] = -1;
      //} else if(dis == enmy[i + 1].first){ range[i] += i + 1;
      //if(dis == enmy[i + 1].first){ range[i] += i + 1;
      //} else if(dis < enmy[i + 1].first){ range[i] = -1;//
      }else range[i] = itr - enmy.begin() - 1;
    } else {
       range[i] = N;}
  }

  ll cnt = enmy[0].second;
  vector<ll> current_dm(N + 1, 0);
  current_dm[0] = enmy[0].second;
  if(range[0] == -1) current_dm[1] -= enmy[0].second;
  else current_dm[range[0] + 1] -= enmy[0].second;

  rep(i, 0, N){
    if(current_dm[i] < enmy[i].second){
      ll dm = enmy[i].second - current_dm[i];
      cnt += dm;
      current_dm[i] += dm;
      if(range[i] == -1)current_dm[i + 1] -= dm;
      //else current_dm[range[i]] -= dm; 
      else{
       //if(i == range[i] -1) current_dm[range[i] + 1] -= dm;
       //else current_dm[range[i] + 1] -= dm;
       current_dm[range[i] + 1] -= dm;
      }
    }
      current_dm[i + 1] += current_dm[i];

  }

  cout << cnt << endl;

}

Measured memory_bytes: 9588
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
ll n;
int dp[20][2];
vector<int> v;
int solve(int now,int less)
{
    if(now==(int)v.size()) return 0;
    if(dp[now][less]!=-1) return dp[now][less];
    int limit=less?9:v[now];
    int &ans=dp[now][less];
    ans=0;
    for(int i=0;i<=limit;i++) ans=max(ans,i+solve(now+1,less||(i<v[now])));
    return ans;
}
int main()
{
    scanf("%lld",&n);
    while(n)
    {
        v.push_back(n%10);
        n/=10;
    }
    reverse(v.begin(),v.end());
    memset(dp,-1,sizeof(dp));
    printf("%d\n",solve(0,0));
    return 0;
}



Measured memory_bytes: 256
N, x = map(int, input().split())
A = [int(x) for x in input().split()]

D = [0]*N
answer = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        d = A[i] + A[i+1] - x
        e = min(A[i+1], d)
        answer += e
        A[i+1] -= e
        d -= e
        if d > 0:
            A[i] -= d
            answer += d
print(answer) 


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  long double w, h, x, y;
  cin >> w >> h >> x >> y;
  long double ans = w*h/2;
  int cent = 0; //中心を通るか
  if (x == w/2 && y == h/2) cent = 1;
  cout << ans << " " << cent << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
vlist = list(map(int, input().split()))

# most_commonを使うためにリストをCounterオブジェクトに渡す
Counter_evens = Counter(vlist[::2])
Counter_odds = Counter(vlist[1::2])


# even_indexes
top2_even = Counter_evens.most_common(2)  # [(一番多い要素,その出現回数),(2番目に多い要素,その出現回数)]

E_most_common = top2_even[0][0]
Emnum = top2_even[0][1]

if len(top2_even) == 2:
    E_2nd_common = top2_even[1][0]
    E2num = top2_even[1][1]
else:
    E_2nd_common = 'foo'
    E2num = 0

# odd_indexes
top2_odd = Counter_odds.most_common(2)

O_most_common = top2_odd[0][0]
Omnum = top2_odd[0][1]

if len(top2_odd) == 2:
    O_2nd_common = top2_odd[1][0]
    O2num = top2_odd[1][1]
else:
    O_2nd_common = 'foo'
    O2num = 0


if E_most_common == O_most_common:  # most commonどうしが衝突してしまっている。
    # もし偶数番目・奇数番目をどちらもmost commonに書き換えると、3つ目の条件「数列は1種類の数ではだめ」が満たされない。
    # なので奇数番目・偶数番目のどちらかは2番目に多いやつに書き換える必要がある

    # 偶数番目をmost commonに、oddsを2nd commonにそろえる場合に書き換えないといけない要素の数
    x = len(vlist[::2]) - Emnum + len(vlist[1::2]) - O2num
    # 逆の場合
    y = len(vlist[::2]) - E2num + len(vlist[1::2]) - Omnum

    print(min(x, y))
else:
    # most common は衝突していない、つまり異なる数。よって3つ目の条件「数列は1種類の数ではだめ」は満たされている。
    # 両方とも most commonに書き換えてOK
    print(len(vlist[::2]) - Emnum + len(vlist[1::2]) - Omnum)


Measured memory_bytes: 18656
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;

int main(void){
    string s;
    cin >> s;
    char f = s[0];
    for (ll i = 1; i < s.size(); i++){
        if (f == s[i]){
            cout << "Bad" << endl;
            return 0;
        }
        f = s[i];
    }
    cout << "Good" << endl;
    return 0;
}


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

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

    int n, k, ans = 0;
    cin >> n >> k;
    while (n != 0) {
        n /= k;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256