akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int stop[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

int main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    int s, g; cin >> s >> g;
    for(int j = 0; j < 15; j++) {
      if(j < 9 && s < 6 && g < 6 && s > g) j += 9;
      if(s == stop[j]) {
        for(int k = 0; k < 15; k++) {
          int num = (j+k)%15;
          cout << stop[num];
          if(stop[num] != g) cout << ' ';
          else {
              cout << endl;
              break;
          }
        }
      }
    if(s < 6 && s < g && j > 5) break;
    }
  }
}

Measured memory_bytes: 1160
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]

def BubbleSort(N, A):

    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(A[j][1]) < int(A[j - 1][1]):
                A[j], A[j - 1] = A[j - 1], A[j]
    
    return A

def SelectionSort(N, A):

    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        
        A[i], A[minj] = A[minj], A[i]
            
    return A

def is_stable(A, A_):
    for i in range(len(A_) - 1):
        if A_[i][1] == A_[i + 1][1]:
            j = A.index(A_[i])
            k = A.index(A_[i + 1])
            
            if j > k:
                return "Not stable"
    
    return "Stable"

def main():
    N = int(input())
    A = input().split()

    BA = BubbleSort(N, A[:])
    SA = SelectionSort(N, A[:])

    print(" ".join(list(map(str, BA))))
    print(is_stable(A, BA))
    print(" ".join(list(map(str, SA))))
    print(is_stable(A, SA))


main()



Measured memory_bytes: 7752
n,m = map(int,input().split())

a = [[0 for i in range(m)] for j in range(n)]

for i in range(n):
    a_tmp = list(map(int,input().split()))
    for j in range(m):
        a[i][j] = a_tmp[j]

b=[]
for i in range(m):
    b.append(int(input()))
    
for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j]*b[j]
    print(c)

Measured memory_bytes: 8000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ld a, b, x; cin >> a >> b >> x;
  if(2*x < a*a*b) {
    ld d = x*2/a/b;
    cout << fixed << setprecision(10) << atan2(b, d) / M_PI * 180 << endk;
  } else {
    ld d = (a*a*b-x)*2/a/a;
    cout << fixed << setprecision(10) << atan2(d, a) / M_PI * 180 << endk;
  }
  return 0;
}


Measured memory_bytes: 3856
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N];
    int total = 0, S1 = 0, S2 = 0, min = 10000;
    for (int i=0; i<N; i++) {
      W[i] = sc.nextInt();
      total += W[i];
    }
    for (int i=0; i<N; i++) {
      for (int j=0; j<i; j++) {
        S1 += W[j];
      }
      S2 = total - S1;
      min = Math.min(Math.abs(S1 - S2), min);
      S1 = 0; S2 = 0;
    }
    System.out.println(min); 
  }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		String W = scn.nextLine();
		int count = 0;
		final String LAST_DATA = "END_OF_TEXT";
		while (scn.hasNextLine()) {
			String T = scn.next();
			if (T.equals(LAST_DATA)) {
				break;
			}
			W = W.toLowerCase();
			T = T.toLowerCase();
			if (T.equals(W)) {
				count++;
			}
		}
		System.out.println(count);
	}
}



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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int k=0;
  for(int i=1; i<(n+1);i++){
    int a;
    cin >> a;
    if(i%2==1&&a%2==1){
      k++;
    }
  }
  cout << k << endl;
  return 0;

}

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

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

    vector<int> A(N);

    for (int i = 0; i < N;i++){
        cin >> A.at(i);
    }

    vector<pair<int, int>> pairs(N);

    for (int i = 0; i < N;i++){
        pairs.at(i) = make_pair(A.at(i),i+1);
    }

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

    for (int i = 0; i < N;i++){
        cout << pairs.at(i).second << " ";
    }
    cout << "" << endl;
}

Measured memory_bytes: 2048
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] blood;
		int n=0,k=0;
		boolean ok = true;
		
		while(sc.hasNext()){
			n = sc.nextInt();
			k = sc.nextInt();
			if(n==0 && k==0) break;
			
			blood = new int[k];
			for(int i = 0;i<k;i++) blood[i] = sc.nextInt();
			
			for(int i = 0;i<n;i++){
				for(int j = 0;j<blood.length;j++){
					blood[j] -= sc.nextInt();
					if(blood[j]<0) ok = false;
				}
			}
			
			System.out.println(ok ? "Yes" : "No");
			ok = true;
		}
	}
}

