akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s;
  cin >> s;
  ll n=s.size();
  map<ll,ll> cnt;
  ll tmp=1;
  ll tsum=0;
  for(ll i=0;i<n;i++) {
    (tsum+=tmp*(s[n-1-i]-'0'))%=2019;
    (tmp*=10)%=2019;
    cnt[tsum]++;
  }
  cnt[0]++;
  ll ans=0;
  for(auto p:cnt) {
    ans+=p.second*(p.second-1)/2;
  }
  cout << ans << endl;
}

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

using namespace std;

const int N = 2e5+15;
int a[N];

bool canDoit(int c,int n){
	if(c==1){
		for(int i=0;i<n-1;++i){
			if(a[i]>=a[i+1]){
				return false;
			}
		}
		return true;
	}
	stack<pair<int,int> > st;
	int u = 0;
	if(a[0] ==1){
		u = 1;
	}
	st.push(make_pair(1,1));
	for(int i=u;i<n;++i){		
		int t = 0;
		while(!st.empty()){
			if( st.top().first>a[i]){
				st.pop();
				t = 1;
			} else {
				break;
			}
		}
		int cur = a[i];
		while(!st.empty()){
			if( st.top().first == cur){
				t = 1;
				int sc = st.top().second + 1;
				if(sc<=c){
					st.top().second += 1;
					break;
				} else {
					st.pop();
					--cur;
				}
			} else {
				st.push(make_pair(cur,t+1));
				break;
			}
		}
		if(st.size()==0){
			return false;
		}
	}
	return true;
}
void solve(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
	}
	int l = 1,r = n, mid;

	while(l<r){
		mid = (l + r)/2;
		if(canDoit(mid,n)){
			r = mid;
		} else {
			l = mid+1;
		}
	}
	printf("%d\n",l);
}
int main(){
	//freopen("input.txt","r",stdin);
	solve();
}

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

using namespace std;
//int arr[109][3];
int arr[10050];
int main() {
 /*   vector<string> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        string str;
        cin >> str;
        s.push_back(str);
        for (int j = 0; j < num; ++j) {
            int count = 0;
            string a;
            cin >> a;
            a.erase(a.begin() + 2);
            a.erase(a.begin() + 4);
            string q;
            for (int k = 0; k < 6; ++k)
                q += a[0];
            if (q == a) {
                arr[i][0]++;
            }else {
                for (int l = 0; l < 5; ++l)
                    if (a[l] > a[l + 1])
                        count++;
                if (count < 5)
                    arr[i][2]++;
                else
                    arr[i][1]++;

            }
        }
    }

*/
int n;
cin>>n;
    for (int i = 1; i <=100 ; ++i) {
        for (int j = 1; j <=100 ; ++j) {
            for (int k = 1; k <=100 ; ++k) {
                int x=pow(i,2)+pow(j,2)+pow(k,2)+i*j+k*j+i*k;
                if(x<10050)
                    arr[x]++;

            }
        }
    }
    for (int i =1; i <=n ; ++i) {
        cout<<arr[i]<<endl;
    }
}


Measured memory_bytes: 3612
object Main extends App{
  import scala.io.StdIn.readLine
  
  val s = readLine.split("").map(_.toInt)
  val xs = (0 to s.length - 3).map(x => 100 * s(x) + 10 * s(x + 1) + s(x + 2))
  
  println(xs.map(a => math.abs(753 - a)).min.toString)

}


Measured memory_bytes: 54852
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  int N;
  cin >> N;

  vector<VI> groups;
  vector<PII> edges;

  if (N % 2 == 0) {
    for (int i = 1; i * 2 <= N; ++i) {
      groups.PB(VI{i, N - i + 1});
    }
  } else {
    for (int i = 1; i * 2 <= N; ++i) {
      groups.PB(VI{i, N - i});
    }

    groups.PB(VI{N});
  }

  const int S = SZ(groups);
  for (int i = 0; i < S; ++i) {
    for (int j = i + 1; j < S; ++j) {
      for (int a : groups[i]) for (int b : groups[j]) {
        edges.emplace_back(a, b);
      }
    }
  }

  cout << SZ(edges) << "\n";
  for (auto &E : edges) { cout << E.st << " " << E.nd << "\n"; }
}



