akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int N;
vi c;
vi s;
vi f;

void solve(int t, int st){
    if(st == N - 1){
        cout << t << endl;
        return;
    }
    if(t < s[st]){
        t = s[st];
    }else{
        int tmp = s[st];
        while(true){
            tmp = tmp + f[st];
            if(tmp >= t){
                t = tmp;
                break;
            }
        }
    }
    solve(t + c[st], st + 1);
}

int main(){
    ios::sync_with_stdio(false);

    cin >> N;
    int ci, si, fi;
    rep(i, N - 1){
        cin >> ci >> si >> fi;
        c.push_back(ci);
        s.push_back(si);
        f.push_back(fi);
    }
    rep(i, N){
        solve(0, i);
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
namespace std

{
    class Test 
    {
        static void Main(string[] args) {
            
            List<int> ary_num = new List<int>();
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            
            for (int i = 0; i< n; i++) {
                var inp = int.Parse(input[i]);
                ary_num.Add(inp);
            }
           
            Test obj = new Test();
            obj. Serach(ary_num, n);
           
           
          
        }
        
        public void Serach(List<int> ary_num, int num) {
          int min = ary_num[0];
          int max = ary_num[0];
          long sum = ary_num[0];
           
            for (int i = 1; i < num; i++) {
                if (min > ary_num[i]) min = ary_num[i]; 
               
                if (max < ary_num[i]) max = ary_num[i]; 
                
                sum += ary_num[i];
            }
            Console.WriteLine(min + " " + max + " " + sum);
            
        }
    }
}


Measured memory_bytes: 17960
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    N, M = LI()

    A = SR(N)
    B = SR(N)

    ans = 0

    for i in range(N):
        for j in range(M):
            if A[i][j] != B[i][j]:
                ans += 1
    print(ans)
    return


if __name__ == "__main__":
    solve()



Measured memory_bytes: 70992
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int f(int x) {
		x = Math.abs(x);
		return Math.max(x - 1, 0);
	}
	
	void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[2 * n - 1];
		for (int i = 0; i < 2 * n - 1; i++) {
			a[i] = nextInt();
		}
		Arrays.sort(a);
		int[][] dp = {{}, {1} };
		for (int i = 1; i < n; i++) {
			int addL = a[n - i] != a[n - 1 - i] ? 1 : 0;
			int addR = a[n - 1 + i] != a[n - 2 + i] ? 1 : 0;
			
			int[][] nxt = new int[2 * i + 2][2 * i + 2];
			for (int cnt = 1; cnt <= 2 * i - 1; cnt++) {
				for (int place = 0; place < cnt; place++) {
					
					int realCnt = cnt + addL + addR;
					int realPlace = place + addL;
					
					for (int toPlace = 0; toPlace < realCnt; toPlace++) {
						int newCnt = realCnt - f(toPlace - realPlace);
						int newPlace = toPlace <= realPlace ? toPlace : realPlace + 1;
						
						nxt[newCnt][newPlace] += dp[cnt][place];
						if (nxt[newCnt][newPlace] >= P) {
							nxt[newCnt][newPlace] -= P;
						}
					}
					
				}
			}
			dp = nxt;
		}
		
		long ret = 0;
		for (int[] row : dp) {
			for (int val : row) {
				ret += val;
			}
		}
		
		out.println(ret % P);
	}
	
	static final int P = 1_000_000_007;

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 23620
#include<iostream>
#include<queue>
using namespace std;
static const int N=100;
static const int infty=(1<<21);

int n,m[N][N];
int d[N];

void bfs(int s)
{
  queue<int> q;
  q.push(s);
  for(int i=0;i<n;i++) d[i]=infty;
  d[s]=0;
  int u;

  while(!q.empty())
  {
    u=q.front(); q.pop();
    for(int v=0;v<n;v++)
    {
      if(m[u][v]==0) continue;
      if(d[v]!=infty) continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int i=0;i<n;i++)
  {
    cout<<i+1<<" "<<((d[i]==infty)?(-1):d[i]) <<endl;
  }
}

int main()
{
  //入力
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++)
  for(int j=0;j<n;j++) m[i][j]=0;

  for(int i=0;i<n;i++)
  {
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++)
    {
      cin>>v;
      v--;
      m[u][v]=1;
    }
  }

  bfs(0);

}


