akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include <climits>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
#define d_arr(arr, h, w) rep(i,(h) ){ cout << "["; rep(j,(w) ) { cout << (arr)[i][j] << ", "; } cout << "]" << endl;}
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x);

typedef pair<int ,int> P;

/*
1行目 カードの山の個数n(100以下の正の整数)
2行目 左から1番目の山の情報 a b（整数；半角空白区切り）
a 山の1番上のカードに書かれた数
b 山の1番下のカードに書かれた数
3行目 左から2番目の山の情報a b（整数；半角空白区切り）
：
：
n+1行目 左からn番目の山の情報a b（整数；半角空白区切り）
 */


//dp[l][r] = index-lから始まって、index-rで終わる配列の最小値コスト
//

int dp[100][100] = {0};

int main()
{
    int n;
    cin >> n;
    vector<int> a,b;
    rep(i,n) 
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
        cin >> tmp;
        b.push_back(tmp);
    }

//    rep(i,100){ rep(j,100){ dp[i][j] = (1<<32)-1; } }
    rep(i,100){ rep(j,100){ dp[i][j] = INT_MAX; } }
    rep(i,100){  dp[i][i+1] = 0;  }
    repi(len,1,a.size()+1)
    {
        rep(l,n)
        {
            if( n  < l + len  ) { break; }
            int r = l + len;
            repi(m,l+1,r)
            {
                //cout << "(m,l,r) = (" << m << "," << l << " " << r << ")" << endl;
                dp[l][r] = min(dp[l][r],  dp[l][m] + dp[m][r] + a[l]*b[m-1]*a[m]*b[r-1]);
            }
        }
    }
    //rep(i,n+1){
    //    rep(j,n+1){ 
    //    
    //        cout << dp[i][j] << ", ";
    //    } 
    //    cout << endl;
    //}
    cout << dp[0][n] << endl;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, x;
    cin >> n;
    stack<ll> s;
    ll ans = 1;
    for(int i=0;i<n;i++){
    	cin >> x;
    	s.push(x);
    	ll num = s.size();
    	if(num * 2 - 1 > x){
    		s.pop();
    		ans *= num;
    		ans %= mod;
    	}
    }
    ll num = s.size();
    for(ll i = 1; i <= num; i++){
    	ans *= i;
    	ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1<<20;
int n, a[maxn], x[maxn], y[maxn];
int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) x[i] = y[i] = 1;
	for(int i = n; i; i--) {
		int t = n-i+1;
		x[a[i]+1]+=t, y[a[i]-1]+=t;
	}
	for(int i = 1; i <= n; i++) x[i] += x[i-1];
	for(int i = n; i; i--) y[i] += y[i+1];
	for(int j = 1; j <= n; j++) cout << x[j] << " "; cout << '\n';
	for(int i = 1; i <= n; i++) cout << y[i] << " ";
}


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

int main(){
  int N,W;
  cin >> N >> W;
  int v[128],w[128];
  for(int i=1; i<=N; ++i){
    cin >> v[i] >> w[i];
  }

  int V[128][16384] = {};
  // ???????????????????????????
  for(int i=0; i<=127; ++i) V[i][0] = 0;
  for(int i=0; i<=16383; ++i) V[0][i] = 0;
    
  for(int i=1; i<=N; ++i){
    for(int c=1; c<=W; ++c){
      if(c-w[i] < 0){
        V[i][c] = V[i-1][c];
      } else {
        V[i][c] = max(V[i-1][c-w[i]]+v[i],V[i-1][c]);
      }
    }
  }

  cout << V[N][W] << endl;
}

Measured memory_bytes: 11268
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e6 + 5;
int trie[nax][26];
int nxt = 1,ans=0;
vector<bool> is_end(nax);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> input(n);
    vector<vector<int>> paths(n); 
    int node;
    for(int i=0;i<n;i++){
        string& s = input[i];
        cin >> s;
        reverse(s.begin(),s.end());
        node = 0;
        for(auto ch : s){
            paths[i].push_back(node);
            if(trie[node][ch-'a']==0){
                trie[node][ch-'a'] = nxt++;
            }
            node = trie[node][ch-'a'];
        }
        is_end[node]=true;//no charactor in the node
    }
    // check from prefix of each string
    for(int i=0;i<n;i++){
        string& s = input[i];
        set<char> prefixs;
        for(int pre=s.length() -1;pre>=0;pre--){
            prefixs.insert(s[pre]);
            node = paths[i][pre];
            for(auto some_prefix : prefixs){
                ans+=is_end[trie[node][some_prefix-'a']];
            }
        }
    }
    printf("%lld \n",ans-n);
    return 0;
}

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i <= n-3; i++) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {

	int H, W;
	scanf("%d %d", &H, &W);

	int G[H + 1][W + 1];
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			scanf("%d", &G[i][j]);
		}
	}

	int dp[H + 1][W + 1];
	for (int i = 0; i <= H; ++i) {
		dp[i][0] = 0;
	}
	for (int i = 0; i <= W; ++i) {
		dp[0][i] = 0;
	}

	int maxLength = 0;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (G[i][j] == 1) {
				dp[i][j] = 0;
			} else {
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
				maxLength = max(maxLength, dp[i][j]);
			}
		}
	}
	cout << maxLength * maxLength << endl;

	return 0;
}