Measured memory_bytes: 96912
#include <iostream>

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

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  //入力終了

  //左端が正なら積も正
  if(a>0)
    cout << "Positive" << endl;
  //a=0なら積も0
  else if(a == 0)
    cout << "Zero" << endl;
  else{
    //0をまたげば積も0
    if(b>=0)
      cout << "Zero" << endl;
    else{
      //区間幅が偶数なら積もは正
      if( (b-a+1)&1 )
	cout << "Negative" << endl;
      //区間幅が奇数なら積は負
      else
	cout << "Positive" << endl;
    }
  }

    return 0;
}


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

void chmin(int& a, int b) {
  if (a > b) a = b;
}

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> minus, plus;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x >= 0) {
      plus.push_back(x);
    } else {
      minus.push_back(-x);
    }
  } 
  
  sort(minus.begin(), minus.end());
  
  int ans = 300000000;
  
  int M = minus.size(), P = plus.size();
  // minusの個数, Kとのminを
  int minus_num = min(M, K);
  int plus_num = min(P, K);
  
  if (minus_num == 0) {
    ans = plus[K-1];
  } else if (plus_num == 0) {
    ans = minus[K-1];
  } else {
    for (int i = K - plus_num; i <= minus_num; i++) {
      chmin(ans, min(minus[i-1], plus[K-i-1]) + minus[i-1] + plus[K-i-1]);
    }
  }
  cout << ans << endl;
  

}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    int ans = 0;

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

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;

struct mf{
	struct edg{ int pos, cap, rev; };
	vector<edg> gph[MAXN];
	void clear(){ for(int i=0; i<MAXN; i++) gph[i].clear(); }
	void add_edge(int s, int e, int x){
		gph[s].push_back({e, x, (int)gph[e].size()});
		gph[e].push_back({s, 0, (int)gph[s].size()-1});
	}
	int dis[MAXN], pnt[MAXN];
	bool bfs(int src, int sink){
		memset(dis, 0, sizeof(dis));
		memset(pnt, 0, sizeof(pnt));
		queue<int> que;
		que.push(src);
		dis[src] = 1;
		while(!que.empty()){
			int x = que.front();
			que.pop();
			for(auto &e : gph[x]){
				if(e.cap > 0 && !dis[e.pos]){
					dis[e.pos] = dis[x] + 1;
					que.push(e.pos);
				}
			}
		}
		return dis[sink] > 0;
	}
	int dfs(int x, int sink, int f){
		if(x == sink) return f;
		for(; pnt[x] < gph[x].size(); pnt[x]++){
			edg e = gph[x][pnt[x]];
			if(e.cap > 0 && dis[e.pos] == dis[x] + 1){
				int w = dfs(e.pos, sink, min(f, e.cap));
				if(w){
					gph[x][pnt[x]].cap -= w;
					gph[e.pos][e.rev].cap += w;
					return w;
				}
			}
		}
		return 0;
	}
	lint match(int src, int sink){
		lint ret = 0;
		while(bfs(src, sink)){
			int r;
			while((r = dfs(src, sink, 2e9))) ret += r;
		}
		return ret;
	}
}mf;

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}AD, BD;

int n, A[MAXN], B[MAXN];

