akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
INF = 1 << 50


class SegTree():
    def __init__(self, n_, ele_id, operation_func):
        self.n = 1
        while self.n < n_:
            self.n *= 2
        self.data = [ele_id] * (2 * self.n - 1)
        self.ele_id = ele_id
        self.operation_func = operation_func

    def __getitem__(self, idx):
        return self.data[idx + self.n - 1]

    def update_all(self, data_init):
        for i in range(len(data_init)):
            self.data[i + self.n - 1] = data_init[i]
        for i in range(self.n - 2, -1, -1):
            self.data[i] = self.operation_func(self.data[2 * i + 1],
                                               self.data[2 * i + 2])

    def update(self, idx, x):
        # idx番目の要素をxに更新する
        idx += self.n - 1
        self.data[idx] = x
        while idx > 0:
            idx = (idx - 1) // 2
            self.data[idx] = self.operation_func(self.data[2 * idx + 1],
                                                 self.data[2 * idx + 2])

    def query(self, a, b):
        return self.query_(a, b, 0, 0, self.n)

    def query_(self, a, b, k, l, r):
        # [a, b)の最小値を求める
        if r <= a or b <= l:
            # [a, b)が[l, r)と交差しない
            return self.ele_id

        if a <= l and r <= b:
            # [a, b)が[l, r)を完全に含む
            return self.data[k]
        else:
            # [a, b)と[l, r)は一部被る
            child_l = self.query_(a, b, 2 * k + 1, l, (l + r) // 2)
            child_r = self.query_(a, b, 2 * k + 2, (l + r) // 2, r)
            return self.operation_func(child_l, child_r)


n, m = map(int, input().split())
l_dict = [[] for _ in range(n)]
r_dict = [[] for _ in range(n)]
edge = []
for i in range(m):
    l, r, c = map(int, input().split())
    l -= 1
    r -= 1
    l_dict[l].append(i)
    r_dict[r].append(i)
    edge.append((l, r, c))

dp = [INF] * n
dp[0] = 0
seg_rmq = SegTree(n, INF, min)
seg_rmq.update(0, 0)

for i in range(1, n):
    for j in r_dict[i]:
        l, r, c = edge[j]
        tmp = seg_rmq.query(l, r)
        dp[i] = min(dp[i], tmp + c)

    seg_rmq.update(i, dp[i])

ans = dp[-1] if dp[-1] != INF else -1

print(ans)


Measured memory_bytes: 123952
import java.util.*;

class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int c = 0;

        if (S.equals("RRR")) {
            c = 3;
        } else if (S.equals("RRS") || S.equals("SRR")) {
            c = 2;
        } else if (S.equals("SSS")) {
            c = 0;
        } else {c = 1;}

        System.out.println(c);
    }
}

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

int main() {
  int n, q, l, r;
  string s;

  cin >> n >> q >> s;

  vector<int> memo(n, 0);

  for (int i = 0; i < n - 1; i++)
    if (s[i] == 'A' && s[i + 1] == 'C') {
      memo[i + 1] = memo[i] + 1;
    } else {
      memo[i + 1] = memo[i];
    }

  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    cout << memo[r - 1] - memo[l - 1] << endl;
  }

  return 0;
}

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

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

int main(){
	ll N,K,W; cin>>N>>K;
	rep(i,N) cin>>W;
	cout<<(N+K-3)/(K-1);
}

Measured memory_bytes: 256
def solve():
    import numpy as np
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = np.array(f_i.readline().split(), dtype=np.int64)
    
    ans = 0
    for i in range(60):
        cnt = np.count_nonzero((A >> i) & 1)
        ans += (1 << i) * cnt * (N - cnt)
    
    print(ans % mod)

solve()

Measured memory_bytes: 62692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
vector<ll> z_algorithm(const string &s)
{
  vector<ll> prefix(s.size());
  for (int i = 1, j = 0; i < s.size(); i++)
  {
    if (i + prefix[i - j] < j + prefix[j])
    {
      prefix[i] = prefix[i - j];
    }
    else
    {
      int k = max(0LL, j + prefix[j] - i);
      while (i + k < s.size() && s[k] == s[i + k])
        ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int)s.size();
  return prefix;
}
int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> b(n);
rep(i, n){
  cin >> b[i];
}
vector<vector<ll>> v,vv;
rep(j,30){
  string a1="";
  string a2="";
  string bb="";
  rep(i,n){
    if(a[i]>>j & 1LL){a1+='1';a2+='0';}
    else {a1+='0';a2+='1';}
    if(b[i]>>j & 1LL)bb+='1';
    else bb+='0';
  }
  v.push_back(z_algorithm(bb+'|'+a1+a1));
  vv.push_back(z_algorithm(bb+'|'+a2+a2));
}
rep(i,n){
  bool ok=1;
  ll ans=0;
  rep(j,30){
    if(v[j][i+n+1]!=n&&vv[j][i+n+1]!=n){
      ok=0;
      break;
    }
    if(vv[j][i+n+1]==n)ans+=1LL<<j;
  }
  if(ok)cout << i << ' ' << ans <<endl;
}
return 0;
}

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

