akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef IS_MY_ENV
#include <tourist>
#endif
using namespace std;

#define qp queue<pair<int,int>>

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };

int h, w;

inline bool in ( int y, int x ) {
    return 0 <= y && y < h && 0 <= x && x < w;
}

char mp[1010][1010];

int cnt = 0;

qp solve( qp q ) {
    qp n;
    while ( !q.empty() ) {
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        for ( int i = 0; i < 4; i++ ) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if ( in ( ny, nx ) && mp[ny][nx] == '.' ) {
                mp[ny][nx] = '#';
                cnt++;
                n.push( make_pair(ny, nx) );
            }
        }
    }
    return n;
}

signed main() {

    qp q;

    cin >> h >> w;
    for ( int i = 0; i < h; i++ ) {
        scanf("%s", mp[i]);
        for ( int j = 0; j < w; j++ ) {
            if ( mp[i][j] == '#' ) {
                q.push ( make_pair ( i, j ) );
                cnt++;
            }
        }
    }
    int ans = 0;
    while ( cnt != h * w ) {
        q = solve(q);
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11392
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

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

    for (int k = 0; k < N; ++k) {
        i64 l = ( -(N-1) + k ) * D + k * C;
        i64 r = ( -(N-1) + k ) * C + k * D;

        if (A + l <= B && B <= A + r) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int a[22];
int sp=0;
int push(int x){
  sp++;
  a[sp]=x;
}
int pop(){
  int x;
  x=a[sp];
  sp--;
  return x;
}
int main(){
  int x;
  while(scanf("%d",&x)!=EOF){
    if(x==0)printf("%d\n",pop());
    else push(x);
  }
  return 0;
}

Measured memory_bytes: 600
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;


#define FASTIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt", "w+", stdout)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define DBG printf("hey!!!\n")
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << " -- " << #x << ": " << (x) << "\n"
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))



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



const ll MAX= 998244353;
const ll MAX2=1271309838631957LL;
long double PI = acosl(-1);
const ll INF = 1e15;
const int NMAX = 2e5+5;
const int MAXLG = log2(NMAX)+1;
const int oo = 1e9+10;
const int sz = 100005;
const int MOD = 10000019;
const double EPS = 1e-9;

/// code starts from here

void solve(){
    int n, k;
    vector<int> v;

    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }


    ll dp[NMAX];
    for(int i = 0; i < n; i++){
        dp[i] = INF;
    }

    dp[0] = 0;

    for(int i = 1; i < n; i++){
        for(int j = i-1; i-j <= k && j >= 0; j--){
            dp[i] = min(dp[i], dp[j]+abs(v[i]-v[j]));
        }
    }
    cout << dp[n-1] << endl;
}

int main(){
    //IN;
    FASTIO;

    solve();




}


Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    string s; cin >> s;
    vl w(n,0);
    vl e(n,0);
    ll W=0,E=0;
    rep(i,n){
        w[i] = W;
        if(s[i] == 'W') W++;
    }
    for(ll i=n-1; i>=0; i--){
        e[i] = E;
        if(s[i] == 'E') E++;
    }
    ll mn = INF;
    rep(i,n){
        mn = min(w[i]+e[i],mn);
    }
    cout << mn << endl;
    /*rep(i,n) cout << w[i] << " ";
    cout << endl;
    rep(i,n) cout << e[i] << " ";*/
}