Measured memory_bytes: 768
N, X = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

ans = 0

N.times do |i|
  r_sum = 0
  l_sum = 0
  left = i - 1
  right = i + 1

  if left >= 0
    l_sum = A[i] + A[left]
  else
    l_sum = -1
  end

  if right <= N - 1
    r_sum = A[i] + A[right]
  else
    r_sum = -1
  end

  if r_sum > X && right <= N - 1
    cnt = [A[right], r_sum - X].min
    r_sum -= cnt
    A[right] -= cnt
    ans += cnt

    if r_sum > X
      cnt = [A[i], r_sum - X].min
      r_sum -= cnt
      A[i] -= cnt
      ans += cnt
    end
  end

  if l_sum > X && left >= 0
    cnt += [A[left], l_sum - X].min
    l_sum -= cnt
    A[left] -= cnt
    ans += cnt

    if l_sum > X
      cnt += [A[i], l_sum - X].min
      l_sum -= cnt
      A[i] -= cnt
      ans += cnt
    end
  end
end

puts ans


Measured memory_bytes: 11156
import bisect
primes = [0, 0] + [1] * 32767
for i in range(2, 182):
    if primes[i]:
        for j in range(i*i, 32769, i):
            primes[j] = 0

prime_values = [i for i, v in enumerate(primes) if v]
while True:
    n = int(input())
    if n == 0:
        break
    eov = bisect.bisect(prime_values, n//2)
    print(sum(primes[n-p] for p in prime_values[:eov]))




Measured memory_bytes: 6044
#include <iostream>
#include <algorithm>
#include <cstdio>
  
using namespace std;
  
const int N = 1e5;
  
int n, m, s[N], t[N], p[N], sum[2][N];
  
main(){
  cin >> n >> m;
  for(int i=0;i<n;i++) cin >> s[i] >> t[i];
  for(int i=0;i<m;i++) cin >> p[i];
  sort(p, p+m);
  fill(sum[0], sum[2], 0);
  for(int i=0;i<m-1;i++){
    for(int j=0;j<2;j++) sum[j][i+1] = sum[j][i];
    sum[i%2][i+1] += p[i+1] - p[i];
  }
  long long ans = 0;
  for(int i=0;i<n;i++){
    bool f = false;
    if(s[i] > t[i]){
      swap(s[i], t[i]);
      f = true;
    }
    int l = upper_bound(p, p+m, s[i]) - p;
    int r = upper_bound(p, p+m, t[i]) - p;
    if(l >= r) ans += t[i] - s[i];
    else{
      r--;
      if(f){
        ans += t[i] - p[r];
        if((r - l) % 2) ans += p[l] - s[i];
        ans += sum[r%2][r] - sum[r%2][l];
      }else{
        ans += p[l] - s[i];
        if((r - l) % 2) ans += t[i] - p[r];
        ans += sum[1-l%2][r] - sum[1-l%2][l];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB")puts("No");
	else puts("Yes");
	ggr
}


Measured memory_bytes: 256
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

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

    int ans = H / A;
    if(H % A != 0){
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
#from functools import lru_cache
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
MOD = 998_244_353
 
def main(A, B, C, D):
	d = np.zeros((C + 1, D + 1), np.int64)
	d[A,B]=1
	for i in range(A+1,C+1):
  		d[i,B] = B*d[i-1,B] % MOD
	for j in range(B+1,D+1):
		d[A,j] = A*d[A,j-1] % MOD
 
	for i in range(A+1,C+1):
		for j in range(B+1,D+1):
			d[i,j]=((((j*d[i-1,j]) % MOD + i*d[i,j-1] % MOD) % MOD) -((i-1)*((j-1)*d[i-1,j-1] % MOD)% MOD)% MOD)
    
	return d[C,D] % MOD
          
"""    
    print(d[C][D] % MOD)
    dp = np.zeros((C + 1, D + 1), np.int64)
    dp[C, D] = 1
    for d in range(D, 0, -1):
        dp[C, d - 1] = dp[C, d] * C % MOD
    for c in range(C - 1, -1, -1):
        x = 0
        for d in range(D, -1, -1):
            dp[c, d] = (d * dp[c + 1, d] + x) % MOD
            x += dp[c + 1, d]
            x *= c
            x %= MOD
    return dp[A, B]
"""

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8, i8, i8, i8)
 
    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()
 
from my_module import main
 
A, B, C, D = map(int, read().split())
print(main(A, B, C, D))


Measured memory_bytes: 97156
#include <stdio.h>

int main(void) {
	int a, b;
	int num = 0;

	scanf("%d%d", &a, &b);

	if (b == 0) {
		printf("1\n");
		return 0;
	}
	for (; b > 1; b++) {
		b -= a;
		num++;
	}
	printf("%d", num);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int m1;
int m2;
int m3;
int m4;
int m5;
int m6;
int m7;
int m8;
int m9;
int m10;

int big=0;
int flag=0;


int main(void){
	
	scanf("%d",&m1);
	scanf("%d",&m2);
	scanf("%d",&m3);
	scanf("%d",&m4);
	scanf("%d",&m5);
	scanf("%d",&m6);
	scanf("%d",&m7);
	scanf("%d",&m8);
	scanf("%d",&m9);
	scanf("%d",&m10);

	for(;;){
		flag=0;
		if (m1<m2){
			big=m2;
			m2=m1;
			m1=big;
			flag=1;
					}
		if (m2<m3){
			big=m3;
			m3=m2;
			m2=big;
			flag=1;
					}
		if (m3<m4){
			big=m4;
			m4=m3;
			m3=big;
			flag=1;
					}
		if (m4<m5){
			big=m5;
			m5=m4;
			m4=big;
			flag=1;
					}
		if (m5<m6){
			big=m6;
			m6=m5;
			m5=big;
			flag=1;
					}
		if (m6<m7){
			big=m7;
			m7=m6;
			m6=big;
			flag=1;
					}
		if (m7<m8){
			big=m8;
			m8=m7;
			m7=big;
			flag=1;
					}
		if (m8<m9){
			big=m9;
			m9=m8;
			m8=big;
			flag=1;
					}
		if (m9<m10){
			big=m10;
			m10=m9;
			m9=big;
			flag=1;
					}

		if (flag==0)
			break;


		
				}

	printf("%d\n",m1);
	printf("%d\n",m2);
	printf("%d\n",m3);


	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <stack>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <cmath>
#include <numeric>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

typedef vector<double> arr;
typedef vector<arr> mat;

arr sol(mat A,arr y){//Ax=y
  int n = A.size();
  mat B(n,arr(n));
  for(int i = 0; i < n; ++i)
    B[i][i] = 1;
  
  for(int i = 0; i < n; ++i){
    for(int j=i+1;j < n; ++j){
      if(abs(A[j][i]) > abs(A[i][i])){
         swap(A[j],A[i]);
         swap(B[j],B[i]);
      }
    }
    double d = A[i][i];
    for(int j = 0; j < n; ++j){
      A[i][j] /= d;
      B[i][j] /= d;
    }

    for(int j = 0; j < n; ++j){
      if(i==j) continue;
      double m = A[j][i];
      for(int k = 0; k < n; ++k){
        A[j][k] -= A[i][k] * m;
        B[j][k] -= B[i][k] * m;
      }
    }
  }
  
  arr ret(n);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      ret[i] += B[i][j] * y[j];
  
  return ret;
}

int main()
{
  int d;
  while(cin >> d && d){
    double v[d+10];
    rep(i,d+3) cin >> v[i];

    vector<int> idx(d+3);
    for(int i = 0; i < d+3; ++i)
      idx[i] = i;
    //cout << "hoge" << endl;
    do{
      mat A(d+1,arr(d+1));
      arr y(d+1);
      for(int i = 0; i < d+1; ++i){
        double dd = 1;
        for(int j = 0; j < d+1; ++j){
          A[i][j] = dd;
          dd *= idx[i];
        }
        y[i] = v[idx[i]];
      }
      //cout << "hoge" << endl;
      arr x = sol(A,y);
      //cout << "hoge" << endl;
      int diffcnt = 0;
      int ans;
      for(int i = 0; i < d+3; ++i){
        double su = 0;
        double dd = 1;
        for(int j = 0; j < d+1; ++j){
          su += x[j] * dd;
          dd *= i;
        }
        if(abs(su-v[i]) > 1e-5){
          ++diffcnt;
          ans = i;
        }
      }
      
      if(diffcnt == 1){
        //cout << x << endl;
        cout << ans << endl;
        break;
      }
      
    }while(next_permutation(idx.begin(), idx.end()));
    
  }
}

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

int a, b, c, x, y, price, chpst=10000000000;

int m2n(int nedan){
  if(nedan==x)return a;
  else if(nedan==y)return b;
  else return 0;
}

int main(){
  cin >> a >> b >> c >> x >> y;
  for(int i=0; i<=min(x, y); i++){
    price=a*x+b*y+i*(2*c-a-b);
    chpst = min(chpst, price);
  }
  for(int i=min(x, y)+1; i<=max(x, y); i++){
    price += (2*c-m2n(max(x, y)));
    chpst = min(chpst, price);
  }
  cout << chpst;
  return 0;
}
  

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

int main()
{
    int N;
    cin >> N;
    int A;
    int arrA[N] = {0};
    for (int i = 0; i < N - 1; i++) {
        cin >> A;
        arrA[A - 1]++;
    }

    for (int i = 0; i < N; i++) cout << arrA[i] << endl;
    return 0;
}

Measured memory_bytes: 4280
#include<iostream>
#include<cstdio>
#include<list>
using namespace std;

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

	list<int> ans;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (n % 2)
		{
			if (i % 2) ans.push_back(a);
			else ans.push_front(a);
		}
		else
		{
			if (i % 2) ans.push_front(a);
			else ans.push_back(a);
		}
	}

	auto itr = ans.begin();
	for (int i = 0; i < n - 1; i++)
	{
		cout << *itr << " ";
		itr++;
	}
	cout << *itr << endl;

	return 0;
}

Measured memory_bytes: 8448
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		long[] ary=new long[N];
		long[] ary2=new long[N];
		for(int i=0; i<N; i++) {
			ary[i]=sc.nextLong()*2;
		}
		Arrays.sort(ary);
		for(int i=0; i<N; i++) {
			ary2[i]=ary[i];
		}
		int kosu=0;
		for(int i=N-1; i>=0; i--) {
			//String ab="";
			if(ary[i]%2!=1) {
				long sp=solve_pair(ary[i]);
				int a=lowerBound(ary2,sp);
				//System.out.println(a+" "+solve_pair(ary[i]));
				if(a==-1) {
					//存在しないなら何もしない
				}
				else if(a>=0 && ary2[a]==sp && ary[a]%2==0 && ary2[a]%2==0 &&ary[i]%2==0 && ary2[i]%2==0 && a<i) {
					kosu++;
					ary2[a]--;
				}
				else {
					//足して2ベキにならないなら何もしない
				}
			}
			else {
				//そもそも使われていたら使わない
			}
		}
		System.out.println(kosu);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static final int lowerBound(final long[] arr, final long value) {
		int low = 0;
		int high = arr.length;
		int mid;
		while (low < high) {
			mid = ((high - low) >>> 1) + low;    //(low + high) / 2 (オーバーフロー対策)
			if (arr[mid] < value) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		if(low<arr.length) {
			return low;
		}
		else {
			return -1;
		}
	}
	static long solve_pair(long a) {
		int k=0;
		long b=a;
		while(b>0) {
			k++;
			b/=2;
		}
		long aaa=1;
		for(int i=0; i<k; i++) {
			aaa*=2;
		}
		//System.out.println("ret "+(aaa-a));
		return (aaa-a);
	}
}


Measured memory_bytes: 53868
N, M, C = map(int,input().split())
B = list(map(int, input().split()))
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)

x = 0


for i in range(N):
    k = C
    for j in range(M):
        k = k + grid[i][j] * B[j]
    if k > 0:
        x = x +1
    else:
        pass

print(x)

Measured memory_bytes: 3060
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n;
string s;
int32_t main(){
CODE_START;
cin>>s;
cout<<"2018";
for(ll i=4;i<s.size();i++)
    cout<<s[i];
}



Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
st = [[] for _ in range(C)]
TT1 = [0 for _ in range(10**5+2)]
for i in range(N):
    s,t,c = rl()
    TT1[s] += 1
    TT1[t+1] -= 1
    st[c-1].append([s,t])
for st_i in range(len(st)):
    st_ = st[st_i]
    if len(st_) <= 1: continue
    st_.sort(key=lambda x:x[0])
    l = []
    new = 0
    lst_ = len(st_)
    for i in range(lst_):
        if new == 0:
            s,t = st_[i]
            if i != lst_ -1 and t==st_[i+1][0]:
               new = 1
               continue
            else:
                l.append([s,t])
        else:
            t = st_[i][1]
            if i != lst_ -1 and t==st_[i+1][0]:
                new = 1
                continue
            else:
                l.append([s,t])
    st[st_i] = l


TT2 = [0 for _ in range(10**5+2)]

for st_ in st:
    if len(st_) == 0: continue
    for i in range(len(st_)):
        TT2[st_[i][0]] += 1
        TT2[st_[i][1]+1] -= 1

for i in range(1,len(TT1)):
    TT1[i] += TT1[i-1]
    TT2[i] += TT2[i-1]

print(min(max(TT1),max(TT2)))


Measured memory_bytes: 22428
/* AOJ 1051 Citation Format */

#include <iostream>

using namespace std;

typedef pair<int, int> pii;

void citation_format(int n_pages);
void print_range(pii range);

const int MAX_N = 50;

int
main()
{
    for (;;) {
        int n_pages;

        cin >> n_pages;
        if (n_pages == 0) break;

        citation_format(n_pages);
    }

    return 0;
}

void
citation_format(int n_pages)
{
    pii ranges[MAX_N + 1];
    int n_ranges = 0;
    int i;

    ranges[0] = pii(-1, -1);

    while (n_pages--) {
        int page;

        cin >> page;

        if (page > ranges[n_ranges].second + 1) {
            n_ranges++;
            ranges[n_ranges] = pii(page, page);
        } else {
            ranges[n_ranges].second = page;
        }
    }

    print_range(ranges[1]);
    for (i = 2; i <= n_ranges; i++) {
        cout << ' ';
        print_range(ranges[i]);
    }
    cout << endl;
}

void
print_range(pii range)
{
    if (range.first == range.second)
        cout << range.first;
    else
        cout << range.first << '-' << range.second;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s1,s2;
    cin >> s1 >> s2;
    vector<int> vec;
    rep(i,n){
        if(s1[i] == s2[i]){
            vec.pb(0);
        }else{
            vec.pb(1);
            i++;
        }
    }
    ll ans = 1;
    int nw = -1;
    rep(i,vec.size()){
        if(nw == -1){
            if(vec[i] == 0){
                ans = (ans*3)%MOD;
            }else{
                ans = (ans*6)%MOD;
            }
        }else if(nw == 0){
            ans = (ans*2)%MOD;
        }else{
            if(vec[i] == 1){
                ans = (ans*3)%MOD;
            }
        }
        nw = vec[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int maxv = min(a, b);
  int minv = max(0, a + b - n);
  cout << maxv << " " << minv << endl;
}

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

int main() {
  int n, min=1000, max=0;
  cin >> n;
  
  for (int i=0; i<n; i++) {
    int a;
    cin >> a;
    if (a<min) min=a;
    if (a>max) max=a;
  }

  cout << max-min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
#define rep(i,x) for(int i=1; i<=(x); i++)

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

  int room[5][4][11];
  rep(i,4) rep(j,3) rep(k,10) room[i][j][k] = 0;
  rep(i,n){
    int b,f,r,v;
    cin >> b >> f >> r >> v;
    room[b][f][r] += v;
  }

  rep(i,4){
    rep(j,3){
      rep(k,10){
        cout << " " << room[i][j][k];
      }
      cout << endl;
    }
    if(i<4){
      rep(m,20) cout << "#";
      cout << endl;
    }
  }

  return 0;
}
  



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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define endl '\n'
#define MAX

typedef long long ll;
typedef pair<int,int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int maxn = 300 + 2;

double dp[maxn][maxn][maxn];
bool ok[maxn][maxn][maxn];
int n;

double solve(int c1, int c2, int c3){
	
	if(c1 + c2 + c3 == 0)
		return 0.0;
	
	if(c1 < 0 || c2 < 0 || c3 < 0)
		return 0.0;
		
	if(ok[c1][c2][c3])
		return dp[c1][c2][c3];
	ok[c1][c2][c3] = true;
	
	double po = (1.0 * (n - c1 - c2 - c3) ) / (1.0 * n);
	double p1 = 1.0 * c1 / (1.0 * n);
	double p2 = 1.0 * c2 / (1.0 * n);
	double p3 = 1.0 * c3 / (1.0 * n);
	
	double E1 = (1.0 + solve(c1 - 1, c2, c3) ) * p1;
	double E2 = (1.0 + solve(c1 + 1, c2 - 1, c3)) * p2;
	double E3 = (1.0 + solve(c1, c2 + 1, c3 - 1)) * p3;
	double E = (E1 + E2 + E3 + po) / (1.0 - po);
	
	return dp[c1][c2][c3] = E;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cout << setprecision(10) << fixed;
	
	cin >> n;
	
	int s1 = 0, s2 = 0, s3 = 0;
	
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		if(x == 1)
			s1++;
		if(x == 2)
			s2++;
		if(x == 3)
			s3++;
	}
	
	cout << solve(s1, s2, s3) << endl;

	return 0;
}

Measured memory_bytes: 241920
n = int(input())
l = list(map(int,input().split()))
if(n<3):
    print(0)
else:
    p = 0
    for i in range(2,n):
        for j in range(1,i):
            for k in range(j):
                if(l[i] != l[j] and l[j] != l[k] and l[k] != l[i]):
                    if(l[i]+l[j]+l[k] > 2*max(l[i],l[j],l[k])):
                        p += 1
    print(p)

Measured memory_bytes: 73696
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N;
ll K;
ll D[10010];
std::map<ll, ll> mp;

bool check( ll x )
{
  while( x > 0 )
  {
    ll d = x%10;
    if( mp.count(d) )
      return false;
    x /= 10;
  }

  return true;
}

int main()
{
  std::cin >> N >> K;

  rep( i, K )
    std::cin >> D[i], ++mp[D[i]];

  while( true )
  {
    if( check( N ) )
    {
      std::cout << N << std::endl;

      return 0;
    }
    
    ++N;
  }

  return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
DP=[[1000,1000,0] for i in range(N+1)]
for i in range(N):
  DP[i+1][0]=max(DP[i][0],DP[i][1]+DP[i][2]*A[i])
  DP[i+1][1]=DP[i+1][0]%A[i]
  DP[i+1][2]=DP[i+1][0]//A[i]
print(DP[N][0])


Measured memory_bytes: 61792
from sys import stdin


def resolve():
    n = int(stdin.readline().rstrip())
    # s = stdin.readline().rstrip()
    # A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
    a = [int(x) for x in stdin.readline().rstrip().split()]

    a = sorted(a)
    predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
    if a != predict:
        return 0

    ret = 1
    for i in range(0, n // 2):
        ret = (ret * 2) % 1000000007
    return ret


print(resolve(), '\n')
# print(*data, sep='\n')


Measured memory_bytes: 56556
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  
  long int n,ans=0,num=0;
  long long int sum=0;
  scanf("%ld",&n);
  long int i,j,k;
  for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
          {
              for(k=1;k<=n;++k)
                 {
                     num=__gcd(i,j);
                     ans=__gcd(k,num);
                     sum+=ans;
                 }
          }
    }
         
   cout<<sum;
  
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

struct RSQ{
    vector<int> dat;
    int n = 1;

    void init(int x){
        while(x > n){
            n *= 2;
        }
        dat.resize(4*n-1,0);
    }

    void add(int i,int x){
        i += n-1;
        dat[i] += x;
        while(i > 0){
            i = (i-1)/2;
            dat[i] = dat[2*i+1] + dat[2*i+2];
        }
    }

    int getSum(int a,int b,int k,int l,int r){
        if(r < a || b < l) return 0;
        if(a <= l && r <= b) return dat[k];
        else {
            int vl = getSum(a,b,2*k+1,l,(l+r)/2);
            int vr = getSum(a,b,2*k+2,(l+r)/2+1,r);
            return vl+vr;
        }
    }

};

RSQ seg[26];

int main(){
    int n,_n=1;
    string s;
    int q;
    cin >> n >> s >> q;
    while(n > _n){
        _n *= 2;
    }
    rep(i,26){
        seg[i].init(_n);
    }
    rep(i,n){
        int num = s[i] - 'a';
        seg[num].add(i,1);
    }

    int f,pos,tmp,tmp2;
    int l,r,ret;
    string c;

    rep(i,q){
        cin >> f;
        if(f==1){
            cin >> pos >> c;
            pos--;
            tmp = c[0] - 'a';
            tmp2 = s[pos] - 'a';
            s[pos] = c[0];
            seg[tmp].add(pos,1);
            seg[tmp2].add(pos,-1);
        }else{ 
            cin >> l >> r;
            l--; r--;
            ret = 0;
            rep(j,26){
                if(seg[j].getSum(l,r,0,0,_n-1) > 0) ret++;
            }
            cout << ret << endl;
        }
    }

    return 0;
}


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

const int N = 2e5 + 4;
int n, a[N];
long long res;
map<long long, int> Map;
long long Sum;

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	
	Map[0] = 1;
	for (int i = 1; i <= n; ++i) {
		Sum += 1LL * a[i];
		res += Map[Sum];
		Map[Sum]++;
	}
	cout << res;
	
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
        for (auto &u : v) os << u << endl;
        return (os);
}


template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
        for (auto &u : v) is >> u;
        return (is);
}

int main() {
    int N, M;
    int A[305][305];

    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j]; --A[i][j];
        }
    }

    int ng = -1, ok = N + 1;
    while (abs(ok - ng) > 1) {
        int m = (ok + ng) / 2;
        set<int>dame;
        int surface[305] = {};
        while (dame.size() < M) {
            int cnt[305] = {};
            for (int i = 0; i < N; i++) cnt[A[i][surface[i]]]++;
            bool flag = false;
            for (int i = 0; i < M; i++) {
                if (cnt[i] > m) { flag = true; dame.insert(i); break; }
            }
            if (!flag) { ok = m; break; }
            for (int i = 0; i < N; i++) {
                while (surface[i] < M && dame.find(A[i][surface[i]]) != dame.end()) {
                    surface[i]++;
                }
            }
        }
        if (ok != m) ng = m;
    }
    cout << ok << endl;
    return (0);
}