Measured memory_bytes: 18456
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using Pil = pair<int, long long>;


int N;
long long K;


vector<int>A, F;
vector<Pil> C;

long long calc_syugyo(long long boder);


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

	A = vector<int>(N);
	F = vector<int>(N);

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

	sort(A.begin(),A.end());
	sort(F.begin(), F.end(), greater<int>());

	C = vector<Pil>(N);
	for (int i = 0; i < N; i++) {
		C[i].second = (long long)A[i] * F[i];
		C[i].first = i;
	}
	
	sort(C.begin(), C.end(), [](Pil const& l, Pil const& r) {
		return l.second > r.second;
		});
		

	long long boder = 1;
	while (boder<C[0].second) { boder = boder << 1; }
	long long step = boder/2;
	while (step>0) {
		long long syugyo_cost = calc_syugyo(boder - step);

		if (syugyo_cost <= K) {
			boder -= step;
		}
		step /= 2;
	}
	if (boder == 1) {
		long long syugyo_cost = calc_syugyo(0);
		if (syugyo_cost <= K) {
			boder = 0;
		}
	}

	cout << boder << endl;

	return 0;
}

long long calc_syugyo(long long boder)
{
	long long cost_sum = 0;

	for (int i = 0; i < N; i++) {
		if (C[i].second <= boder) {
			break;
		}
		long long c = (C[i].second - boder - 1) / F[C[i].first] + 1;
		cost_sum += c;
	}
	
	return cost_sum;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 5;

int n, k;
int alive[2 * N];

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

    cin >> n >> k;

    if(k == 1 || k == 2 * n - 1)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
        if(n == 2)
        {
            cout << 1 << endl << 2 << endl << 3 << endl;
            return 0;
        }

        memset(alive, true, sizeof(alive));
        alive[k] = false;
        alive[k - 1] = false;
        alive[k + 1] = false;
        if(k > 2)
            alive[k - 2] = false;
        else
            alive[k + 2] = false;

        int j = 1;
        for(int i = 1; i <= 2 * n - 1; i++)
        {
            if(i == n  - 1)
            {
                if(k == 2)
                {
                    cout << k + 1 << endl << k << endl << k - 1 << endl << k + 2 << endl;
                }
                else
                {
                    cout << k - 1 << endl << k << endl << k + 1 << endl << k - 2 << endl;
                }
                i += 3;
                continue;
            }

            while(!alive[j])
                j++;
            cout << j << endl;
            alive[j] = false;
        }
    }


    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   vector<char> v;
   char c;
   while(cin>>c)
   {
       if(c=='B' && v.size()!=0)
         v.pop_back();
       else if(c=='B' && v.size()==0)
          continue;
        else
            v.push_back(c);
   }
   for(auto x:v)
    cout<<x;
   
    return 0;
}








Measured memory_bytes: 3652
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		while(n != 0 || m != 0){
			int max = 0;
			int[] a = new int[n];
			for(int i = 0; i < n; i++){
				a[i] = scan.nextInt();
			}
		
			for(int i = 0; i < n; i++){
				for(int j = i + 1; j < n; j++){
					int tmp = a[i] + a[j];
					if(tmp > max && tmp <= m){
						max = tmp;
					}
				}
			}
			if(max == 0){
				System.out.println("NONE");
			}else{
				System.out.println(max);
			}
			n = scan.nextInt();
			m = scan.nextInt();
		}
	}
}


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

