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

using namespace std;

#undef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool x) { return (x ? "T" : "F"); }
string to_string(const char* s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename V>
string to_string(V v) {
    bool f = true; string res = "[";
    for (const auto& x: v) {
        if (!f) res += ", ";
        f = false;
        res += to_string(x); } res += "]";
    return res;
}
void debug() { cerr << endl; }
template <typename H, typename... T>
void debug(H h, T... t) { cerr << " " << to_string(h); debug(t...); }
#ifdef LOCAL
#define dbg(args...) cerr<<"("<<#args<<") =", debug(args)
#else
#define dbg(args...) 2019
#endif

using ll=long long ;
void solve() {
    int n; ll k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    vector<int> las(200'005, -1);
    vector<vector<ll>> to(64, vector<ll>(n));
    for (int i = 0; i < 2*n; i++) {
        int x = a[i%n];
        if (las[x] != -1) {
            to[0][las[x]%n] = i - las[x] + 1;
        }
        las[x] = i;
    }
    dbg(to);
    ll lim = n*k;
    int J = 0;
    for (int j = 1; j < 64; j++) {
        for (int i = 0; i < n; i++) {
            ll d = to[j-1][i];
            to[j][i] = d + to[j-1][(i+d)%n];
        }
        if (to[j][0] > lim) {
            J = j; break;
        }
    }
    dbg(to);
    ll I = 0;
    while (true) {
        while (J>=0 && I + to[J][I%n] > lim) {
            J--;
        }
        dbg(I, J);
        if (J < 0) break;
        I += to[J][I%n];
        dbg(I, J);
    }
    assert(lim - I <= n);
    fill(las.begin(), las.end(), -1);
    vector<int> res;
    for (ll i = I; i < lim; i++) {
        int x = a[i%n];
        if (las[x] == -1) {
            res.push_back(x);
            las[x] = 1;
        } else {
            while (!res.empty() && las[x] != -1) {
                las[res.back()] = -1;
                res.pop_back();
            }
        }
    }
    for (auto& x: res) {
        cout << x << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 105060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(void) {
	int N,K;
	cin >> N >> K;
	vector<int> V(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	long long res = 0;
	for (int r = 0; r < K+1; ++r) {
		for (int l = 0; l < K-r+1; ++l) {
			priority_queue<int> pq;
			long long score = 0;
			for (int i = 0; i < r && i < N; ++i) {
				score += V[i];
				pq.push(-V[i]);
			}
			for (int i = 0; i < l && N-i-1 >= r; ++i) {
				score += V[N-i-1];
				pq.push(-V[N-i-1]);
			}

			for (int i = 0; i < K-r-l && !pq.empty() && pq.top() > 0; ++i) {
				score += pq.top();
				pq.pop();
			}
			res = max(score,res);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
int main(){
	int n;
	int i,j;
	int min,max;
	long long int sum;
	scanf("%d",&n);
	if(n==0){
		return 0;
	}
	
	int a[n];
	
	for(i=0;i<n;i++){ 
		scanf("%d",&a[i]);
	}
	min=a[0];
	max=a[0];
	sum=a[0];


	for(j=1;j<n;j++){
		if(a[j]>=max) max=a[j];
		else if(a[j]<=min) min=a[j];
		sum+=a[j];
	}
	printf("%d %d %lld\n",min,max,sum);

	return 0;
}

Measured memory_bytes: 636
import sys
sys.setrecursionlimit(10 ** 6)
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    G[x].append(y)
d = [-1] * N


def dfs(u):
    if d[u] != -1:
        return d[u]

    ma = 0
    for w in G[u]:
        ma = max(ma, dfs(w))

    d[u] = ma + 1
    return ma + 1


ans = 0
for i in range(N):
    ans = max(ans, dfs(i))

print(ans - 1)



Measured memory_bytes: 154060
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] d = new int[N];
  
    for(int i=0; i<N; i++){
    d[i] = sc.nextInt();
    }

    int m = 0;

    for(int i=0; i<N-1; i++){
       for(int j=i+1; j<N; j++){
          

             int a = d[i]*d[j];
             m += a;
          
       }
    }
    System.out.println(m);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
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; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    ll count=0;
    rep(i,s.size()){
      if(s[i]!=t[i]) count++;
    }
    cout<<count<<endl;
}

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

using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	vector<int> num(n);
	for (int i = 0; i < n; i++) {
		cin >> num[i];
	}
	cout << ((n - 1) + (k - 2)) / (k - 1) << endl;

}

Measured memory_bytes: 640
import sys
N = int(sys.stdin.readline())
H = [0] + list(map(int, sys.stdin.readline().split()))

max_jump=0
jump=0

for i in range(2,N+1):
  if H[i] <= H[i-1]:
    jump += 1
    max_jump = max(jump, max_jump)
  else:
    jump = 0
print(max_jump)

Measured memory_bytes: 14252
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, x;

	cin >> a >> b >> x;

	if (x >= a && x <= a+b) cout << "YES" << endl;
	else cout << "NO" << endl;

	
	

}
	

Measured memory_bytes: 256
def re_into(nums, count, list_size):
    numbers = []
    for i in nums:
        if i % 2 == 0:
            numbers.append(i // 2)

    if len(numbers) == list_size:
        count += 1
        re_into(numbers, count, list_size)
    else:
        print(count)


n = input()
nums = list(map(int, input().split()))
l = len(nums)

re_into(nums, 0, l)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int count = 0;
  for(int j = 0; j < N; j++){
    for(int k = 0; k < N; k++){
      count += vec.at(j)*vec.at(k);
    }
  }
  int minus = 0;
  for(int m = 0; m < N; m++){
    minus += vec.at(m)*vec.at(m);
  }
  int ans;
  ans = (count - minus)/2;
  
  cout << ans << endl;
}
   
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

vi B,L;
int n,t,l,b;
long double dp[103][103];//dp[i][j]:= i?????????????????????j?????????
int main(){
	while(1){
		cin >> n >> t >> l >> b;
		REP(i,101) REP(j,101) dp[i][j] = 0;
		B.clear(); L.clear();
		if(n==0&&t==0&&l==0&&b==0) break;
		int tmp;
		REP(i,l){
			cin >> tmp;
			L.pb(tmp);
		}
		REP(i,b){
			cin >> tmp;
			B.pb(tmp);
		}
		dp[0][0] = 1.0;
		REP(i,t){
			REP(j,n){
				FOR(k,1,7){
					int pos = j + k;
					if(pos > n) pos = n - (k - (n - j));
					REP(w,B.size()){
						if(pos == B[w]) pos = 0;
					}
					bool Skipflag = false;
					REP(w,L.size()){
						if(pos == L[w]) Skipflag = true;
					}

					if(!Skipflag) dp[i+1][pos] += dp[i][j]*(1.0/6.0);
					else dp[i+2][pos] += dp[i][j]*(1.0/6.0);
				}
			}
		}
		long double ans = 0;
		FOR(i,1,t+1) ans += dp[i][n];
		cout << shosu(10) << ans << endl;

	}
}

Measured memory_bytes: 1456
N = gets.to_i
D = []
while line = gets
  D << line.chomp.split(' ').map(&:to_i)
end

sum = 0
(0..N-3).each do |i|
  if D[i][0] == D[i][1] && D[i+1][0] == D[i+1][1] && D[i+2][0] == D[i+2][1]
    sum += 1
  end
end

if sum >= 1
  puts "Yes"
else
  puts "No"
end

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    int left = 0;
    int right = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'B') {
            left = i;
            break;
        }
    }
    for (int i = left + 1; i < s.length(); ++i) {
        if (s[i] == 'W') {
            right = i;
            break;
        }
    }

    while (left < s.length() && right < s.length()) {
        while (right < s.length() && s[right] == 'B') ++right;
        if (right >= s.length()) break;
        while (left < right && s[left] == 'W') ++left;
        if (left >= right) {
            ++right;
            continue;
        }
        ans += right - left;
        swap(s[left], s[right]);
        ++left;
        ++right;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans,tt=-1e9-1;
struct node
{
	int x,y;
}a[100001];
bool cmp(node x,node y)
{
	return x.y<y.y;
}
signed main()
{
	int x,y;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		a[i].x=x-y;
		a[i].y=x+y;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	if(a[i].x>=tt)
	{
		ans++;
		tt=a[i].y;
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size(), ans = 0;
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  else {
    rep(i, n/2) {
      if(s.at(i) != s.at(n-1-i)) ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL //デバッグ出力系
#define dout(s) cout<<s<<"\n";
#define debug() if(true)
#else
#define dout(s)
#define debug() if(false)
#endif//
#define next asdnext
#define prev asdprev
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define vout(v) for(auto &i:v){cout<<i<<" ";}cout<<"\n"; //配列出力
#define vin(v) for(auto &i:v)cin>>i; //配列入力
#define vec(v,n) vector<int> v(n,0);
typedef long long ll;
typedef unsigned long long ull;

void Main() {
	int N;
	cin >> N;
	vec(W, N);

	vector<int> sums(N+1);
	rep(i,N) {
		cin >> W[i];
		sums[i + 1] = sums[i] + W[i];
	}
	int ans = 1e10;
	rep(i,N) {
		ans = min(abs(sums[N] - (sums[i+1] * 2)), ans);
	}

	cout << ans << "\n";
}

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


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

int main() {
	char s[10];

	cin >> s;
	string ans ="Good";
	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1]) ans = "Bad";

	}

	cout << ans << endl;
	return 0;
}

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

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

constexpr int MOD = 998244353;
using mint = ModInt<MOD>;
int main() {
	int n; cin >> n;
	string _s; cin >> _s;
	int s[3 * n];
	const string rgb = "RGB";
	for(int i = 0; i < 3 * n; ++i) {
		for(int j = 0; j < 3; ++j) {
			if(rgb[j] == _s[i]) {
				s[i] = (1 << j);
			}
		}
	}
	int cnt[1 << 3] = {};
	const int FULL = (1 << 3) - 1;
	mint ans = 1;
	for(int i = 0; i < 3 * n; ++i) {
		if(cnt[FULL - s[i]] > 0) {
			ans *= cnt[FULL - s[i]];
			--cnt[FULL - s[i]];
		} else {
			bool find = false;
			int sum = 0;
			for(int j = 0; j < 3; ++j) {
				if(s[i] == (1 << j)) continue;
				if(cnt[1 << j] > 0) {
					sum += cnt[1 << j];
					if(not find) {
						--cnt[1 << j];
						++cnt[s[i] + (1 << j)];
					}
					find = true;
				}
			}
			if(find) {
				ans *= sum;
			} else {
				++cnt[s[i]];
			}
		}
	}
	for(int i = 1; i <= n; ++i) {
		ans *= i;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4916
n = int(input()) 
v = list(map(int, input().split()))
c = list(map(int, input().split()))

max_diff_v_c = 0
for i in range(n):
    diff_v_c = v[i] - c[i]
    if diff_v_c > 0:
        max_diff_v_c += diff_v_c

print(max_diff_v_c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
int a[maxn];
int b[maxn];
int n;


int main()
{
  scanf("%d",&n);
  for(int i = 1; i <= n; i ++){
    scanf("%d",&a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  int maxx = b[n];
  int k = b[n - 1];

  for(int i = 1; i <= n; i ++){
    if(a[i] == maxx)  printf("%d\n", k);
    else              printf("%d\n", maxx);
  }
  return 0;
}

Measured memory_bytes: 3200
using System;

public class Program
{
    public static void Main()
    {
        while (true) {
            string[] str = Console.ReadLine().Split();
            if (str[0] == "0" && str[1] == "0") return;
            int hit = 0, blow = 0;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (str[0][i] == str[1][j])
                    {
                        if (i == j)
                        {
                            hit++;
                        }
                        else
                        {
                            blow++;
                        }
                    }
                }
            }
            Console.WriteLine("{0} {1}", hit, blow);
        }
    }
}

Measured memory_bytes: 9228
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int a,b,c;
	string s;
	while(cin>>s)
	{
		int len=s.size();
		for(int i=len-3;i>=0;i-=2)
		{
			if(s.substr(0,(i+1)/2)==s.substr((i+1)/2,(i+1)/2))
			{
				cout<<i+1<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

//write bug free code
ll a,b;
char op;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>a>>op>>b;

if(op=='+') cout<<a+b<<endl;
if(op=='-') cout<<a-b<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int s[26] = { 0 };
	char n;
	char N[26] = { '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' };

	while (cin >> n) {
		if(islower(n)==0)n=tolower(n);
		s[n - 'a'] += 1;
	}
	for (int i = 0; i < 26; i++) {
		cout <<N[i] <<" "<< ":"<<" "<< s[i] << endl;
	}
	return 0;
}

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

ll gcd(ll a,ll b){return(a%b)?gcd(b,a%b):b;}

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

int main(){
    ll a,b;
    cin>>a>>b;
    
    cout<<lcm(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
long long a;
long long dp[51][51][2550];

int main() {
	cin >> n >> a;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	sort(v.begin(), v.end());
	int max_v = *max_element(v.begin(), v.end());
	
	for (int j = 0; j < n + 1; ++j) {
		for (int k = 0; k < j+1; ++k) {
			for (int s = 0; s < n*max_v + 1; ++s) {
				if (j == 0 && k == 0 && s ==0) dp[j][k][s] = 1;
				if (j >= 1 && s < v[j - 1]) dp[j][k][s] = dp[j - 1][k][s];
				if (j >= 1 && s >= v[j - 1] && k >= 1) {
					dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - v[j - 1]];
				}
			}
		}
	}
	long long cnt = 0;
	for (int k = 1; k < n + 1;++k ) {
			cnt += dp[n][k][a * k];
	}
	cout << cnt << endl;
	return 0;
}

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


int main(){
    string s;cin>>s;
    ll countb = 0;
    ll ans = 0;
    int n = s.size();
    for(int i = 0;i<n;i++){
        if(s[i]=='W') {
            ans+=countb;
        }

        else {
            countb++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010
ll h,w;
ll dp[1001][1001];

ll f(vvll& a,ll x,ll y) {
	if(a[x][y]==0)
		return 0;
	if(x==h-1&&y==w-1)
		return a[x][y]%M;
	if(x<h-1)if(dp[x+1][y]==-1)
		dp[x+1][y]=f(a,x+1,y);
	if(y<w-1)if(dp[x][y+1]==-1)
		dp[x][y+1]=f(a,x,y+1);
	if(x==h-1)return dp[x][y+1]%M;
	if(y==w-1)return dp[x+1][y]%M;
	return (dp[x+1][y]+dp[x][y+1])%M;
}
int main(){
	IOS;
	char c;
	cin>>h>>w;
	rep(i,0,1001)rep(j,0,1001)dp[i][j]=-1;
	vvll a(h, vll(w));rep(i,0,h)rep(j,0,w){cin>>c;if(c=='.')a[i][j]=1;else a[i][j]=0;}
	cout<<f(a,0,0);
	return 0;
}



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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();

		s[3] = '8';

		pr.println(s);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 24276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int answer = a- 2*b;
		if(answer < 0) {
			System.out.println(0);
		}else {
			System.out.println(answer);
		}

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    REP(i,n) cin >> x[i] >> y[i] >> z[i];
    ll ans=0, tmp;
    REP(bit, (1<<3)) {
        vector<ll> v(n);
        REP(i,n) {
            tmp = 0;
            if(bit>>0 & 1) tmp += x[i]; else tmp -= x[i];
            if(bit>>1 & 1) tmp += y[i]; else tmp -= y[i];
            if(bit>>2 & 1) tmp += z[i]; else tmp -= z[i];
            v[i] = tmp;
        }
        sort(ALL(v), greater<ll>());
        ll sum = 0;
        REP(i,m) sum += v[i];
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

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

    vector<int> vec;
    if(s == 1000000000){
        for(int i = 0;i < n;i++){
            if(i < k){
                vec.push_back(s);
            }else{
                vec.push_back(s-1);
            }
        }
    }else{
        for(int i = 0;i < n;i++){
            if(i < k){
                vec.push_back(s);
            }else{
                vec.push_back(s+1);
            }
        }
    }

    cout << vec[0];
    for(int i = 1;i < n;i++){
        cout << " " << vec[i];
    }
    cout << endl;

    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1000003;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

template <typename T = int64>
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...));
}

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

template <typename F>
struct FixPoint : F {
  FixPoint(F &&f) : F(forward<F>(f)) {}

  template <typename... Args>
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template <typename F>
inline decltype(auto) MFP(F &&f) {
  return FixPoint<F>{forward<F>(f)};
}

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

  int ans;
  if (N < 10) {
    ans = R + (100 * (10 - N));
  } else {
    ans = R;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF -2147483647
int main(){
  int a,b[100000];
  int c,d[100000],e[100000],q=0;
  cin>>a;
  for(int i=0;i<a;i++) cin>>b[i];
  cin>>c;
  for(int i=0;i<c;i++) cin>>d[i]>>e[i];
  for(int j=0;j<c;j++){
    int w=0;
    for(int i=0;i<a;i++){
      if(i+1==d[j]) w+=e[j];
      else w+=b[i];
    }
    cout<<w<<"\n";
  }
}


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



using namespace std;
int C=0;

void bubbleSort(int A[],int N) {
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int j = N-1;j>=1;j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				C++;
				flag = 1;
			}
		}
		
	}
}




int main()
{
	int N;
	int S[100];

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

	bubbleSort(S, N);

	for (int i = 0;i < N-1;i++) {
		cout << S[i]<<" ";
	}

	cout << S[N-1] << endl;
	cout << C<< endl;

    return 0;
}

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

using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        v.emplace_back(-t);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += -v[i] * (1 - (i % 2) * 2);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define offset 
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 1003455
int cost[20],vlearn[20][20];
int valor[20];

int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,x;
    cin>>n>>m>>x;
    forr(i,0,n)
    {
        cin>>cost[i];
        forr(j,0,m)
        {
            cin>>vlearn[i][j];
        }
    }
    int minn=INF;
    forr(i,0,1<<n)
    {
        memset(valor,0,sizeof valor);
        int costo=0;
        forr(bit,0,n)
        {
            if (i&(1<<bit))
            {
                forr(k,0,m)
                {
                    valor[k]+=vlearn[bit][k];
                }
                costo+=cost[bit];
            }
        }
        bool invalid=0;
        forr(k,0,m)
        {
            if (valor[k]<x)
                invalid=1;
        }
        if (invalid)
            continue;
        minn=min(minn,costo);
    }
    if (minn==INF)
        cout<<-1;
    else
        cout<<minn;
}
// PLUS ULTRA!!

Measured memory_bytes: 3640
#include <stdio.h>
#define max 100000

int a[max] , n;

int partition(int p , int r)
{
	int x , i , j , t;
	x = a[r];
	i = p - 1;
	for( j = p; j < r; j++)
	{
		if(a[j] <= x)
		{
			i++;
			t = a[i];
			a[i] = a[j];
			a[j] = t;
		}
	}
	t = a[i+1];
	a[i+1] = a[r];
	a[r] = t;
	return i + 1;
}

int main(void)
{
	int i , q;
	scanf("%d",&n);
	for( i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	q = partition(0,n-1);
	
	for( i = 0; i < n; i++)
	{
		if( i ) printf(" ");
		if( i == q) printf("[");
		printf("%d",a[i]);
		if( i == q) printf("]");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2084
let () =
  let read_dice () = Scanf.sscanf (read_line ()) "%d %d %d %d %d %d" (fun a b c d e f ->  [(a,f) ;(b,e) ;(c,d) ] ) in
  let faces1 = read_dice () in
  let faces2 = read_dice () in
  let scan faces2 bop =
    let r1,r2 = List.fold_left2 (
                    fun (r1,r2) (a,b) (c,d) -> let b1,b2 = (a = c && b = d), (a = d && b = c) in
                                               if b1 && b2 then 1, true
                                               else if b1 then 1 * r1, r2
                                               else if b2 then -1 * r1, r2
                                               else 0, false
                  ) (1,false) faces1 faces2
    in
    bop r1 0 || (r1 <> 0 && r2 )
  in
  let rec loop faces2 bop = function
      0 -> false
    | i -> scan faces2 bop || let faces2' = (List.tl faces2) @ [(List.hd faces2)] in
                              loop faces2' bop (i-1)
  in
  print_string @@ if loop faces2 (>) 3 || loop (List.rev faces2) (<) 3 then "Yes\n"
                  else "No\n"


Measured memory_bytes: 2252
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    cin >>x;
    vector<bool> expo(x+1);

    expo[1] = 1;
    for (int b = 2; b <= x; b++) {
        int v = b * b;
        while(v <= x) {
            expo[v] = 1;
            v *= b;
        }

    }
    for (int i = x; i >= 1; i--){
        if(expo[i]) {
            cout <<i<<endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N;
int A;
int RES[200001];

int main(void){
    cin >> N;
    REP(i,N-1) {
        cin >> A;
        RES[A]++;
    }
    for(int i=1;i<=N;i++) cout << RES[i] << endl;
    return 0;
}



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

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

  int tot = pow(3, N);
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int cnt = 1;
  for (int i = 0; i < N; i++) {
    if (A.at(i) % 2 == 0) cnt *= 2;
  }

  cout << tot - cnt << endl;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A,B,C,K; cin >> A >> B >> C >> K;
    ll num=0, sum=0;
    num += min(A,K);
    sum += min(A,K);
    if (num<K) {
        num+=  min(B, K-num);
    } 
    if (num<K) {
        sum -= min(C, K-num);
        num += min(C,K-num);
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <utility>
#include <iterator>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
using namespace std; 
  
typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

#define IOS ios_base::sync_with_stdio(false);\
        cin.tie(0);\
        cout.tie(0);
#define endl "\n"  
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) 
#define FOREACH(a, b) for (auto&(a) : (b)) 
#define rep(i, n) FOR(i, 0, n) 
#define repn(i, n) FORN(i, 1, n) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALLA(arr, sz) arr, arr + sz 
#define all(c) c.begin(),c.end()
#define SORT(v) sort(all(v)) 
#define REVERSE(v) reverse(all(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define w(x)   int x; cin>>x; while(x--)
#define sz(a) int((a).size())
#define ps(x,y)         fixed<<setprecision(y)<<x
int main()
{
	IOS;
	int n;
	cin>>n;
	vi v(n);
	rep(i,n)
	{
		cin>>v[i];
	}
	vi dp(n,1000000005);
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		for(int x:{i-1,i-2})
		{
			if(x>=0)
			{
				dp[i]=min(dp[i],dp[x]+abs(v[x]-v[i]));
			}
		}
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.math.*;
import java.util.*;
@SuppressWarnings("Duplicates")
// author @mdazmat9
public class Main{
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        int test = 1;
        //test=sc.nextInt();
        for (int ind = 0; ind < test; ind++) {
            solve();
        }
        out.flush();
    }
    static void solve(){
        long n=sc.nextInt()-1;
        long ans=n*(n+1);
        ans/=2;
        out.println(ans);



    }







    static int[] intarray(int n){ int [] a=new int[n];for(int i=0;i<n;i++)a[i]=sc.nextInt();return a; }
    static long[] longarray(int n){ long [] a=new long[n];for(int i=0;i<n;i++)a[i]=sc.nextLong();return a; }
    static ArrayList<Integer> intlist(int n){ArrayList<Integer> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextInt());return list; }
    static ArrayList<Long> longlist(int n){ArrayList<Long> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextLong());return list; }
    static int[][] int2darray(int n,int m){ int [][] a=new int[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextInt(); } }return a; }
    static long[][] long2darray(int n,int m){ long [][] a=new long[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextLong(); } }return a; }
    static char[][] char2darray(int n,int m){ char [][] a=new char[n][m];for(int i=0;i<n;i++){ String s=sc.next(); a[i]=s.toCharArray(); }return a; }

    static double pi=3.14159265358979323846264;
    public static double logb( double a, double b ) {return Math.log(a) / Math.log(b); }
    static long fast_pow(long a, long b,long abs) {
        if(b == 0) return 1L;
        long val = fast_pow(a, b / 2,abs);
        if(b % 2 == 0) return val * val % abs;
        else return val * val % abs * a % abs;
    }
    static long abs = (long)1e9 + 7;
    static   void shuffle(int[] a) { int n = a.length;for(int i = 0; i < n; i++) { int r = i + (int) (Math.random() * (n - i));int tmp = a[i];a[i] = a[r];a[r] = tmp; } }
    static long gcd(long a , long b) {
        if(b == 0) return a;
        return gcd(b , a % b);
    }
}

class Scanner {
    public BufferedReader reader;
    public StringTokenizer st;
    public Scanner(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }
    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            } catch (Exception e) {
                throw (new RuntimeException());
            }
        }
        return st.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 24660
n, w = [int(i) for i in input().split()]
V, W = zip(*[[int(i) for i in input().split()] for j in range(n)])

dp = [[0]*(w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if W[i] <= j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-W[i]]+V[i], dp[i+1][j-W[i]]+V[i])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[n][w])


Measured memory_bytes: 15696
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a = gif
b = gif
puts 2*b-a


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

int main() {
  int l, r, d; cin >> l >> r >> d;
  cout << r / d - (l-1) / d << endl;
  return 0;
}

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

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

  cin >> a >> b >> c;

  if((a%2==0)||(b%2==0)||(c%2==0)){
    cout << "0" << endl;
  }else{
    cout << min(a*b,min(b*c,a*c)) << endl;
  }

  return (0);
}


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

int main(){
    string s,ans="NO";
    cin >> s;
    for(int i = 0;i <= 7;i ++){
        string sl,sr;
        sl = s.substr(0,i);
        sr = s.substr(s.size()-(7-i));
        if(sl+sr=="keyence") ans="YES";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

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

using namespace std;

typedef long long ll;

struct Event
{
public:
  ll t;
  int type;
  ll x;

  bool operator<(const Event &right) const
  {
    if (t == right.t)
    {
      return type == -1;
    }
    return t < right.t;
  }
};

int main(int argc, char const *argv[])
{
  ll n, q;
  cin >> n >> q;
  vector<Event> e(2 * n);
  vector<ll> d(q);
  REP(i, n)
  {
    ll s, t, x;
    cin >> s >> t >> x;
    e[i].t = s - x;
    e[i].type = 1;
    e[i].x = x;
    e[i + n].t = t - x;
    e[i + n].type = -1;
    e[i + n].x = x;
  }
  REP(i, q)
  {
    cin >> d[i];
  }
  sort(ALL(e));
  set<ll> s;
  ll start = 0;
  for (auto query : d)
  {
    for (ll i = start; i <= e.size(); i++)
    {
      if (i == e.size())
      {
        cout << -1 << endl;
        start = i;
        break;
      }
      auto event = e[i];
      if (event.t <= query)
      {
        if (event.type == 1)
        {
          s.insert(event.x);
        }
        else
        {
          s.erase(event.x);
        }
      }
      else
      {
        if (s.empty())
        {
          cout << "-1" << endl;
        }
        else
        {
          cout << *s.begin() << endl;
        }
        start = i;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 21504
#n = int(input())
#s = input()
#n, k= map(int,input().split())
#da = list(map(int,input().split()))
class SegTree:
    def __init__(self,n):
        self.size=1
        while(n>self.size):
            self.size<<=1
        self.nod=[0 for i in range(self.size*2-1)]
    def update(self,k,a):
        k+=self.size-1
        self.nod[k]+=a
        while(k>0):
            k=(k-1)>>1
            self.nod[k]|=a
    def dedate(self, k, a):
        k += self.size-1
        self.nod[k] -= a
        while(k>0):
            k=(k-1)>>1
            self.nod[k] = self.nod[(k<<1)|1]|self.nod[(k+1)<<1]
    def query(self,a,b,k,l,r):
        if(r<=a or b<=l):
            return 0
        if(a<=l and r<=b):
            return self.nod[k]
        else:
            return self.query(a,b,(k<<1)|1,l,(l+r)>>1)|self.query(a,b,(k+1)<<1,(l+r)>>1,r)

def pop_c(x):
    ret = 0
    while x:
        ret += x&1
        x>>=1
    return ret

n = int(input())
t = input()
q = int(input())
EE = ord('a')
st = SegTree(n)
s = [t[i] for i in range(n)]

def adding(x, c):
    global st
    st.dedate(x, 1<<(ord(s[x])-EE))
    st.update(x, 1<<(ord(c)-EE))
    s[x] = c

def query(l, r):
    now = st.query(l, r+1, 0, 0, st.size)
    return pop_c(now)

for i in range(n):
    st.update(i, 1<<(ord(s[i])-EE))
ans = []
for i in range(q):
    x,l,r = map(str,input().split())
    if x=='1':
        adding(int(l)-1, r)
    else:
        ans.append(query(int(l)-1, int(r)-1))
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 116044
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    int N, M;
    cin >> N >> M;
    vector<set<int>> graph(N + 1, set<int>());
    rep(i, M) {
        int u, v, w;
        cin >> u >> v >> w;
        graph[u].insert(v);
        graph[v].insert(u);
    }

    vint visited(N + 1, -1);
   
    queue<int> q;
    int ans = 0;
    REP(i, 1, N + 1) {
        if (visited[i] != -1) { continue; }

        ans++;
        q.push(i);
        while (1) {
            if (q.size() <= 0) {
                break;
            }
            auto nd = q.front();
            q.pop();
            for (auto & adj : graph[nd]) {
                if (visited[adj] == -1) {
                    visited[adj] = 1;

                    q.push(adj);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::cin>>n;
    std::vector<int> l(n), r(n);
    for(int i = 0;i < n;i++){
        std::cin>>l[i]>>r[i];
    }

    int sum = 0;
    for(int i = 0;i < n;i++){
        sum += r[i] - l[i] + 1;
    }
    std::cout<<sum<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    int n;
    cin  >> n;
    int s[n];
    int total = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        total += s[i];
    }
    sort(s, s + n);
    if (total % 10 == 0) {
        for (int i = 0; i < n; i++) {
            if (s[i] % 10 != 0) {
                total -= s[i];
                break;
            }
        }
    }
    if (total % 10 == 0) {
        total = 0;
    }
    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>
#include <atcoder/convolution>
#include <atcoder/modint>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>

using namespace std;
using namespace atcoder;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
	// printElems(&a[0], &a[n]);　みたいな感じで使う。
	void printElems(const int* begin, const int* end)
	{
		for (const int* p = begin; p != end; ++p) {
			cout << *p << ' ';
		}
		cout << endl;
	}
}

#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n+1; i++)
#define repr(i,n) for(ll i=n-1; i>=0; i--)
#define repr1(i,n) for(ll i=n; i>0; i--)
#define FOR(i,j,n) for(ll i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(ll i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<ll,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const ll BIG = 1LL<<60;
const string yes = "Yes";
const string no = "No";

//----------------------------------------------

fenwick_tree<ll> f(500005);

int main(){
	int n,q;
	cin >> n >> q;
	rep(i,n){
		ll a;
		cin >> a;
		f.add(i,a);
	}
	vll ans;
	rep(i,q){
		ll t,u,v;
		cin >> t >> u >> v;
		if(t == 0){
			f.add(u,v);
		}
		else{
			ans.push_back(f.sum(u,v));
		}
	}
	for(ll x : ans){
		prints(x);
	}


	return 0;
}




Measured memory_bytes: 10236