Measured memory_bytes: 640
from math import gcd

def lcm(a, b):
    return a*b//gcd(a,b)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9 + 7
    LCM = 1
    for a in A:
        LCM = lcm(LCM, a)
    ans = 0
    for a in A:
        ans += (LCM//a)
        

    print(ans % mod)
main()

Measured memory_bytes: 75132
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    B_left = sorted(B_left, reverse=True)
    if len(B_left) > 0:
        ans = 0
        for i, b in enumerate(B_left):
            H -= b
            ans += 1
            if H <= 0:
                break
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 18564
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 1){
            System.out.println("Hello World");
        } else {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
        sc.close();

    }

}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  in(int, n);
  in(string, c);
  int l = 0, r = n - 1;
  int ans = 0;
  while (l < r) {
    if (c[l] == 'R') { ++l; continue; }
    if (c[r] == 'W') { --r; continue; }
    dbg(l, r);
    ++ans;
    ++l;
    --r;
  }
  out(ans);
}

Measured memory_bytes: 3744
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M, P;
  cin >> N >> M >> P;

  vector<vector<pair<int, int>>> G(N);
  F0R(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].emplace_back(b, c - P);
  }

  int inf = 1e9;

  vector<int> ds(N, INT32_MIN);
  bitset<2500> vs(false);

  auto dfs = [&](auto dfs, int v, int coin) {
    if (ds[v] >= coin || ds[v] >= inf) return;
    if (vs[v]) {
      coin = inf;
    }
    ds[v] = coin;
    vs[v] = true;

    for (auto& p : G[v]) {
      dfs(dfs, p.first, coin >= inf ? inf : coin + p.second);
    }
    vs[v] = false;
  };
  dfs(dfs, 0, 0);

  int r = ds[N - 1];
  cout << (r >= inf ? -1 : r < 0 ? 0 : r);
}
#endif