int main(){
	// sengen
	int n;
	string s;
	// nyuryoku
	cin >> n >> s;
	// keisan
	int sum[n];
	if(s[0] == 'W'){
		sum[0] = 1;
	}else{
		sum[0] = 0;
	}
	for(int i=1;i<n;i++){
		if(s[i] == 'W'){
			sum[i] = sum[i-1] + 1;
		}else{
			sum[i] = sum[i-1];
		}
	}
	int min = (n-1) - (sum[n-1] -sum[0]);
	for(int i=1;i<n;i++){
		int hmin = sum[i-1] + (n-i-1) -(sum[n-1] - sum[i]);
		if(hmin < min){
			min = hmin;
		}  
	}
	cout << min;
}

Measured memory_bytes: 1796
import java.util.*;
import java.lang.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    HashMap<Integer,Integer> m=new HashMap<Integer,Integer>();
    long sum=0;
    for(int i=0;i<n;i++)
    {
      int val=sc.nextInt();
      m.put(val,m.getOrDefault(val,0)+1);
      sum+=val;
    }
    int q=sc.nextInt();
    for(int j=0;j<q;j++)
    {
      int b=sc.nextInt();
      int c=sc.nextInt();
      if(m.containsKey(b))
      {
        int num=m.get(b);
        sum+=num*(c-b);
        m.remove(b);
        m.put(c,m.getOrDefault(c,0)+num);     
      }
      System.out.println(sum);
    }
  }
}


Measured memory_bytes: 64308
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}
    
	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;
    
	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	// エラトステネスのふるい
	int n = 100001;
	vector<int> isPrimeVec(n, 1);
	isPrimeVec[0] = 0;
	isPrimeVec[1] = 0;
	for (int i = 2; i < n; i++)
	{
		if (isPrimeVec[i])
		{
			int j = i + i;
			while (j < n)
			{
				isPrimeVec[j] = 0;
				j += i;
			}
		}
	}
    
	// 2017-likeかどうか
	vector<int> isLike2017(n, 0);
	for (int i = 0; i < n; i++)
	{
		if (isPrimeVec[i])
		{
			if (isPrimeVec[(i + 1) / 2])
			{
				isLike2017[i] = 1;
			}
			else
			{
				isLike2017[i] = 0;
			}
		}
	}
    
	// 累積和
	vector<int> s(n + 1);
	for (int i = 0; i < n; i++)
	{
		s[i + 1] = s[i] + isLike2017[i];
	}
	
	// クエリ処理
	int q;
	cin >> q;
	int ans = 0;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << (s[r+1] - s[l]) << endl;
	}
}

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

#define ll int
#define nl endl
#define pi 3.14159265358979323846
#define ff first 
#define ss second
#define pb push_back
#define watch(xxx) cerr<<(#xxx)<<" is "<<xxx<<nl;

const int N=200100;

vector<int> v;
//~ int m[1000006+100];

int main(){

ll t=1; 
//~ scanf("%d",&t);

while(t--){
ll n; scanf("%d",&n);
unordered_map<ll,ll> m;
for(int i=0;i<n;i++){ int x;scanf("%d",&x);v.pb(x); m[x]++;  }

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

v.resize(distance(v.begin(),unique(v.begin(),v.end())));
n=(int)v.size();

for(int i=0;i<n;i++){ 
	if(m[v[i]]==0)continue;
	for(int j=v[i];j<=v[n-1];j+=v[i]){
		if(j!=v[i] && m[j]) m[j]=0;
		else if(j==v[i] && m[j]>1) m[j]=-1; 
	}
}

ll ans=0;

for(auto i:m) if(i.ss>0) ans++;
	printf("%d\n",ans);
	
	
	 
}
	return 0;
}


Measured memory_bytes: 43352
from functools import reduce
def comb(n, max_k, mod):
    """
    (n,k) := n個からk個選ぶ組み合わせ
    k = 0~max_Kまでを計算して返す
    """
    res = [1]*(max_k+1)
    t = 1
    for i in range(max_k+1):
        res[i] *= t
        t *= n-i
        t %= mod

    n = reduce(lambda x,y: (x*y)%mod, range(1,max_k+1), 1)
    n = pow(n, mod-2, mod)

    for i in reversed(range(max_k+1)):
        res[i] *= n
        res[i] %= mod
        n *= i
        n %= mod
    return res

X,Y = map(int,input().split())

d = X+Y

if d%3 != 0:
    print(0)
else:
    n = d//3
    if X < n or 2*n < X:
        res = 0
    else:
        res = comb(n,X-n, 10**9+7)[X-n]
    print(res)


Measured memory_bytes: 22444
#include<stdio.h>
#include<math.h>

