akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    int n = s.length();
    ll ans = 0, cnt = 0;
    FOR(i, 0, n) {
        if (s[i] == 'W') {
            ans += i - cnt;
            ++cnt;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0;j<a;j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
int main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0)
    {
        if(k%2==0)
        {
            cout<<x;
        }
        else
        {
            ll y = abs(x - d);
            ll z = abs(x + d);
            cout<<min(y,z)<<endl;
        }
    }
    x = abs(x);
    if((x/k) >= d)
    {
        x = x - k*d;
        cout<<x<<endl;
    }
    else if(x>0)
    {

        while(x>=0 && k>0)
        {
            if(x - d>=0)
            {
                x = x - d;
                k--;
            }
            else
            {
                break;
            }

        }
        if(k==0)
        {
            cout<<x<<endl;
        }
        else
        {
            if(k%2==0)
                cout<<x<<endl;
            else
            {
                ll y = abs(x - d);
                ll z = abs(x + d);
                cout<<min(y,z)<<endl;
            }
        }
    }

}


Measured memory_bytes: 7832
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const double PI = acos(-1);  // PI = 3.141593...

struct Dice {
    int n1, n2, n3, n4, n5, n6;
    Dice(int _n1, int _n2, int _n3, int _n4, int _n5, int _n6) 
    :n1(_n1), n2(_n2), n3(_n3), n4(_n4), n5(_n5), n6(_n6) {
    }
    void east() {
        int tmp = this->n1;
        this->n1 = this->n4;
        this->n4 = this->n6;
        this->n6 = this->n3;
        this->n3 = tmp;
    }
    void west() {
        int tmp = this->n1;
        this->n1 = this->n3;
        this->n3 = this->n6;
        this->n6 = this->n4;
        this->n4 = tmp;
    }
    void south() {
        int tmp = this->n1;
        this->n1 = this->n5;
        this->n5 = this->n6;
        this->n6 = this->n2;
        this->n2 = tmp;
    }
    void north() {
        int tmp = this->n1;
        this->n1 = this->n2;
        this->n2 = this->n6;
        this->n6 = this->n5;
        this->n5 = tmp;
    }
};