#define ll long long
using namespace std;
const int N = 200 + 9;
ll mod = 1e9L + 9;

void test() {
    int n, w;
    cin >> n >> w;
    vector<ll> weights(n), values(n);
    for (int i = 0; i < n; i++)cin >> weights[i] >> values[i];
    /*
     * dp[i] => max value with weight i
     */
    vector<ll> dp(w + 1);
    for (int item = 0; item < n; item++) {
        //item
        /* weight_item = 3
         * dp[5] = max(dp[5],dp[w-weight_item]+val_item)
         */
        vector<ll> new_dp = dp;
        int cur_w = weights[item], cur_v = values[item];
        for (int weight = cur_w; weight <= w; weight++) {
            new_dp[weight] = max(dp[weight], dp[weight - cur_w] + cur_v);
        }
        for (int i = 1; i <= w; i++)new_dp[i]=max(new_dp[i],new_dp[i-1]);
        dp = new_dp;
    }
    cout << dp[w] << endl;


}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //    freopen("input.in", "r", stdin);
    int t = 1;
//    cin >> t;
//    scanf("%d", &t);
    for (int cas = 1; cas <= t; cas++) {
//        printf("Case %d: ", cas);
        test();
    }
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = ~(1<<31);
const double pi = acos(-1);
 
int main() {
//	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	map<char,int> og;
	string s;
	cin >> s;
	rep(i,0,s.size()) og[s[i]]++;
	rep(i,0,n-1) {
		cin >> s;
		map<char,int> ne;
		rep(a,0,s.size()) ne[s[a]]++;
		iter(it,og) {
			og[it->first] = min(it->second, ne[it->first]);
		}
	}
	string best = "";
	iter(it,og) {
		char da = it->first;
		rep(i,0,it->second) best+=da;
	}
	cout << best << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#define INF 1000000000
#define MN 200005
using namespace std;
vector<int> neg, pos;
int n, k;
int a[MN],b[MN];
int main() {
	scanf("%d", &n);
	int i;
	for (i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i] - i;
	}
	sort(b + 1, b + 1 + n);
	int cb=b[n/2+1];
	long long ans = 0;
	for (i = 1; i <= n; i++) {
		ans += abs(a[i] - (cb + i));
	}
	printf("%lld", ans);
	return 0;
}




Measured memory_bytes: 1792
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc088_a.cpp
 * time   : Thu Apr 30 17:30:27 2020
 * quest  : A - Infinite Coins
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, a;
  cin >> n >> a;
  cout << ((n % 500) <= a ? "Yes" : "No") << "\n";
  return 0;
}


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

long long sum(long long n) {
    return n * (n+1) / 2;
}

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

    cout << sum(n) - 3*sum(n/3) - 5*sum(n/5) + 15*sum(n/15) << "\n";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n_a=0,n_b=0;
    char a='0',b='1';
    string s;
    cin>>s;
    for(char c:s){
        if(c!=a)n_a++;
        else n_b++;
        a+=b;
        b=a-b;
        a=a-b;
    }
    cout<<(n_a>n_b?n_b:n_a)<<"\n";
}

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