Measured memory_bytes: 5380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)
ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int zero_flag = 0;
    int count = 0;
    map<int, int> mp;
    ll ans = 1;
    rep(i, 0, n) {
        cin >> a[i];
        if(a[i] == 0) {
            count++;
        }
        mp[a[i]]++;
    }

    if(mp[0] >= 2) {
        cout << 0 << endl;
        return 0;
    }
    else if(mp[0]%2 == 1 && n%2 == 0) {
        cout << 0 << endl;
        return 0;
    }

    rep(i, 0, n/2) {
        if(mp[a[i]] != 2 && mp[0] != 1) {
            cout << 0 << endl;
            return 0;
        }
        else {
            ans *= 2;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    string s,s1,s2;
    cin>>s;
    if(s.size()%2){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,0,s.size()){
        if(i%2){
            if(s[i]!='i'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else if(s[i]!='h'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, k, m;
  while(cin >> n >> k >> m, n){
    vector<int> V;
    for(int i = 1; i <= n; ++i)
      V.push_back(i);
    --m;
    while(V.size() > 1){
      V.erase(V.begin()+m);
      m = (m+k-1)%(int)V.size();
    }
    cout << V[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 3248
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
	uint8_t s, w;
	scanf("%hhu%hhu", &s, &w);
	//scanf("%"PRIu8"%"PRIu8, &s, &w);
	puts(w>=s?"unsafe":"safe");
}



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

using namespace std;

#define debug(x) cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) for (auto i : v) cerr << i << " "; cerr << endl;

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);

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

    long long n, m, k;

    cin >> n >> m >> k;

    vector<long long> a(n + 1), b(m + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        b[i] += b[i - 1];
    }

    int ans = 0;

    for (int i = 0, j = m; i <= n; i++) {
        if (a[i] > k) break;
        while (a[i] + b[j] > k && j >= 0) j--;
        ans = max(ans, i + j);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6344
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
#define first fi
#define second se
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000],ab[220000];
pair<int,int> pp[220000];
string s,ss[220000],sa;
char ch[110][110];
queue<int> que;
signed main(){
    cin>>n;
    if(n>=30){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 10480
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

const int maxn = 1e6 + 20, lg = 20, inf = 1e9 + 5;

int n;
int fen[2][maxn];
vector<pair<int, int> > cards;//The second parameter should be a negative amount
vector<pair<pair<int, int>, bool> > srt; //{ { a, b }, id } and b is negative
map<int, int> m;
vector<int> uni;

void add(bool id, int idx, int val){
    for(; idx < maxn; idx += idx & -idx)
        fen[id][idx] = max(fen[id][idx], val);
}
int get_max(int id, int idx){
    int mx = 0;
    for(; idx; idx -= idx & -idx)
        mx = max(fen[id][idx], mx);
    return mx;
}
void create(){
    for(auto p : cards){
        srt.push_back({{-p.second, -p.first}, 0});
        srt.push_back({p, 1});
    }
    sort(srt.begin(), srt.end());
}
void calc(){
    for(auto p : srt){
        int a = p.first.first;
        int b = -p.first.second;
        bool id = p.second;
        int dp = 1 + get_max(!id, b - 1);
        add(id, b, dp);
        //cout << a << ' ' << b << ' ' << id << ' '<<dp<<endl;
    }
}
void ansing(){
    cout << max(get_max(0, maxn - 1), get_max(1, maxn - 1)) << endl;
}
void comp_map(){
    vector<int>::iterator ip;
    sort(uni.begin(), uni.end());
    ip = unique(uni.begin(), uni.end());
    uni.resize(distance(uni.begin(), ip));
    for(int i = 0; i < uni.size(); i++)
        m[uni[i]] = i + 1;
}
void comp_it(){
    for(int i = 0; i < n; i++){
        cards[i] = {m[cards[i].first], -m[-cards[i].second]};
    }
}
void input(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;

        uni.push_back(a);
        uni.push_back(b);

        cards.push_back({a, -b});
    }
}
void comping(){
    comp_map();
    comp_it();
}
int main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    char c;
    cin >> c;
    cout << char(c + 1);
}
/*    input();
    comping();
    create();
    calc();
    ansing();
}*/


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

int dx[6] = {1,1,0,-1,-1,0}, dy[6] = {0,1,1,0,-1,-1};

int main(){
	int t,n;
	while(scanf("%d%d", &t, &n),t||n){
		int deta[200][200];
		int cost[200][200];
		rep(i,200) rep(j,200) deta[i][j] = 0;
		rep(i,200) rep(j,200) cost[i][j] = INF;
		rep(i,n){
			int x, y;
			scanf("%d%d", &x, &y);
			x += 100; y += 100;
			deta[x][y] = 1;
		}
		if(t == 0){
			cout << "1" << endl;
			continue;
		}
		int sx, sy;
		scanf("%d%d", &sx, &sy);
		sx += 100; sy += 100;
		deta[sx][sy] = 2;
		cost[sx][sy] = 0;
		queue<P> que;
		que.push(P(sx,sy));
		while(que.size() != 0){
			P p = que.front(); que.pop();
			rep(i,6){
				P tmp = p;
				tmp.fi += dx[i];
				tmp.sec += dy[i];
				if(deta[tmp.fi][tmp.sec] == 0 && cost[tmp.fi][tmp.sec] > cost[p.fi][p.sec]+1){
					deta[tmp.fi][tmp.sec] = 2;
					cost[tmp.fi][tmp.sec] = cost[p.fi][p.sec]+1;
					if(cost[tmp.fi][tmp.sec] != t) que.push(tmp);
				}
			}
		}
		int cnt = 0;
		rep(i,200) rep(j,200){
			if(deta[i][j] == 2) cnt++;
		}
		cout << cnt << endl;
	}
	
}

Measured memory_bytes: 1544
#include <iostream>
#include <vector>
int main() {
int n, ans = 0;
std::cin >> n;
std::vector<int> a(n+1, 0);
for (int i = 0; i < n; i++) {
int x;
std::cin >> x;
a[x] = a[x - 1] + 1;
if (a[x] > ans) ans = a[x];
}
std::cout << (n - ans) << std::endl;
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

const long long mod = 998244353;

int a, b, c, d;
long long e[3030][3030], p[3030][3030], q[3030][3030];

void add(long long& a, long long b)
{
	b %= mod;
	a += b;
	if (a >= mod)
		a -= mod;
}

int main()
{
	scanf ("%d %d %d %d", &a, &b, &c, &d);

	e[c][d] = 1;
	for (int i = c; i >= a; i--) for (int j = d; j >= b; j--){
		add(e[i - 1][j - 1], e[i][j] * (i - 1));
		add(e[i - 1][j - 1], e[i][j] * (j - 1));
		add(p[i][j - 1], e[i][j]);
		add(q[i - 1][j], e[i][j]);
		add(e[i - 1][j - 1], e[i][j] * (i - 1) * (j - 1));
		add(p[i][j - 1], e[i][j] * (i - 1));
		add(q[i - 1][j], e[i][j] * (j - 1));

		add(p[i][j - 1], p[i][j] * (i - 1));
		add(e[i][j - 1], p[i][j]);

		add(q[i - 1][j], q[i][j] * (j - 1));
		add(e[i - 1][j], q[i][j]);
	}
	printf ("%lld\n", (e[a][b] + p[a][b] + q[a][b]) % mod);

	return 0;
}

Measured memory_bytes: 214676
n,q = map(int,input().split())
a = list(map(int,input().split()))
x = [int(input()) for _ in range (q)]

sort_x = sorted(x)
ans = {}
if n % 2 == 1:
    small_position = 0
    border_position = int((n-1)/2)
else:
    small_position = 1
    border_position = int(n/2)
sum_all = sum(a[border_position:])
a.append(1000000000)
a.append(1000000000)
x_index = 0
flag = False

for compare in a[border_position:]:
    compare_x = sort_x[x_index]
    small_a = a[small_position]
    while 2*sort_x[x_index] - small_a <= compare:
        ans[sort_x[x_index]] = sum_all
        x_index += 1
        if x_index == q:
            flag = True
            break
    sum_all = sum_all + small_a - compare
    small_position += 2
    if flag:
        break
for x_i in x:
    print(ans[x_i])



Measured memory_bytes: 24140
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;

vector<int> a;

vector < vector<int> > g;

void dfs1(int v, int p, int d)
{
    a[v] = d;
    for (int to : g[v])
        if (to != p)
            dfs1(to, v, d + 1);
}

int dfs2(int v, int p, int t)
{
    int dt = a[v] - t;
    if (dt <= 0)
        return 0;
    int ans = t + dt - 1;
    for (int to : g[v])
        if (to != p)
            ans = max(ans, dfs2(to, v, t + 1));
    return ans;
}
signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int n, u, v;
    cin >> n >> u >> v;
    g.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    a.resize(n + 1);
    dfs1(v, 0, 0);
    cout << dfs2(u, 0, 0);
    
    return 0;
}

Measured memory_bytes: 10240
using System;
using System.Collections.Generic;

class MainClass
{
    public static void Main(string[] args)
    {
        var N = LnInt();
        var K = LnInt();
        var Xs = LnInts();
        var sum = 0;
        for (var i = 0; i < Xs.Length; i++)
        {
            var ax = Math.Abs(Xs[i]);
            var bx = Math.Abs(Xs[i] - K);
            if (ax < bx)
            {
                sum += ax;
            }
            else
            {
                sum += bx;
            }
        }
        Console.WriteLine(sum*2);
    }


    public static int[] LnInts()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var ins = new int[vs.Length];
        for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]);
        return ins;
    }

    public static int LnInt()
    {
        var vs = Console.ReadLine().Trim();
        return int.Parse(vs);
    }

    public static string[] LnStrs()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        return vs;
    }
    public static string LnStr()
    {
        var vs = Console.ReadLine().Trim();
        return vs;
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    1-indexed であることに注意 !!
*/
template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= (i & (-i))) res += dat[i];
        return res;
    }

    T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    void add(int k, T x) {
        if (k == 0) return;
        for (int i = k; i <= n; i += (i & (-i))) dat[i] += x;
    }

    /*
        a[0] + a[1] + ... + a[res] >= x
    */
    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, k = 1;
        while (k < n) k <<= 1;
        for (; k > 0; k >>= 1) {
            if (res + k <= n && dat[res + k] < x) {
                x -= dat[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

signed main() {
    int n, q;
    cin >> n >> q;
    int c[n];
    rep(i, n) {
        cin >> c[i];
        c[i]--;
    }
    int l, r;
    vector<pair<pair<int, int>, int>> v(q);
    rep(i, q) {
        cin >> l >> r;
        v[i].first.first = r;
        v[i].first.second = l;
        v[i].second = i;
    }
    sort(ALL(v));
    int ans[q];
    int pre = 0;
    int la[n];
    fill(la, la + n, -1);
    BIT<int> bit(n);
    rep(i, q) {
        while (pre < v[i].first.first) {
            if (la[c[pre]] != -1) bit.add(la[c[pre]] + 1, -1);
            bit.add(pre + 1, 1);
            la[c[pre]] = pre;
            pre++;
        }
        ans[v[i].second] = bit.sum(v[i].first.second, v[i].first.first + 1);
    }
    rep(i, q) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 17364
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
struct val2entry {
    ll value;
    int counter;
};
struct psum {
    ll val1;
    deque<val2entry> val2;
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> p(n);
    cin >> p;
    vector<psum> sums;
    ll ans = 0, sum2 = 0;
    for(int i = 0; i < n; i++) {
        psum newsum = {p[i], {{0, 1}}};
        while(not sums.empty() and sums.back().val1 <= p[i]) {
            int total = 0;
            for(auto& e : sums.back().val2) {
                total += e.counter;
                sum2 -= e.value * e.counter;
            }
            newsum.val2.push_back({sums.back().val1, total});
            sum2 += sums.back().val1 * total;
            sums.pop_back();
        }
        if(not sums.empty()) {
            int total = 0;
            while(not sums.back().val2.empty() and sums.back().val2.front().value <= p[i]) {
                total += sums.back().val2.front().counter;
                sum2 -= sums.back().val2.front().value * sums.back().val2.front().counter;
                sums.back().val2.pop_front();
            }
            sums.back().val2.push_front({p[i], total});
            sum2 += p[i] * total;
        }
        sums.push_back(newsum);
        ans += sum2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 92060
#include <stdio.h>
#include <string.h>
int n,S[1000000000];
int binarySearch(int key){
  int left=0,right=n+1,mid;
    while (left<right){
      mid=(left+right)/2;
      if(S[mid]==key){
        return 1;
      }else if(key<S[mid]){
        right=mid;
      }else if(key>S[mid]){
        left=mid+1;
      }
    }
      return 0;
}

int main(){
  int i,T,cnt=0,q;
  scanf("%d", &n);
  for ( i = 1; i <= n; i++){
     scanf("%d", &S[i]);
  }
  scanf("%d",&q);
  for ( i = 1; i <= q; i++){
    scanf("%d",&T);
   if(binarySearch(T)){
     cnt++;
     }
   }
   printf("%d\n",cnt);
    return 0;
  }



Measured memory_bytes: 2108
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
sum_A = sum(A)
is_ok = True
for i in range(M):
    check = 1 / (4 * M)
    if A[i] / sum_A < check:
        is_ok = False
        break
print("Yes" if is_ok else "No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int i,j;
	int n,q;
	int m,d,a[100];
	int max;
	
	while(1)
		{
			for(i=0;i<100;i++)
				{
					a[i] = 0;
				}
				
			scanf("%d %d ",&n,&q);
			if(n == 0 && q == 0)break;
			
			for(i=0;i<n;i++)
				{
					scanf("%d ",&m);
					
					for(j=0;j<m;j++)
						{
							scanf("%d ",&d);
							a[d]++;
						}
				}
			
			max = 0;
			for(i=0;i<100;i++)
				{
					if(max < a[i])
						{
							max = a[i];
						}
				}
			if(max < q){printf("0\n");}
			else
				{
					for(i=0;i<100;i++)
						{
							if(max == a[i])
								{
									printf("%d\n",i);
									break;
								}
						}
				}
		}
	return 0;
}
							
			

Measured memory_bytes: 0
import sys

N = int(input())
E = [list(map(int, input().split())) for _ in range(N)]

inf = float('inf')
for i in range(N):
	E[i][i] = inf

for k in range(N):
	for i in range(N):
		if i == k:
			continue
		for j in range(N):
			if k == j or i == j:
				continue
			direct = E[i][j]
			detour = E[i][k]+E[k][j]
			if direct == inf or detour == inf:
				continue

			if direct > detour:
				print(-1)
				sys.exit()

			elif direct == detour:		
				E[i][j] = inf
				E[j][i] = inf

answer = 0
for i in range(N):
	for j in range(N):
		if E[i][j] == inf:
			continue
		
		answer += E[i][j]

print(answer//2)

Measured memory_bytes: 48476
import sys
import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, D = list(readline().decode('utf8').strip())
for ops in itertools.product(['+', '-'], repeat=3):
    eq = A + ops[0] + B + ops[1] + C + ops[2] + D
    x = eval(eq)
    if x == 7:
        break
ans = eq + '=7'
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  char a_str[b + 1] = {0};
  for(int i = 0; i < b; ++i) a_str[i] = '0' + a;
  char b_str[a + 1] = {0};
  for(int i = 0; i < a; ++i) b_str[i] = '0' + b;
  if(strcmp(a_str, b_str) <= 0) cout << a_str << endl;
  else cout << b_str << endl;
  return 0;
}

Measured memory_bytes: 256
'use strict';

const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
//　最初の行の数値を獲得
let N = input * 1;
let ans = 1;
let den = Math.pow(10,9) + 7;

for(let i = 1; i <= N; i++){
	ans *= i;
  	if(ans > den){
    	ans = ans % den;
    }
}

console.log(ans);

Measured memory_bytes: 9164
from collections import defaultdict
from bisect import *
def solve():
  ans = float('inf')
  N = int(input())
  L_y = defaultdict(lambda: [-float('inf'),float('inf')])
  R_y = defaultdict(lambda: [-float('inf'),float('inf')])
  U_x = defaultdict(lambda: [-float('inf'),float('inf')])
  D_x = defaultdict(lambda: [-float('inf'),float('inf')])
  R_xpy = defaultdict(lambda: [-float('inf'),float('inf')])
  R_y_x = defaultdict(lambda: [-float('inf'),float('inf')])
  L_xpy = defaultdict(lambda: [-float('inf'),float('inf')])
  L_y_x = defaultdict(lambda: [-float('inf'),float('inf')])
  U_xpy = defaultdict(lambda: [-float('inf'),float('inf')])
  U_y_x = defaultdict(lambda: [-float('inf'),float('inf')])
  D_xpy = defaultdict(lambda: [-float('inf'),float('inf')])
  D_y_x = defaultdict(lambda: [-float('inf'),float('inf')])
  for i in range(N):
    x,y,u = input().split()
    x,y = int(x),int(y)
    if u=='D':
      insort(D_x[x],y)
      insort(D_xpy[x+y],x)
      insort(D_y_x[y-x],x)
    if u=='U':
      insort(U_x[x],y)
      insort(U_xpy[x+y],x)
      insort(U_y_x[y-x],x)
    if u=='L':
      insort(L_y[y],x)
      insort(L_xpy[x+y],x)
      insort(L_y_x[y-x],x)
    if u=='R':
      insort(R_y[y],x)
      insort(R_xpy[x+y],x)
      insort(R_y_x[y-x],x)
  for k,v in R_y.items():
    for zahyou in v[1:-1]:
      ind = bisect_right(L_y[k],zahyou)
      dis = L_y[k][ind]-zahyou
      ans = min(ans,dis)
  for k,v in D_x.items():
    for zahyou in v[1:-1]:
      ind = bisect_right(U_x[k],zahyou)
      dis = zahyou-U_x[k][ind-1]
      ans = min(ans,dis)
  for k,v in L_y_x.items():
    for zahyou in v[1:-1]:
      ind = bisect_right(U_y_x[k],zahyou)
      dis = zahyou-U_y_x[k][ind-1]
      dis *= 2
      ans = min(ans,dis)
  for k,v in R_xpy.items():
    for zahyou in v[1:-1]:
      ind = bisect_right(U_xpy[k],zahyou)
      dis = U_xpy[k][ind]-zahyou
      dis *= 2
      ans = min(ans,dis)
  for k,v in L_xpy.items():
    for zahyou in v[1:-1]:
      ind = bisect_right(D_xpy[k],zahyou)
      dis = zahyou-D_xpy[k][ind-1]
      dis *= 2
      ans = min(ans,dis)
  for k,v in R_y_x.items():
    for zahyou in v[1:-1]:
      ind = bisect_right(D_y_x[k],zahyou)
      dis = D_y_x[k][ind]-zahyou
      dis *= 2
      ans = min(ans,dis)
  ans *= 5
  return ans if ans<float('inf') else 'SAFE'
print(solve())

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

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    rep(i, n){
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i, m){
        int a =q.top();q.pop();
        q.push(a/2);
    }
    ll ans = 0 ;
    rep(i,n){
        ans += q.top(); q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
 
void main() {
    auto X = readln.chomp.map!(c => cast(int)(c - '0')).array;
    Tuple!(int, string) func(int sum, string str, int[] left) {
        if (left == null) return tuple(sum, sum == 7 ? str : null);
        auto a = func(sum + left[0], str ~ "+", left[1..$]);
        auto b = func(sum - left[0], str ~ "-", left[1..$]);
        if (a[0] == 7) return a;
        return b;
    }
    auto ops = func(X[0], "", X[1..$])[1];
    writefln("%d%c%d%c%d%c%d=7", X[0], ops[0], X[1], ops[1], X[2], ops[2], X[3]);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;
long long gcd( long long a, long long b ) {
    
    if ( b == 0 ) { return a; }
    
    return gcd( b, a%b );
}

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


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

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


int main() {

    int N;
    long long X;
    cin >> N >> X;
    vector<long long> A(N+1);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    A[N] = X;

    sort( A.begin(), A.end() );
    vector<long long> B(N);
    for ( int i = 1; i < N+1; i++ ) {
        B[i-1] = A[i]-A[i-1];
    }

    long long ans = B[0];
    for ( int i = 1; i < N; i++ ) {
        ans = gcd(ans,B[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;


int main(){
    int n, k;
    cin >> n >> k;
    ll ans = LINF;
    vector<ll> A(n + 1, 0);
    for (int i = 0; i < n; i++) cin >> A[i + 1];
    for (int bit = 0; bit < 1 << n; bit++) {
        ll money = 0;
        int cnt = 0;
        ll nax = 0;
        for (int i = 0; i < n; i++) {
            bool flag = (bit >> i & 1);
            if(flag){
                ll h = A[i + 1];
                chmax(h, nax + 1);
                chmax(nax, h);
                money += max(0LL, h - A[i + 1]);
                cnt++;
            } else {
                if(A[i + 1] > nax) cnt++;
                chmax(nax, A[i + 1]);
            }
        }
        if(cnt >= k) {
            chmin(ans, money);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ps = []
for _ in range(m):
    _p, _s = map(str, input().split())
    _p = int(_p)
    ps.append([_p, _s])

ac = [False]*n
wa = [0]*n

for _p, _s in ps:
    if ac[_p-1]:
        continue

    if _s == "AC":
        ac[_p-1] = True
    elif _s == "WA":
        wa[_p-1] += 1

ans = [0, 0]
for _ac, _wa in zip(ac, wa):
    if _ac:
        ans[0] += 1
        ans[1] += _wa

print(*ans)


Measured memory_bytes: 23540
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
const long double PI = 3.14159265359;
bool ok[100010];
int cnt[100010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	VE p(m); vector<string>s(m); rep(i, m)cin >> p[i] >> s[i];
	rep(i, m)p[i]--;
	int ans = 0;
	rep(i, m) {
		if (s[i] == "AC") {
			if (!ok[p[i]])ans++;
			ok[p[i]] = true;
			
		}
		else {
			if (!ok[p[i]])cnt[p[i]]++;
		}
	}
	int tmp = 0;
	rep(i, 100010) {
		if (ok[i]) {
			tmp += cnt[i];
		}
	}
	cout << ans << " " << tmp << endl;
	return 0;
}

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

int main()
{
    string S;
    string S1="";
    cin>>S;
    int Q,T,F,r=0;
    cin>>Q;
    char C;
    for(int i=0;i<Q;i++){
        cin>>T;
        if(T==1){
            r++;
        }else{
            cin>>F>>C;
            if(F==1&&r%2==0){
                S1+=C;
            }else if(F==1&&r%2!=0){
                S=S+C;
            }else if(F==2&&r%2==0){
                S=S+C;
            }else{
                S1+=C;
            }
        }
    }
    if(r%2==0) {
    reverse(S1.begin(),S1.end());
    cout<<S1<<S<<endl;
    }else{
        reverse(S.begin(),S.end());
        cout<<S<<S1<<endl;
    }
}

Measured memory_bytes: 1600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<Int MOD = 1000000007>
struct Mod{
  Int prev=0;
  vector<Int> fact,inv,finv;
  Mod(){}
  Mod(Int n){init(n);}
  
  Int pow(Int x,Int n){
    Int res=1;
    while(n){
      if(n&1) (res*=x)%=MOD;
      (x*=x)%=MOD;
      n>>=1;
    }
    return res;
  }
  
  Int inverse(Int a){
    return pow(a,MOD-2);
  }
  
  void init(Int n){
    if(prev>=n) return;
    prev=n;
    fact=inv=finv=vector<Int>(n);
    
    fact[0]=1;
    for(Int i=1;i<n;i++)
      fact[i]=(fact[i-1]*i)%MOD;
    
    inv[1]=1;
    for(Int i=2;i<n;i++)
      inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    
    finv[0]=1;
    for(Int i=1;i<n;i++)
      finv[i]=finv[i-1]*inv[i]%MOD;
  }
  
  Int comb(Int n,Int k){
    Int res=1;
    for(Int i=0;i<k;i++){
      res*=(n-i)%MOD;
      res%=MOD;
      res*=inverse(i+1);
      res%=MOD;
    }
    return res;
  }
  
  //only for prime MOD
  Int C(Int n,Int k){
    if(k<0||k>n) return 0;
    return fact[n]*finv[k]%MOD*finv[n-k]%MOD;
  }

  Int H(Int n,Int k){
    return C(n+k-1,n);
  }

  Int S(Int n,Int k){
    Int res=0;
    for(Int i=1;i<=k;i++){
      Int tmp=C(k,i)*pow(i,n)%MOD;
      if((k-i)&1) res+=MOD-tmp;
      else res+=tmp;
      res%=MOD;
    }
    res=res*finv[k]%MOD;
    return res;
  }
  
  Int B(Int n,Int k){
    Int res=0;
    for(Int j=1;j<=k;j++){
      res+=S(n,j);
      res%=MOD;
    }
    return res;
  }
  
  Int montmort(Int n){
    Int res=0,rinv=1;
    for(Int k=2;k<=n;k++){
      rinv=rinv*inverse(k)%MOD;
      if(k%2) res+MOD-rinv;
      else res+=rinv;
      res%=MOD;
    }
    for(Int i=1;i<=n;i++) res=res*i%MOD;
    return res;
  }
  
  // calculate P(t) from given points in [0,N]
  Int LagrangePolynomial(vector<Int> &y,Int t){
    Int n=y.size()-1;
    init(n+1);
    Int num=1;
    for(Int i=0;i<=n;i++)
      num=num*((t-i)%MOD)%MOD;
    Int res=0;
    for(Int i=0;i<=n;i++){
      Int tmp=(y[i]*num%MOD)*inverse((t-i)%MOD)%MOD;
      tmp=tmp*finv[i]%MOD;
      tmp=tmp*finv[n-i]%MOD;
      if((n-i)&1) tmp=MOD-tmp;
      res=(res+tmp)%MOD;
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  const Int MOD = 1e9+7;
  Mod<MOD> mod(2e5);
  Int n,k;
  cin>>n>>k;
  cout<<mod.B(n,k)<<endl;
  return 0;
}



Measured memory_bytes: 7480
#!/usr/bin/env python3
import sys


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[float('inf') for _ in range(10**5+1)] for _ in range(N)]
    dp[0][0] = 0
    dp[0][v[0]] = w[0]

    js = [0,v[0]]

    for i in range(1,N):
        for j in js[:]:
            js.append(j+v[i])
        js = list(set(js))

        for j in js:
            if j - v[i] >= 0:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i])
            else:
                dp[i][j] = dp[i-1][j]

    res = 0
    for i,j in enumerate(dp[-1]):
        if j != float("inf") and j <= W:
            res = i
    print(res)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];
  
  ll res = 1e18;
  rep(i, n - k + 1) {
    ll left = x[i];
    ll right = x[i + k - 1];
    res = min(res, min(abs(left), abs(right)) + right - left);
  }
  cout << res << endl;
}


Measured memory_bytes: 1152
package main

import "fmt"

func main() {
        var a, b, c, d, e, f int
        fmt.Scan(&a, &b, &c, &d, &e, &f)
        maxDense := 0.0
        maxW := 100 * a
        maxS := 0
        for i := 0; 100*a*i <= f; i++ {
                for j := 0; 100*b*j <= f-100*a*i; j++ {
                        w := 100 * (a*i + b*j)
                        cap := e * (a*i + b*j)
                        for k := 0; c*k <= cap && c*k <= f-w; k++ {
                                for l := 0; d*l <= cap-c*k && d*l <= f-w-c*k; l++ {
                                        sal := c*k + d*l
                                        var den float64
                                        if k == 0 && l == 0 {
                                                den = 0.0
                                        } else {
                                                den = float64(sal) / float64(w+sal)
                                        }
                                        if maxDense < den {
                                                maxDense = den
                                                maxW = w + sal
                                                maxS = sal
                                        }
                                }
                        }
                }
        }
        fmt.Printf("%d %d\n", maxW, maxS)
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long m = sc.nextLong();
    long sum = 0;
    for(int i = 0; i < m; i++){
      long a = sc.nextLong();
      sum += a;
    }
    if(sum > n){
      System.out.println(-1);
    }
    else{
      System.out.println(n-sum);
    }
  }
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> p) {
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] != i + 1) {
      ans++;
    }
  }
  if (ans == 2 || ans == 0) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  solve(N, std::move(p));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, A, B, a = 0, b = 0; string S; cin >> N >> A >> B >> S;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'a' && a < A + B) {
            printf("%s\n", "Yes");
            a++;
        }
        else if (S[i] == 'b' && b + 1 <= B && a < A + B) {
            printf("%s\n", "Yes");
            a++, b++;
        }
        else printf("%s\n", "No");
    }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

signed main() {
    string s;
    cin >> s;
    int n = s.length();
    s = '2' + s;
    bool check = true;
    if (s[1] == '0' || s[n] == '1') {
        check = false;
    }
    for (int i = 1; i < n; i++) {
        if (s[i] != s[n - i]) check = false;
    }
    if (!check) {
        cout << -1 << endl;
        return 0;
    }
    s[n] = '1';
    queue<int> temp;
    for (int i = 1; i <= n; i++) if (s[i] == '1') temp.push(i);
    for (int i = 1; i < n; i++) {
        if (i == temp.front()) temp.pop();
        cout << i << " " << temp.front() << endl;
    }
    return 0;
}


Measured memory_bytes: 2300
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;



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

  string s;
  int ans = 0;

  cin >> s;

  for(int i=0;i<s.size();i++){
    if(s[i] == '2'){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		System.out.println(Math.max(a * b, Math.max(a + b, a - b)));

		sc.close();
	}

}


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

struct p{
	long long x,y,idx;
	unsigned long long sqrdist(p b){
		return (x-b.x)*(x-b.x)+(y-b.y)*(y-b.y);
	}
	void read(){
		cin >> x >> y;
	}
	long long operator *(p b){
		return x*b.y - y*b.x;
	}
	bool operator ==(p b){
		return x == b.x && y == b.y;
	}
	void operator -=(p b){
		x -= b.x,y -= b.y;
	}
	bool operator >=(p b){
		return x >= b.x && y >= b.y;
	}
	bool operator <=(p b){
		return x <= b.x && y <= b.y;
	}
	p operator -(p b){
		return {x-b.x,y-b.y};
	}
	long long crossprod(p a , p b){
		a.x -= x , b.x -= x , a.y -= y , b.y -= y;
		return a*b;
	}
};

struct segment{
	p p1,p2;
	void equal(p a , p b){
		p1 = a , p2 = b;
	}
	void readseg(){
		p1.read(),p2.read();
	}
};

bool comp(p a , p b){
	return a.y < b.y;
	//
}

void convexhull(vector<p> v , vector<p> c){
	sort(v.begin(),v.end(),comp);
	for(long long q = 0 ; q < 2 ; q += 1){
		vector<p> g;
		g.push_back(v[0]);
		for(long long i = 1 ; i < v.size() ; i += 1){
			while(g.size() >= 2 && ((v[i] - g[g.size()-2])*(g.back() - g[g.size()-2]) <= 0)){
				g.pop_back();
			}
			g.push_back(v[i]);
		}
		if(q == 0){
			g.pop_back();
		}
		for(p i : g){
			c.push_back(i);
		}
		reverse(v.begin(),v.end());
	}
}

bool intersect(segment a , segment b){
	for(long long i = 0 ; i < 2 ; i += 1){
		p p1 = a.p1;
		long long v1 = (b.p1 - p1)*(a.p2 - p1) , v2 = (b.p2 - p1)*(a.p2 - p1);
		if(v1 * v2 > 0){
			return false;
		}else if(v1 == 0 && v2 == 0){
			if(max(a.p1.x,a.p2.x) < min(b.p1.x,b.p2.x) || max(a.p1.y,a.p2.y) < min(b.p1.y,b.p2.y)){
				return false;
			}
		}
		swap(a,b);
	}
	return true;
}

bool equal(vector<p> a , vector<p> b){
	if(a.size() != b.size()){
		return false;
	}
	for(long long i = 0 ; i < a.size() ; i += 1){
		if(a[i] == b[i]){
			continue;
		}
		return false;
	}
	return true;
}
long long fact[100001],x[100001],n,k,ans,val;
const long long mod = 1000000007;

long long invmod(long long a){
	long long ret = 1 , pw = mod-2;
	while(pw > 0){
		if(pw % 2 == 1){
			ret *= a;
			ret %= mod;
		}
		pw /= 2;
		a *= a;
		a %= mod;
	}
	return ret;
}

long long chose(long long a , long long b){
	long long v = fact[a]*invmod(fact[a-b]);
	v %= mod;
	v *= val;
	return v%mod;
}

int main(){
	cin >> n >> k;
	if(k == 1){
		cout << 0 << endl;
		return 0;
	}
	for(long long i = 0 ; i < n ; i += 1){
		cin >> x[i];
	}
	fact[0] = 1;
	for(long long i = 1 ; i <= n ; i += 1){
		fact[i] = fact[i-1]*i;
		fact[i] %= mod;
	}
	sort(x,x+n);
	val = invmod(fact[k-1]);
	for(long long i = n-1 ; i >= 0 ; i -= 1){
		if(n-i >= k){
			ans -= chose(n-i-1,k-1)*x[i];
			ans %= mod;
		}
		if(i >= k-1){
			ans += chose(i,k-1)*x[i];
			ans %= mod;
		}
	}
	ans += mod;
	ans %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

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

int main()
{
   int n, m, x[101] = {}, y[101] = {};
   cin >> n >> m >> x[0] >> y[0];
   FOR(i, 1, n + 1)
   cin >> x[i];
   FOR(i, 1, m + 1)
   cin >> y[i];

   sort(x, x + n + 1);
   sort(y, y + m + 1);

   if (x[n] < y[0])
      cout << "No War" << endl;
   else
      cout << "War" << endl;
   return 0;
}



Measured memory_bytes: 256
use std::io;

fn main() {
  let mut input_line = String::new();
  io::stdin().read_line(&mut input_line).unwrap();
  let N = input_line.trim().parse::<usize>().unwrap();
  let Ni = N as isize;
  
  let mut input_line = String::new();
  io::stdin().read_line(&mut input_line).unwrap();
  let data = input_line.trim().split(" ").map(|x| x.parse::<isize>().unwrap()).collect::<Vec<_>>();

  let step = (N * (N+1) / 2) as isize;
  let total = data.iter().fold(0,|a, b| a + b);
  if total % step != 0 {
    println!("NO");
  }
  else {
    let K = total / step;
    let mut delta: Vec<isize> = Vec::with_capacity(N);
    for i in 0..N {
      delta.push(data[i] - data[(N + i-1) % N]);
    }
    let invalid = delta.iter().map(|x| (K-x < 0) || ((K-x) % Ni > 0)).fold(false,|a, b| a || b);
    if invalid {
      println!("NO");
    }
    else {
      let sum = delta.iter().map(|x| (K-x) / Ni).fold(0, |a, b| a + b);
      if sum == K {
        println!("YES");
      }
      else {
        println!("NO");
      }
    }
  }
}    

Measured memory_bytes: 3580
//
// Created by 江口慎悟 on 2019-03-19.
//



#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;
int b(int N, const vector<int>& d){
    vector<bool> occur(200,false);
    int count = 0;

    for(int i = 0; i < N; i++){
        if(!occur[ d[i] ] ){
            count++;
            occur[ d[i]] = true;
        }
    }

    return count;

}

int main(){

    int N; cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    cout << b(N, d);

}

Measured memory_bytes: 256