Measured memory_bytes: 3152
from sys import stdin

def main():
    n=int(input())
    As=list(map(int, stdin.readline().split()))
    As.sort()
    check=[0]*(10**6+10)
    for a in As:
        count=1
        while a*count < 10**6+2 and a*count < As[-1]+1:
            if check[a*count]<2:
                check[a*count]+=1
            count+=1
    ans=0
    for a in As:
        if check[a]==1:
            ans+=1
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  int64_t N,M;
  cin>>N>>M;
  int64_t answer=1;
  int maxdel=0;
  vector<int> a(N+2),del(N+2);
  vector<int64_t> fib(N+2);
  a[M+1]=N+1;
  a[0]=-1;
  for(int i=1;i<=M+1;i++){
    if(i!=M+1)
      cin>>a[i];
    del[i-1]=a[i]-a[i-1]-2;
    maxdel=max(del[i-1],maxdel);
  }
  for(int i=0;i<maxdel+2;i++){
    if(i==0||i==1)
      fib[i]=1;
    else{
      fib[i]=fib[i-1]+fib[i-2];
      fib[i]=fib[i]%1000000007;
    }
  }
  for(int i=0;i<=M;i++){
    if(del[i]<0&&i!=0){
      answer=0;
      break;
    }
    else{
      answer*=fib[del[i]];
      /*cout<<del[i]<<fib[del[i]]<<endl;*/
      answer=answer%1000000007;
    }
  }
  //cout<<maxdel<<endl;
  cout<<answer;
}

Measured memory_bytes: 1792
// 2020-08-11 17:54:56
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<P> L, R; // score, k
  auto f = [](vector<P>& vec) {
    ll res = 0, sz = vec.size();
    vector<vector<ll> > mp(sz+1);
    for(const auto& p : vec) {
      mp[min(p.second, sz)].push_back(p.first);
    }
    multiset<ll> s;
    REPCM(k, sz, 1) {
      for(auto score : mp[k]) s.insert(score);
      if(!s.empty()) {
        res += *s.rbegin();
        s.erase(prev(s.end()));
      }
    }
    return res;
  };
  rep(i, n) {
    ll k, l, r;
    cin >> k >> l >> r;
    if(l == r) {
      ans += l;
    } else if(l > r) {
      ans += r;
      L.emplace_back(P(l-r, k));
    } else {
      ans += l;
      R.emplace_back(P(r-l, n-k));
    }
  }
  ans += f(L);
  ans += f(R);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  cin >> t;
  rep(ti, t) answer();
  return 0;
}

Measured memory_bytes: 13916
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
using namespace std;

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