int main() {
    int n;
    while (cin >> n, n) {
        int ans = 0;
        n = 1000 - n;
        for (auto & i : {500, 100, 50, 10, 5, 1}) {
            ans += n / i, n -= i * (n / i);
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n){
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int MIN = 1e9;
        rep(i, 0, n - 1){
            MIN = min(MIN, a[i + 1] - a[i]);
        }
        cout << MIN << endl;
    }
}

Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int a, b, m;
	cin >> a >> b >> m;
	vector<int> ap(a), bp(b);
	vector<int> x(m), y(m), c(m);
	int ans = INF;
	int am = INF; int bm = INF;
	rep(i, a) {
		cin >> ap[i];
		chmin(am, ap[i]);
	}
	rep(i, b) {
		cin >> bp[i];
		chmin(bm, bp[i]);
	}
	chmin(ans, am + bm);
	rep(i, m) {
		cin >> x[i] >> y[i] >> c[i];
		x[i]--; y[i]--;
		chmin(ans, ap[x[i]] + bp[y[i]] - c[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4224
N,C,K = map(int,input().split())
T = []
for i in range(N):
    T.append(int(input()))

T.sort()

ans = 0
p = C
d_time = 0

for i in range(N):
    if T[i] - d_time > K or p == C:
        ans += 1
        d_time = T[i]
        p = 1
    else:
        p += 1

print(ans)


Measured memory_bytes: 13352
#include <bits/stdc++.h>
#define int long long
const int mod = 1000000007;
using namespace std;

int sum[(1<<18)+321], mulpath[(1<<18)+321], revpath[(1<<18)+321];
int p[(1<<18)+321];
int n, ans=0;
int cl[(1<<18)+321], cr[(1<<18)+321];
vector<int> cleanse;

void mul(int &x, int k)
{
	x=(x*k)%mod;
}

void add(int &x, int k)
{
	x+=k;
	if(x>mod) x-=mod;
}

int binpow(int a, int b)
{
	int ans=1, cac=a;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*cac)%mod;
		}
		b>>=1;
		cac=(cac*cac)%mod;
	}
	return ans;
}

void dfs(int node)
{
	mulpath[node]=node;
	if(node>1) mulpath[node]=(mulpath[node]*mulpath[node/2])%mod;
	if(node>n/2)
	{
		cl[node]=node;
		cr[node]=node;
		return;
	}
	int ch=node*2;
	dfs(ch);
	cl[node]=cl[ch];
	ch+=1;
	dfs(ch);
	cr[node]=cr[ch];
}

void gol(int node, int org), gor(int node, int org);

void solve(int node)
{
	// cout<<node<<endl;
	for(int i=cl[node*2]; i<=cr[node*2]; i++)
	{
		gol(p[i], ((mulpath[i]*revpath[node/2])%mod*mulpath[p[i]])%mod);
	}
	for(int i=cl[node*2+1]; i<=cr[node*2+1]; i++)
	{
		gor(p[i], ((mulpath[i]*revpath[node])%mod*mulpath[p[i]])%mod);
	}
	for(auto i:cleanse)
	{
		sum[i]=0;
	}
	cleanse.clear();
}

void gol(int node, int org)
{
	while(node)
	{
		cleanse.push_back(node);
		int ins=org;
		mul(ins, revpath[node/2]);
		add(sum[node], ins);
		if(node>1)
		{
			ins=org;
			mul(ins, revpath[node/4]);
			mul(ins, node);
			add(sum[node], mod-ins);
		}
		node>>=1;
	}
}

void gor(int node, int org)
{
	while(node)
	{
		int ins=org;
		mul(ins, revpath[node]);
		mul(ins, sum[node]);
		add(ans, ins);
		node>>=1;
	}
}

signed main()
{
	cin>>n;
	n=(1<<n)-1;
	mulpath[0]=1;
	for(int i=n/2+1; i<=n; i++)
	{
		cin>>p[i];
		p[i]+=n/2;
	}
	dfs(1);
	for(int i=0; i<=n; i++)
	{
		revpath[i]=binpow(mulpath[i], mod-2);
	}
	// cout<<n<<endl;
	for(int i=1; i<=n; i++)
	{
		if(i<=n/2)
		{
			solve(i);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 30944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 998244353;
// const ll INF = 1000000000000000000LL;

int main(){
 int n;
 string s;
 cin >> n >> s;
 int w_cnt=0;
 rep(i,n){
    if(s[i] == 'W') w_cnt++;
 }
 int r_cnt = s.size()-w_cnt;
 int ans1 = min(w_cnt,r_cnt);
 int ans2=0;
 rep(i,r_cnt){
    if(s[i]=='W')
    ans2++;
 }
 cout << min(ans1,ans2) << endl;
 return 0;
}

Measured memory_bytes: 3748
n, m = map(int, input().split())
ansers = [list(map(int, input().split())) for _ in range(n)]
foods = [0] * (m + 1)

for i in range(n):
    for j in range(1, len(ansers[i])):
        foods[ansers[i][j]] += 1

print(foods.count(n))


Measured memory_bytes: 9108
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x,0))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
  cin>>n;
	vec1(a,n);
  vector<int> b=a;
  sort(all(b));
  rep(i,n){
  	if(a[i]==b[n-1]) cout<<b[n-2]<<endl;
    else cout<<b[n-1]<<endl;
  }
}


Measured memory_bytes: 3200
#include <stdio.h>
int main(void) {
    long long N,i,min,profit,temp;
    scanf("%lld",&N);
    scanf("%lld",&temp);
    scanf("%lld",&profit);
    min=temp;
    if (min>profit) min=profit;
    profit-=temp;
    for (i=0; i<N-2; i++) {
        scanf("%lld",&temp);
        if (temp-min>profit) profit=temp-min;
        if (temp<min) min=temp;
    }
    printf("%lld\n",profit);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include<iomanip>
#define sqr(x) (x)*(x)
#define ll long long
using namespace std;
ll num[300001],l[300001],r[300001],ans=-1152921504606846976,n,i,j;
priority_queue<int,vector<int>,greater<int>/**/> le;
priority_queue<ll> ri;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>num[i];
		l[n]+=num[i];
		le.push(num[i]);
	}
	for (i=n+1;i<=n*2;i++)
	{
		cin>>num[i];
	}
	for (i=n*2+1;i<=n*3;i++)
	{
		cin>>num[i];
		r[2*n+1]+=num[i];
		ri.push(num[i]);
	}
	for (i=n+1;i<=n*2;i++)
	{
		if (le.top()<num[i])
		{
			l[i]=l[i-1]+num[i]-le.top();
			le.push(num[i]);
			le.pop();
		}
		else
		{
			l[i]=l[i-1];
		}
	}
	for (i=2*n;i>n;i--)
	{
		if (ri.top()>num[i])
		{
			r[i]=r[i+1]+num[i]-ri.top();
			ri.push(num[i]);
			ri.pop();
		}
		else
		{
			r[i]=r[i+1];
		}
	}
	for (i=n;i<=2*n;i++)
	{
		if (ans<l[i]-r[i+1]) ans=l[i]-r[i+1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  ll dis=abs(a-b);
  ll sp=v-w;
  if(sp<0){
    sp=0;
  }
  if(sp*t>=dis){
    cout<<"YES";
  }
  else{
    cout<<"NO";
  }
}


Measured memory_bytes: 3640
s=input()
t=input()
l_s=len(s)
l_t=len(t)

s=sorted(s)
t=sorted(t, reverse=True)

cnt=0

if l_s<=l_t:
    for i in range(l_s):
        if ord(s[i])<ord(t[i]):
            print("Yes")
            exit()
        elif ord(s[i])>ord(t[i]):
            print("No")
            exit()
        else:
            cnt+=1

    if cnt==l_s==l_t:
        print("No")
    else:
        print("Yes")

else:
    for i in range(l_t):
        if ord(s[i])<ord(t[i]):
            print("Yes")
            exit()

        elif ord(s[i])>ord(t[i]):
            print("No")
            exit()

    print("No")

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

map<long long, long long>M[63];
long long power3[63], N, power2[63], mod = 1000000007, cnts;

long long dfs(long long pos, long long sum) {
	if (sum < 0) return 0;
	if (pos < 0) return 1;
	if (sum >= power2[pos]) return power3[pos + 1];
	if (M[pos][sum] >= 1) return M[pos][sum] - 1;
	long long res = 0; cnts++;
	res += dfs(pos - 1, sum - (0LL << pos));
	res += dfs(pos - 1, sum - (1LL << pos));
	res += dfs(pos - 1, sum - (2LL << pos));
	res %= mod;
	M[pos][sum] = res + 1;
	return res;
}

int main() {
	cin >> N;
	power3[0] = 1; for (int i = 1; i < 63; i++) power3[i] = (power3[i - 1] * 3) % mod;
	power2[0] = 2; for (int i = 1; i < 63; i++) power2[i] = power2[i - 1] + (2LL << i);
	cout << dfs(60, N) << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = k; i < n; i++) {
		if (a[i] > a[i - k])
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 4024
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        n: usize,
        m: usize,
        c: i32,
        b: [i32; m],
        a: [[i32; m] ; n]
    );
    
    let mut ans = 0;
    let mut val: i32;
    
    for i in 0..n {
        val = c;
        for j in 0..m {
            val += a[i][j] * b[j];
        }
        ans += if val > 0 { 1 } else { 0 };
    }
    
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

def nextPermutations(X):
  buf = X[-1]
  for i in range(N):
    if X[N-i-1]<buf:
      break
    buf = X[N-i-1]
  pov = N-i-1
  v = X[pov]
  mina = 8
  answer = 0
  for i in range(pov,N):
    if X[i]>v and X[i]<=mina:
      answer = i
      mina = X[i]
  X[pov],X[answer] = X[answer],X[pov]
  X = X[:pov+1]+sorted(X[pov+1:])
  return X
  
if P[::]==Q[::]:
  print(0)
else:
  for i in range(N):
    if P[i]<Q[i]:
      min = P
      max = Q
      break
    if Q[i]<P[i]:
      min = Q
      max = P
      break
  count = 0
  while min[::]!=max[::]:
    min = nextPermutations(min[::])
    count+=1
  print(count)

    

Measured memory_bytes: 3064
$a = <>;
%hash = ();
$i = 1;
for(;<>;$i++){
	chomp($_);
	@ar=($_=~/\D/g);
	@ar=sort@ar;
    $val = join"",@ar;
    $hash{$val} = $hash{$val} + 1;
}
$sum = 0;
foreach (keys(%hash)){
	$sum += $hash{$_} * ($hash{$_}-1) / 2;
}
print $sum;


Measured memory_bytes: 22912
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N,D;
	String X;
	public void solve() {
		N = nextInt();
		X = next();
		D = nextInt();

		char[] ch = X.toCharArray();
		boolean[] used = new boolean[N];
		int change = 0;
		for(int i = 0;i < N;i++){
			if(change >= D)break;
			if(ch[i] == '0'){
				used[i] = true;
				change++;
				ch[i] = '1';
			}
		}

		for(int i = N - 1;i >= 0;i--){
			if(change >= D)break;
			if(!used[i] && ch[i] == '1'){
				change++;
				ch[i] = '0';
			}
		}

		out.println(String.valueOf(ch));
	}
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24476
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<ll> v,w;
  map<ll,ll> mp;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    v.push_back(a);
    w.push_back(a);
    mp[a]++;
  }

  sort(v.begin(),v.end());
  sort(w.begin(),w.end());
  reverse(v.begin(),v.end());

  ll ans=0;
  for(int i=0;i<n;i++){
    if(mp[v[i]]<=0) continue;
    for(int j=32;j>0;j--){
      ll z=(1<<j);
      if(z<=v[i]) continue;
      if(mp[z-v[i]]){
        if(z-v[i]==v[i]&&mp[z-v[i]]==1) continue; 
        mp[z-v[i]]--;
        mp[v[i]]--;
        ans++;
      }
    }
  }

  cout<<ans<<endl;



  return 0;
}