Measured memory_bytes: 4144
//
//  main.cpp
//  programs
//
//  Created by Arunesh Sarker on 18/11/19.
//  Copyright © 2019 Arunesh Sarker. All rights reserved.
//

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <cstdlib>
using namespace std;
vector<string> st;
typedef unsigned long long ll;
#define mod 1000000007
     
  // Function to return LCM of two numbers
int fact(int n)
{
    // single line to find factorial
    return (n==1 || n==0) ? 1: n * fact(n - 1);
}
 ll gcd(ll a, ll b)
 {
     if (a == 0)
         return b;
     return gcd(b % a, a);
 }
   
 // Function to find gcd of array of
 // numbers
 ll findGCD(ll arr[], ll n)
 {
     ll result = arr[0];
     for (ll i = 1; i < n; i++)
     {
         result = gcd(arr[i], result);
   
         if(result == 1)
         {
            return 1;
         }
     }
     return result;
 }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    int p1[n];
    int q1[n];
    int ref[n];
    for(int i=0;i<n;i++)
        ref[i]=i+1;
    for(int i=0;i<n;i++)
        cin>>p1[i];
    for(int i=0;i<n;i++)
        cin>>q1[i];
    
    int pos1=0;int pos2=0;int ctr=0;
    do
    {
        int fl1=0;int fl2=0;
        for(int i=0;i<n;i++)
        {
            if(p1[i]!=ref[i])
                fl1=1;
        }
        for(int i=0;i<n;i++)
        {
            if(q1[i]!=ref[i])
                fl2=1;
        }
        if(fl1==0)
            pos1=ctr;
        if(fl2==0)
            pos2=ctr;
        ctr++;
        
    }while(next_permutation(ref,ref+n));
    cout<<abs(pos1-pos2)<<"\n";
    
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S = input()
if S[0] != 'A':
  print('WA')
  exit()