int main() {
	int n, m;
	cin >> n;
	vector<string> s(n);
	rep(i, 0, n) {
		cin >> s[i];
	}
	cin >> m;
	vector<string> t(m);
	rep(i, 0, m) {
		cin >> t[i];
	}

	int ans = 0;
	rep(i, 0, n) {
		string a = s[i];
		int x = 0, y = 0;
		rep(j, 0, n) {
			if (a == s[j]) {
				x++;
			}
		}
		rep(j, 0, m) {
			if (a == t[j]) {
				y++;
			}
		}
		ans = max(ans, x - y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

ll sa(ll a, ll b, ll c) {
  ll ma = max(max(a, b), c);
  ll mi = min(min(a, b), c);
  return ma - mi;
}

ll solv(ll H, ll W) {
  ll res = INF;
  rep(i, H) {
    if (i == 0) {
      continue;
    }

    ll Sa = i * W;

    // 縦に割るパターン
    ll Sb = (H - i) * (W / 2);
    ll Sc = H * W - Sa - Sb;
    res = min(res, sa(Sa, Sb, Sc));

    // 横に割るパターン
    ll Sb2 = ((H - i) / 2) * W;
    ll Sc2 = H * W - Sa - Sb2;
    res = min(res, sa(Sa, Sb2, Sc2));
  }
  return res;
}

signed main() {
  init();
  ll H, W;
  cin >> H >> W;
  if (H % 3 == 0 || W % 3 == 0) {
    COUT(0);
    return 0;
  }

  ll ans1 = solv(H, W);
  ll ans2 = solv(W, H);
  ll ans = min(ans1, ans2);
  COUT(ans);

  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  int e;
  while(cin >> e and e){
    int res = INF;
    REP(i, 105){
      int ne = e;
      if(pow(i, 3) > ne) break;
      ne -= pow(i, 3);
      REP(j, 1005){
        int nne = ne;
        if(pow(j, 2) > nne) break;
        nne -= pow(j, 2);
        res = min(i + j + nne, res);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3244
n = int(input())
a = [0] * 60001

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      i = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
      a[i] += 1

print('\n'.join(map(str, a[1:n + 1])))

Measured memory_bytes: 10044
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> build_fail(const string &s){
  vector<int> fail(s.size()+1);
  int j = fail[0] = -1;
  for(int i=1;i<=(int)s.size();i++){
    while(j>=0&&s[j]!=s[i-1])j=fail[j];
    fail[i]=++j;
  }
  return fail;
}
string w;
int main() {
  cin >> w;
  vector<int> fail_w = build_fail(w);
  if(w == string(w.size(), w[0])) {
    cout << w.size() << endl;
    cout << 1 << endl;
    return 0;
  }
  string rev_w = w;
  reverse(rev_w.begin(), rev_w.end());
  vector<int> fail_rev_w = build_fail(rev_w);
  if(w.size() - fail_w[w.size()] == w.size() || w.size() % (w.size() - fail_w[w.size()]) != 0) {
    cout << 1 << endl;
    cout << 1 << endl;
  }else{
    cout << 2 << endl;
    int answer = 0;
    for(int i = 1; i < w.size(); i++) {
      int revi = w.size() - i;
      if(i - fail_w[i] == i || i % (i - fail_w[i]) != 0) {
        if(revi - fail_rev_w[revi] == revi || revi % (revi - fail_rev_w[revi]) != 0) {
          answer++;
        }
      }
    }
    cout << answer << endl;
  }
}


Measured memory_bytes: 5136
s=input()

A=set()
for i in range(10**6+10):

	if i==0:
		pass
	else:
		if s%2==0:
			s/=2
		else:
			s=3*s+1
	if s in A:
		print i+1
		quit()
	else:
		A.add(s)

Measured memory_bytes: 27884
inp=list(map(int,input().split()))
b=list(map(int,input().split()))
n=inp[0]
m=inp[1]
c=inp[2]
wa=0
seikai=0
for i in range(n):
  retu= list(map(int,input().split()))
  for j in range(m):
    kake=retu[j]*b[j]
    wa=wa+kake
  if wa+c>0:
    seikai=seikai+1
  wa=0
print(seikai)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
double N,blank = -1;
double arr[5];
int cnt[5]={0};
double dp[302][302][302];
double call(){
	int i,j=0;
	if(cnt[0]==N)	return 0;
	if(dp[cnt[1]][cnt[2]][cnt[3]]!=blank)
		return dp[cnt[1]][cnt[2]][cnt[3]];

	double p =cnt[0];
	double d = N/(N-p);
	for(i=1;i<=3;i++){
		if(cnt[i]==0)
			continue;
		cnt[i]-=1;
		cnt[i-1]+=1;
		j++;
		d+=call()*(cnt[i]+1)/(N-p);
		cnt[i]+=1;
		cnt[i-1]-=1;
	}
	return dp[cnt[1]][cnt[2]][cnt[3]]=d;
}

int main()
{
	
	cin>>N;
	int n;
	for(int i=0;i<=300;i++)
		for(int j=0;j<=300;j++)
			for(int k=0;k<=300;k++)
				dp[i][j][k]= -1;

	for(int i=0;i<N;i++){
		cin>>n;
		cnt[n]+=1;
	}
	cout<<setprecision(12) << call();
	return 0;
}

Measured memory_bytes: 218280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  200005

ll n,m;
vi adj[N];
bool vis[N];
ll c=0;
void dfs(ll n)
{
    vis[n]=1;
    c++;
    for(auto u:adj[n])
    {
        if(!vis[u])
        {
            dfs(u);
        }
    }
}
void solve()
{
    cin>>n>>m;
    rep(i,0,m)
    {
        ll x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    ll ans=0;
    rep(i,1,n+1)
    {
        if(!vis[i])
        {
            c=0;
            dfs(i);
            ans=max(ans,c);
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

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

int main()
{
    // 整数の入力
    long long total,i,N,minVal,temp;
    cin >> N;
    total = 0;
    minVal = 101;
    for (i=0;i<N;i++){
        cin >> temp;
        total += temp;
        if (temp % 10 != 0 && temp < minVal ){
            minVal = temp;
        }
    }
    if (total % 10 == 0){
        if (minVal == 101){
            cout << 0 << endl;
        }else{
            cout << total - minVal << endl;
        }
    }else{
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.server.ExportException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main m = new Main();
        m.solve();
    }
    private void solve() throws Exception {
        FastScan scan = new FastScan(System.in);
        int N = scan.scanInt();
        List<List<Path>> graph = new ArrayList(N);
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < N - 1; i++) {
            int a = scan.scanInt()-1;
            int b = scan.scanInt()-1;
            long c = scan.scanLong();
            graph.get(a).add(new Path(b, c));
            graph.get(b).add(new Path(a, c));
        }
        int Q = scan.scanInt();
        int K = scan.scanInt()-1;
        Queue<Integer> queue = new ArrayDeque<>();
        long[] distances = new long[N];
        boolean[] visited = new boolean[N];
        Arrays.fill(distances, Long.MAX_VALUE);
        distances[K] = 0;
        queue.add(K);
        while(!queue.isEmpty()) {
            int current = queue.poll();
            visited[current] = true;
            for (Path p : graph.get(current)) {
                if (visited[p.to]) {
                    continue;
                }
                distances[p.to] = distances[current] + p.cost;
                queue.add(p.to);
            }
        }
        for (int i = 0; i < Q; i++) {
            int from = scan.scanInt() - 1;
            int to = scan.scanInt() - 1;
            System.out.println(distances[from] + distances[to]);
        }
    }

    class Path {
        int to;
        long cost;
        Path(int to, long cost) {
            this.to = to;
            this.cost = cost;
        }
    }
    class FastScan {
        BufferedReader br;
        StringTokenizer st;
        FastScan(InputStream is) {
            InputStreamReader isr = new InputStreamReader(is);
            this.br = new BufferedReader(isr);
        }
        String next() throws IOException {
            while (this.st == null || !this.st.hasMoreTokens()) {
                this.st = new StringTokenizer(br.readLine().trim());
            }
            return st.nextToken();
        }
        long scanLong() throws IOException {
            return Long.parseLong(this.next());
        }
        int scanInt() throws IOException {
            return Integer.parseInt(this.next());
        }
        double scanDouble() throws IOException {
            return Double.parseDouble(this.next());
        }
        char scanCharacter() throws IOException {
            return this.next().charAt(0);
        }
        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 84084
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            Console.WriteLine(int.Parse(str[0])+int.Parse(str[1])/2);
        }
    }
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

ll gcd(ll x, ll y) {
  while (x) {
    y %= x;
    swap(x, y);
  }
  return y;
}

int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int t;
  cin >> t;
  while (t--) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (b > d || a < b) {
      cout << "No\n";
      continue;
    }

    //if (c >= b) {
      //cout << "Yes\n";
      //continue;
    //}

    ll g = gcd(b, d);
    ll r = a % g;

    ll up = (b - 1 - r) / g;
    ll down = (c + 1 <= r ? 0 : (1 + c - r + g - 1) / g);

    if (down <= up) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
    }
  }
}



Measured memory_bytes: 256
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
M = int(input())
UV = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for i in range(N)]
for i,(a,b) in enumerate(AB):
    a,b = a-1,b-1
    es[a].append((b,i))
    es[b].append((a,i))

paths = [0] * M
for i,(u,v) in enumerate(UV):
    u,v = u-1,v-1
    stack = [u]
    visited = [0] * N
    visited[u] = 1
    edges = [-1] * N
    while stack:
        s = stack.pop()
        for to,j in es[s]:
            if visited[to]: continue
            visited[to] = 1
            edges[to] = j
            stack.append(to)
            if to == v:
                break
        else:
            continue
        while edges[v] >= 0:
            j = edges[v]
            paths[i] |= (1<<j)
            a,b = AB[j]
            a,b = a-1,b-1
            v = a if a!=v else b
        break

dp = [0] * (1<<M)
for b in range(1,1<<M):
    k = len(bin(b))-3
    dp[b] = dp[b-2**k] | paths[k]

ans = 0
for i,d in enumerate(dp):
    b = N-1 - bin(d).count('1')
    ans += 2**b if bin(i).count('1')%2==0 else -2**b
print(ans)

Measured memory_bytes: 46568
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int main(void){
  int n, r;
  scanf("%d%d", &n, &r);
  printf("%d\n", n>=10?r:r+100*(10-n));
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

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

	int dp[19];
	dp[0] = 0;
	string s;
	cin >> s;
	int n = s.length();
	set<char> sc = { 'A', 'G', 'C', 'T' };
	for (int i = 0; i < n; i++) {
		if (sc.find(s[i]) == sc.end()) {
			dp[i] = 0;
		}
		else {
			if (i - 1 < 0) dp[i] = 1;
			else dp[i] = dp[i - 1] + 1;
		}
	}
	int ret = 0;
	for (int i = 0; i < n; i++) {
		ret = max(ret, dp[i]);
	}
	cout << ret << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    n %= 1000;
    if(n == 0) print(0);
    else print(1000 - n);

}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
ld eps=1e-9;

#define Seg_Max_N (1<<18) 
using Value = long long int ;
Value dat[2 * Seg_Max_N];
struct segtree {
	int N;
	const Value ini = 0;
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = max(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return max(al, ar);
	}
};
int main() {
	long long int N; cin >> N;
	vector<long long int>hs;
	vector<long long int>dps;
	segtree seg(N);
	for (size_t i = 0; i < N; i++)
	{
		int a; cin >> a; a--; hs.emplace_back(a);
	}
	for (size_t i = 0; i < N; i++)
	{
		long long int next = seg.query(0, hs[i]);
		seg.update(hs[i], next + hs[i] + 1);
	}
	long long int ans =N*(N+1)/2- seg.query(0, N);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5912
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}


int main() {
    ll n;
    cin>>n;
    vector<ll> v(n),m(n+1,0);
    rep(i, n) {
        ll tmp;
        cin>>tmp;
        if (m[tmp - 1]==0) {
            m[tmp]=1;
        }else m[tmp]=m[tmp-1]+1;
    };
    pr(n - *max_element(m.begin(), m.end()));
    
}



Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
		try {
      		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int count = 0;
      		String s = br.readLine();
      		String t = br.readLine();
      		for(int i=0; i<3; i++) {
          		if(s.charAt(i) == t.charAt(i)) {
              		count++;
				}
			}
			System.out.println(count);
        } catch(Exception e) {
          System.out.println(e);
        }
	}
}

Measured memory_bytes: 23252
Vertex = Struct.new(:id, :adj_list, :distance) do
	def to_s
		"#{id} #{distance || -1}"
	end
end

def bfs!(vertexes, distance)
	next_list = vertexes.select{ |v| v.distance.nil? }.inject([]) do |result, v| 
		v.distance = distance
		v.adj_list.select{ |v| v.distance.nil? }.inject(result) { |r, adj| r << adj }
	end

	bfs!(next_list, distance + 1) unless next_list.empty?
end

n = STDIN.gets.to_i
vertex_list = Array.new(n) { |i| Vertex.new(i + 1) }
n.times do
	vertex_no, degree, *adj_list = STDIN.gets.split.map(&:to_i)

	vertex = vertex_list[vertex_no - 1]
	vertex.adj_list = adj_list[0...degree].map! { |adj| vertex_list[adj - 1] }
end

bfs!([vertex_list[0]], 0)
vertex_list.each { |v| puts v }

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

int main() {
    int X,Y;
    cin >> X>> Y;
    int ans;
    ans = 0;
    if( X==1 ){
        ans += 300000;
    }
    else if( X==2 ){
        ans += 200000;
    }
    else if( X==3 ){
        ans += 100000;
    }
    else{

    }
    if( Y==1 ){
        ans += 300000;
    }
    else if( Y==2 ){
        ans += 200000;
    }
    else if( Y==3 ){
        ans += 100000;
    }
    else{

    }
    if( X==1 && Y==1 ){
        ans += 400000;
    }
    else{
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	//string S,T,U[52];
	ll count = 10;
	ll count2 = 0;
	float sum = 0;
	float min = 1000000;
	ll max = 0;
	float smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	
	cin >> N;
	cin >> T >> A;

	rep(i, 0, N) {
		cin >> h[i];
	}

	rep(i, 0, N) {
		
		sum = T - h[i] * 0.006;

		//cout << sum << endl;

		smax = abs(A - sum);

		//cout << smax << endl;

		if (min >= smax) {
			count = i+1;
			min = smax;
		}

	}
	
	cout << count << endl;
	
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {
	
	int a, b, c;

	cin >> a >> b >> c;

	if (c >= a && c <= b) {
		Yes;
	}
	else {
		No;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
// all ways to form pairs so that p[0] paired with p[n-1], p[1] with p[n-1], ...
void paired_permutations(int n, const function<void(vector<int>& p)>& f) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    function<void(int)> rb = [&](int i) {
        if(i == n / 2) {
            f(p);
        } else {
            for(int j = i + 1; j < n - i; j++) {
                swap(p[j], p[n - 1 - i]);
                rb(i + 1);
                swap(p[j], p[n - 1 - i]);
            }
        }
    };
    if(n % 2) {
        for(int i = 0; i < n; i++) {
            swap(p[i], p[n / 2]);
            rb(0);
            swap(p[i], p[n / 2]);
        }
    } else {
        rb(0);
    }
}
bool is_palindrome(const string& s) {
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w;
    cin >> h >> w;
    #define H 12
    static string s[H];
    for(int i = 0; i < h; i++) {
        cin >> s[i];
    }
    bool can = false;
    paired_permutations(w, [&](vector<int>& p) {
        multiset<string> x;
        for(int i = 0; i < h; i++) {
            string cur = "";
            for(int j = 0; j < w; j++) {
                cur += s[i][p[j]];
            }
            reverse(cur.begin(), cur.end());
            if(x.count(cur)) {
                x.erase(x.find(cur));
            } else {
                reverse(cur.begin(), cur.end());
                x.insert(cur);
            }
        }
        can |= h % 2 ? x.size() == 1 and is_palindrome(*x.begin()) : x.empty();
    });
    cout << (can ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  ll n, k; cin >> n >> k;
  vector<int> bit(50);
  rep(i, n) {
    ll a; cin >> a;
    for(int i=0; i<50; i++) {
      ll s = 1LL<<i;
      if (a & s) {
        bit[i]++;
      }
    }
  }

  vector<ll> diff(50);

  ll ret = 0;
  rep(j, 50) {
    ll ans = 0;
    ll sum = 0;
    for(int i=49; i>=0; i--) {
      ll s = 1LL<<i;
      if (bit[i] >= n-bit[i]) {
        ans += bit[i]*s;
      } else {
        if (sum + s <= k && (i != j)) {
          ans += (n-bit[i])*s;
          sum += s;
        } else {
          ans += bit[i]*s;
        }
      }
    }
    chmax(ret, ans);
  }

  cout << ret << endl;
}

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

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


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


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


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

dp = None


def main():
    N, T = li_input()
    A = li_input()

    cmin = A[0]
    ans = 0
    maxp = -1

    for i in range(1, len(A)):
        if A[i] < cmin:
            cmin = A[i]
            continue

        if A[i] - cmin > maxp:
            ans = 1
            maxp = A[i] - cmin
        elif A[i] - cmin == maxp:
            ans += 1

    print(ans)


main()


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

vector<int> make_div(int n){
    vector<int> res;
    for(int i = 1; i < sqrt(n)+1; ++i){
        if (n%i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n/i);
        }
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    vector<int> A;
    A.resize(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    int ans = 0;
    for (int i = 0; i < N; ++i){
        int flag = false;
        auto left = lower_bound(A.begin(), A.end(), A[i]); 
        auto rihgt = upper_bound(A.begin(), A.end(), A[i]);
        if (rihgt - left > 1) continue;

        auto divs = make_div(A[i]);
        for (int j = 0; j < divs.size(); ++j){
            if (binary_search(A.begin(), A.end(), divs[j]) && divs[j] != A[i]){
                flag = true;
                break;
            }
        }
        if (flag == false) {
            ans++;
            //cout << A[i] << endl;
        }

    }
    cout << ans << endl;


}

using namespace std;

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    int f=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i])b[f++]=a[i];
    }
    sort(b,b+f);
    if(f<=k)printf("%d",0);
    else
    {
        int num=0;
        for(int i=0; i<f-k; i++)
            num+=b[i];
        printf("%d",num);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;

int main()
{
  ll n, sum = 0;
  cin >> n;
  vector<ll> a(n + 1), b(n);

  REP(i, n + 1)
  {
    cin >> a[i];
  }
  REP(i, n)
  {
    cin >> b[i];
  }
  REP(i, n)
  {
    if (a[i] >= b[i])
    {
      sum += b[i];
    }
    else
    {
      sum += a[i];
      b[i] -= a[i];
      if (a[i + 1] >= b[i])
      {
        sum += b[i];
        a[i + 1] -= b[i];
      }
      else
      {
        sum += a[i + 1];
        a[i + 1] = 0;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 4776
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
int main(){
  string s;
  cin >> s;
  long long a = 0, b = 0, w = 0;
  for(auto c : s) if(c == 'B') b++;
  else if(c == 'W') a += b;
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x*2<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll a[n];
    ll x=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2==0)x+=a[i];
        else x-=a[i];
    }
    vi ans(n);
    ans[0]=x/2;
    for(int i=1;i<n;i++){
        ans[i]=a[i-1]-ans[i-1];
    }
    print(ans);
}


Measured memory_bytes: 4736
import copy
import math
import time
import statistics
import math
import itertools
import bisect
from decimal import *

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():

    start = time.time()

    #n, q = get_int_multi()
    n = get_int()

    a = get_int_list()
    a.sort()

    ans = 0
    for i in range(n):
        for ii in range(i+1,n):
            if a[i] == a[ii]:
                continue
            for iii in range(ii+1,n):
                if a[ii] == a[iii]:
                    continue
                if a[i] + a[ii] > a[iii]:
                    ans += 1

    print(ans)



if __name__ == '__main__':
    main()




Measured memory_bytes: 11088
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <valarray>
#include <list>
#include <cstring>

using namespace std;

typedef long long ll;

template <int SIZE>
struct UnionFind {
    int i2g[SIZE];
    std::vector<int> g2i[SIZE];
    inline void init() {
        for (int i = 0; i < SIZE; ++i) {
            i2g[i] = i;
            g2i[i].assign(1, i);
        }
    }
 
    inline void merge(int ia, int ib) {
        if (is_same_group(ia, ib)) return;
        if (g2i[i2g[ia]].size() < g2i[i2g[ib]].size()) swap(ia, ib);
        int ga = i2g[ia], gb = i2g[ib];
        for (int j : g2i[gb]) i2g[j] = ga;
        g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());
        g2i[gb].clear();
    }
 
    inline bool is_same_group(int ia, int ib) {
        return i2g[ia] == i2g[ib];
    }
};

const int MN = 1010;
UnionFind<MN> uf;
int n;
int me, ne;
vector<int> v;

bool solve() {
    int tw = 1-(me-ne)%2;
    if (n % 2) {
        return tw == 0;
    }
    int evn = 0;
    int ze = 0;
    for (int d: v) {
        if (d % 2 == 0) {
            evn++;
        }
        ze += d*(d-1)/2;
    }
    ze -= ne;
    if (evn == 0) return ze % 2;
    if (evn == 1) return 1;
    return 1-tw;
}

int main() {
    uf.init();
    cin >> n;
    me = n*(n-1)/2;

    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < n; j++) {
            if (s[j] == 'Y') {
                ne++;
                uf.merge(i, j);
            }
        }
    }
    ne /= 2;
    for (int i = 0; i < n; i++) {
        int c = uf.g2i[i].size();
        if (c) {
            v.push_back(c);
        }
    }
    if (solve()) {
        printf("Taro\n");
    } else {
        printf("Hanako\n");
    }
    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define PER(i,n) for (int i=(N-1);i>=0;--i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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 int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int g[100][100]; // 白：０、黒：１

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

    REP(i, 50) REP(j, 100) g[i][j] = 1;

    REP(k, A - 1) {
        int i = 2*(k / 50);
        int j = 2*(k % 50);
        g[i][j] = 0;
    }

    REP(k, B - 1) {
        int i = 99 - 2*(k / 50);
        int j = 2*(k % 50);
        g[i][j] = 1;
    }

    cout << 100 << " " << 100 << endl;
    REP(i, 100) {
        REP(j, 100) cout << (g[i][j] == 0 ? "." : "#");
        cout << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
x = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
y = []
for i in range(len(s)):
    for j in range(len(x)):
        if s[i] == x[j]:
            y.append(x[(j+n)%26])
ans = ''.join(y)
print(ans)


Measured memory_bytes: 3188