Measured memory_bytes: 41824
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

#define P 1000000007

using namespace std;

int main() {
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) if(s[i] == '9') {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


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

public class Solution
{
    static long Search(long ok, long ng)
    {
        while (Math.Abs(ok - ng) > 1)
        {
            var mid = (ok + ng) / 2;
            if (Solve(mid))
            {
                ok = mid;
            }
            else
            {
                ng = mid;
            }
        }
        return ok;
    }

    static bool Solve(long score)
    {
        var k = K;
        for (int i = 0; i < N; i++)
        {
            if (A[i] * F[i] > score)
            {
                var need = A[i] - (int)Math.Floor(score / (double)F[i]);
                if (need > 0)
                {
                    k -= need;
                    if (k < 0)
                    {
                        return false;
                    }
                }
            }
        }

        return true;
    }

    static int N;
    static long K;
    static long[] A;
    static long[] F;

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        N = (int)vals[0];
        K = vals[1];
        A = Console.ReadLine().Split(' ').Select(long.Parse).OrderBy(x => x).ToArray();
        F = Console.ReadLine().Split(' ').Select(long.Parse).OrderByDescending(x => x).ToArray();

        var max = Enumerable.Range(0, N).Max(i => A[i] * F[i]);
        var min = Search(max + 1, -1);

        Console.WriteLine(min);
    }
}