int main(void){
	double x1,y1,x2,y2,x3,y3,xp,yp,r;
	double a1,b1,c1,a2,b2,c2;
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a1 = (x2-x1)*2;
		b1 = (y2-y1)*2;
		c1 = x1*x1-x2*x2+y1*y1-y2*y2;
		a2 = (x3-x1)*2;
		b2 = (y3-y1)*2;
		c2 = x1*x1-x3*x3+y1*y1-y3*y3;
		xp = (b1*c2-b2*c1)/(a1*b2-a2*b1);
		yp = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		r = sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));
		printf("%.3lf %.3lf %.3lf\n",xp,yp,r);
	}
	return 0;
}

Measured memory_bytes: 656
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int dis = 0;
    int now;
    for(int i = 1;;i++){
      now = i;
      dis += i;
      if(dis >= x){
        break;
      }
    }
    System.out.println(now);
  }
}


Measured memory_bytes: 22612
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	private Scanner in = new Scanner(System.in);
	
	private Main() {
		int n = in.nextInt();
		
		for(int i=0;i<n;i++) {
			ArrayList<Integer> dataset = new ArrayList<Integer>();	
			for(int j=0;j<10;j++) {
				 dataset.add(in.nextInt());
			}
			int[] cylinders = new int[2];
			backtrack(dataset, cylinders); //筒(の最後の要素)
		}
		
	}
	
	private void backtrack(ArrayList<Integer> data,int[] cylinders) {
		if(data.isEmpty()) {
			System.out.println("YES");
			return;
		}
		
		int head = data.get(0);
		
		if(head > cylinders[0]) {
			cylinders[0] = head;
			data.remove(0);
			backtrack(data,cylinders);
		} else if(head > cylinders[1]) {
			cylinders[1] = head;	
			data.remove(0);
			backtrack(data,cylinders);
		} else {
			System.out.println("NO");
			return;
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main();
	}

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    int n;
    cin >> n;
    int x = 0;
    while(true) {
        if(x >= n) break;
        x += 1000;
    }
    cout << x - n << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std; 
#define endl '\n' 
typedef long long int lli ; 
using namespace std; 

int main(int argc, char const *argv[])
{	
	vector<int> a(3); 
	for(int i = 0; i<3; ++i){
		int a_; 
		cin >> a_; 
		a.push_back(a_); 
	}
	sort(a.rbegin(), a.rend()); 
	int ans = abs(a[2] - a[1]) + abs(a[1] - a[0]); 
	cout <<ans; 
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  DFLMKWR
 */

#include <iostream>

using namespace std;

const int m = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long s = 0, x, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    ans += s * x % m;
    ans %= m;
    s = (s + x) % m;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

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

    priority_queue<int> a;
    rep(i, n){
        int a_i;
        cin >> a_i;
        a.push(a_i);
    }

    rep(i, m){
        int now = a.top(); a.pop();
        now /= 2;
        a.push(now);
    }

    ll cost = 0;
    rep(i, n){
        int now = a.top(); a.pop();
        cost += now;
    }

    cout << cost << endl;

    return 0;
}


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

///////////////////////////////////////////////////////////////////

vector<bool> sieve(int N) {
    vector<bool> ret(N+1);
    int i;
    for (int z = 1; z <= 5; z += 4) {
        for (int y = z; y*y <= N; y += 6) {
            for (int x = 1; x*x <= N and (i = 4*x*x+y*y) <= N; ++x) {
                ret[i] = !ret[i];
            }
            for (int x = y+1; x*x <= N and (i = 3*x*x-y*y) <= N; x += 2) {
                ret[i] = !ret[i];
            }
        }
    }
    for (int z = 2; z <= 4; z += 2) {
        for (int y = z; y*y <= N; y += 6) {
            for (int x = 1; x*x <= N and (i = 3*x*x+y*y) <= N; x += 2) {
                ret[i] = !ret[i];
            }
            for (int x = y+1; x*x <= N && (i = 3*x*x-y*y) <= N; x += 2) {
                ret[i] = !ret[i];
            }
        }
    }
    for (int y = 3; y*y <= N; y += 6) {
        for (int z = 1; z <= 2; ++z) {
            for (int x = z; x*x <= N && (i = 4*x*x+y*y) <= N; x += 3) {
                ret[i] = !ret[i];
            }
        }
    }
    for (int i = 5; i*i <= N; ++i) {
        if (ret[i]) {
            for (int k = i*i; k <= N; k+=i*i) {
                ret[k] = false;
            }
        }
    }
    ret[2] = ret[3] = true;

    return ret;
}

//////////////////////////////////////////////////////////////////////////////

const int MAX = 100000000;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    auto table = sieve(MAX);
    int N; cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (table[a]) ans++;
    }

    cout << ans << endl;
}