S = S[1:]
S_mod = S[1:-1]
if S_mod.count('C') != 1:
  print('WA')
  exit()
S = S.replace('C', '')
if not S.islower():
  print('WA')
  exit()
print('AC')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int ballsCount = 0;

		String line = sc.nextLine();
		String[] lines = line.split("");

		for (int i = 0; i < lines.length; i++) {
			if (1 == Integer.parseInt(lines[i])) {
				ballsCount++;
			}else {

			}
		}
		
		System.out.println(ballsCount);
	}

}


Measured memory_bytes: 21584
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
c.sort()
from bisect import bisect_left
from bisect import bisect_right
ans=0
for b in b:
    aa=bisect_left(a,b)
    cc=bisect_right(c,b)
    ans+=aa*(n-cc)
print(ans)

Measured memory_bytes: 105444
/*
 *  Created on: 31 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ll a, b; cin >> a >> b;
    ll ans = a * b;
    cout << ans;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, m;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  if(n%2){
    FOR(i, 0, m) cout << i+1 << " " << n-i << endl;
  }else{
    FOR(i, 0, min(n/4, m)) cout << i+1 << " " << n-i << endl;
    FOR(i, 0, m-min(n/4, m)) cout << n/2-i-1 << " " << n/2+i+1 << endl;
  }
}

Measured memory_bytes: 3668
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int>pii;
vector<pii>pat[400];
bool flag[400][400];
bool isok[400];
void dfs(int s, int node, int t)
{
	if (flag[s][node])
	{
		isok[s] = false;
		return;
	}
	flag[s][node] = true;
	for (int i = int(pat[node].size()) - 1; i >= 0; i--)
	{
		if (pat[node][i].second < t)dfs(s, pat[node][i].first, pat[node][i].second);
	}
}
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(make_pair(zb, i));
		pat[zb].push_back(make_pair(za, i));
	}
	for (int i = 0; i < num; i++)
	{
		isok[i] = true;
		dfs(i, i, way);
	}
	int ans = 0;
	for (int i = 0; i < num; i++)
	{
		for (int j = i + 1; j < num; j++)
		{
			if (isok[i] && isok[j])
			{
				bool f = true;
				for (int k = 0; k < num; k++)if (flag[i][k] && flag[j][k])f = false;
				if (f)ans++;
			}
		}
	}
	printf("%d\n", ans);
}

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

int main(){
    int N; cin >>N;
    vector<int> A;
    vector<bool> check(N, true);

    int next = 1;
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        if(a==next){
            next++;
        } else {
            count++;
        }
    }
    if(count == N) cout << -1 << endl;
    else cout << count << endl;
    
}

Measured memory_bytes: 384