Measured memory_bytes: 49932
import re

N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for i in range(Q)]

array = [0 for i in range(N + 1)]
for i in range(N) :
    array[i + 1] = array[i] + (1 if S[i: i + 2] == 'AC' else 0)

for i in range(Q) :
    print(array[L[i][1] - 1] - array[L[i][0] - 1])


Measured memory_bytes: 32464
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++)  cin >> a[i], a[i]-=i+1;
    sort(a, a+n);
    ll tmp = 0;
    for(int i = 0; i < n; i++)  tmp += abs(a[i]-a[n/2]);
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
char a[100002],c[100002];
int main()
{
	cin>>a;
	int b=strlen(a),d;
	for(int i=0;i<b;i++)
	{
		if(a[i]=='p')
		{
			c[i]='q';
		}
		else if(a[i]=='q')
		{
			c[i]='p';
		}
		else if(a[i]=='b')
		{
			c[i]='d';
		}
		else if(a[i]=='d')
		{
			c[i]='b';
		}
	}
	for(int i=0;i<b;i++)
	{
		d=b-1-i;
		if(a[i]!=c[d])
		{
			cout<<"No"<<endl;return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	num := make([]int, 4)
	for i := 0; i < 4; i++ {
		num[i], _ = strconv.Atoi(string(s[i]))
	}

	if num[0]+num[1]+num[2]+num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d+%d+%d+%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]+num[1]+num[2]-num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d+%d+%d-%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]+num[1]-num[2]+num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d+%d-%d+%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]+num[1]-num[2]-num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d+%d-%d-%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]-num[1]+num[2]+num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d-%d+%d+%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]-num[1]+num[2]-num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d-%d+%d-%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]-num[1]-num[2]+num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d-%d-%d+%d=7", num[0], num[1], num[2], num[3]))
		return
	} else if num[0]-num[1]-num[2]-num[3] == 7 {
		fmt.Println(fmt.Sprintf("%d-%d-%d-%d=7", num[0], num[1], num[2], num[3]))
		return
	}
}


