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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);

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

    vector<int> dp(k + 1, 2);

    for(int i = a[0]; i <= k; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(i - a[j] >= 0)
            {
                if(dp[i - a[j]] == 2)
                {
                    dp[i] = 1;
                    break;
                }        
            }
        }
    }

    // for(int i = 0; i <= k; i++)
    // {
    //     cout << dp[i] << " ";
    // }

    // cout << "\n";
    
    if(dp[k] == 1)
    {
        cout << "First";
    }
    else
    {
        cout << "Second";
    }
    
    
    return 0;
}

Measured memory_bytes: 3776
#include <cstdio>
#include <algorithm>
long long a[300002], SH[300002], ST[300002], FH[300002], FT[300002], O[300002];
int N, Q, q[300002], D;
inline long long C(int x)
{
	return (long long)x * (x + 1) / 2;
}
inline long long WH(int l, int r)
{
	return FH[l] - SH[r] + SH[l] + C(r - l);
}
inline bool CH(int x, int y, int z)
{
	long long wx = FH[x] + SH[x] + C(x);
	long long wy = FH[y] + SH[y] + C(y);
	long long wz = FH[z] + SH[z] + C(z);
	return (wy - wx) * (z - y) <= (wz - wy) * (y - x);
}
inline long long WT(int l, int r)
{
	return FT[l] - ST[r] + ST[l] + C(l - r);
}
inline bool CT(int x, int y, int z)
{
	long long wx = FT[x] + ST[x] + C(x);
	long long wy = FT[y] + ST[y] + C(y);
	long long wz = FT[z] + ST[z] + C(z);
	return (wx - wy) * (y - z) >= (wy - wz) * (x - y);
}
inline long long Range(int l, int r)
{
	return FH[l] + SH[l] + FT[r] + ST[r] + C(r - l - 1);
}
inline void NiroBC(int l, int r)
{
	if (l == r)
	{
		O[l] = std::max(O[l], Range(l - 1, r + 1));
		return;
	}
	int m = l + r >> 1;
	NiroBC(l, m);
	NiroBC(m + 1, r);
	static long long w[300002];
	for (int i = l; i <= r; i++)
		w[i] = -1LL << 60;
	D = 0;
	for (int i = l - 1; i < m; i++)
	{
		while (D > 1 && CH(q[D - 1], q[D], i))
			D--;
		q[++D] = i;
	}
	for (int i = m + 1, u = D; i <= r; i++)
	{
		while (u > 1 && WH(q[u], i) <= WH(q[u - 1], i))
			u--;
		w[i] = WH(q[u], i) + FT[i + 1] + ST[i + 1] + SH[i];
	}
	D = 0;
	for (int i = r + 1; i > m + 1; i--)
	{
		while (D > 1 && CT(q[D - 1], q[D], i))
			D--;
		q[++D] = i;
	}
	for (int i = m, u = D; i >= l; i--)
	{
		while (u > 1 && WT(q[u], i) <= WT(q[u - 1], i))
			u--;
		w[i] = WT(q[u], i) + FH[i - 1] + SH[i - 1] + ST[i];
	}
	for (int i = l + 1; i <= m; i++)
		w[i] = std::max(w[i - 1], w[i]);
	for (int i = r - 1; i > m; i--)
		w[i] = std::max(w[i + 1], w[i]);
	for (int i = l; i <= r; i++)
		O[i] = std::max(O[i], w[i]);
}
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%lld", a + i);
	for (int i = 1; i <= N; i++)
		SH[i] = SH[i - 1] + a[i];
	for (int i = N; i; i--)
		ST[i] = ST[i + 1] + a[i];
	q[D = 1] = 0;
	for (int i = 1; i <= N; i++)
	{
		while (D > 1 && WH(q[D - 1], i) >= WH(q[D], i))
			D--;
		FH[i] = std::max(FH[i - 1], WH(q[D], i));
		while (D > 1 && CH(q[D - 1], q[D], i))
			D--;
		q[++D] = i;
	}
	q[D = 1] = N + 1;
	for (int i = N; i; i--)
	{
		while (D > 1 && WT(q[D - 1], i) >= WT(q[D], i))
			D--;
		FT[i] = std::max(FT[i + 1], WT(q[D], i));
		while (D > 1 && CT(q[D - 1], q[D], i))
			D--;
		q[++D] = i;
	}
	for (int i = 1; i <= N; i++)
		O[i] = -1LL << 60;
	NiroBC(1, N);
	for (int i = 1; i <= N; i++)
		O[i] -= SH[N];
	for (scanf("%d", &Q); Q--; )
	{
		int x;
		long long y;
		scanf("%d%lld", &x, &y);
		printf("%lld\n", std::max(FH[x - 1] + FT[x + 1], O[x] - y + a[x]));
	}
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;

    map<string, int> cnt;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ++cnt[s];
    }

    ll ans = 0;
    for (auto p : cnt) {
        ll x = p.second;
        ans += (x * (x - 1)) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size()-1
#define F(i,a,b) for (int i=a;i<=b;++i)
#define DF(i,a,b) for (int i=a;i>=b;--i)
#define pb push_back
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
int read(){
    char ch=getchar(); int w=1,c=0;
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
    for (;isdigit(ch);ch=getchar()) c=(c<<3)+(c<<1)+(ch^48);
    return w*c;
}
const int M=3333,mod=998244353; 
LL f[M][M],A,B,C,D; 
LL dp(int x,int y){
	if (x>=A && y>=B){
		if (f[x][y]) return f[x][y];
		return f[x][y]=(1ll*dp(x,y-1)*x+1ll*dp(x-1,y)*y-1ll*dp(x-1,y-1)*(x-1)%mod*(y-1)%mod+mod)%mod;
	}
	else return 0;
}
int main(){
	A=read(),B=read(),C=read(),D=read();
	f[A][B]=1;
	cout<<dp(C,D)<<"\n";  
    return 0;
}



Measured memory_bytes: 82176
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t ll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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

using namespace std;


class C {
	int a, b, ab;
	int needa, needb;
public:
	C()
	{
		cin >> a >> b >> ab >> needa >> needb;

		if (needa > needb)
		{
			needa ^= needb; needb ^= needa; needa ^= needb;
			a ^= b; b ^= a; a ^= b;
		}
	}
	void solve()
	{
		ll ans{ LLMAX };
		int tmpa, tmpb;
		ll tmpcost;

		// make all a with ab
		// make all b with ab
		tmpa = needa; tmpb = needb;
		tmpcost = 2LL * ab * tmpa;
		tmpb -= tmpa;
		if (tmpb)
			tmpcost += 2LL * ab * tmpb;
		chmin(ans, tmpcost);

		// make all a with ab
		// make remaining b with b
		tmpa = needa; tmpb = needb;
		tmpcost = 2LL * ab * tmpa;
		tmpb -= tmpa;
		if (tmpb > 0)
			tmpcost += (ll)b * tmpb;
		chmin(ans, tmpcost);

		// make all a with a
		// make all b with b
		tmpa = needa; tmpb = needb;
		tmpcost = (ll)a * needa;
		tmpcost += (ll)b * needb;
		chmin(ans, tmpcost);

		// make all a with a
		// make all b with ab
		tmpa = needa; tmpb = needb;
		tmpcost = (ll)a * needa;
		tmpcost += 2LL * ab * needb;
		chmin(ans, tmpcost);

		cout << ans << endl;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

vector<long long> fact, fact_inv, inv;   //fact[i]=i!                       nが10^7より大きいと配列が大きすぎる？
void init_nCk(int SIZE) {                //inv[i]=i^(-1)           
    fact.resize(SIZE + 5);               //fact_inv[i]=inv[i]の累積積
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;                          
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    if(n<=10000000)return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
    else {
        ll ans=1;
    for(ll i=n; i>n-k; i--){
        ans=ans*i%mod;
    }
    for(ll i=1; i<=k; i++){
        ans=(ans*modpow(i,mod-2))%mod;
    }
    return ans;
    }
}

int main(){
    int  n,a,b;
    cin>>n>>a>>b;
    init_nCk(510000);
    cout<<(2*mod+modpow(2,n)-1-nCk(n,a)-nCk(n,b))%mod<<endl;
return 0;
}

Measured memory_bytes: 12160
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

int main(){
  char A; cin >> A; A++;
  cout << A << endl;

  return 0;
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string str1, str2;
    cin >> str1;
    cin >> str2;
    reverse(str2.begin(), str2.end());
    cout << (str1 == str2 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

struct BIT{
    int n;
    VL bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void init(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void add(int i, ll x){
        i++;
        while (i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }

    // [0, i]
    ll sum(int i){
        i++;
        ll ret = 0;
        while (i > 0){
            (ret += bit[i]) %= mod;
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    ll sum(int l, int r){
        if (l >= r) return 0;
        return (sum(r-1) - sum(l-1) + mod) % mod;
    }
};

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();

    BIT bit(n);
    bit.add(0, 1);
    map<int, int> mp;
    REP(i,n){
        if (mp.count(a[i]) && mp[a[i]] < i - 1){
            ll x = bit.sum(mp[a[i]]);
            bit.add(i, x);
        }
        mp[a[i]] = i;
    }
    cout << bit.sum(n - 1) << endl;
    return 0;
}


Measured memory_bytes: 12032
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
s = 0
for v in c.values():
    if v >= 2:
        s += v*(v-1)//2

for i in range(n):
    k = a[i]
    ans = s
    v = c[k]
    if v >= 3:
        ans -= v-1
    if v <= 2:
        ans -= v*(v-1)//2
    print(ans)

Measured memory_bytes: 90060
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var lefts = new int[m];
        var rights = new int[m];
        for (int i = 0; i < m; i++)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            lefts[i] = ab[0];
            rights[i] = ab[1];
        }
        
        n += 1;
        var mostNears = new int[n];
        for (int i = 0; i < m; i++)
        {
            mostNears[rights[i]] = Math.Max(mostNears[rights[i]], lefts[i]);
        }

        var count = 0;
        var unbridged = 1;
        for (int i = 1; i < n; i++)
        {
            if (mostNears[i] < unbridged)
            {
                continue;
            }

            count++;
            unbridged = i;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 18364
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	while (true) {
		int n, p;
		cin >> n >> p;
		if (n == -1) return;
		vector<int> inputs;
		for (int i = n + 1; i <= n + 1000; ++i) {
			int ok = 1;
			for (int q = 2; q * q <= i; ++q) {
				if (i % q == 0) {
					ok = 0;
				}
			}
			if (ok == 1) inputs.push_back(i);
		}
		vector<int> hoge;
		REP(i, inputs.size()) {
			for (int q = i; q < inputs.size(); ++q) {
				hoge.push_back(inputs[i] + inputs[q]);
			}
		}
		sort(ALL(hoge));
		cout << hoge[p - 1] << endl;
	}
}
#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    ll p = 1;
    ll count = 0;
    for(ll i = 0; i < n; i++){
        if(a[i] == p){
            p++;
            count++;
        }
    }
    
    if(p == 1){
        cout << -1 << endl;
    }else{
        cout << n - count << endl;
    }
}

Measured memory_bytes: 1792
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    vl v;
    v.pb(0);
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
    }
    ll dp[n+1];
    dp[1]=1;
    multiset <ll> s;
    s.insert(v[1]);
    for(int i=2;i<=n;i++)
    {
        auto it=s.lower_bound(v[i]);
        if(it==s.begin())
        {
            dp[i]=dp[i-1]+1;
            s.insert(v[i]);
        }
        else
        {
            it--;
            s.erase(it);
            dp[i]=dp[i-1];
            s.insert(v[i]);
        }
    }
    cout<<dp[n];
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 18292
import numpy as np
import sys
import math
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = {}
dL = {}

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 
    if r in dR:
        dR[r] += 1
    else:
        dR[r] = 1

    if r in dL:
        ans += dL[r]

    if l in dL :
        dL[l] += 1
    else:
        dL[l] = 1  

print(ans)

Measured memory_bytes: 95436
h,w=map(int,input().split())
a=[]
flg=True
for i in range(h):
    a.append(list(input()))
tmp=0
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            if j<tmp:
                flg=False
            else: tmp=j
if flg:
    print("Possible")
else:
    print("Impossible")

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

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


def main():
    rr = []

    M = 20000
    s = set()
    for i in range(int(M**0.5)+1):
        for j in range(int(M**0.5)+1):
            t = i**2+j**2
            if t > 1:
                s.add(t)

    n = I()
    ni = 0
    while ni < n:
        ni += 1
        a,b = LI()
        t = a**2 + b**2
        r = 'P'
        for c in s:
            if t % c == 0 and t // c in s:
                r = 'C'
                break

        rr.append(r)

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


print(main())




Measured memory_bytes: 9732
import java.util.*;

public class Main {
  private static final int MOD = 1_000_000_007;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    // inside A
    int a = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        if (A[i] > A[j]) {
          a++;
        }
      }
    }
    
    Arrays.sort(A);
    int sumP = 0;
    for (int i = N-1; i >= 1; i--) {
      for (int j = i-1; j >= 0; j--) {
        if (A[i] > A[j]) {
          sumP++;
        }
      }
    }
    
    long ans = (((long)a*K)%MOD + (((long)K*(K-1)/2%MOD)*sumP)%MOD)%MOD;
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 26708
def nibu():
    n,q=map(int,input().split())
    s=[0]+list(input())+[0]
    td=[input().split()for i in range(q)][::-1]

    L=0
    R=n+1

    for t,d in td:
        if t==s[L+1] and d=='L':
            L+=1
        elif t==s[L] and d=='R':
            L-=1
        
        if t==s[R-1] and d=='R':
            R-=1
        elif t==s[R] and d=='L':
            R+=1

    return max(0,R-L-1)

print(nibu())

Measured memory_bytes: 42252
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        
        int n = 0;
        n = sc.nextInt();
        int A[] = new int[n];
        for(int i = 0; i < n; i++){
            A[i] = sc.nextInt();
        }

        Arrays.sort(A);

        int ans = 0;
        int q = sc.nextInt();
        for(int i = 0; i < q; i++){
            int m = sc.nextInt();
            int ok = 0, ng = n;
            while(ng - ok > 1){
                int mid = (ok + ng) / 2;
                if(A[mid] <= m)ok = mid;
                else ng = mid;
            }
            if(A[ok] == m)ans++;
        }
        System.out.println(ans);
    }
  
}


Measured memory_bytes: 68628
# B
import numpy as np
from collections import deque
# input
N, M = map(int, input().split())
G = dict()
for n in range(1, N+1):
    G[n] = []
    
visited = [0]*(N+1)
for m in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)
    if m == 0:
        pt = [A, B]
        visited[A] = 1
        visited[B] = 1

# from left
s = pt[0]
add_left = list()

while True:
    left_ext = [l for l in G[s] if visited[l] == 0]
    if len(left_ext) != 0:
        s = left_ext[0]
        visited[s] = 1
        add_left.append(s)
    else:
        break

# from right
s = pt[1]
add_right = list()

while True:
    right_ext = [l for l in G[s] if visited[l] == 0]
    if len(right_ext) != 0:
        s = right_ext[0]
        visited[s] = 1
        add_right.append(s)
    else:
        break
pt = list(reversed(add_left)) + pt + add_right
print(len(pt))
print(" ".join([str(a) for a in pt]))

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


void solve(std::string s){
    int rockCount = 0;
    int paperCount = 0;
    for (auto ch : s) {
      if (ch == 'g') {
	  rockCount++;
      } else {
	  paperCount++;
      }
    }
    int maxPaper = s.size()/2;
    cout << maxPaper - paperCount << endl;
}

// 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)
int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 512
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

a = cino(True)
a = list(a)
s = []
for i in a:
    if i=='B' and len(s)>0:
        s.pop()
    elif i=='0' or i=='1':
        s.append(i)

print(''.join(s))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;++i)
int main(){
  string r, a;
  while(cin>>r>>a, r!="0"){
    int h = 0, b = 0;
    REP(i, 4) REP(j, 4){
      if(r[i] == a[j]){
        if(i == j) h++;
        else b++;
      }
    }
    cout<<h<<" "<<b<<endl;
  }
  return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int h, w, h1, w1;
  cin >> h >> w;
  cin >> h1 >> w1;

  int ans = (h - h1) * (w - w1);

  cout << ans << endl;

  return 0;
}


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