int main() {
    int n1, n2, n3, n4, n5, n6;
    char ch;
    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    Dice dice(n1, n2, n3, n4, n5, n6);
    while(cin >> ch) {
        if(ch == 'E') dice.east();
        if(ch == 'W') dice.west();
        if(ch == 'S') dice.south();
        if(ch == 'N') dice.north();
    }
    cout << dice.n1 << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main () {
	int x, y;

	scanf("%d %d", &x, &y);
	if ( (x + y) > 16) {
		printf (":(\n");
	}
	if(x > 8 || y > 8) {
		printf (":(\n");
	}
	else{
		printf("Yay!\n");
	}
	return 0;
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(2*N);
  REP(i, 2*N) cin >> A[i];

  sort(ALL(A));

  int ans = 0;
  REP(i, 2*N){
    if(i%2 == 0) ans += A[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int x,a,b,c;
    std::cin >> x;
    for (int i = 0; i < x;i++){
        std::cin >> a >> b >> c;
        if ( a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b) {
            std::cout << "YES" << std::endl;
}       else  {
            std::cout << "NO" << std::endl;
}
}
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] chars = s.toCharArray();
		int cash = 0;
		int l = s.length();
		for(int i = 0; i < chars.length; i++) {
			if(chars[i]=='S') {
				cash++;
			} else {
				if(cash>0) {
					cash--;
					l-=2;
				}
			}
		}
		System.out.println(l);
	}
}


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

void Main() {
    // input
    string S, T;
    int A, B;
    string U;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    // process
    if (U ==S) {
        A--;
    } else if (U == T) {
        B--;
    } else {
        cout << "Error";
    }


    // output
    cout << A << " " << B << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >>n;
  ll ans=0;
  for (ll i=1;i<=sqrt(n);i++) {
    if (n%i==0) {
      if (n/i<i+2) {
        break;
      }
      ans += n/i-1;
    }
  }
  cout<<ans;
}

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

int main() 
{
  set<int> s;
  int n;
  cin >> n;
  for(int i=0; i< n; ++i){
    int d;
    cin >> d; // d wo tatede input
    s.insert(d); //set ni tuika
  }
  cout << s.size() << endl;
  return 0; 

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	int n,a;
	cin >> n >> a;
	cout << n * n - a;
}


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

int main(){
    int N,T; cin >> N >> T;
    vector<int> c(N),t(N);
    for(int i=0;i<N;i++){
        cin >> c[i] >> t[i];
    }
    int min_cost = c[0];
    bool flag = true;
    for(int i=0;i<N;i++){
        if(t[i]<=T){
            flag =false;
            if(min_cost > c[i]){
                min_cost = c[i];
            }
        }
    }
    if(flag){
        cout << "TLE" << endl;
    }else{
        cout << min_cost << endl;
    }
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
H = LIST()

view_hotel = 0
height = 0
for i in range(N):
	if H[i] >= height:
		view_hotel += 1
		height = H[i]

print(view_hotel)

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

ll gcd(ll n, ll m){
	if(n < m)
		swap(n,m);
	return (m == 0)? n : gcd(m,n%m);
}
void doit(){
	ll n, m;
	cin >> n >> m;
	ll k = gcd(n,m);
	cout << (n * m) / k << nl;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input1.txt","r",stdin);
//    freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t = 1;
//	 cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3612
from collections import deque
s = deque(list(input()))
n = int(input())
q = deque()
for _ in range(n):
    q.append(list(input().split()))
d = 0
for r in q:
    if r[0] == '1':
        d = d ^ 1
    else:
        if int(r[1]) & (d+1):
            s.appendleft(r[2])
        else:
            s.append(r[2])
if d == 1:
    s.reverse()
ans = "".join(list(s))
print(ans)

Measured memory_bytes: 35428
import math
n = int(input())

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

if n == 1:
    if a[0] == 0:
        print(1)
    else:
        print(0)
    exit()



if n % 2 == 1:
    ans = 2 ** ((n-1) // 2)
else:
    ans = 2 ** (n//2)


if n % 2 == 1:
    for i in range(n):
        if i == 0:
            if a[i] == 0:
                continue
            else:
                print(0)
                exit()
        else:
            if a[i] == math.ceil(i/2)*2:
                continue
            else:
                print(0)
                exit()
else:
    for i in range(n):
        if a[i] == math.floor(i/2)*2+1:
            continue
        else:
            print(0)
            exit()

print(ans % (10**9+7))

Measured memory_bytes: 13812
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
   ll x, ans=0, tmp, it;
int pre(){
    
    
    for(ll i=-1e3; i<1e3; i++){
	tmp = -(x-i*i*i*i*i);
	if (tmp<=0) 
	    it=-1;
	else
	    it=1;
	for(ll j=0; ; j+=it){
	    ll a=j*j*j*j*j;
	       if(a ==tmp){
		cout << i << " " <<j<< endl;
		return 0;
	    }
	    if(a>tmp*it)
		break;
	}
    }
}

int main() {
 
    cin >> x;
    pre();
    
	 
} 

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner( System.in );

        int health = Integer.parseInt(scan.next()); 
        int attack = Integer.parseInt(scan.next());

        if( health % attack == 0 ){
            System.out.println( health/attack );
        }else{
            System.out.println( health/attack + 1);
        }
    }
}

Measured memory_bytes: 21844
# frozen_string_literal: true

# Builtin if ruby was 2.4 or above.
module Enumerable
  def sum(init = 0, &block)
    target = block_given? ? map(&block) : self
    target.reduce(init, :+)
  end
end

x, y, _a, _b, _c = gets.chomp.split(' ').map(&:to_i)
reds = gets.chomp.split(' ').map(&:to_i).sort.reverse
greens = gets.chomp.split(' ').map(&:to_i).sort.reverse
whites = gets.chomp.split(' ').map(&:to_i).sort.reverse

red_candidates = reds.take(x)
green_candidates = greens.take(y)
no_white_total = red_candidates.sum + green_candidates.sum

class OrderedStackGroup
  def initialize(arrays, compare)
    @arrays = arrays
    @compare = compare || ->(a, b) { a <=> b }
  end

  def pop
    @arrays.max do |a, b|
      if a.empty? && b.empty?
        0
      elsif a.empty?
        -1
      elsif b.empty?
        1
      else
        @compare.call(a.last, b.last)
      end
    end.pop
  end
end

sg = OrderedStackGroup.new(
  [red_candidates, green_candidates],
  ->(a, b) { b <=> a }
)

total = whites.reduce(no_white_total) do |acm, white|
  popped = sg.pop
  break acm if popped.nil? || white <= popped

  acm + white - popped
end

puts total


Measured memory_bytes: 33540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const ll MN = 100000;
bool f[MN+1];
ll c[MN+1];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    vll x(m), y(m);
    rep(i, m){
        cin >> x[i] >> y[i];
    }
    f[1] = 1;
    repr(i, 1, MN+1){
        c[i] = 1;
    }
    rep(i, m){
        if(f[x[i]]){
            f[y[i]] = 1;
        }
        c[x[i]]--;
        c[y[i]]++;
        if(c[x[i]] == 0){
            f[x[i]] = 0;
        }
    }
    ll ans = 0;
    repr(i, 1, MN+1){
        ans += f[i];
    }
    cout << ans << endl;
    return 0;
}

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

class Vector2
{
public:
	Vector2() : x( 0 ), y( 0 ){}
	Vector2( int _x, int _y ) : x( _x ), y( _y ){}
	Vector2& operator=( const Vector2& v )
	{
		this->x = v.x;
		this->y = v.y;
		return *this;
	}
	Vector2 operator-( const Vector2& v )
	{
		Vector2 ret;
		ret.x = this->x - v.x;
		ret.y = this->y - v.y;
		return ret;
	}
	int clossProduct( const Vector2& v )
	{
		return static_cast<double>( this->x ) * v.y > static_cast<double>( this->y ) * v.x
			? 1 : -1;
	}

	int x, y;
};

bool solve()
{
	Vector2 coodi[ 5 ];
	for( int i = 0; i < 5; ++i ){
		Vector2 v;
		cin >> v.x >> v.y;
		coodi[ i ] = v;
	}
	int closs[ 2 ][ 3 ];
	for( int i = 0; i < 2; ++i ){
		Vector2& o = coodi[ 3 + i ];
		for( int j = 0; j < 3; ++j ){
			Vector2 v = coodi[ ( j + 1 ) % 3 ] - coodi[ j ];
			Vector2 w = o - coodi[ j ];
			closs[ i ][ j ] = v.clossProduct( w );
		}
	}
	for( int i = 0; i < 2; ++i ){
		int a = closs[ i ][ 0 ] * closs[ i ][ 1 ];
		int b = closs[ i ][ 1 ] * closs[ i ][ 2 ];
		int c = closs[ i ][ 2 ] * closs[ i ][ 0 ];
		closs[ i ][ 0 ] = a;
		closs[ i ][ 1 ] = b;
		closs[ i ][ 2 ] = c;
	}
	if( ( ( closs[ 0 ][ 0 ] > 0 && closs[ 0 ][ 1 ] > 0 && closs[ 0 ][ 2 ] > 0 )
		&& ( closs[ 1 ][ 0 ] < 0 || closs[ 1 ][ 1 ] < 0 || closs[ 1 ][ 2 ] < 0 ) )
		|| ( ( closs[ 0 ][ 0 ] < 0 || closs[ 0 ][ 1 ] < 0 || closs[ 0 ][ 2 ] < 0 )
		&& ( closs[ 1 ][ 0 ] > 0 && closs[ 1 ][ 1 ] > 0 && closs[ 1 ][ 2 ] > 0 ) ) ){
		return true;
	}
	return false;
}

int main()
{
	int n;
	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			if( solve() ){
				cout << "OK" << endl;
			}else{
				cout << "NG" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int n, x; cin >> n >> x;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans=1, sum=0;
    rep(i,n){
        sum += v[i];
        if(sum > x) break;
        ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X,Y; cin >> X >> Y;
    int Z=Y-2*X;
    int ok=1;
    if (Z<0||Z%2!=0) ok=0;
    int y=Z/2,x=X-y;
    if (x<0) ok=0;
    cout << (ok?"Yes":"No") << '\n';
}

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

#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#define int long long

void solve()
{
    int n;
    cin >> n;
    int a[n][2];
    for(int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1];
    for(int i = 1; i < n - 1; i++)
    {
        if(a[i][0] == a[i][1] && a[i - 1][0] == a[i - 1][1] && a[i + 1][0] == a[i + 1][1])
        {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
vector<long long> a;
int n;
long long Go(int from, int to, long long ca, long long cb) {
  if (to - from == 1) {
    return 0;
  }
  long long best;
  best = (long long) 1e18;
  for (int i = from + 1; i < to; i++) {
    long long cur = a[i] * (ca + cb) + Go(from, i, ca, ca + cb) + Go(i, to, ca + cb, cb);
    best = min(best, cur);
  }
  return best;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << Go(0, n - 1, 1, 1) + a[0] + a[n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int a = sc.nextInt();
                int b = sc.nextInt();
                int k = (int)Math.log10(b) + 1;
                a = (int)(a * Math.pow(10 , k) + b);
                double yono = Math.sqrt(a);
                if(yono - Math.ceil(yono) == 0){
                        System.out.println("Yes");
                }else{
                        System.out.println("No");
                }
        }
}
//腹痛は治りました
//今日はAtCoderをそんなにできそうにありません

Measured memory_bytes: 35868
A, B = map(int, input().split())
pal = [10001, 1010, 100]
count = 0

for i in range(1, 10):
    for j in range(10):
        for k in range(10):
            if A <= pal[0] * i + pal[1] * j + pal[2] * k <= B:
                count += 1
            else:
                continue

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
int a[200005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    int flag=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i+1])
        {
            flag=0;
            break;
        }
    }
    if(flag==1)
        puts("YES");
    else
        puts("NO");
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m;
    ll sum =0;
    cin >> n >> m;
    vector<pair<int, int>> vec(n);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        vec[i] = make_pair(a, b);
    }
    sort(all(vec));
    int i=0;
    while(m!=0){
        ll rest = min(vec[i].second, m);
        sum += vec[i].first * rest;
        m -= rest;
        i++;
    }
    out(sum);
    
}

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

long long solve(long long v)
{
    if( v % 2 == 0 )
         return 0;
    return v;
}

int main()
{
    long long x, y, z;
    std::cin >> x >> y >> z;
    long long int ans;
 
    ans = solve(x*y);
    ans = std::min(ans, solve(z*y)  );
    ans = std::min(ans, solve(x*z)  );
 
   std::cout << ans;
}

Measured memory_bytes: 256
/*
	DATE:		2020-03-02 18:38:57
	NAME:		
	PROBLEM:	ABC1257E
*/
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e5;
const int MAXQ = 2e4;

namespace BIT {
  int tree[MAXN + 7];

  void reset() {
    memset(tree, 0, sizeof tree);
  }

  void upd(int i, int k) {
    while (i < MAXN + 7) {
      tree[i] += k;
      i += i & (-i);
    }
  }

  int qry(int i) {
    int ans = 0;
    while (i > 0) {
      ans += tree[i];
      i -= i & (-i);
    }
    return ans;
  }

  int qryr(int l, int r) {
    if (l == 1) {
      return qry(r);
    }
    return qry(r) - qry(l - 1);
  }
};

char st[MAXN + 7];
char st2[MAXN + 7];

int ty[MAXQ + 7];
int id[MAXQ + 7];
char c[MAXQ + 7];
int l[MAXQ + 7];
int r[MAXQ + 7];
int ans[MAXQ + 7];

int main() {
  int tc = 1;
  // cin >> tc;

  for (int tci = 1; tci <= tc; tci++) {
    int n;
    scanf("%d\n", &n);

    scanf("%s", st + 1);

    int q;
    scanf("%d", &q);

    for (int qi = 1; qi <= q; qi++) {
      scanf("%d", &ty[qi]);
      if (ty[qi] == 1) {
        scanf("%d %c", &id[qi], &c[qi]);
      }
      else {
        scanf("%d %d", &l[qi], &r[qi]);
      }
    }

    for (char ch = 'a'; ch <= 'z'; ch++) {
      BIT::reset();
      for (int i = 1; i <= n; i++) {
        st2[i] = st[i];
        if (st2[i] == ch) {
          BIT::upd(i, 1);
        }
      }
      for (int qi = 1; qi <= q; qi++) {
        if (ty[qi] == 1) {
          if (st2[id[qi]] == ch) {
            BIT::upd(id[qi], -1);
          }
          st2[id[qi]] = c[qi];
          if (st2[id[qi]] == ch) {
            BIT::upd(id[qi], 1);
          }
        }
        else {
          ans[qi] += (BIT::qryr(l[qi], r[qi]) > 0);
        }
      }
    }

    for (int qi = 1; qi <= q; qi++) {
      if (ty[qi] == 2) {
        printf("%d\n", ans[qi]);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3584
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
ans = 10**18
for i, cumsum in enumerate(accumulate(a), start=1):
    if i==n:
        break
    sunuke = cumsum
    araiguma = total - cumsum
    ans = min(ans, abs(sunuke - araiguma))
    
print(ans)

Measured memory_bytes: 24176
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int w,h;
  int vx[4]={1,0,-1,0};
  int vy[4]={0,-1,0,1};
  while(cin>>w>>h,h+w){
    string str[h];
    for(int i=0;i<h;i++)cin>>str[i];
    bool Map[h][w];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	Map[i][j]=false;
    queue<pair<int,int> >que;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(str[i][j]=='@'){
	  que.push(mp(i,j));
	  Map[i][j]=true;
	}
      }
    }
    while(!que.empty()){
      pair<int,int>now=que.front();
      que.pop();
      //cout<<now.F<<" "<<now.S<<endl;
      for(int i=0;i<4;i++){
	if(now.S+vy[i]>=0&&now.S+vy[i]<w&&now.F+vx[i]>=0&&now.F+vx[i]<h&&(!Map[now.F+vx[i]][now.S+vy[i]])&&str[now.F+vx[i]][now.S+vy[i]]=='.'){
	  Map[now.F+vx[i]][now.S+vy[i]]=true;
	  que.push(mp(now.F+vx[i],now.S+vy[i]));
	}
      }
    }
    ll ans=0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(Map[i][j])
	  ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3056
import java.util.*;

class Main {
    static String[] strs = {
        "dream",
        "dreamer",
        "erase",
        "eraser"
    };
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        while (true) {
            boolean endsWithStr = false;
            for (String str: strs) {
                if (s.endsWith(str)) {
                    endsWithStr = true;
                    s = s.substring(0, s.length() - str.length());
                    break;
                }
            }
            if (!endsWithStr) {
                System.out.println("NO");
                break;
            }
            if (s.length() == 0) {
                System.out.println("YES");
                break;
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 56388
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int sum = 0;
	for (auto& x : A) {
		cin >> x;
		sum += x;
	}
	vector<pair<int,int>> a;
	for (int i = 0; i < N; ++ i) {
		a.push_back({abs(N*A[i] - sum), i});
	}
	sort(a.begin(), a.end());
	cout << a[0].second << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N;
    long long int mul=0;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        if(i%3==0 || i%5==0)
            continue;
        mul=mul+i;
    }
    printf("%ld",mul);
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll n;
    cin >> n;
    auto A = InputVec(n);
    deque<ll> B;
    for (int i = 0; i < n; ++i) {
        if(i % 2 == 0){

            B.push_back(A[i]);
        }else{
            B.push_front(A[i]);
        }
    }
    if(n%2==0){
        for (int i = 0; i < n; ++i) {
            cout << B[i] << " ";
        }
    }else{
        for (int i = 0; i < n; ++i) {
            cout << B[n-1-i] << " ";
        }
    }
    cout << endl;
}


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

using namespace std;

const int mod=1e9+7;

int tax[26];

string s;

int main()
{
    int n;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        tax[s[i]-'a']++;
    }
    int ans=1;
    for(int i=0;i<26;i++)
    {
        ans=1ll*ans*(tax[i]+1)%mod;
    }
    cout<<ans-1<<'\n';
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>
#include <queue>

using namespace std;
typedef long long int ll;

int main(){

    ll N, M;
    cin >> N >> M;
    vector<double > A(N);
    priority_queue<ll > que;
    for(ll i = 0; i < N; i++){
        cin >> A[i];
        que.push(A[i]);
        
    }

    
    sort(A.rbegin(), A.rend());

    while(M > 0){
        double price = floor( que.top() / 2);
        que.pop();
        M--;
        que.push(price);
    }

    //合計
    ll sum = 0;
    while(!que.empty()){
        sum += que.top();
        que.pop();
    }

    cout << sum << endl;

} 

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

struct BipartiteMatching {
  vector<vector<int>> graph;
  vector<int> match,used;
 
  BipartiteMatching(int n):graph(n),used(n, 0),match(n, -1){}
 
  void add_edge(int u,int v){
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
 
  bool dfs(int now){
    used[now]=1;
    for(auto to:graph[now]){
      int to_match=match[to];
      if(to_match==-1||(!used[to_match]&&dfs(to_match))){
        match[now]=to;
        match[to]=now;
        return true;
      }
    }
    return false;
  }
 
  int bipartite_matching(){
    int res=0;
    for(int i=0;i<graph.size();i++){
      if(match[i]==-1){
        for(int j=0;j<graph.size();j++) used[j]=0;
        if(dfs(i)) res++;
      }
    }
    return res;
  }
};

int N,M;
int A[101][101];

set<int> se[101];
int B[101][101];
int C[101][101];

void solve(int col){
  BipartiteMatching BG(2*N+1);
  for(int i=0;i<N;i++){
    vector<int> used(N+1,0);
    for(auto val:se[i]){
      int t=(val-1)/M;
      if(used[t]) continue;
      used[t]=true;
      BG.add_edge(i,N+t);
    }
  }

  int m=BG.bipartite_matching();

  for(int i=0;i<N;i++){
    int tar=BG.match[i]-N;
    auto itr=se[i].lower_bound(tar*M+1);

    B[i][col]=*itr;
    se[i].erase(itr);
  }
  return;
}


int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>A[i][j];
      se[i].insert(A[i][j]);
    }
  }

  for(int i=0;i<M;i++) solve(i);

  for(int i=0;i<M;i++){
    vector<int> v;
    for(int j=0;j<N;j++) v.push_back(B[j][i]);
    sort(v.begin(),v.end());
    for(int j=0;j<N;j++) C[j][i]=v[j];
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++) cout<<B[i][j]<<" ";
    cout<<endl;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++) cout<<C[i][j]<<" ";
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())

S = []
for i in range(M):
    s = list(map(int, input().split()))
    S.append(s)

P = list(map(int, input().split()))

count = 0
for i in range(2**N):
    switch = []
    for j in range(N):
        if ((i >> j) & 1):
            switch.append(j+1)
    #print(switch)
    c = 0
    for m in range(M):
        S_ = S[m]
        c_ = 0
        for s_ in range(1, S_[0]+1):
            if S_[s_] in switch:
                c_ += 1
        if c_ % 2 == P[m]:
            c += 1
    if c == M:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

int N;

void childs(int num, vi &child){
    int row = num / N;
    int col = num % N;
    if(row > 0){
        child.pb((row - 1)* N + col);
    }
    if(row < N - 1){
        child.pb((row + 1) * N + col);
    }
    if(col > 0){
        child.pb(row * N + col - 1);
    }
    if(col < N - 1){
        child.pb(row * N + col + 1);
    }
}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    cin >> N;
    int n2 = N * N;
    vi perm(n2);
    rep(i, n2){
        cin >> perm[i];
        perm[i]--;
    }

    vi paths(n2);
    rep(i, n2){
        int row = i / N;
        int col = i % N;
        paths[i] = min({row, N - 1 - row, col, N - 1 - col});
    }

    int ans = 0;
    vi vals(n2, 1);

    queue<int> q;
    for(auto p : perm){
        ans += paths[p];
        vals[p] = 0;
        q.push(p);
        while(!q.empty()){
            int x = q.front();
            q.pop();
            vi child;
            childs(x, child);
            for(auto c : child){
                if(paths[c] > vals[x] + paths[x]){
                    paths[c] = vals[x] + paths[x];
                    q.push(c);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8988
from itertools import accumulate

n = int(input())
acc = [0] + list(accumulate(map(int, input().split())))
dp = [[0] * (n + 1) for _ in range(n)]
for w in range(2, n + 1):
    for l in range(n - w + 1):
        r = l + w
        dp[l][r] = min(dp[l][m] + dp[m][r] for m in range(l + 1, r)) + acc[r] - acc[l]
print(dp[0][n])


Measured memory_bytes: 44892
N, Q = map(int, input().split())
ss = '#' + input() + '#'
tds = [tuple(input().split()) for _ in range(Q)]

# 左端
iL = 0
for t, d in reversed(tds):
    if t == ss[iL] and d == 'R':
        iL -= 1
    if t == ss[iL+1] and d == 'L':
        iL += 1
    if iL == N:
        break

# 右端
iR = N+1
for t, d in reversed(tds):
    if t == ss[iR] and d == 'L':
        iR += 1
    if t == ss[iR-1] and d == 'R':
        iR -= 1
    if iR == 1:
        break

ans = N - min(N, iL+N+1-iR)
print(ans)


Measured memory_bytes: 95788
import math

n,d = map(int,input().split())
points = []
ans = 0
for i in range(n):
    point = list(map(int,input().split()))
    points.append(point)


for i,pi in enumerate(points):
    if i==n-1:
        break
    for pj in points[i+1:]:
        distance = math.sqrt(sum([(x-y)**2 for x,y in zip(pi,pj)]))
        if distance%1==0:
            ans +=1
print(ans)
            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main() {
    int ans = 0;
    string s;
    cin >> s;
    int l = 0,r = s.size()-1;
    while(1){
        if(l == r) break;
        if(s[l] == s[r] && r-l == 1) break;
        else if(s[l] == s[r]){
            l++;
            r--;
        }else if(s[l] != s[r] && s[l] == 'x'){
            l++;
            ans++;
        }else if(s[l] != s[r] && s[r] == 'x'){
            r--;
            ans++;
        }else if(s[l] != s[r] && s[r] != 'x' && s[l] != 'x'){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
from collections import defaultdict


def main():
    N = int(input())
    S = input()
    x = 0
    ans = 0
    for s in S:
        if s == "I":
            x += 1
        else:
            x -= 1
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LLINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll n; cin >> n;
	if (n % 2)
		cout << n * 2;
	else
		cout << n;
}

Measured memory_bytes: 256
n = gets.to_i
S = gets.chomp

r = 0
g = 0
b = 0
(n).times do |i|
  r += 1 if S[i] == "R"
  g += 1 if S[i] == "G"
  b += 1 if S[i] == "B"
end


sum = r * g * b

(n).times do |i|
	((i+1)..(n)).each do |j|
      k = (j-i) + j
      break if k >= n
      sum -= 1 if S[i] != S[j] && S[j] != S[k] && S[i] != S[k]
    end
end
puts sum

Measured memory_bytes: 14392
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    repp(i,0,N) cin >> A[i];
    repp(i,0,N) cin >> B[i];
    repp(i,0,N-1) cin >> C[i];
    int ans = 0;

    repp(i,0,N) {
        ans += B[A[i]-1];
        if (i > 0 && A[i] - A[i-1] == 1) {
            ans += C[A[i-1]-1];
        }
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    Graph G(N);
    for (int i = 0; i < N; ++i) {
        int u, k;
        cin >> u >> k;
        --u;
        for (int i = 0; i < k; ++i) {
            int v;
            cin >> v;
            --v;
            G[u].push_back(v);
        }
    }
    vector<int> dist(N, -1);
    dist[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        auto q = que.front(); que.pop();
        for (auto&& nq : G[q]) {
            if (dist[nq] != -1) continue;
            dist[nq] = dist[q] + 1;
            que.push(nq);
        }
    }
    for (int i = 0; i < N; ++i)  cout << i+1 << " " << dist[i] << endl;
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main() {
    #ifndef ONLINE_JUDGE
	// freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> nums(n);
    vector<ll> count(n);
    for_(i, 0, n) {
        cin >> nums[i];
        nums[i] -= 1;
        count[nums[i]] += 1;
    }

    ll total = 0;
    for (ll i: count)  {
        if (i > 1) total += (i*(i-1))/2;
    }

    vector<ll> red(n);
    for_(i, 0, n) {
        red[i] = count[i] - 1;
    }

    for_(i, 0, n) {
        cout << (ll) total - (ll) red[nums[i]] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 7296
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = scan.nextInt();
		scan.close();
		long sum = 0;
		int max = a[0];
		for(int i = 1 ; i < n ; i++) {
			if(a[i] < max) sum+= (max - a[i]);
			else max = a[i];
		}
		System.out.println(sum);
	}
}


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

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;


int main()
{
    lli n;
    cin >>n;
    lli sum = (n*(n+1))/2;
    lli x = n/3;
    x = (x*(x+1))/2;
    x *= 3;
    sum -= x;
    x = n/5;
    x = (x*(x+1))/2;
    x *= 5;
    sum -= x;
    x = n/15;
    x = (x*(x+1))/2;
    x *= 15;
    sum += x;

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


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-15
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll dp[1010];
int N;
vector<int> g[1010];
int X[1010];
int dp2[1010][5010];
int rec(int v){
	ll sum = 0;
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		if(rec(u)==-1)return -1;
		sum += (ll)(X[u]+dp[u]);
	}
	for(int i=0;i<=g[v].size();i++){
		for(int j=0;j<=5000;j++){
			dp2[i][j]=0;
		}
	}
	dp2[0][0]=1;
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		for(int j=0;j<=5000;j++){
			if(j>=X[u]&&dp2[i][j-X[u]]==1)dp2[i+1][j]=1;
			if(j>=dp[u]&&dp2[i][j-dp[u]]==1)dp2[i+1][j]=1;
		}
	}
	int ret = -1;
	for(int i=0;i<=X[v];i++)if(dp2[(int)g[v].size()][i]==1)ret=i;
	if(ret==-1){
		return -1;
	}
	return dp[v]=sum-ret;
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<N;i++){
		int par;
		scanf("%d",&par);
		par--;
		g[par].pb(i); 
	}
	for(int i=0;i<N;i++)scanf("%d",&X[i]);
	//for(int i=N-1;i>=0;i--)cout << rec(i) << endl;
	if(rec(0)==-1)printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 19840
from numpy import int_

mod = 10 ** 9 + 7

N, K = map(int, input().split())

M = int(N ** 0.5)

T = [N // i - N // (i + 1) for i in range(1, M + 1)]
A = int_([1] * (N - sum(T)) + T[::-1])

dp = A[:]
for _ in range(K - 1):
    dp = A * dp.cumsum()[::-1] % mod

print(dp.sum() % mod)

Measured memory_bytes: 14684