Measured memory_bytes: 512
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

from collections import deque

mod = 10**9+7

n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

que = deque()
dep = [0]*n
que.append((0,-1, 0))
order = []
while que:
    cur, prev, d = que.popleft()
    dep[cur] = d
    order.append(cur)
    for to in G[cur]:
        if to != prev:
            que.append((to, cur, d+1))

cnt = [1]*n
for i in reversed(order):
    for to in G[i]:
        if dep[to] < dep[i]:
            cnt[to] += cnt[i]

power = [0]*(n)
powe2_n = pow(2, n, mod)
powe2_n = pow(powe2_n, mod-2, mod)
power[n-1] = powe2_n
for i in reversed(range(n-1)):
    powe2_n *= 2
    powe2_n %= mod
    power[i] = powe2_n
ans = 0
que = deque()
que.append((0, -1))

while que:
    cur, prev = que.pop()
    if len(G[cur]) == 1:
        if prev == -1:
            que.append((G[cur][0], cur))
        continue

    prob = 1
    prob -= power[n-2]

    for to in G[cur]:
        if to == prev:
            bubun_cnt = n-cnt[cur]
        else:
            que.append((to, cur))
            bubun_cnt = cnt[to]
        tmp = 1-power[bubun_cnt-1]
        tmp *= power[n-1-bubun_cnt-1]
        prob -= tmp
    prob %= mod
    ans += power[0]*prob
    ans %= mod

print(ans)



Measured memory_bytes: 106872
#include <cstdio>
#include <cctype>
#include <utility>
#include <map>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	map<int, int> m1, m2;
	for (;;) {
		int c = in(), b;
		in();
		m1[c]++;
		if ((b = gcu()) == '\n')
			break;
		ungetc(b, stdin);
	}
	for (int c, d; scan(c, d);) {
		if (m2.count(c))
			m2[c]++;
		else if (m1.count(c))
			m2[c] = m1[c] + 1;
	}
	for (auto a: m2)
		outl(a.first, ' ', a.second);
}


Measured memory_bytes: 2484
from collections import Counter


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


res = prime_factorize(int(input()))

counter = Counter(res)
keys = counter.keys()

result = 0
for key in keys:
    items = counter.get(key)

    start = 1

    while items - start >= 0:
        items = items - start
        result += 1
        start += 1

print(result)


Measured memory_bytes: 9376
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, a, b;
    cin >> n >> a >> b;
    if ((int) (abs(a - b)) % 2 == 0)
        cout << "Alice";
    else
        cout << "Borys";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 100005
using namespace std;