void input(int *,int *,int );
int compare_int( const void *a, const void *b); //比較用関数
int search(int *,int ,int );

int main()
{
	int n;
	int *a;
	int *b;
	int t, st;

	scanf("%d",&n);

	a=(int *)malloc(n*sizeof(int));
	b=(int *)malloc(n*sizeof(int));

	input(a,b,n);
	qsort(b,n,sizeof(int),compare_int);
	t=search(a,b[0],n);
	a[t]=0;
	st=search(a,b[1],n);
	a[t]=b[0];

	for(int i=0; i<n; i++){
		if(i!=t)
			printf("%d\n",a[t]);
		else
			printf("%d\n",a[st]);
	}

	free(a);
	free(b);

	return 0;
}

void input(int *a,int *b,int n)
{
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
}

int compare_int( const void *a, const void *b)
{  //qsort用整数比較関数

	return(*(int *)b-*(int *)a);   //引数はvoid *型と規定されているのでint型にcastする
}

int search(int *a,int target,int n)
{
	int i;

	for(i=0; i<n; i++){
		if(target==a[i])
			break;
	}

	return i;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
using ll =  long long;
const int INF = 0x3f3f3f3f;

int N;
string names[200];
int scores[200];

bool cmp(const pair<string, pair<int, int>>& p1, const pair<string, pair<int, int>>& p2)
{
	if(p1.first != p2.first) return p1.first < p2.first;
	else return p1.second.first > p2.second.first;
}

void solve()
{
	vector<pair<string, pair<int, int>>> v;
	for(int i=0;i<N;++i)v.emplace_back(names[i],make_pair(scores[i], i+1));
	sort(v.begin(),v.end(),cmp);
	for(auto x : v){
		cout << x.second.second << endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i)cin>>names[i]>>scores[i];
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include "lib.h"
using namespace std;
#define LLINF 1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define rep(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
typedef long long ll;
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
ll n, A[100001+5+100001];
vector <ll> v;
ll fw[100001+5+100001];
void update(ll x, ll v)
{
	x++; //fw is one-indexed
	for(; x <= 2*n; x+=x&(-x)) fw[x] += v;
}
ll sum(ll x)
{
	ll res = 0;
	x++; //fw is one-indexed
	for(; x; x-=x&(-x)) res += fw[x];
	return res;
}
bool bstar(ll x)
{
	v.clear();
	ll total = 0, ans = 0;
	memset(fw, 0, sizeof (fw) );
	// for(auto i : v)cout << i << '\n';
	total = 0;
	for(ll i = 0; i < n; i++)
	{
		total += ((A[i] >= x) ? 1 : -1);
		// if(db) cout << total << '\n';
		ans += sum(total+n) + ((total >= 0) ? 1 : 0);
		update(total+n, 1);
	}
	return ans >= ( (n*(n+1))/2 )/2 ;
}
int main()
{
	cin >> n; 
	ll st=LLINF, en=0, mid=0;
	for(ll i = 0; i < n; i++)
	{
		cin >> A[i];
		st = min(st, A[i]);
		en = max(en, A[i]);
	} 
	en = en + 1; //so st can reach en(the last element)  (my binary search might be abit different)
	while(en-st > 1)
	{
		mid = ((st+en)/2);
		if(bstar(mid))st = mid;
		else en = mid;
	}
	cout << st << '\n';
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    rep(i,n-1)if(v[i]==v[i+1]){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#define mod 1000000007
using namespace std;
long long x,y,tx,ans,fac[1000001],invfac[1000001];
void exgcd(long long a,long long b)
{
	if (b==0)
	{
		x=1;
		y=0;
		return;
	}
	exgcd(b,a%b); 
	tx=x;
	x=y;
	y=tx-a/b*y;
	return;
}
long long C(long long a,long long b)
{
	if (a>b)
		return 0;
	return fac[b]*invfac[a]%mod*invfac[b-a]%mod;
}
int main()
{
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	h--;
	w--;
	a--;
	b--;
	fac[0]=1;
	for (int i=1;i<=1000000;++i)
		fac[i]=fac[i-1]*i%mod;
	exgcd(fac[1000000],mod);
	invfac[1000000]=x;
	for (int i=999999;i>=0;--i)
		invfac[i]=invfac[i+1]*(i+1)%mod;
	for (int i=a+1;i<=h;++i)
		ans=(ans+((C(i,w-b-1+i)-(i!=a+1)*C(i-1,w-b-2+i))%mod+mod)%mod*C(h-i,h-i+b+1)%mod)%mod;
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,x;
  cin>>a>>b>>x;

  long long int A;
  if(a!=0){
   A=(a-1)/x;
  }
  else{
     A=-1;
  }

  long long int B=b/x;

  long long int ans=B-A;


  cout<<ans<<endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

namespace fuck
{
	const int N=101000,M=N*4;
	int begin[N],next[M],to[M],w[M];
	int n,m,e;
	void add(int x,int y,int z,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		w[e]=z;
		if(k)add(y,x,-z,0);
	}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int i=1,u,v,k;i<=m;i++)
		{
			scanf("%d%d%d",&u,&v,&k);
			add(u,v,k);
		}
	}

	bool vis[N];
	int f[N];

	bool dfs(int p,int x)
	{
		if(vis[p])return f[p]==x;

		vis[p]=1,f[p]=x;

		for(int i=begin[p];i;i=next[i])
			if(!dfs(to[i],x+w[i]))return 0;
		return 1;
	}

	bool judge()
	{
		for(int i=1;i<=n;i++)
			if(!vis[i] && !dfs(i,0))
				return 0;
		return 1;
	}

	void solve()
	{
		initialize();
		printf("%s\n",judge()?"Yes":"No");
	}
}

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


Measured memory_bytes: 7680
n = str(input())
if n == "1":
    print(1)
    exit()
if n[0] == "1":
    tmpint = eval("9"*(len(n)-1))
    #print("tmpint",tmpint)
else:
    tmpint = eval(str(eval(n[0])-1) + "9"*(len(n)-1))
    #print("tmpint",tmpint)
tmpsum = sum([
        eval(str(tmpint)[i]) for i in range(len(str(tmpint)))
    ])
ssum = sum([
        eval(n[i]) for i in range(len(str(n)))
    ])
print(max(tmpsum,ssum))
#print(tmpsum,ssum)

Measured memory_bytes: 3064
import sys

S = input()

count = 0
for i in range(len(S)):
    if i == 0 and S[i] != "A":
        print("WA")
        sys.exit()

    if i == len(S)-1 and count != 1:
        print("WA")
        sys.exit()

    if i != 0 and i != len(S)-2 and S[i].isupper() and S[i] != "C":
        print("WA")
        sys.exit()

    if i >= 2 and i <= len(S)-2 and S[i] == "C":
        count += 1

print("AC")


Measured memory_bytes: 9052
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();

        int answer = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                for (int k = 0; k <= C; k++) {
                    if (500*i + 100*j + 50*k == X) { answer++; }
                }
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{
    int A,B,S;
    cin>>A>>B;
    if(A>=1&&A<=9 && B>=1&&B<=9)
    {
        cout<<A*B;
    }
    else
    {
        cout<<"-1";
    }
    return 0;
}

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

using ll = long long;
const int INF = 1<<29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

class Kuro{
public:
	int x;
	int y;
	int step;
};

int H,W;
vector<string> a;
queue<Kuro> que;

int maxval=0;
void bfs(){
	while(!que.empty()){
		Kuro q=que.front();
		que.pop();
		rep(i,4){
			int nx=q.x+dx[i];
			int ny=q.y+dy[i];
			if(0<=nx && nx<H && 0<=ny && ny<W && a[nx][ny]!='#'){
				a[nx][ny]='#';
				Kuro qq;
				qq.x=nx;
				qq.y=ny;
				qq.step=q.step+1;
				que.push(qq);
				chmax(maxval,qq.step);
			}
		}
	}
}

int main() {


	cin >> H >> W;
	a=vector<string>(H,"");

	rep(i,H){
		cin >> a[i];
		rep(j,W){
			if(a[i][j]=='#'){
				Kuro k;
				k.x=i;
				k.y=j;
				k.step=0;
				que.push(k);
			}

		}
	}

	bfs();

	p(maxval);
	return 0;
}



Measured memory_bytes: 13456
# -*- coding: utf-8 -*-
from itertools import combinations

N,D = list(map(int, input().rstrip().split()))
X_list = [list(map(int, input().rstrip().split())) for i in range(N)]
#-----

cnt=0
for p1,p2 in combinations(range(1,N+1), 2):
    sum=0
    for i in range(D):
        sum += ( X_list[p1-1][i] - X_list[p2-1][i] )**2
    
    dist = sum**(1/2)
    if dist % 1 == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3188
A1=[int(e) for e in input().split()]
A2=[int(f) for f in input().split()]
A3=[int(g) for g in input().split()]
N=int(input())
for i in range(N):
    b=int(input())
    for j in range(3):
        if b==A1[j]:
            A1[j]= -1
        elif b==A2[j]:
            A2[j]= -1
        elif b==A3[j]:
            A3[j]= -1
if A1[0]==-1 and A2[0]==-1 and A3[0]==-1:
    print('Yes')
elif A1[1]==-1 and A2[1]==-1 and A3[1]==-1:
    print('Yes')
elif A1[2]==-1 and A2[2]==-1 and A3[2]==-1:
    print('Yes')
elif A1[0]==-1 and A1[1]==-1 and A1[2]==-1:
    print('Yes')
elif A2[0]==-1 and A2[1]==-1 and A2[2]==-1:
    print('Yes')
elif A3[0]==-1 and A3[1]==-1 and A3[2]==-1:
    print('Yes')
elif A1[0]==-1 and A2[1]==-1 and A3[2]==-1:
    print('Yes')
elif A3[0]==-1 and A2[1]==-1 and A1[2]==-1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int N, M, Q, a, b, c, d;
vector<vector<ll> > total;
vector<ll> koho(10);

void dfs(int j, int n){ // jは深さ、 nは数字
  if(j == N+1) {
    return;
  }
  koho[j - 1] = n;
  for(int i = n; i <= M; i++){
    dfs(j + 1, i);
  }
  if(j == N) {
    total.push_back(koho);
    return;
  } 
}

int main() {
  cin >> N >> M >> Q;
  vector<vector<ll> > kumi(Q, vector<ll>(4, 0));

  rep(i, Q){
    cin >> kumi[i][0] >> kumi[i][1] >> kumi[i][2] >> kumi[i][3];
  }

  // 集合を作成する
  rep(i, M + 1){
    dfs(1, i+1);
  }
  

  ll ans = 0, tmp;
  // 探索する
  rep(i, total.size()){
    tmp = 0;
    koho = total[i];
    rep(j, Q){
      a = kumi[j][0] - 1;
      b = kumi[j][1] - 1;
      c = kumi[j][2];
      d = kumi[j][3];
      if(koho[b]-koho[a] == c) tmp += d;
      // rep(k, N){
      //   cout << koho[k] << " ";
      // }
      // cout << endl;
    }
    
    ans = max(ans, tmp);
  }
  
  
  print(ans);

}


Measured memory_bytes: 13936
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()

ans = 0
if A.count(1) == 0:
    ans = -1

else:
    i = 1
    for a in A:
        if i != a:
            ans += 1
        else:
            i += 1

print(ans)

Measured memory_bytes: 54808
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#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 vvv(type, c, m, n, l, i) vector<vector<vector<type>>> c(m, vector<vector<type>>(n, vector<type>(l, i)));
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>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>n; --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;
int main() {
	string s; cin >> s;
	string line;
	int cnt = 0;
	while(true) {
	    cin >> line;
	    if(line == "END_OF_TEXT") break;
	    if(len(line) != len(s)) continue;
	    string s2 = "";
	    rep(i, 0, len(line)) s2 += tolower(line[i]);
	    if(s2 == s) ++cnt;
	}
	P(cnt);
	return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                bool f1 = false;
                bool f2 = false;
                bool f3 = false;
                for (auto iter = begin(s); iter != end(s); iter++) {
                    // cout << *iter -  << endl;
                    if (!f1) {
                        if (*iter - '0' == i) {
                            f1 = true;
                        }
                        continue;
                    }
                    if (!f2) {
                        if (*iter - '0' == j) {
                            f2 = true;
                        }
                        continue;
                    }
                    if (!f3) {
                        if (*iter - '0' == k) {
                            f3 = true;
                        }
                    }
                }
                // cout << f1 << f2 << f3 << endl;
                if (f1 && f2 && f3) {
                    ans++;
                }
            }
        }
    }   
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 3672
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<cmath>
#include<iomanip>

using namespace std;

typedef pair<double,int> PDI;
int N,M;

int pos[10000][2];
vector<int> edge[10000];
int visited[10000];

double solve(int s){

    visited[s]=1;

    int cnt=1;

    priority_queue<PDI> pq;
    for(unsigned int i=0;i<edge[s].size();++i){

        int x0 = pos[s][0];
        int y0 = pos[s][1];
        int x1 = pos[edge[s][i]][0];
        int y1 = pos[edge[s][i]][1];

        double cost = sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));

        pq.push(make_pair(cost,edge[s][i]));

    }

    double sum=0;

    while(!pq.empty()){

        PDI p = pq.top(); pq.pop();

        double cost = p.first;
        int    node = p.second;

        if(visited[node])continue;
        visited[node]=1;
        sum += cost;
        ++cnt;

        for(unsigned int i=0;i<edge[node].size();++i){

            int next = edge[node][i];

            if(visited[next])continue;

            int x0 = pos[node][0];
            int y0 = pos[node][1];
            int x1 = pos[next][0];
            int y1 = pos[next][1];

            double cost = sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));

            pq.push(make_pair(cost,next));
        }

    }

    return sum;

}