int main(){
	scanf("%d",&n);
	AD.init(n);
	BD.init(n);
	for(int i=0; i<n; i++){
		scanf("%d",&A[i]);
		AD.uni(i, A[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%d",&B[i]);
		BD.uni(i, B[i]);
	}
	for(int i=0; i<n; i++){
		if(A[i] == i){
			mf.add_edge(2 * n, i, 1e9);
		}
		if(B[i] == i){
			mf.add_edge(i + n, 2 * n + 1, 1e9);
		}
		if(A[i] == B[i]){
			int ca = AD.find(i);
			int cb = BD.find(i);
			mf.add_edge(cb + n, ca, 1);
		}
		int ca = AD.find(i);
		int cb = BD.find(i);
		mf.add_edge(ca, cb + n, 1);
	}
	cout << -mf.match(2 * n, 2 * n + 1) + n << endl;
}


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

int main() {
 int a;
 cin>>a;
 cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3508
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion



int main(void) {
  ll x;
  cin >> n >> x;
  m = INF;
  FOR(i, 0, n) {
	cin >> tmp;
	m = min(m, tmp);
	x -= tmp;
  }
  cout << n + x / m << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main(){
  int n,m;
  cin>>n>>m;
  int w[n],v[n];
  for(int i=0;i<n;i++){
      cin>>w[i]>>v[i];
  }
  int ks[n+1][m+1];
  for(int i=0;i<=n;i++){
      for(int j=0;j<=m;j++){
            if(i==0||j==0)
                ks[i][j]=0;
            else if(w[i-1]<=j) 
                ks[i][j]=max((v[i-1]+ks[i-1][j-w[i-1]]),ks[i-1][j]);
            else 
                ks[i][j]=ks[i-1][j];
      }
  }
  cout<<ks[n][m];
  return 0;
}

Measured memory_bytes: 79104
import java.io.*;
class Main{
  public static void main(String[] args)throws IOException{
  BufferedReader mBufferedReader=new BufferedReader(new InputStreamReader(System.in));
  String str=mBufferedReader.readLine();
  String[] arr=str.split(" ");
  int a=Integer.parseInt(arr[0]);
  int b=Integer.parseInt(arr[1]);
  System.out.println((a*b)+" "+(a+b)*2);
 }
}


Measured memory_bytes: 24180
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    int sum = 0;
    rep(i, N) {
        cin >> a[i];
        sum += a[i] - 1;
    }

    cout << sum << endl;
    return 0;
}

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

int n,m;
int dp[444];
vector<P>v[444];

int dfs(int now){

  if(dp[now])return dp[now];
  
  int res=0;
  
  r(i,v[now].size()){
    int nex=v[now][i].first;
    int cost=v[now][i].second;
    res=max(res,dfs(nex)+cost);
  }
  return dp[now] = res;
}

int main(){

  cin>>n>>m;

  r(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    v[a].push_back(P(b,c));
  }

  cout<< dfs(0) <<endl;
}



Measured memory_bytes: 3112
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int INF=0x3f3f3f3f;
const int N=20005;

int a[N],b[N];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

int main(void) {
	int n=read(),k=read(),q=read();
	rep(i,1,n) b[i]=a[i]=read();
	std:: sort(b+1,b+n+1);
	int ans=INF;
	rep(ti,1,n) {
		int mn=b[ti];
		std:: vector <int> v,r;
		v.push_back(0);
		rep(i,1,n) if (a[i]<mn) v.push_back(i);
		v.push_back(n+1);
		int pre=v[0];
		for (int i=1;i<v.size();++i) {
			int now=v[i];
			int len=now-pre-1;
			if (len<k) {pre=now; continue;}
			std::vector <int> s;
			rep(j,pre+1,now-1) s.push_back(a[j]);
			std:: sort(s.begin(),s.end());
			rep(j,0,len-k) r.push_back(s[j]);
			pre=now;
		}
		std:: sort(r.begin(),r.end());
		if (q<=r.size()) ans=std:: min(ans,r[q-1]-mn);
	}
	printf("%d\n", ans);
	return 0;
}

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

ll kaijo(ll x ,ll y){
    if(x/y==0) return 0;
    else{
        return x/y + kaijo(x/y,y);
    }
}
int main()
{
    ll n;
    ll ans2;
    ll ans5;
    cin >> n;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll m=n/2;
        ans2=kaijo(m,2);
        ans5=kaijo(m,5);

    }
    cout << min(ans2,ans5) << endl;
    return 0;
}

Measured memory_bytes: 256
/* Sorting Three Numbers */
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a <= b && b <= c){
        printf("%d %d %d\n", a, b, c);
    }
    else if(a <= c && c <= b){
        printf("%d %d %d\n", a, c, b);       
    }
    else if(b <= a && a <= c){
        printf("%d %d %d\n", b, a, c); 
    }
    else if(b <= c && c <= a){
        printf("%d %d %d\n", b, c, a);
    }
    else if(c <= b && b <= a){
        printf("%d %d %d\n", c, b, a);
    }
    else{
        printf("%d %d %d\n", c, a, b);
    }
    return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int LCSRe[5009][5009];
string str;
string longestRepeatedSubstring()
{
	int n = str.length();
	string res;
	int res_length = 0;
	int i, index = 0;
	for (i=1; i<=n; i++)
	{
		for (int j=i+1; j<=n; j++)
		{
			if (str[i-1] == str[j-1] &&
				LCSRe[i-1][j-1] < (j - i))
			{
				LCSRe[i][j] = LCSRe[i-1][j-1] + 1;
				if (LCSRe[i][j] > res_length)
				{
					res_length = LCSRe[i][j];
					index = max(i, index);
				}
			}
			else
				LCSRe[i][j] = 0;
		}
	}

	if (res_length > 0)
		for (i = index - res_length + 1; i <= index; i++)
			res.push_back(str[i-1]);

	return res;
}

int main()
{
  int n;
  cin>>n;
  cin>>str;
  string temp=longestRepeatedSubstring();
  cout<<temp.size()<<endl;
	return 0;
}


Measured memory_bytes: 96768
use std::io;

fn main() {
     print!("{}", execute(from_stdin()));
}

fn execute(s: String) -> String {
    let v: Vec<usize> = s
        .split_whitespace()
        .into_iter()
        .map(|s| s.parse().unwrap())
        .collect();

    let h1 = v[0];
    let m1 = v[1];
    let h2 = v[2];
    let m2 = v[3];
    let k = v[4];

    let start = h1 * 60 + m1;

    let end = h2 * 60 + m2;

    let result = end - start - k;

    result.to_string()
}

fn from_stdin() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim_end().to_owned()
}