int main() {
  int i;
  string s, t, f;
  bool x=false;
  cin >> s >> t;
  f=s;
  for(i=0;i<s.size();i++) {
    f = f.substr(1)+f[0];
    if(f==t) {
      x=true;
      break;
    }
  }
  if(x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

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

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


int main()
{
	ll a[4];
	rep( i, 4 ) cin >> a[i];

	ll ans = -1e18;
	rep( i, 2 )
	{
		rep( j, 2 )
		{
			chmax( ans, a[i] * a[2 + j] );
		}
	}

	if ( ans < 0 )
	{
		if ( a[0] * a[1] < 0 || a[2] * a[3] < 0 )
			cout << 0 << endl;
		else
			cout << ans << endl;
	}
	else
		cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 3212
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
mod = 10 ** 9 + 7

N = INT()
L = N.bit_length()

for i in range(N):
	for j in range(i+1, N):
		for k in range(L):
			if (i >> k) & 1 != (j >> k) & 1:
				print(k+1, end=" ")
				break
	if i != N-1:
		print()


Measured memory_bytes: 6084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>

using namespace std;

int main(){
    string s;
    cin >> s;
    bool flag = false;
    
    if(s[0] == 'A'){
        flag = true;
    }else{
        cout << "WA" << endl;
        return 0;
    }

    int cnt = 0;
    for(int i = 2; i <= s.length() - 2; i++){
        if(s[i] == 'C') cnt++;
    }
    if(cnt == 1) flag = true;
    else{
        cout << "WA" << endl;
        return 0;
    }
    int count = 0;
    for(int i = 0; i < s.length(); i++){
        if(isupper(s[i])) { // cが大文字のとき
            count++;
        }
    }
    if(count == 2){
        flag = true;
    }else{
        flag = false;
        cout << "WA" << endl;
        return 0;
    }

    if(flag) cout << "AC" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a - c) * (b - d);
    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  string s = readString();
  vi l(n + 2), r(n + 2);
  for (int i = 1; i < n; i++) {
    l[i] = l[i - 1];
    if (s[i - 1] == 'W') l[i]++;
  }
  for (int i = n; i > 1; i--) {
    r[i] = r[i + 1];
    if (s[i - 1] == 'E') r[i]++;
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    chmin(ans, l[i - 1] + r[i + 1]);
  }
  print(ans);
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;


int main(void){

	
	int N, M; cin >> N >> M;
	vector<int> H(N);
	REP(i,N) cin >> H[i];
	vector<int> ok(N, true);

	REP(i,M){
		int A, B; cin >> A >> B;
		A--; B--;
		if(H[A] > H[B]) ok[B] = false;
		else if(H[B] > H[A]) ok[A] = false;
		else{
			ok[A] = ok[B] = false;
		}
	}

	int ans = 0;
	REP(i,N){
		if(ok[i]) ans++;
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 3996
using System;

namespace atcoder
{
    class Atcoder170
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(" ");
            int a = Int32.Parse(input[0]);
            int b = Int32.Parse(input[1]);

            if (b % 2 == 1)
            {
                Console.WriteLine("No");
                return;
            }
            
            if (b == (a * 2) || b == (a * 4))
            {
                Console.WriteLine("Yes");
                return;
            }

            for(int cc = a - 1, d = 1; cc > 0; cc--, d++) 
            {
                if ((cc * 2 + d * 4) == b)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 27476
import std.stdio, std.conv, std.string, std.array;
void main(){
	int check,cnt=0;
	auto n = readln.chomp.to!int;
	for(uint i;i<n;++i){
		check = 0;
		auto s = readln.chomp.to!int;
		for(uint x=1;x*x<s;++x){
			if((s+x+1)%(x*2+1)==0){
				check=1;
				break;
			}
		}
		if(check==0) cnt++;
	}
	cnt.writeln;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
 
using namespace std;
 
string s, t;
int dp[3003][3003];
 
void lcs(int n, int m)
{
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else if (s[i - 1] == t[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
}
 
int main()
{
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	lcs(n, m);
	string res = "";
	int i = n, j = m;
	while (i >= 1 && j >= 1)
	{
		if (s[i-1] == t[j-1])
		{
			res = s[i - 1] + res;
			i--;
			j--;
		}
		else if (dp[i-1][j] > dp[i][j-1])
			i--;
		else
          	j--;
	}
	cout << res << endl;
	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int n;
    cin>>n;
    
    int t[n],x[n],y[n];
    rep(i,n){
        cin>>t[i]>>x[i]>>y[i];
    }

    int now=0,nx=0,ny=0;
    bool possible=true;
    rep(i,n){
        if(t[i]-now<abs(nx-x[i])+abs(ny-y[i]) ||
        (t[i]-now-(abs(nx-x[i])+abs(ny-y[i])))%2!=0){
            possible=false;
        }
        now=t[i],nx=x[i],ny=y[i];
    }
    if(possible){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;

}
/*


*/


Measured memory_bytes: 1536
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        long sum = 0;
        for(int i = 0; i < a; i++){
            if((i+1) % 3 != 0){
                if((i+1) % 5 != 0){
                    sum = sum + (i+1);
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35784
#include <iostream>
#include <string>

using namespace std;

int n;
int t[1 << 20], a[1 << 20], h[1 << 20];
const int MOD = 1000000007;
long long ans;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", t + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  h[0] = t[0];
  for (int i = 1; i < n; i++) {
    if (t[i] > t[i - 1]) {
      h[i] = t[i];
    }
  }
  if (h[n - 1] && h[n - 1] != a[n - 1]) {
    puts("0");
    return 0;
  }
  h[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] > a[i + 1]) {
      if (h[i] && h[i] != a[i]) {
        //
        //    	  for (int i = 0; i < n; i++) {
        //    		  printf("=%d ",h[i]);}
        //    	  printf("%d\n",i);
        puts("0");
        return 0;
      }
      h[i] = a[i];
    }
  }
  ans = 1;
  for (int i = 0; i < n; i++) {
    if (h[i] > a[i] || h[i] > t[i]) {
      puts("0");
      return 0;
    }
    if (!h[i]) {
      ans = ans * min(a[i], t[i]) % MOD;
    }
  }
  printf("%d\n", (int)ans);
}


Measured memory_bytes: 1408
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();

        int ans = 0;

        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 0; i<n; i++){
            for (int j = i+1; j<n; j++){
                ans = ans + arr.get(i)*arr.get(j);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35760
def min(a,b); a < b ? a : b; end
  
N = gets.to_i
S = Array.new(N + 1,0)
gets.split.map(&:to_i).each_with_index do |a,i|
  S[i + 1] = S[i] + a
end
puts (1 ... N).inject(1 << 40){|s, i| min(s, (S[N] - 2 * S[i]).abs) }

Measured memory_bytes: 16772
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  cin>>A>>B;
  if((B-1)%(A-1)==0) cout<<(B-1)/(A-1)<<endl;
  else cout<<(B-1)/(A-1)+1<<endl;
}



Measured memory_bytes: 3572
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        int n = Integer.parseInt(in.readLine());

        String[][] ss = in.lines()
          .limit(n)
          .map(l -> l.split(" "))
          .toArray(String[][]::new);

        Map<String,Integer> map = new HashMap<>();
        IntStream.range(0, n)
          .forEach(i -> map.put(ss[i][0]+ss[i][1], i+1));

        Arrays.parallelSort(ss, (a, b) -> {
          if(!a[0].equals(b[0]))
            return a[0].compareTo(b[0]);
          else
            return - Integer.parseInt(a[1]) + Integer.parseInt(b[1]);
        });

        Arrays.stream(ss).forEach(s -> out.println(map.get(s[0]+s[1])));
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 28628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String[] cellAry = new String[3];		// 3行分の文字を格納する配列
		Scanner sc = new Scanner(System.in);

		// 入力された3文字を受け取る
		for (int i = 0; i < cellAry.length; i++) {
			cellAry[i] = sc.nextLine();
		}

		// 前からi番目の1文字だけを表示する処理
		for (int i = 0; i < cellAry.length; i++) {
			System.out.print(cellAry[i].charAt(i));
		}

	}
}

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

l=[0]*9
for rate in a:
    if 1<=rate<=399:
        l[0]=1
    elif 400<=rate<=799:
        l[1]=1
    elif 800<=rate<=1199:
        l[2]=1
    elif 1200<=rate<=1599:
        l[3]=1
    elif 1600<=rate<=1999:
        l[4]=1
    elif 2000<=rate<=2399:
        l[5]=1
    elif 2400<=rate<=2799:
        l[6]=1
    elif 2800<=rate<=3199:
        l[7]=1
    else:
        l[8]+=1

large=sum(l)

if sum(l)-l[8]==0:#rate>=3200のみの時
    small=1
else:
    small=sum(l)-l[8]

print(small, large)

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

using namespace std;

const int N = (int)1e6 + 5;

int pref[N];
int suff[N];

string scan() {
  char b[N];
  scanf("%s", &b);
  return b;
}

int main() {
  int n;
  scanf("%d", &n);
  string s;
  s = scan();
  pref[0] = (s[0] == 'W');
  for (int i = 1; i < n; ++i)
    pref[i] = pref[i - 1] + (s[i] == 'W');
  for (int i = n - 1; i >= 0; i--)
    suff[i] = suff[i + 1] + (s[i] == 'E');
  int ans = n;
  for (int i = 0; i < n; ++i) {
    if (i)
      ans = min(ans, pref[i - 1] + suff[i + 1]);
    else
      ans = min(ans, suff[i + 1]);
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010];
    cin >> N;
    rep(i,0,N){
        cin >> A[i];
        A[i]--;
    }
    ll ans = 0;
    rep(i,0,N){
        if(A[A[i]] == i) ans++;
    }
    print(ans/2);
}

Measured memory_bytes: 1024