/*
  verified on 2020/04/29
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp
*/



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

int main()
{
  int a,b,c,d,p,cost;
  cin >> a >> b >> c >> d >> p;
  if(p<=c) cost=b;
  else cost=b+(p-c)*d;
  cout << min(cost,a*p) << endl;
  return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>

int a[200010];
int ans[200010];
int main(){
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++)scanf("%d",&a[i]);
for(int i=2;i<=n;i++)ans[a[i]]++;
  for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    rep(i, M) {
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }

    vector<int> cnt(N);
    rep(i, M)++ cnt[a[i]], ++cnt[b[i]];

    rep(i, N) cout << cnt[i] << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int A,B,K;
    cin >> A >> B >> K;
    set<int> st;
    for(int i = 1; i <= K; i++){
        int left = A + i - 1; 
        int right = B - (i-1);
        if(left <= B) st.insert(left);
        if(right >= A) st.insert(right);
    }
    auto ite = st.begin();
    for(; ite != st.end(); ite++){
        cout << *ite << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.rbegin(),a.rend());
    priority_queue<pair<int,pair<int,int>>> pq;
    pq.push({a.at(0),{a.at(0),a.at(0)}});
    ll ans = 0;
    for(int i=1;i<n;i++){
        auto x  = pq.top();
        pq.pop();
        ans += x.first;
        int c1 = x.second.first;
        int c2 = x.second.second;
        int nxt = a.at(i);
        pair<int,int> np1 = {c1,nxt}, np2 = {nxt,c2};

        pq.push({min(c1,nxt),np1});
        pq.push({min(nxt,c2),np2});
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll a,b,c;
    cin >>a>>b>>c;
    ll mx=max({a,b,c});
    if(a+b+c-mx==mx){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }



    return 0;
    

}

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

int main() {
    int N, K;
    cin >> N >> K;
    int h[N];
    for (int i = 0; i < N; i++) cin >> h[i];
    sort(h, h+N);

    int ans = 1000000000;
    for (int i = 0; i < N-K+1; i++) {
        int memo = h[i+K-1] - h[i];
        if (memo < ans) {
            ans = memo;
        }
    }
    cout << ans << endl;
}


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

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

    int count = 0;

    for (int i = 0; i < 30; i++) {
        for (int j = 0; j < 20; j++) {
            int rem = N;
            rem -= 4 * i + 7 * j;
            if (rem == 0) count++;
        }
    }

    cout << (count <= 0 ? "No" : "Yes") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c,d,sum;

  scanf("%d\n%d\n%d\n%d", &a,&b,&c,&d);
  sum=a+b+c+d;
  a=sum/60;
  b=a*60;
  sum=sum-b;
  printf("%d\n%d\n", a,sum);
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include <map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	ll n;
	cin >> n;
	ll mod = 1e9 + 7;
	vector<ll> a(n);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		sum = sum % mod;
	//	cout << sum << endl;
	}
	ll ans = 0;
	rep(i, n - 1) {
		sum -= a[i];
		sum = (sum + mod) % mod;
		ans += sum * a[i];
		ans = ans % mod;
		ans = (ans + mod) % mod;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4344
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/01/20 21:30:49
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s; cin>>s;
  map<char, int> cc;
  for (auto c:s)
    cc[c]++;
  if (cc.size() == 2 and
    cc.begin()->second == 2 and next(cc.begin())->second == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3668
import java.util.*;
public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //int a = sc.nextLong();
        //intb = sc.nextLong();
        //String s = sc.next();
        //Long x = sc.nextLong();


        System.out.println(n*n);
    }
}


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

int32_t main()
{
    int h,n;
    cin>>h>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }
    sort(a.begin(),a.end());
    vector<int> s(n);
    fill(s.begin(),s.end(),0);
    s[0]=a[0];
    for(int i=1;i<n;i++)
    {
        s[i]=s[i-1]+a[i];
        //cout<<s[i]<<" ";
    }
    vector<int>::iterator it=upper_bound(s.begin(),s.end(),h);
    int y=it-s.begin();
    //cout<<y<<endl;
    if(y>n) cout<<"No";
    if(y==n) 
    {
        if(h>s[n-1]) {cout<<"No"; return 0;}
        else {cout<<"Yes"; return 0;}
    }
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
N, D = map(int,input().split())
LX = [list(map(int, input().split())) for i in range(N)]