int main(){

    cin.sync_with_stdio(false);

    cin >> N >> M;

    for(int i=0;i<N;++i) cin >> pos[i][0] >> pos[i][1];

    double sum=0;

    for(int i=0;i<M;++i){

        int a,b;

        cin >> a >> b;

        edge[a-1].push_back(b-1);
        edge[b-1].push_back(a-1);

        int x0 = pos[a-1][0];
        int y0 = pos[a-1][1];
        int x1 = pos[b-1][0];
        int y1 = pos[b-1][1];

        sum += sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));

    }

    for(int i=0;i<N;++i){

        if(visited[i]==0)
            sum -= solve(i);

    }

    cout << setprecision(3) << fixed << sum << endl;

    return 0;

}

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

#define ll long long
 
int main() {
    string s; ll k; cin >> s >> k;
    for(int i = 0; i < s.size(); i++) {
    	k -= pow(((int)s[i] - '0'), 5000000000000000);
    	if(k <= 0) { cout << s[i]; break;}
    }
    return 0;
}

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

using P = pair<int, int>;

struct edge {
    int to, weight;
};

constexpr int INF = 1e9;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<edge>> g(N);
    for(int i=0; i<M; ++i) {
        int a, b, l;
        cin >> a >> b >> l;
        a--; b--;
        g[a].push_back((edge){b, l});
        g[b].push_back((edge){a, l});
    }

    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> d(N, INF);
    for(int i=0; i<K; ++i) {
        int s;
        cin >> s;
        s--;
        que.push(make_pair(0, s));
        d[s] = 0;
    }

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) {
            continue;
        }
        for(auto& e : g[v]) {
            if(d[e.to] > d[v] + e.weight) {
                d[e.to] = d[v] + e.weight;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }

    double res = 0;
    for(int i=0; i<N; ++i) {
        res = max(res, (double)d[i]);
        for(int j=0; j<g[i].size(); ++j) {
            res = max(res, (d[i] + d[g[i][j].to] + g[i][j].weight) / 2.0);
        }
    }
    cout << (int)floor(res + 0.5) << endl;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

int n;

int main(){
	cin >> n;
	vector<ll>a(n+2);
	vector<ll>b(n+1);

	for(int i=1; i < n+2; i++)cin >> a[i];
	for(int i=1; i < n+1; i++)cin >> b[i];

	ll ans = 0;
	for(int i = 1; i < n+1; i++){
		ans += min(a[i],b[i]);
		int temp = b[i]-a[i];
		ll rest = max(temp, 0);
		ans += min(a[i+1], rest);
		a[i+1] = max(a[i+1]-rest,(ll)0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int arr[11],i,j,k=0,max;
    for(i=0; i<10; i++)
    {
        scanf("%d",&arr[i]);
    }
    while(k!=3)
    {
        j=0;
        max=-1;
        for(i=0; i<10; i++)
        {
            if(arr[i]>=max)
            {
                max=arr[i];
                j=i;
            }
        }
        arr[j]=0;
        printf("%d\n",max);
        k++;
    }
    return 0;

}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int m = n/2;
  int ans = 0;
  rep(i, m){
    if (s[i] != s[n-i-1]) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3560
// Problem : A - Zero-Sum Ranges
// Contest : AtCoder - AtCoder Grand Contest 023
// URL : https://atcoder.jp/contests/agc023/tasks/agc023_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	unordered_map<ll,int,custom_hash> m;
	ll sum=0,ans=0;
	m[0]=1;
	F0R(x,N)
	{
		int nb;
		cin>>nb;
		sum+=nb;
		ans+=m[sum];
		m[sum]++;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 14588
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;



int main(){
    int n;cin>>n;
    int sum=0;
    int s[n];for(int i=0;i<=n-1;i++)cin>>s[i],sum+=s[i];
    sort(s,s+n);

    if(sum%10==0){
        int i=0;
        while(i<=n-1){
            if(s[i]%10!=0)break;
            i++;
        }
        if(i==n)sum=0;
        else sum-=s[i];
    }
    cout<<sum<<endl;
    return 0;
}





Measured memory_bytes: 256
import sys

N=input()
a=map(int, raw_input().split())
#print a
#print max(a)

dict={}


for i in range(len(a)):
	if a[i] in dict:
		dict[ a[i] ]+=1 
	else:
		dict[ a[i] ]=1

#print dict

max_sum=0
for key,value in dict.items():
	#print key,value
	sum=dict[key]
	if key-1 in dict:
		sum+=dict[key-1]
	if key+1 in dict:
		sum+=dict[key+1]

	if max_sum<sum:
		max_sum=sum

print max_sum




Measured memory_bytes: 17516