#[test]
fn test_execute() {
    assert_eq!(execute("10 0 15 0 30".to_owned()), "270");
    assert_eq!(execute("10 0 12 0 120".to_owned()), "0");
}


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

int main(){
    int n;
    cin>>n;
    int a=0,b=0,c=0;
    for(int i=0;i<n;i++){
        int s;
        cin>>s;
        if(s%4==0) a++;
        else if(s%2==0) b++;
        else c++;
    }
    if(b) c++;
    if(a+1>=c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N,X,M;
    cin>>N>>X>>M;
    map<ll,ll> ind;
    v sums(M+1,0);

    sums[0] = X;
    ind[X] = 1;
    ll now = X;
    ll now_ind = 2;
    ll loop_sum = 0, loop_N =0;
    ll r = 0;//0-index

    while(true){
        now = (now*now)%M;
        sums[now_ind-1] = sums[now_ind-2] + now;
        if(ind[now] == 0){
            ind[now] = now_ind;
        }
        else{
            loop_sum = sums[now_ind-1] - sums[ind[now]-1];
            loop_N = now_ind - ind[now];
            r = ind[now]-1;
            break;
        }
        now_ind++;     
    }

    ll ans = 0;
    if(r < N-1){
        ans += sums[r];
        ll loops = (N-r-1)/loop_N;
        ans += loop_sum * loops;
        ans += sums[N-1- loops * loop_N] - sums[r];
    }
    else{
        ans = sums[N-1];
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 7212
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
#define IINF (1<<21)
typedef long long ll;

int main() {
  int N;
  cin >> N;
  // ll q[N];
  ll q[10100];
  ll maximum = 0;

  REP(i, N) {
    cin >> q[i];
    maximum = max(maximum, q[i]);
  }

  // int table[maximum + 1];
  int table[12000];
  REP(i, 12000) {
    table[i] = 1;  // possibly prime number
  }
  table[0] = 0;
  table[1] = 0;

  for (ll base = 2; base <= 10100; base++) {
    if (!table[base]) continue;
    for (ll p = 2; base * p <= 10100; p++) {
      // dump(base * p);
      table[base * p] = 0;
    }
  }


  ll sum = 0;
  REP(i, N) {
    // dump(i);

    if (q[i] < 10100) {
      sum += table[q[i]];
    } else {
      int ok = 1;
      for (ll base = 2; base <= 10000 && base * base <= q[i]; base++) {
        if (q[i] % base == 0) {
          ok = 0;
          break;
        }
      }
      if (ok) sum++;
    }
  }
  //
  // REP(i, 100) {
  //   // dump(table[i]);
  //   if (i) cout << " ";
  //   cout << table[i];
  // }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, m;
	cin >> n >> m;
	unordered_map<int, int> mp;
	int L = 0, R = n + 1;
	rep(_, m) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		chmax(L, l);
		chmin(R, r);
	}
	int ans = 0;
	rep(i, n) {
		if (i >= L && i <= R)
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

string ProcessOnce(string s, bool last) {
  int n = s.size();
  int i = n - 1;
  while (i - 1 >= 0 && s[i - 1] == s[i]) i--;
  string w = s;
  reverse(w.begin(), w.end());
  s += w;
  if (last) return s.substr(i, n);

  int diff = n - 1 - i;
  int right = n + diff;
  int left = right - n + 1;
  return s.substr(left, n);
}

string Process(string s, int k) {
  for (int i = 0 ; i < k; ++i) {
    s = ProcessOnce(s, i == k - 1);
  }
  return s;
}

int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  if (k > 20) {
    k = 20;
  }

  string result = "";
  
  string w = s;
  reverse(w.begin(), w.end());

  string ss = s + w;

  for (int i = 0; i <= n; ++i) {
    string cur = ss.substr(i, n);
    cur = Process(cur, k - 1);
    if (result == "" || result > cur) {
      result = cur;
    }
  }
  cout << result << endl;

  return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	string S;
	cin >> S;
	int ans=0;
	rep(i,S.size()){
		int l=0;
		for(int j=i; j<S.size(); j++){
			if(S[j]=='A'||S[j]=='C'||S[j]=='G'||S[j]=='T') l++;
			else break;
		}
		ans=max(ans,l);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int x = 1000000;
    for(int i=0; i<s.size()-2;i++){
        string t = {s[i],s[i+1],s[i+2]};
        int tmp = stoi(t);
        if(abs(x-753) > abs(tmp-753)){
            x=tmp;
        }
    }
    cout<<abs(x-753)<<endl;
}

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

using namespace std;
typedef long long LL;
const int Max_Num=100010;
struct edge{
  int to, cost;
};
vector<edge> G[Max_Num];
int ans[Max_Num];

void dfs(int n, bool col){
  ans[n]=col;
  rep(i,G[n].size()){
    if(ans[G[n][i].to]!=-1) continue;
    if(G[n][i].cost%2) dfs(G[n][i].to,!col);
    else dfs(G[n][i].to,col);
  }
}

int main(){
  int N;
  cin >> N;
  rep(i,N-1){
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    edge e={v,w};
    G[u].emplace_back(e);
    e={u,w};
    G[v].emplace_back(e);
  }
  rep(i,N) ans[i]=-1;
  dfs(0,0);
  rep(i,N) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    int N;
    cin >> N;
    cout << N*N*N << endl;
    return 0;
}


Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class VW
  attr_reader :value, :weight
  def initialize(value, weight)
    @value = value
    @weight = weight
  end
  def to_s
    "V:#{@value} W:#{@weight}"
  end
end

class Solver
  def main
    # 問題2: ナップサック問題
    # https://qiita.com/drken/items/a5e6fe22863b7992efdb
    # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp

    n, upper_w = gets.split.map(&:to_i)

    ks = Array.new(n)
    n.times do |i|
      # [Value, Weight]
      ks[i] = VW.new(*gets.split.map(&:to_i))
    end
    # pp knapsacks

    # 重さwで運べる最大の価値を格納
    # dp[i][w] = v
    # dp[0] : 初期条件
    dp = Array.new(n+1) { Array.new(upper_w+1, 0) }
    dp[0] = Array.new(upper_w+1, 0)

    0.upto(n-1) do |i|
      item = ks[i]
      0.upto(upper_w) do |w|
        dp[i+1][w] =
            if w < item.weight
              # 現在の重さより左側は上から下ろしてくるだけ
              dp[i][w]
            else
              # 現在の重さ以上の部分（右側）は
              # 重さ分左のvalue + 現在value or 下ろすだけ
              [dp[i][w - item.weight] + item.value, dp[i][w]].max
            end
      end
      # pp "#{i+1}: #{dp[i+1]}"
    end

    puts dp[n][upper_w]
  end
end

if __FILE__ == $0
  Solver.new.main
end



Measured memory_bytes: 15012
#include <stdio.h>

int main(){

    int data[50][3];
    int i,j,sum;
    i = 0;
    while(1){
        scanf("%d%d%d",&data[i][0],&data[i][1],&data[i][2]);
        if(data[i][0] == -1 && data[i][1] == -1 && data[i][2] == -1){
            break;
        }
        i++;
    }

    i = 0;
    while(1){
        sum = 0;
        sum = data[i][0] + data[i][1];
        if(data[i][0] == -1 && data[i][1] == -1 && data[i][2] == -1){
            break;
        }else if(data[i][0] == -1 || data[i][1] == -1){
            printf("F\n");
        }else if(sum >= 80){
            printf("A\n");
        }else if(sum >= 65 && sum < 80){
            printf("B\n");
        }else if(sum >= 50 && sum < 65){
            printf("C\n");
        }else if(sum >= 30 && sum < 50){
            if(data[i][2] >= 50){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else{
            printf("F\n");
        }
        i++;
    }

    //テスト用
    // i = 0;
    // while(1){
    //     printf("%d %d %d\n",data[i][0],data[i][1],data[i][2]);
    //     if(data[i][0] == -1 && data[i][1] == -1 && data[i][2] == -1){break;}
    //     i++;
    // }
}


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


int main()
{
	const int MOD=1e9+7;
	int N,K;
	cin>>N>>K;
	ll l=0;
	ll r=0;
	rep(i,K)
	{
		l+=i;
		r+=N-i;
	}
	ll ans=(r-l+1)%MOD;
	for(int i=K;i<=N;i++)
	{
		l+=i;
		r+=N-i;
		(ans+=r-l+1)%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> mochis(N);
  int duplicated = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> mochis.at(i);
  	for (int j = 0; j < i; j++) {
      if (mochis.at(j) == mochis.at(i)) {
      	duplicated++;
        break;
      }
    }
  }
  cout << N - duplicated << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(void){
    long long x;
    cin>>x;
    long long ans=(x/11)*2;
    x%=11;
    if(x==0)cout<<ans<<endl;
    else if(x<7)cout<<ans+1<<endl;
    else cout<<ans+2<<endl;
    return 0;
}


Measured memory_bytes: 256
from math import factorial
def comb(n):
    if n == 1 or n == 0:
        return 0
    return int(n * (n-1) / 2 )

n = int(input())
a = list(map(int, input().split()))

count = {}
ans = 0

for i in range(n):
    count.setdefault(a[i], 0)
    count[a[i]] += 1

for v in count.values():
    ans += comb(v)


for i in range(n):
    v = count[a[i]]
    print(ans - comb(v) + comb(v-1))

Measured memory_bytes: 26140
import sys
S=sys.stdin.readlines()
def Binit(B,siz):
  while len(B)<siz+1:
    B.append(0)
  while len(B)>siz+1:
    del B[-1]
  for i in range(siz+1):
    B[i]=0
  B.append(siz)

def Badd(B,a,x):
  z=a
  while z<=B[-1]:
    B[z]+=x
    z+=(z&(-z))

def Bsum(B,a):
  r=0
  z=a
  while z>0:
    r+=B[z]
    z-=(z&(-z))
  return r

def Bssum(B,a,b):
  return Bsum(B,max(a,b))-Bsum(B,min(a,b)-1)

N=int(S[0])
X=[list(map(int,S[i+1].split())) for i in range(N)]
X.sort()
for i in range(N):
  X[i][0]=i
D=dict()
Y=sorted([X[i][1] for i in range(N)])
for i in range(N):
  D[Y[i]]=i
for i in range(N):
  X[i][1]=D[X[i][1]]
B1,B2=[],[]
Binit(B1,N+1)
Binit(B2,N+1)
for i in range(N):
  Badd(B2,i+1,1)
mod=998244353
P=N*pow(2,N-1,mod)%mod
Z=[[1,1,1,1],[1,1,1,0],[1,1,0,1],[1,0,1,1],[1,0,0,1],[0,1,1,1],[0,1,1,0]]
A=0
for i in range(N):
  Badd(B2,X[i][1]+1,-1)
  V=[Bsum(B1,X[i][1]+1),Bsum(B2,X[i][1]+1)]
  W=[pow(2,V[0],mod)-1,pow(2,i-V[0],mod)-1,pow(2,V[1],mod)-1,pow(2,N-i-1-V[1],mod)-1]
  for j in range(7):
    A=1
    if Z[j][0]:
      A=A*W[0]%mod
    if Z[j][1]:
      A=A*W[1]%mod
    if Z[j][2]:
      A=A*W[2]%mod
    if Z[j][3]:
      A=A*W[3]%mod
    P=(P+A)%mod
  Badd(B1,X[i][1]+1,1)
print(P)

Measured memory_bytes: 171564
using System;

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            string c = Console.ReadLine();

            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                string ai = a.Substring(i, 1);
                string bi = b.Substring(i, 1);
                string ci = c.Substring(i, 1);

                if (ai == bi && bi == ci)
                    continue;
                if (ai != bi && bi != ci && ci != ai)
                {
                    cnt = cnt + 2;
                    continue;
                }

                ++cnt;
            }

            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 13140
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int H, W; cin >> H >> W;
	int c[10][10];
	rep(i, 10)rep(j, 10)cin >> c[i][j];
	rep(k, 10)rep(i, 10)rep(j, 10)c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	int res = 0;
	rep(i, H)rep(j, W)
	{
		int A; cin >> A;
		if (A != -1)res += c[A][1];
	}
	cout << res << '\n';
}

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

int main() {
  long long N,sum=0;
  cin>>N;
  rep(i,N){
  if(!((i+1)%3==0)&&!((i+1)%5==0)){
  sum=sum+i+1;
  }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <string>
#define ll long long int
using namespace std;

const int m=1000000007;

int main()
{
    int k;
    cin>>k;
    int i=1;
    int n=7;
    if(k%2==0 || k%5==0)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        bool flag=0;
        while(i<=1000000)
        {
            if(n%k==0)
            {
                cout<<i<<endl;
                flag=1;
                break;
            }
            else
            {
                n=n*10+7;
                n=n%k;
                i++;
            }
        }
        if(flag==0)
        {
            cout<<"-1"<<endl;
        }
    }
}


Measured memory_bytes: 3584
import sys

sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline


def inpS(): return inp().rstrip().decode()


readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
INF = 1 << 60

# ---------------------------------------------------
# ---------------------------------------------------
# ---------------------------------------------------

cnt = 0
def resolve():
    def merge(l, r):
        global cnt
        mA = []
        l_i = 0
        r_i = 0
        while l_i < len(l) and r_i < len(r):
            if l[l_i] <= r[r_i]:
                mA.append(l[l_i])
                l_i += 1
            else:
                mA.append(r[r_i])
                r_i += 1
                # Lの個数から今のL_indを引けばRより大きい個数がわかる
                cnt += len(l) - l_i
        # 残りを加える
        if l_i < len(l):
            mA.extend(l[l_i:])
        elif r_i < len(r):
            mA.extend(r[r_i:])
        return mA

    def mergesort(arr):
        if len(arr) <= 1:
            return arr
        mid = len(arr) // 2
        left = mergesort(arr[:mid])
        right = mergesort(arr[mid:])

        return merge(left, right)

    N = int(inp())
    A = list(map(int, inp().split()))

    mergesort(A)
    print(cnt)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 24412
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    b = [int(i) for i in ipt().split()]
    hq = []
    ans = 0
    for i,bi in enumerate(b):
        if bi > a[i]:
            heapq.heappush(hq,(-bi,i))
    while len(hq) > 0:
        #print(hq,b)
        nbi,i = heapq.heappop(hq)
        if i == n-1:
            bp = b[0]
        else:
            bp = b[i+1]
        bm = b[i-1]
        t = (-a[i]-nbi)//(bm+bp)
        if t == 0:
            print(-1)
            exit()
        b[i] -= (bm+bp)*t
        if b[i] > a[i]:
            heapq.heappush(hq,(-b[i],i))
        ans += t
    print(ans)
    return

if __name__ == '__main__':
    main()


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

using namespace std;

int main(void) {
    int x, y;
    cin >> x >> y;

    if (x == y) {
        cout << "Yes" << endl;
        return 0;
    }

    set <int> a, b;
    a.insert(1);
    a.insert(3);
    a.insert(5);
    a.insert(7);
    a.insert(8);
    a.insert(10);
    a.insert(12);

    b.insert(4);
    b.insert(6);
    b.insert(9);
    b.insert(11);

    bool x_in_a = (a.find(x) != a.end());
    bool y_in_a = (a.find(y) != a.end());

    bool x_in_b = (b.find(x) != b.end());
    bool y_in_b = (b.find(y) != b.end());

    if ((x_in_b && y_in_b) || (x_in_a && y_in_a)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main()
{
    int a, b;
    cin >> a >> b;

    if (a > b) swap(a, b);

    int k = (a + b)/2;

    if (abs(a - k) == abs(b - k))
        cout << k << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import fractions

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    dp = {}
    dp[0, 0] = 0
    dp[0, 1] = -100000000000
    for i in range(1, N):
        dp[i, 0] = max(dp[i-1,0]+A[i-1], dp[i-1,1]-A[i-1])
        dp[i, 1] = max(dp[i-1,0]-A[i-1], dp[i-1,1]+A[i-1])
    print(max(dp[N-1,0]+A[N-1], dp[N-1,1]-A[N-1]))

Measured memory_bytes: 57988
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

struct edge { 
    int to;
    ll cost;
};

typedef vector<vector<edge>> Graph;

vector<ll> dijkstra(Graph G, ll s) {
    ll inf = 1e18;
    priority_queue<Pll, vector<Pll>, greater<Pll>> que;
    vector<ll> d(G.size(), inf);
    d[s] = 0;
    que.push(Pll(0, s));
    
    while (!que.empty()) {
        Pll p = que.top();
        que.pop();
        
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (auto &i : G[v]) {
            edge e = i;
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(Pll(d[e.to], e.to));
            }
        }
    }
    return d;
}


int main() {
    int v, e, r;
    cin >> v >> e >> r;

    Graph G(v);
    for (int i = 0; i < e; i++) {
        ll s, t, d;
        cin >> s >> t >> d;
        edge e;  e.to = t;  e.cost = d;
        G[s].push_back(e);
    }

    vector<ll> d = dijkstra(G, r);
    ll inf = 1e18;
    for (int i = 0; i < v; i++) {
        if (d[i] == inf) cout << "INF" << endl;
        else cout << d[i] << endl;
    }

}



Measured memory_bytes: 30848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll k, s;
  cin >> k >> s;
  ll res = 0;
  rep(i, k+1) {
    rep(j, k+1) {
      ll tmp = s-i-j;
      if (0<=tmp && tmp<=k) res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#include<assert.h>
#define LL long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define F first
#define S second
using namespace std;
string s;
int ans;
void dfs(int n,string t){
  if((t<=s||n>1)&&t.size()>=3){
  	bool cnt[10];
  	for(int i=0;i<10;i++)
  	  cnt[i]=false;
  	for(int i=0;i<t.size();i++)
  	  cnt[int(t[i]-'0')]=true;
  	if(cnt[3]==true&&cnt[5]==true&&cnt[7]==true){
      ans++;
    }
  }
  if(n==1)
    return;
  dfs(n-1,t+"3");
  dfs(n-1,t+"5");
  dfs(n-1,t+"7");
}
int main(){
  cin>>s;
  dfs(s.size(),"3");
  dfs(s.size(),"5");
  dfs(s.size(),"7");
  cout<<ans;
  return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        long ans = 0;
        long count = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'B') count++;
            if (s[i] == 'W') ans += count;
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11616
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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*b/gcd(a,b);}
ll MOD=1000000007;





int main(){
  int n;
  cin >> n;
  if(n%2==0){
    cout << n/2 << endl; 
  }else{
    cout << n/2 + 1 << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
B = [0 for _ in range(N)]
C = []
for i in range(N,0,-1):
    tmp = sum(B[i-1::i])
    if tmp%2!=A[i-1]:
        B[i-1] = 1
        C.append(str(i))
print(len(C))
if len(C)!=0:
    print(" ".join(C))

Measured memory_bytes: 17224
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        int ans = 0;

        if(n < 600){
            ans = 8;
        }else if(n < 800){
            ans = 7;
        }else if(n < 1000){
            ans = 6;
        }else if(n < 1200){
            ans = 5;
        }else if(n < 1400){
            ans = 4;
        }else if(n < 1600){
            ans = 3;
        }else if(n < 1800){
            ans = 2;
        }else if(n < 2000){
            ans = 1;
        }

        System.out.println(ans);
    }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
typedef complex<int> point;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

#define watch(x) cerr << (#x) << " = " << (x)    << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

void smain() {

    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1);
}

Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var s = next();
  var N = s.length;
  var K = nextInt();
  var output = 0;
  var dp = new Array(105);
  for(var i = 0; i < 105; i++){
    dp[i] = new Array(K);
    for(var j = 0; j < 4; j++){
      dp[i][j] = new Array(2).fill(0);
    }
  }
  dp[0][0][0] = 1;
  for(var i = 0; i < N; i++){
    for(var j = 0; j < 4; j++){
      for(var k = 0; k < 2; k++){
        var d = myconv(s[i], 1);
        for(var l = 0; l < 10; l++){
          var ni = i + 1;
          var nj = j;
          var nk = k;
          if(l != 0){
            nj++;
          }
          if(nj > K){
            continue;
          }
          if(k == 0){
            if(l > d){
              continue
            }
            if(l < d){
              nk = 1;
            }
          }
          dp[ni][nj][nk] += dp[i][j][k];
        }
      }
    }
  }
  myout(dp[N][K][0] + dp[N][K][1]);
}



Measured memory_bytes: 30032
#include <stdio.h>
#include <cmath>
int main(void){
  int a,b,c,k,mx,total;
  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);
  mx = fmax(a,fmax(b,c));
  total = a+b+c+mx*pow(2,k)-mx;
  printf("%d",total);
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String string = sc.nextLine();
		//		StringBuilder s = new StringBuilder(string);
		long ans =0 ;
		int p = 0;
		boolean flag = true;

		for(int i = 0;i < string.length();i++){
			//			System.out.println("i "+i+" "+s.charAt(i));
			if(string.charAt(i) == 'B'){
				if(flag){
					p = i;
					flag = false;
				}
			}else {
				if(!flag){
					ans += i -p;
					p += 1;
				}
			}

		}
		System.out.println(ans);

	}
}



Measured memory_bytes: 27184
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define S second
#define MOD 1000000007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define MAXN 100008

signed main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int h, a;
    cin>>h>>a;
    cout<<ceil((double)h/a)<<endl;
}

Measured memory_bytes: 256
n = int(input())

res_count = 0
res = 1
for i in range(1, n + 1):
    a = i
    count = -1
    mod = 0
    while mod == 0 and a >= 1:
        mod = a % 2
        a = int(a / 2)
        count = count + 1
    if res_count < count:
        res_count = count
        res = i

print(res)


Measured memory_bytes: 3060