cnt=0
for i in range(N-1):
    for j in range(i+1,N):
        LXP = np.array(LX[i])
        LXQ = np.array(LX[j])
        ans = (float(np.sqrt(sum((LXP - LXQ) ** 2))))
        if ans.is_integer():
            cnt += 1

print(cnt)

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >> N;
    vector<ll> A(N); cin >> A;
    sort(all(A), greater<ll>());

    ll stick[2] = {0,0};
    int c = 0;
    int i;
    for (i = 1; i < N; i++) {
        if (A[i] == A[i - 1]) {
            stick[c] = A[i];
            if (c == 1) {
              c = 0;
              break;
            }
          	c++;
            i++;
        }
    }
    cout << stick[0] * stick[1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  map<int, int> mp;
  rep(_, n) {
    Cin(int, a);
    mp[a]++;
  }
  int ans = 0;
  for (auto e : mp)
    if (e.second % 2) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include<stdio.h>

int a[45];

int fibonacci(int n){
  if(n==0||n==1) return 1;
  if(a[n]!=-1) return a[n];
  return a[n]=fibonacci(n-1)+fibonacci(n-2);
}

int main(){
  int n,i,ans;

  scanf("%d",&n);
  for(i=2;i<45;i++) a[i]=-1;

  ans=fibonacci(n);

  printf("%d\n",ans);

    return 0;
}


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

struct Work{
    ll a;
    ll b;
    Work(ll a, ll b): a(a), b(b) {}
    Work(){}

    bool operator<(const Work &another) const
    {
        if(b==another.b){
            return a < another.a;
        }else{
            // !
            return b > another.b;
        }
    }

    string ToString(){
        stringstream ss;
        ss << a << ' ' << b;
        return ss.str();
    }
};

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

    // input
    ll N;
    cin >> N;

    ll b_max = 0;
    vector<Work> V;
    FOR(i, 0, N){
        ll a, b; cin >> a >> b;
        chmax(b_max, b);
        V.push_back(Work(a, b));
    }
    sort(ALL(V));

    ll deadline = b_max;
    for(auto w : V){
        if(w.b < deadline){
            deadline = w.b;
        }
        // p(w.ToString());
        deadline -= w.a;
    }

    if(deadline>=0){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main() {
  int n,q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> st(26,{inf});
  rep(i,n){
    st[s[i]-'a'].insert(i);
  }
  

  while(q--){
    int a;
    cin >> a;
    if(a==1){
      int b; char c;
      cin >> b >> c; b--;
      st[s[b]-'a'].erase(b);
      s[b] = c;
      st[c-'a'].insert(b);
    } else {
      int b,c; cin >> b >> c; b--;
      int cnt=0;
      rep(j,26)if(!st[j].empty()){
        int it1 = *st[j].lower_bound(b);
        int it2 = *st[j].lower_bound(c);
        if(it1<it2){ cnt++; }
      }
      cout << cnt << endl;
    }
  }
    return 0;
}


Measured memory_bytes: 26244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int a, b, c; std::cin >> a >> b >> c;
    std::cout << (a <= c && c <= b ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    int n;
    cin>>n;
    set<int> s;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin>>temp;
        s.insert(temp);
    }
    if(s.size()==n)
        cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


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

int main() {
    
    string X;
    cin >> X;
    
    long long count = 0;
    long long ans = 0;
    
    for ( long long i = 0; i < X.length(); i++ ) {
        
        if ( X[i] == 'S' ) {
            count++;
        }
        else {            
            if ( count ) { count--; }
            else { ans++; }
        }
    }
    ans += count;
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int r[100001][3]={0},d[100001][3]={0};
vector<int> A[200001];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n,m,s,t,u,v;
   cin>>n>>m;
   rep(i,0,m) cin>>u>>v, A[u].push_back(v);
   cin>>s>>t;
   queue<pair<int,int> > q;
   q.push({s,0});
   while(!q.empty())
   {
   	int a=q.front().fi,b=q.front().se;
   	q.pop();
   	for(auto i: A[a])
   	{
   		if(d[i][(b+1)%3]) continue;
   		d[i][(b+1)%3]=d[a][b]+1;
   		q.push({i,(b+1)%3});
	   }
   }
   if(d[t][0]) cout<<d[t][0]/3;
   else cout<<"-1";
}






Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define N 15
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
int n,m;
int A[N][N];
int ans;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
		scanf("%d",&A[i][j]);
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){
		int res=0;
		for(int k=1;k<=m;k++){
			res+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
		}
		int t=sqrt(res);
		if(t*t==res)ans++;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,max=1;
    int a[]={1,2,4,8,16,32,64};
    scanf("%d",&n);
    for(int i=0;i<7;i++){
        if(n>=a[i] && max<a[i]) max=a[i];
    }
    printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>                                                                                                      
    
int main(void){
    int num;
    scanf("%d", &num);
    int s[4];
    for(int i = 0; i < 4; i++){
        s[3-i] = num % 10; 
        num /= 10; 
    }   
    int cnt = 7 - s[0];
    if(s[1] + s[2] + s[3] == cnt) printf("%d+%d+%d+%d", s[0], s[1], s[2], s[3]);
    else if(-s[1] + s[2] + s[3] == cnt) printf("%d-%d+%d+%d", s[0], s[1], s[2], s[3]);
    else if(s[1] - s[2] + s[3] == cnt) printf("%d+%d-%d+%d", s[0], s[1], s[2], s[3]);
    else if(s[1] - s[2] - s[3] == cnt) printf("%d+%d-%d-%d", s[0], s[1], s[2], s[3]);
    else if(s[1] + s[2] - s[3] == cnt) printf("%d+%d+%d-%d", s[0], s[1], s[2], s[3]);
    else if(-s[1] - s[2] + s[3] == cnt) printf("%d-%d-%d+%d", s[0], s[1], s[2], s[3]);
    else if(-s[1] - s[2] - s[3] == cnt) printf("%d-%d-%d-%d", s[0], s[1], s[2], s[3]);
    else if(-s[1] + s[2] - s[3] == cnt) printf("%d-%d+%d-%d", s[0], s[1], s[2], s[3]);
    printf("=7");    
    return 0;
}

Measured memory_bytes: 128
def get_ints():
    return map(int, input().split())

n, m = get_ints()
penalty = 0
oks = 0
ac = []
penalty = []
for i in range(n):
    ac.append(False)
    penalty.append(0)
for i in range(m):
    p, s = input().split()
    p = int(p)
    p -= 1
    if ac[p]:
        continue
    if s == 'AC':
        ac[p] = True
        oks += 1
    else:
        penalty[p] += 1

ans = 0
for i in range(n):
    if ac[i]:
        ans += penalty[i]

print(str(oks) + ' ' + str(ans))


Measured memory_bytes: 4868
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  
  ll X[N],Y[N];
  vector<ll> LX,LY;
  REP(i,N){
    cin>>X[i]>>Y[i];
    LX.PB(X[i]+Y[i]);
    LY.PB(Y[i]-X[i]);
  }
  SORT(LX);
  SORT(LY);
  
  chmax(ans,LX[N-1]-LX[0]);
  chmax(ans,LY[N-1]-LY[0]);
  co(ans);
  return 0;
}

Measured memory_bytes: 9720
process.stdin.resume();
process.stdin.setEncoding('utf-8');
 
let inputString = '';
let currentLine = 0;
 
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
 
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});
 
