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

int main(){
    int n, q;// number of edges = n - 1
    cin >> n >> q;

    vector<vector<int>> graph(n);
    vector<pair<int,int>> edge;
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
        edge.push_back({a,b});// equiv: edge.emplace_back(a,b)
    }

    vector<int> p(q), x(q);
    for(int i=0; i<q; i++){
        cin >> p[i] >> x[i];
    }

    vector<int> counter(n,0);
    for(int i=0; i<q; i++){
        counter[p[i] - 1] += x[i];// doing this mistake forever...
    }

    vector<int> depth(n,0);
    queue<int> que;

    depth[0] = 1;
    que.push(0);

    while(!que.empty()){
        int current = que.front();
        que.pop();

        for(int adjacent : graph[current]){
            if(depth[adjacent]!=0) continue;
            que.push(adjacent);
            depth[adjacent] = depth[current] + 1;

            counter[adjacent] += counter[current];
        }
    }
    for(int i=0; i<n; i++){
        cout << counter[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 19432
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    
    int a,b;
    
    cin >> a>> b;
    
    if((a%2==0)||(b%2==0)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	map<int,int> mp;
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		mp[a]++;
	}
	int ans = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		int a = itr->first;
		int count = itr->second;
		ans += count;
		if(count >= a)
			ans -= a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, p;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> p;
    map<ll, ll> a;
    rep(i, 0, n) {
        ll x; cin >> x;
        a[x%2]++;
    }
    ll ans = 0;
    if (a[1] == 0) {
        if (p == 1) ans = 0;
        else ans = (ll)pow(2, n);
    } else {
        ans = (ll)pow(2, n-1);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    ans=max(a,b);
    if(ans==a){
    ans=ans+max(a-1,b);
    }else{ans=ans+max(a,b-1);
    }
    cout<<ans<<endl;
    }


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

int main() {
	// your code goes here
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(a > 0 && c > 0){
		c -= b;
		if(c <= 0)
		{
			cout << "Yes";
			return 0;
		}
		a -= d;
		if(a <= 0){
			cout << "No";
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>
 
const int64_t cc = pow( 10, 9 ) + 7;
 
bool sort_pair( std::pair< char, int64_t > origin, std::pair< char, int64_t > another )
{
    return origin.first < another.first;
}


int main()
{
    int64_t a,b,c,d,e;
    std::cin>> a;
    std::cin>> b;

    std::vector< int64_t > list( a );

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

    std::vector< int64_t > dp( a + b + 1, INFINITY );

    dp[0] = 0;

    for( int i = 0; i < a; i++ )
    {
        for( int r = 1; r <= b; r++ )
        {
            //std::cout<< abs( list[i] - list[i+r] )<< " " << dp[i+r-1] <<"\n";
            dp[i+r] = std::min( dp[i+r], dp[i] + abs( list[i+r] - list[i] ) );
        }
    }


    std::cout<< dp[a-1];
}



Measured memory_bytes: 1792
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int, int> P;


struct Node {
    int x, y, step = 0;
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int dir[4][2] = { 1,0,0,1,-1,0,0,-1 };
    int H, W, Ch, Dh, Cw, Dw;
    const int maxn = 1e3 + 5;
    char Maze[maxn][maxn];
    int visited[maxn][maxn], ans[maxn][maxn];
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            char temp;
            cin >> temp;
            Maze[i][j] = temp;
            ans[i][j] = -1;

        }
    }
    deque<Node> List;
    List.push_front((Node) { Cw, Ch, 0 });

    while (!List.empty())
    {
        Node nd = List.front(); List.pop_front();
        int x = nd.x, y = nd.y, step = nd.step;
        if (visited[y][x])continue;
        visited[y][x] = 1;
        ans[y][x] = step;
        for (int i = 0; i < 4; i++)
        {
            int xx = x + dir[i][0], yy = y + dir[i][1];
            if (xx > 0 && xx <= W && yy > 0 && yy <= H && !visited[yy][xx] && Maze[yy][xx] == '.')
            {
                List.push_front((Node) { xx, yy, step });
            }
        }
        for (int xx = x - 2; xx <= x + 2; xx++)
        {
            for (int yy = y - 2; yy <= y + 2; yy++)
            {
                if (xx > 0 && xx <= W && yy > 0 && yy <= H && !visited[yy][xx] && Maze[yy][xx] == '.')
                {
                    List.push_back((Node) { xx, yy, step + 1 });
                }

            }
        }
    }
    if (ans[Dh][Dw] < 0) cout << "-1";
    else cout << ans[Dh][Dw];






    return 0;
}

Measured memory_bytes: 13016
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static final int VALUE = 0;
	public static final int WEIGHT = 1;
	
	public static final int IMPOSSIBLE = -1;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();
	}

	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int numOfData = 0;
		while(w != 0){
			numOfData++;
			int n = sc.nextInt();
			int[][] trs = new int[n][2];
			for(int i = 0; i < n; i++){
				String str = sc.next();
				String[] s = str.split(",");
				trs[i][VALUE] = Integer.parseInt(s[0]);
				trs[i][WEIGHT] = Integer.parseInt(s[1]);
			}
			//print(trs,n);
			//ソートしてみる
			//Arrays.sort(trs, new MyComparator());
			//printTRS(trs,n);
			//i番目までを使ってwの重さの時の最大の価値を入れる
			int[][] dp = new int[n + 1][w + 1];
			//Arrays.fill(dp, IMPOSSIBLE);
			
			for(int i = 1; i <= n; i++){
				int wg = trs[i - 1][WEIGHT];
				for(int j = 1; j <= w; j++){
					if(wg <= j){
						dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - wg] + trs[i - 1][VALUE]);
					}
					else{
						dp[i][j] = dp[i - 1][j];
					}
				}
			}
			int[] d = dp[n];
			//print(dp[1]);
			int mw = 0;
			for(int i = 1; i <= w; i++ ){
				if(d[mw] < d[i]){
					mw = i;
				}
			}
			System.out.printf("Case %d:\n%d\n%d\n", numOfData, d[mw], mw);

			w = sc.nextInt();
		}
	}
	
	public static void print(int[] ar){
		int len = ar.length;
		for(int i = 0; i < len; i++){
			System.out.println(i + " : " + ar[i]);
		}
	}

	public static void printTRS(int[][] trs, int n){
		for(int i = 0; i < n; i++){
			System.out.println(i + " : value = " + trs[i][VALUE] + ", weight = " + trs[i][WEIGHT]);
		}
	}

}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> X(N,1);
    vector<int> H(N);
    for(int i=0; i<N; i++){
        cin >> H.at(i);
    }
    int a,b,less_h;
    for(int i=0; i<M; i++){
        cin >> a >> b;
        a = a-1;
        b = b-1;
        if(H.at(a) < H.at(b)){
            X.at(a) = 0;
        }
        else if(H.at(a) > H.at(b)){
            X.at(b) = 0;
        }else if(H.at(a) == H.at(b)){
            X.at(a)=0;
            X.at(b)=0;
        }
    }
    int count = 0;
    for(int check: X){
        if(check == 1){
            count++;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 4024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long x = n * k;
  map<int, vector<int>> mp;
  for (int i = 0; i < n; i++) {
    mp[a[i]].push_back(i);
  }
  vector<long long> vf(n);
  for (auto& m : mp) {
    auto& v = m.second;
    v.push_back(v[0] + n);
    for (int i = 0; i + 1 < (int) v.size(); i++) {
      vf[v[i]] = v[i + 1] - v[i] + 1;
    }
  }
  const long long INF = 1LL << 60;
  vector<vector<long long>> table = {vf};
  for (int u = 1; u <= 60; u++) {
    vector<long long>& cur = table.back();
    vector<long long> nxt(n);
    for (int i = 0; i < n; i++) {
      nxt[i] = min(INF, cur[i] + cur[(i + (cur[i])) % n]);
    }
    table.push_back(nxt);
  }
  long long cur = 0;
  for (int i = (int) table.size() - 1; i >= 0; i--) {
    if (cur + table[i][cur % n] <= x) {
      cur += table[i][cur % n];
    }
  }
  if (cur == x) {
    return 0;
  }
  vector<int> ans;
  set<int> st;
  for (int i = cur % n; i < n; i++) {
    if (st.count(a[i])) {
      while (true) {
        int t = ans.back();
        ans.pop_back();
        st.erase(t);
        if (t == a[i]) break;
      }
    } else {
      ans.push_back(a[i]);
      st.insert(a[i]);
    }
  }
  for (int i = 0; i < (int) ans.size(); i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 132808
#include <iostream>

int main() {

  int A;
  int B;

  std::cin >> A >> B;

  if ((A + B) < 24) {
    std::cout << A + B << std::endl;
  } else if (A + B > 24) {
    std::cout << A + B - 24 << std::endl;
  } else {
    std::cout << 0 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Vs = list(mapint())
Vs.sort()
x = Vs[0]
for v in Vs[1:]:
    x = (x+v)/2
print(x)

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

int main() {
    int k;
    cin >> k;
    if(k%2 == 0 || k%5 == 0) {
        cout << -1 << '\n';
        return 0;
    } else {
        int index = 1, repsept = 7;
        while(1) {
            if(repsept%k == 0) {
                cout << index << '\n';
                return 0;
            }
            repsept = repsept*10 + 7;
            repsept %= k;
            index++;
        }
    }
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	
	ll n;
	cin>>n;
	vll A(n);
	for(int i=0;i<n;i++) cin>>A[i];
	vll pref(n),suff(n);
	ll x =0;
	for(int i=0;i<n;i++)
		x=__gcd(x,A[i]),pref[i]=x;
	x=0;
	for(int i=n-1;i>=0;i--)
		x=__gcd(x,A[i]),suff[i]=x;
	ll ans = -1;
	for(int i=1;i+1<n;i++)
		ans=max(ans,__gcd(pref[i-1],suff[i+1]));
	cout<<max({ans,pref[n-2],suff[1]});

}


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

typedef complex<double> P;

// e·éë·Ã
#define EPS (1e-10)
// 2ÂÌXJ[ªµ¢©Ç¤©
#define EQ(a,b) (abs((a)-(b)) < EPS)

// OÏ (cross product) : a~b = |a||b|sin¦
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

// 2¼üÌ½s»è : a//b <=> cross(a, b) = 0
int is_parallel(P a1, P a2, P b1, P b2) {
  return EQ( cross(a1-a2, b1-b2), 0.0 );
}

int main(){
	int n;
	double x1,x2,x3,x4,y1,y2,y3,y4;

	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		P a(x1,y1), b(x2,y2), c(x3,y3), d(x4,y4);
		if( is_parallel(a,b,c,d) ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int n,l,s[100010];
int main(){
	scanf("%d%d",&n,&l);
	for (int i=0;i<n;i++){
		scanf("%d",s+i);
	}
	for (int i=1;i<n;i++){
		if (s[i]+s[i-1]>=l){
			printf("Possible\n");
			for (int j=1;j<i;j++){
				printf("%d\n",j);
			}
			for (int j=n-1;j>i;j--){
				printf("%d\n",j);
			}
			printf("%d\n",i);
			return 0;
		}
	}
	printf("Impossible\n");
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  map<int, pair<int, int> > M;
  REP(i, m) {
    int p;
    string s;
    cin >> p >> s;
    if (s == "AC") {
      M[p].first = 1;
    } else if (s == "WA") {
      if (M.find(p) == M.end()) {
        M[p].second = 1;
      } else if (M[p].first != 1) {
        M[p].second++;
      }
    }
  }
  int ok = 0, pn = 0;
  for (const auto& e : M) {
    if (e.second.first == 1) {
      ok++;
      pn += e.second.second;
    }
  }
  cout << ok << " " << pn << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 6528
#include <bits/stdc++.h>
        #define ll  long long int
        #define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
        #define mod 1000000007
        using namespace std;
vector<ll> gr[2*100000 +1];    
bool vis[2*100000 +1];

ll dfs(ll i, ll p){
   vis[i] = true;
    if(gr[i].size()==1 && gr[i][0]==p)
    return 1;

    ll ans=1;
    for(auto it: gr[i]){
        if(it!=p && vis[it]== false)
        ans+=dfs(it, i);
    }

    return ans;
}
        int main()
            {fast;
            ll t =1;
            //cin>>t;

        while(t--){
            ll n,m;
            cin>>n>>m;
    memset(vis,0,sizeof(vis));

            while(m--){
             ll u,v;
             cin>>u>>v;
             gr[u].push_back(v);
             gr[v].push_back(u);
            }
            ll ans=0;
            for(ll i=1; i<=n;i++){
                if(vis[i]==false)
                ans= max(ans,dfs(i,-1));
            } 
            cout<<ans<<endl;

        }
                return 0;
        }

Measured memory_bytes: 27228
/**
 *  author: MOOONI
 *  hackers are welcome!
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if (a > k) {
    cout << k << '\n';
    return 0;
  }
  k -= a;
  ans += a;
  if (b > k) {
    cout << ans << '\n';
    return 0;
  }
  k -= b;
  if (c > k) {
    ans -= k;
    cout << ans << '\n';
    return 0;
  }
  k -= c;
  ans -= c;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3624
use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let in_vec: Vec<i64> = read_line();
    let n = in_vec[0];
    let k = in_vec[1];

    let tmp = n % k;
    let res = min(tmp, k - tmp);

    println!("{}", res);
}



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

signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  rep(i,N)cin>>A[i];
  sort(begin(A),end(A));
  int I=0,ans=1e10+7;
  K-=1;
  while(K<=N-1){
    ans=min(A[K]-A[I],ans);
    K+=1;
    I+=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
N,M = map(int, input().strip().split(' '))
G = [[] for _ in range(N)]
for _ in range(M):
  a,b = map(int, input().strip().split(' '))
  a,b = a-1, b-1
  G[a].append(b)
  G[b].append(a)

for i in range(N):
  print(len(G[i]))


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 505;
const int MAX_A = 100005;
int N, K;
int A[MAX_N];
int sumA[MAX_N];

int sumB[MAX_N];
int sumC[MAX_N];

vector<int> v;

signed main()
{
  cin >> N >> K;
  REP(n,N) {
    cin >> A[n];
  }
  sort(A, A+N);

  REP(n,N) {
    sumA[n+1] = sumA[n] + A[n];
  }

  FOR(n,1,sqrt(sumA[N])+1) {
    if(sumA[N]%n == 0) {
      v.push_back(n);
      v.push_back(sumA[N]/n);
    }
  }
  sort(begin(v), end(v));

  int ans = 0;
  for(int a : v) {
    if(sumA[N] % a != 0) continue;
    vector<int> hoge;
    REP(n,N) {
      if(A[n]%a == 0) continue;
      hoge.push_back(A[n]%a);
    }
    sort(begin(hoge), end(hoge));
    memset(sumB, 0, sizeof(sumB));
    memset(sumC, 0, sizeof(sumC));
    REP(n,hoge.size()) {
      sumB[n+1] = sumB[n] + hoge[n];
      sumC[n+1] = sumC[n] + (a - hoge[n]);
    }
    REP(n,hoge.size()+1) {
      if(abs(sumB[n] - (sumC[hoge.size()] - sumC[n])) % a == 0) {
        if(sumB[n] <= K && sumC[hoge.size()] - sumC[n] <= K) ans = a;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
// 2020 04 26
// A
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#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 S, W;
    cin >> S >> W;
    if (W >= S) cout << "unsafe";
    else cout << "safe";
    cout << endl;
    


    return 0;
}

Measured memory_bytes: 3632
n,w=map(int,input().split())
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
	a,b=map(int,input().split())
	for j in range(w):
		if j+1-a>=0:
			dp[i+1][j+1]=max(dp[i][j+1],dp[i][j+1-a]+b)
		else:
			dp[i+1][j+1]=dp[i][j+1]
print(dp[-1][-1])


Measured memory_bytes: 171400
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int>vec;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    int zero=0,two=0,one=0;
    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        int z=0;
        while(a%2==0){
            a/=2;
            z++;
            if (z==2)
                break;
        }
        if (z==1)
            one++;
        if (z==2)
            two++;
        if (z==0)
            zero++;
    }

    int last=1;
    for (int i=0;;i++){
            int z=0;
        if (last==1&&zero){
            vec.push_back(1);
            zero--;
            last=0;
    z++;
        }
      else  if (last==0&&two){
            vec.push_back(4);
        two--;
        last=1;
        z++;
       }
        else if (one){
            vec.push_back(2);
            z++;
        }
        if (vec.size()==n)
            break;
            if (z==0){
                break;
            }
    }
    while(1){
        if (one)
            vec.push_back(2),one--;
        if (two)
            vec.push_back(4),two--;
        if (zero)
            vec.push_back(1),zero--;
        if (!one&&!zero&&!two)
            break;
    }
    for (int i=0;i<vec.size()-1;i++){
        if ((vec[i]*vec[i+1])%4!=0)
            return cout<<"No",0;
    }
    cout<<"Yes";
    return 0;

}


Measured memory_bytes: 1400
#include<stdio.h>
int main(void){
	int i,j,k,n,m,a,b,cost[100][100],time[100][100],p,q,r;
	scanf("%d%d",&n,&m);
	while(n!=0 || m!=0){
		for(i=0; i<m; i++){
			for(j=0; j<m; j++){
				cost[i][j]=(i==j)?0:100001;
				time[i][j]=(i==j)?0:100001;
			}
		}
		for(i=0; i<n; i++){
			scanf("%d%d",&a,&b);
			scanf("%d%d",&cost[a-1][b-1],&time[a-1][b-1]);
			cost[b-1][a-1]=cost[a-1][b-1];
			time[b-1][a-1]=time[a-1][b-1];
		}
		for(k=0; k<m; k++){
			for(i=0; i<m; i++){
				for(j=0; j<m; j++){
					cost[i][j]=(cost[i][j]>cost[i][k]+cost[k][j])?(cost[i][k]+cost[k][j]):cost[i][j];
					cost[j][i]=cost[i][j];
					time[i][j]=(time[i][j]>time[i][k]+time[k][j])?(time[i][k]+time[k][j]):time[i][j];
					time[j][i]=time[i][j];
				}
			}
		}
		scanf("%d",&k);
		for(i=0; i<k; i++){
			scanf("%d%d%d",&p,&q,&r);
			printf("%d\n",(r==0)?cost[p-1][q-1]:time[p-1][q-1]);
		}
		scanf("%d%d",&n,&m);
	}
	return 0;
}

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

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

  ll x = a[0];
  ll y = accumulate(a.begin() + 1, a.end(), 0ll);
  ll ans = abs(x - y);
  for (int i = 1; i < n - 1; i++) {
    x += a[i];
    y -= a[i];
    ans = min(ans, abs(x - y));
  }
  cout << ans << endl;
}


Measured memory_bytes: 4712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin>>S;
    int N=S.size();
    map<int,int> m;
    int x=S[N-1]-'0';
    m[0]++;
    m[x]++;
    int cou=10;
    for(int i=N-2;i>=0;i--){
        int y=S[i]-'0';
        y*=cou;
        y%=2019;
        x=x+y;
        x%=2019;
        m[x]++;
        cou*=10;
        cou%=2019;
    }
    int ans=0;
    for(auto p:m){
        ans+=(p.second*(p.second-1))/2;
    }
    cout << ans << endl;
    



}


Measured memory_bytes: 3712
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin –2147483648
#define llmax 9223372036854775807
#define llmin -9223372036854775808
using namespace std;

int n, a[100000];
ll cnt1, cnt2, s;
bool pm;

int main(){
	cin >> n;
	lp(n)
		cin >> a[i];
	
	s = cnt1 = 0;
	pm = true;
	lp(n) {
		s += a[i];
		if (pm) {
			if (s <= 0) {
				cnt1 += 1 - s;
				s = 1;
			}
			pm = false;
		}
		else {
			if (s >= 0) {
				cnt1 += s + 1;
				s = -1;
			}
			pm = true;
		}
	}
	s = cnt2 = 0;
	pm = false;
	lp(n) {
		s += a[i];
		if (pm) {
			if (s <= 0) {
				cnt2 += 1 - s;
				s = 1;
			}
			pm = false;
		}
		else {
			if (s >= 0) {
				cnt2 += s + 1;
				s = -1;
			}
			pm = true;
		}
	}
	cout << min(cnt1, cnt2) << endl;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
 
int main()
{
 
		int N;
		string a;
		cin >> N;
 
		for (int i = 0; i<N; i++) {
			cin >> a;
			if (a == "Y") {
				cout << "Four" << endl;
				break;
		
			}
			if(a!="Y"&&i<N-1)
			{
			continue;
			}
		cout<<"Three"<<endl;
		}
	
}

Measured memory_bytes: 256
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
//#define all(x , n) x+1,x+n+1
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;
using ld = long double;

//#define int ll

const int N = 1e4+54, mod = 1e9 + 7, mod1 = 998244353;
const int MAX = 1e5 + 11 , T = 2000;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const long double INF3 = 1e8 + 11;
const int base = 500;
const int P = 37;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const int LOG = 20;
const double EPS = 1e-4;
const double PI = acos(-1.0);

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
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; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>y01
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
                                  // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}
int query = 0;
ll bp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
///////////////////////////////////////////////////////////

void solve() {
    string s , t;
    cin >> s >> t;
    int cnt = 0;
    for(int i = 0; i < s.size(); i ++) {
        if(s[i] != t[i]) cnt ++;
    }
    cout << cnt;
}

/*
12 13 14


0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
5 6 7 8 9 10 11 12
+8
+8
+8 -9
+8 -9
+8 -9
+8 -9
+8 -9
+8 -9
+8 -9


*/

main() {
  //  file("A");
    ios;
    int tt = 1;
    if(query == 1)
        cin >> tt;
    if(query == 2)
        tt = INF1;
    while(tt --) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3804
import heapq

n = int(input())
M = [list(map(int,input().split())) for _ in range(n)]

q = []

visited = [False]*n

adjs = []
sum_cost = 0
node = 0
visited[node] = True
cnt = 1

while 1:
    for i in range(n):
        if M[node][i] != -1 and visited[i] == False:
            heapq.heappush(q, (M[node][i], i))
    while 1:
        mincost,node = heapq.heappop(q)
        if visited[node] == False:
            break
    sum_cost += mincost
    visited[node] = True
    cnt += 1
    if cnt == n:
        break


print(sum_cost)


    
    



Measured memory_bytes: 6212
import numpy as np
n,d=map(int,input().split())
lis=[[] for j in range(n)]
for i in range(n):
  lis[i]=list(map(int,input().split()))
ans=0
for a in range(n):
  for b in range(n-a-1):
    sum=0
    for c in range(d):
      sum+=(lis[a][c]-lis[a+b+1][c])**2
    if(np.sqrt(sum)%1==0):
      ans+=1
print(ans)

Measured memory_bytes: 12500
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int maxn=205;
struct node
{
    int x,y;
}red[maxn],blue[maxn];
int G[maxn][maxn],pre[maxn],n;
bool vis[maxn];
int num[maxn];

int findpath(int cur)
{
    for(int i=1;i<=2*n;i++)
    {
        if(!vis[i]&&G[cur][i])
        {
            vis[i]=true;
            if(pre[i]==0||findpath(pre[i]))
            {
                pre[i]=cur;
                return 1;
            }
        }
    }
    return 0;
}

int maxmatch()
{
    int res = 0;
    memset(pre,0,sizeof(pre));
    for(int i=1;i<=n;++i)
    {
        memset(vis,0,sizeof(vis));
        if(findpath(i))
            res++;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>red[i].x>>red[i].y;
    }
    for(int i=0;i<n;i++)
    {
        cin>>blue[i].x>>blue[i].y;
        for(int j=0;j<n;j++)
        {
            if(blue[i].x>red[j].x&&blue[i].y>red[j].y)
                G[j+1][i+n+1]=1;
        }
    }
    cout<<maxmatch()<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;


int main()
{
  int n;
  cin >> n;
  vector<lint> a(n);
  REP(i,n) cin >> a[i];
  vector<lint> b(n);
  REP(i,n) cin >> b[i];
  vector<lint> c(n);
  REP(i,n) cin >> c[i];

  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));
  lint cnt = 0;
  vector<lint> b_memo(n, 0);
  auto itr1 = upper_bound(ALL(b), a[0]);
  IFOR(j,distance(b.begin(), itr1),b.size()){
    auto itr2 = upper_bound(ALL(c), b[j]);
    b_memo[j] = distance(itr2, c.end());
    if(j != b.size()-1) b_memo[j] += b_memo[j+1];
  }
  REP(i,n){
    itr1 = upper_bound(ALL(b), a[i]);
    if(itr1 != b.end()) cnt += b_memo[distance(b.begin(), itr1)];
  }

  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3456
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 1844674407370955161
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define min_heap priority_queue<int, vector<int>, greater<int>>
#define max_heap priority_queue<int>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define pp pair<pair<ll,ll>,pair<ll,ll>>
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> 

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    if(a.ss < b.ss) return true; 
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.ff>b.ff) return true;
	else if(a.ff==b.ff) return a.ss<b.ss;
	else return false;
} 
bool sortff_resortss(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.ff<b.ff) return true;
	else if(a.ff==b.ff) return a.ss>b.ss;
	else return false;
}
bool sortbystring(const string &a, const string &b)
{
	string c=a+b;
	string d=b+a;
	if(c>=d) return true;
	else return false;
}

bool sortby(const pair<pair<int,int>,pair<int,int>> &a, const pair<pair<int,int>,pair<int,int>> &b)
{
	return a.ss.ss<b.ss.ss;
}

ll modi(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    { 
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
    return x; 
} 
ll Logn(ll  n, ll r) 
{ 
    return (n > r - 1) ? 1 + Logn(n / r, r) : 0; 
} 

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modinv(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 

int main()
{
	FAST
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9)
		{
			cout<<"hon";
		}
		else if(n%10==3)
		{
			cout<<"bon";
		}
		else
		{
			cout<<"pon";
		}
	}
	return 0;
}
















Measured memory_bytes: 3656
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let a = read_vec::<i64>();
    for i in k..n {
        if a[i - k] < a[i] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6564
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from collections import deque
# queueとして使う場合 push, popleftを使う
from bisect import bisect_left, bisect_right
# bisect_left: 配列の順序関係が崩れない条件で挿入することができる一番左の点
# bisect_right: 配列の順序関係が崩れない条件で挿入することができる一番右の点
# A = [1, 1, 1, 2, 2, 2, 4]
# print(bisect_left(A, 2))  # 3
# print(bisect_right(A, 2))  # 6
# print(bisect_left(A, 3))  # 6
# print(bisect_right(A, 3))  # 6


def main():
    A, B, C, X, Y = map(int,input().split())
    max_C_num = 2 * max(X, Y)
    left_x = X
    left_y = Y
    min_price = 10 ** 10
    for c in range(0, max_C_num + 1, 2):
        left_x = X - c // 2
        left_y = Y - c // 2
        price = C * c
        if price > min_price:
            continue
        if left_x > 0:
            price += A * left_x
        if left_y > 0:
            price += B * left_y
        min_price = min(price, min_price)
    print(min_price)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21668
import math
a, b, x = map(int, input().split())
tank1 = ((2 * b / a)  - (2 * x / (a ** 3)))
tank2 = a * (b ** 2) / (2 * x)
if x >= a * a * b / 2:
    print(math.degrees(math.atan(tank1)))
else:
    print(math.degrees(math.atan(tank2)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  int K, S;
  cin >> K >> S;

  int ans = 0;
  repp(x, 0, K) {
    repp(y, 0, K) {
      int res = S - x - y;
      if (0 <= res && res <= K)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9;
const ll mod = 1e9 + 7;



int main() {
	int a, b;
	cin >> a >> b;
	if (a > b * 2) cout << a - b * 2 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define loop(i,j,n) for(i=j;i<n;i++)
#define rloop(i,j,n) for(i=n;i>=j;i--)
#define INF 2147483647
#define ll long long
#define pii pair<int,int>
#define eps 1e-9
#define mii map<int,int>
#define vi vector<int>
#define all(n) n.begin(),n.end()
#define inf INF
#define INFLL 9223372036854775807
using namespace std;
string s;
int main()
{
    int n,m,cnt=0,i,j,k,tc,t;

    cin>>s;
    n=s.length();
    ll ans=0;
    cnt=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='W')ans+=(ll)(i-cnt ),cnt++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3748
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

# uf = UnionFind(要素数)   で使用
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n     # 各要素の親要素の番号を格納するリスト 要素が根の場合は-(グループの要素数)を格納
    def find(self, x):              # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):          # 要素xが属するグループと、要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):              # 要素xが属するグループのサイズ(要素数)を返す
        return -self.parents[self.find(x)]
    def same(self, x, y):           # 要素xと要素yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)
    def members(self, x):           # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):                # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):          # グループの数を返す
        return len(self.roots())
    def all_group_members(self):    # {ルート要素: [そのグループに含まれる要素のリスト], ...} の辞書を返す
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N + 1)
    for i in range(M):
        uf.union(A[i], B[i])

    ans = 0
    for i in range(1, N + 1):
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
void solve()
{
  int n;
  cin>>n;
  int a[n];
  rep(i,n)
  {
    cin>>a[i];
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  repA(i,2,n)
  {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<dp[n-1];
}
int main()
{
  fastio;
  //fopen();
  int t;
  //cin>>t;
  rep(i,1)
  { 
    //cout<<"Case #"<<i+1<<": ";
    solve();
    cout<<endl;
  }
  
}

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int n;
    string s;
    map <char,int> m;
    ll sum = 0;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>n >>s;
    for (int i=0; i<n; i++) {
        m[s[i]]++;
        if (s[i] == 'G')
            sum += m['R'] * m['B'];
        else if (s[i] == 'B')
            sum += m['G'] * m['R'];
        else
            sum += m['G'] * m['B'];
    }
    for (int j=1; j<=min(2000,n); j++) {
        for (int i=0; i+j+j<n; i++) {
            if (s[i] != s[i+j] && s[i+j] != s[i+j+j] && s[i] != s[i+j+j])
                sum--;
        }
    }
    cout <<sum;



    return 0;
}


Measured memory_bytes: 3664
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
// 必要な変数に定義する
input = input.split('\n');
let info = input.shift();
let V = input[0].split(' ').map(x=>x*1);
let C = input[1].split(' ').map(x=>x*1);
let ans = 0;
for(let i = 0; i < info; i++){
  if(V[i] > C[i]){
  	ans += V[i] - C[i]
  }
}

console.log(ans);

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

int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<long long> A(X);
    for (int i = 0; i < X; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<long long> B(Y);
    for (int i = 0; i < Y; i++)
    {
        cin >> B[i];
    }
    sort(B.begin(), B.end());

    vector<long long> C(Z);
    for (int i = 0; i < Z; i++)
    {
        cin >> C[i];
    }
    sort(C.begin(), C.end());

    vector<int> num{X, Y, Z};
    vector<vector<long long>> cake{A, B, C};
    vector<vector<vector<bool>>> used(X, vector<vector<bool>>(Y, vector<bool>(Z, false)));

    priority_queue<pair<long long, vector<int>>> que;
    que.push(make_pair(
        A.back() + B.back() + C.back(),
        vector<int>{X - 1, Y - 1, Z - 1}));
    for (int i = 0; i < K; i++)
    {
        int x = que.top().second[0];
        int y = que.top().second[1];
        int z = que.top().second[2];

        if (used[x][y][z])
        {
            que.pop();
            i--;
            continue;
        }
        else
        {
            used[x][y][z] = true;
        }

        long long cost = que.top().first;
        for (int j = 0; j < 3; j++)
        {
            vector<int> idx{x, y, z};
            if (idx[j] > 0)
            {
                idx[j]--;
                que.push(make_pair(
                    cost + cake[j][idx[j]] - cake[j][idx[j] + 1],
                    idx));
            }
        }
        cout << que.top().first << endl;
        que.pop();
    }
}


Measured memory_bytes: 180480
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cfloat>
#include <cmath>
#include <functional>
#include <forward_list>
#include <list>


#define DEBUG(x) cout << #x << "\t:" << x << endl;
#define EPS (1e-9)
#define INF (INT_MAX/3)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPV(it,v) for(auto it = (v).begin(); it != (v).end(); ++it)

#define ll long long
#define ull unsigned long long


using namespace std;

class Main {
public:
	bool getAns(int a, int b, int c) {
		return c >= a && c <= b;
	}
};

int main(void) {
	Main main;
	int a, b, c;
	cin >> a >> b >> c;
	cout << (main.getAns(a, b, c) ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int q = in.nextInt();
        int[] a = new int[q];
        for(int i=0; i<q; i++) {
            a[i] = in.nextInt();
        }
        int[] b = new int[n];
        for(int i=0; i<n; i++) {
            b[i] = 0;
        }
        for(int i=0; i<q; i++) {
            int winner = a[i]-1;
            b[winner]+=1;
        }
        for(int i=0; i<n; i++) {
            System.out.println(b[i]+k-q>0 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 59192