function readLine() {
    return inputString[currentLine++];
}

function main() {
  const n = Number(readLine())
  const cs = readLine()
  let s = 0, e = n - 1
  let result = 0
  const r = 'R', w = 'W'
  while (s <= e) {
    let wFound = false
    let rFound = false
    for (let i = s; i < e; i++) {
      if (cs[i] === r) {
        continue
      }
      wFound = true
      rFound = false
      for (let j = e; j > i; j--) {
        if (cs[j] === w) {
          continue
        }
        e = j - 1
        result += 1
        rFound = true
        break
      }
      if (!rFound) {
        break
      }
      s = i + 1
      break
    }
    if (!wFound || !rFound) {
      break
    }
  }
  console.log(result)
}


Measured memory_bytes: 33164
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int mod = 1e9+7;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n,a[maxn];
int ksm(int x,int y){
	if(x<0)return 0;
	int sum=1;
	while(x){
		if(x&1)sum=1ll*sum*y%mod;
		y=1ll*y*y%mod;
		x>>=1;
	}
	return sum;
}
int main(){
	n=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	int ans=0,last=0;
	for(register int i=n;i>=1;i--){
		int sum=(ksm(n-i,4)+1ll*(n-i)*2%mod*ksm(n-i-1,4)%mod)%mod;
		(ans+=1ll*ksm(i-1,4)*2%mod*a[i]%mod*sum%mod)%=mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), ans(n);
    rep(i,n) cin >> a[i];
    rep(i,n) ans[a[i]-1] = i+1;
    rep(i,n) cout << ans[i] << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;

int dp[100005];
int n;
vector <int> v;

int solve(int ind){
    if(ind > n) return INT_MAX;
    if(ind == n) return 0;
    if(dp[ind] != -1) return dp[ind];
    long long ans = INT_MAX;
    int curr_height = v[ind],next_height;
    next_height = v[ind+1];
    ans = min(ans, solve(ind+1)+abs(next_height-curr_height));
    next_height = v[ind+2];
    ans = min(ans, solve(ind+2)+abs(next_height-curr_height));
    return dp[ind] = ans;
}

int32_t main()
{
    cin>>n;
    v.resize(n+1);
    for(int i=1 ; i<=n ; i++) cin>>v[i];
    memset(dp,-1,sizeof dp);
    cout<<solve(1);
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll A,B,Q,l,dla,dua,dlb,dub,ans;
	// A = 2;
	// B = 3;
	// Q = 4;
	cin >> A >> B >> Q; 
	vector<ll> a(A+2);
	vector<ll> b(B+2);
	vector<ll>::iterator iter_lowerA, iter_upperA,iter_lowerB, iter_upperB;
	a[0] = -1 * LINF;
	b[0] = -1 * LINF;
	for (ll i = 1;i <= A;i++){
		cin >> l;
		a[i] = l; 
	}
	a[A+1] = LINF;
	for(ll i = 1;i <= B;i++){
		cin >> l;
		b[i] = l;
	}
	b[B+1] = LINF;

	for(ll i = 0;i < Q;i++){
		cin >> l;
		iter_upperA = upper_bound(ALL(a),l);
		iter_upperB = upper_bound(ALL(b),l);
		dla = distance(a.begin(),iter_upperA) - 1;
		dua = distance(a.begin(),iter_upperA);
		dlb = distance(b.begin(),iter_upperB) - 1;
		dub = distance(b.begin(),iter_upperB);

		ll ans1 = abs(a[dla]-l) + abs(a[dla]-b[dlb]);		
		ll ans2 = abs(a[dla]-l) + abs(a[dla]-b[dub]);		
		ll ans3 = abs(a[dua]-l) + abs(a[dua]-b[dlb]);		
		ll ans4 = abs(a[dua]-l) + abs(a[dua]-b[dub]);
		ll ans5 = abs(b[dlb]-l) + abs(a[dla]-b[dlb]);		
		ll ans6 = abs(b[dlb]-l) + abs(a[dua]-b[dlb]);		
		ll ans7 = abs(b[dub]-l) + abs(a[dua]-b[dub]);		
		ll ans8 = abs(b[dub]-l) + abs(a[dla]-b[dub]);	
		ll ans9 = min(ans1,min(ans2,min(ans3,ans4)));
		ll ans10 = min(ans5,min(ans6,min(ans7,ans8)));
		ans = min(ans9,ans10); 
		cout << ans << endl;	
	}
	
return 0;
	
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct ban
{
    int i;
    int t;
    int z;
    int x;
    ban(){}
    ban(int i, int t, int z, int x)
    {
        this->i = i;
        this->t = t;
        this->z = z;
        this->x = x;
    }
};
bool operator<(const ban& a, const ban& b)
{
    if (a.t < b.t)
        return true;
    if (a.t > b.t)
        return false;
    if (a.z == 1 || a.z == -1)
        return true;
    if (b.z == 1 || b.z == -1)
        return false;
    return false;
}

int n, q;
vector<ban> a;

int ans[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> q;
    for (int i = 1; i <= n; ++i)
    {
        int l, r, x;
        cin >> l >> r >> x;
        --r;
        a.push_back(ban(i, l - x, 1, x));
        a.push_back(ban(i, r - x + 1, -1, x));
    }
    for (int i = 1; i <= q; ++i)
    {
        int t;
        cin >> t;
        a.push_back(ban(i, t, 0, 0));
    }
    sort(a.begin(), a.end());
    multiset<int> s;
    for (int i = 0; i < a.size(); ++i)
    {
        if (a[i].z == 1)
            s.insert(a[i].x);
        else if (a[i].z == -1)
            s.erase(s.find(a[i].x));
        else
        {
            if (s.empty())
                ans[a[i].i] = -1;
            else
                ans[a[i].i] = (*s.begin());
        }
    }
    for (int i = 1; i <= q; ++i)
        cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 22244