akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> rational;

const ll MOD=1000000007;

//最大公約数
ll gcd(ll a,ll b){
    if (b==0) return a;
    return gcd(b,a%b);
}

ll sign(ll a){ 
    if (a>=0) return 1;
    return -1;
}

rational mk_rational(ll a,ll b){
    auto absa=abs(a),absb=abs(b);
    auto common_part=gcd(absa,absb);
    if (!common_part) return rational(0,0);

    if (b==0) return rational(1,0);

    auto sig=sign(a)*sign(b);

    return rational(sig*(absa/common_part),absb/common_part);
}

rational inverse_invert(const rational& a){
    if (a==rational(0,1)) return rational(1,0);
    auto denominator=a.second,numerator=a.first;
    return rational(-1*sign(numerator)*denominator,abs(numerator));
}

ll power_of_2(int exp){
    if (exp==0) return 1;
    if (exp==1) return 2;
    auto temp=power_of_2(exp/2);
    if (exp%2) return (((2*temp)%MOD)*temp)%MOD;
    else return (temp*temp)%MOD;
}

int main(){
    int N;
    map<rational,int> m; 
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        ll A,B;
        scanf("%lld%lld",&A,&B);
        m[mk_rational(A,B)]++;
    }

    ll ans=1ll;

    auto special=m.find(mk_rational(0,0));
    ll compen=special==m.end()?0:special->second;
    if (special!=m.end()) m.erase(special);
    for(auto &ele:m){
        auto key=ele.first;
        auto count=ele.second;
        // printf("key=%lld %lld\n",key.first,key.second);
        // printf("count=%d\n",count);
        ll contrib=power_of_2(count);
        auto other=m.find(inverse_invert(key));

        if (other!=m.end()){
            contrib=((contrib+power_of_2(other->second))%MOD+(MOD-1))%MOD;
            m.erase(other);
        }

        ans=(ans*contrib)%MOD;
    }

    ans=((ans+compen)%MOD+(MOD-1))%MOD;

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 15752
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    pair<int,int> jobs[200001];
    for (int i = 0; i < n; i++) {
        std::cin >> jobs[i].second >>jobs[i].first; 
    }
    //ソート
    sort(jobs, jobs+n);

    //締め切りの早いものから順番に基準を満たすかチェック
    int timesum=0;
    bool flag=true;
    for (int i = 0; i < n; i++) {
        timesum+=jobs[i].second;
        if(timesum>jobs[i].first){
            flag=false;
            break;
        }
    }
    if(flag){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 1792
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())
    L = len(N)

    # dp[i][j][k]
    # i 桁目まで決めて
    # j 個の非0を使って
    # k = 0 : そこまでの桁はNと一致
    # k = 1 : そこまでの桁でN未満であることが確定
    dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)]
    dp[0][0][0] = 1

    from pprint import pprint
    for i, x in enumerate(N):
        for k in range(K + 1):
            # 桁ごと数え上げ
            if x == 0:
                # x == 0
                dp[i + 1][k][0] += dp[i][k][0]
            else:
                # x == 0
                dp[i + 1][k][1] += dp[i][k][0]
                # 0 < n < x
                dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1)
                # n == x
                dp[i + 1][k + 1][0] += dp[i][k][0]
            # N未満で次の桁に1~9を入れる
            dp[i + 1][k + 1][1] += dp[i][k][1] * 9
            # N未満で次の桁に0を入れる
            dp[i + 1][k][1] += dp[i][k][1]

    print(sum(dp[L][K]))  

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff  first
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 1e5+9;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///

void solve()
{
    int a,b;cin>>a>>b;
    if(a==1)a+=100;
    if(b==1)b+=100;
    if(a>b)cout<<"Alice\n";
    else if(b>a)cout<<"Bob\n";
    else cout<<"Draw\n";


}
int main()
{
    FAST;
    //int tc=1;cin>>tc;while(tc--)solve();
    solve();
}



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

#define int long long 

const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int temp = n;
	int dig = 0;
	while(n)
	{
		++dig;
		n/=10;
	}
	
	int ans = 0;
	
	while(dig)
	{
		if(dig&1)
		{
			ans += (temp - pow(10,dig-1) + 1);
		}
		
		temp = pow(10,dig - 1) - 1;
		dig--;
	}
	
	cout << ans;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

vector<vector<ll>> graph;
vector<ll> depth;
void dfs(ll i, ll v) {
    if (depth[i] != -1) return;
    depth[i] = v;
    for (ll e : graph[i]) {
        dfs(e, v+1);
    }
}

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

    ll N;
    cin >> N;
    graph.assign(N, vector<ll>(N));
    depth.assign(N, -1);
    Rep (i, N-1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> c(N);
    ll M = 0;
    Rep (i, N) {
        cin >> c[i];
        
        M += c[i];
    }
    sort(c.begin(), c.end());
    M -= c.back();
    cout << M << "\n";

    dfs(0, 0);
    // Rep (i, N) {
    //     cout << depth[i] << "\n";
    // }

    set<pair<ll, ll>> ans;
    Rep (i, N) {
        ans.insert(make_pair(-depth[i], i));
    }

    vector<ll> output(N);
    ll i = 0;
    for (auto e : ans) {
        output[e.second] = c[i];
        i++;
    }

    for (ll e : output) {
        cout << e << " ";
    }

    cout << endl;
}

Measured memory_bytes: 636672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int count = 0;
		
		String s = stdIn.next();
		
		for(int i = 0; i < 3; i++)
		{
			if(s.charAt(i) == 'o')
			{
				count++;
			}
		}
		
		System.out.println(700 + count * 100);

	}

}


Measured memory_bytes: 35532
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int solve(int n) {
	int res = 0;
	while (n) {
		res += n % 10;
		n /= 10;
	}
	return res;
}

int main() {
	int N, a, b;
	int ans = 0;

	cin >> N >> a >> b;

	for (int i = 1; i <= N; i++) {
		int n = solve(i);
		if (a <= n && n <= b)ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char arr[100500];
int main()
{
    int n,d=1,i;
    char brr[200];
    brr[65] = 'A';
    for(int i = 66;i<91;i++)
       {
            brr[i] = 'A'+d;
            d++;
       }

    cin>>n;
    scanf("%s",arr);
    for(i =0;arr[i] != '\0';i++)
    {
        d = arr[i] +n;
        if(d>90)
        {
            d -=26;
        }
        cout<<brr[d];

    }
    cout<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


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

    int n, k;
    cin >> n >> k;

    vector<int> a(n+1), visited(n+1);

    int cnt = 0;

    reps(i,1,n){
        cin >> a[i];
    }

    int now = 1, t;
    reps(i,1,INF){
        if(visited[now]){
            t = i;
            break;
        }
        visited[now] = i;
        now = a[now];
        ++cnt;
    }

    if(k <= n + 5){
        now = 1;
        rep(i,k){
            now = a[now];
        }
        cout << now << '\n';
    }else{
        k -= visited[now] - 1;
        vector<bool> v(n+1);
        cnt = 1;
        v[now] = true;
        int tmp = now;
        reps(i,1,INF){
            if(v[a[now]]) break;
            now = a[now];
            v[now] = true;
            ++cnt;
        }
        k %= cnt;
        now = tmp;
        rep(i,k){
            now = a[now];
        }
        cout << now << '\n';
    }

    return 0;
}

Measured memory_bytes: 6368
n, a, b = map(int, input().split())
p = 10**9+7

max_r = b

# nCrでnがでかすぎる時は直接計算した方がいい
# 1<=n<=10**9, 1<=k<=10**7くらいのとき

def make_inv(m,p): # 必要なところnCkのkまでの逆元を作る
    inv = [0, 1] + [0] * m # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる
    for i in range(2, m+2):
        inv[i] = -inv[p % i] * (p // i) % p
    return inv

inv = make_inv(max_r+3,p)

def NCr_mod_p(N, r, p):
    ret = 1
    for i in range(r):
        ret *= (N-i)%p
        ret *= inv[i+1]
        ret %= p
    return ret

ans = pow(2,n,p) - 1 - NCr_mod_p(n,a,p) - NCr_mod_p(n,b,p)
print(ans%p)

Measured memory_bytes: 10840
#include <stdio.h>
int main(){
  int n, m, a, sum = 0;
  scanf("%d %d", &n, &m);
  for(int i = 0; i < m; i++){
      scanf("%d", &a);
    //   printf("%d", a);
      sum += a;
  }
//   printf("%d",sum);
  if((n - sum) >= 0) printf("%d", n - sum);
  else printf("-1");
}

Measured memory_bytes: 1732
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e9+7 ;
ll fact(ll x, ll y){
    ll f=1,i=1;
    while(i<=y){
        f=( (f%M) * (x%M) )%M;
        i++;
    }
    return f;
}
int main()
{
    ll n,i,cnt=0,x,y,j;
    cin>>n;
    for(i=1;i<n;i++){
       for(j=1;i*j<n;j++)
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}




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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

char to_lower(char c){
    ll diff = 'A' - 'a';
    return c - diff;
}

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

    // input
    ll N, K;
    cin >> N >> K;

    // メモリ確保テスト
    int dp[1000][1000];
    // 32bit * 1000000 = 4000KB増えるはず

    string s;
    cin >> s;

    s[K-1] = to_lower(s[K-1]);
    p(s);
        
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef vector<bool> vec;
typedef vector<vec> mat;

mat operator*(const mat &A, const mat &B) {
	mat C(A.size(), vec(B[0].size(), 0));
	for(unsigned i = 0; i < A.size(); ++i) {
		for(unsigned j = 0; j < B[0].size(); ++j) {
			for(unsigned k = 0; k < B.size(); ++k) {
				C[i][j] = (C[i][j] | (A[i][k] & B[k][j]));
			}
		}
	}
	return C;
}

mat pow(mat A, int k) {
	const int n = A.size();
	mat B(n, vec(n, false));
	for(int i = 0; i < n; ++i) B[i][i] = true;

	while(k > 0) {
		if(k & 1) B = B * A;
		A = A * A;
		k >>= 1;
	}
	return B;
}

map<pair<int, int>, int> enc;
int encode(const pair<int, int> &p) {
	if(!enc.count(p)) enc.insert(make_pair(p, enc.size()));
	return enc[p];
}

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

	for(int n, m, z; cin >> n >> m >> z && n;) {
		enc.clear();
		const int start = encode({0, -1});

		mat adj(n, vec(n, false));
		while(m--) {
			int u, v;
			cin >> u >> v;
			--u; --v;
			adj[u][v] = adj[v][u] = true;
			encode({u, v});
			encode({v, u});
		}

		const int size = enc.size();
		mat A(size, vec(size, false));

		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				if(adj[i][j]) {
					if(i == 0) A[start][encode({j, 0})] = true;
					const int from = encode({i, j});
					for(int k = 0; k < n; ++k) {
						if(adj[i][k] && j != k) {
							A[from][encode({k, i})] = true;
						}
					}
				}
			}
		}

		A = pow(move(A), z);
		bool ok = false;
		for(int i = 0; i < n; ++i) {
			if(adj[i][n - 1] && A[start][encode({n - 1, i})]) {
			    ok = true;
				break;
			}
		}

		cout << (ok ? "yes" : "no") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
typedef long long int ll;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("o.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    if(n%k==0) cout<<0;
    else cout<<1;
    return 0;
}


Measured memory_bytes: 256
import math
def factorial(x):
    max_num = int(2 * (10 ** 9) ** (1 / 5))
    for a in range(-1 * max_num, max_num):
        for b in range(-1 * max_num, max_num):
            check = math.pow(a, 5) - math.pow(b, 5)
            if check == x:
                return f'{a} {b}'


x = int(input())
print(factorial(x))

Measured memory_bytes: 9368
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int i, j, k;
char s[200010];
int f[200010][2];
int main(){
    int n, m;
    cin >> s;
    n = strlen(s)-1;
    f[0][0] = 1;
    f[0][1] = 0;
    for(i = 1; i <= n; ++i){
        if(s[i] != s[i-1])f[i][0] = max(f[i-1][0], f[i-1][1])+1;
        else f[i][0] = f[i-1][1] + 1;
        if(i>2&&s[i] == s[i-2] && s[i-1] == s[i-3])f[i][1] = f[i-2][0]+1;
        else f[i][1] = max(f[i-2][0], f[i-2][1])+1;
    }
    cout << max(f[n][1], f[n][0]) << endl;
    return 0;
}

Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        for (int x = in.nextInt(), y = in.nextInt();
                x != 0 || y != 0;
                x = in.nextInt(), y = in.nextInt()) {
            int a = x < y ? x : y, b = x < y ? y : x;
            System.out.printf("%d %d\n", a, b);
        }
    }
}

Measured memory_bytes: 40728
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  vector<ll> B(N);
  for(ll i=0;i<N;i++){
    cin>>A.at(i)>>B.at(i);
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(N%2==1){
    ll a=(ll)B.at((N-1)/2)-(ll)A.at((N-1)/2)+(ll)1;
    ll b=(ll)A.at((N-1)/2)-(ll)B.at((N-1)/2)+(ll)1;
    cout<<max(a,b)<<endl;
  }
  if(N%2==0){
    ll a=(ll)B.at(N/2)+(ll)B.at(N/2-1)-((ll)A.at(N/2)+(ll)A.at(N/2-1))+(ll)1;
    ll b=(ll)A.at(N/2)+(ll)A.at(N/2-1)-((ll)B.at(N/2)+(ll)B.at(N/2-1))+(ll)1;
    cout<<max(a,b);
  }
}

Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> node[200005];
bool vis[200005];
int val[200005];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<node[x].size();i++)
    {
        int y=node[x][i];
        if(vis[y]==0)
        {
            val[y] += val[x];
            dfs(y);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,q;
    cin>>n>>q;
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        node[x].push_back(y);
        node[y].push_back(x);
    }
    for(int i=0;i<q;i++)
    {
        int x,y;
        cin>>x>>y;
        val[x] += y;
    }
    dfs(1);
    for(int i=1;i<=n;i++)
    {
        cout<<val[i]<<" ";
    }
    cout<<endl;
    return 0;
}


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

def isprime(num):
    if num == 1:
        return False
    if num == 2:
        return True
    elif num == 3:
        return True
    elif num % 2 == 0:
        return False
    elif num % 3 == 0:
        return False
    else:
        for i in range(5, int(num ** (1/2))+1):
            if num % i == 0:
                return False
                break
        return True

def prime_factor(num, prime_dict):
    if num == 1:
        return prime_dict
    if isprime(num):
        prime_dict[num] += 1
        return prime_dict
    if num % 2 == 0:
        prime_dict[2] += 1
        return prime_factor(num // 2, prime_dict)
    elif num % 3 == 0:
        prime_dict[3] += 1
        return prime_factor(num // 3, prime_dict)
    else:
        for i in range(5, int(num ** (1/2))+1):
            if num % i == 0:
                prime_dict[i] += 1
                return prime_factor(num // i, prime_dict)

prime_dict = {}
for i in range(1, n+1):
    if isprime(i):
        prime_dict[i] = 0

for i in range(1, n+1):
    prime_dict = prime_factor(i, prime_dict)

result = 1
for value in prime_dict.values():
    result *= value+1
    if result > 1000000007:
        result = divmod(result, 1000000007)[1]

print(result)

Measured memory_bytes: 3064
x, y = gets.chomp.split(" ").map(&:to_i)
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if a.include?(x) && a.include?(y)
    puts "Yes"
elsif b.include?(x) && b.include?(y)
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 14188
/*input
30 -50
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> v;


bool cmp(int a,int b){
	return abs(a)<abs(b);
}
int main(){
	IOS;
	int n,l;
	cin>>n>>l;
	REP(i,n) v.pb(l+i);

	sort(ALL(v),cmp);
	int ans=0;
	for(int i=1;i<n;i++) ans+=v[i];
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 256
import math
# import bisect
import sys
# from collections import Counter
input = sys.stdin.readline
def inp():
	return(int(input()))
def inlt():
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(s[:len(s)-1])
def invr():
	return(map(int,input().split()))
def print_fract(p,q):
	g = math.gcd(p,q)
	p//=g
	q//=g
	print(str(p)+"/"+str(q))
# list1, list2 = zip(*sorted(zip(list1, list2)))
# K = inp()
# if K%2 == 0 or K%5 == 0:
# 	print(-1)
# else:
# 	i = 7
# 	while True:
# 		if len(str(i)) == 999982:
# 			break
# 		if i%K == 0:
# 			print(len(str(i)))
# 			break
# 		i = (10*i) + 7
# 777777777777
N = inp()
S = insr()
print(S[:S.count("R")].count("W"))


Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
 
char c[53][53];
int H, W, judge;
 
int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') judge = 1;
		}
	}
	if (judge == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define MOD 1000000007

typedef long long ll;

string s;
ll dp[111111][13], cycle[6] = {1, 10, 9, 12, 3, 4};
/* Find about "cycle" in "https://en.wikipedia.org/wiki/Divisibility_rule#Divisibility_by_13" */

int main(void)
{
	ll i, j, k;

	cin >> s;

	dp[s.size()][0] = 1;
	for (i = s.size() - 1; i >= 0; i--)
		if (s[i] != '?')
		{
			ll rmd = (s[i] - '0') * cycle[(s.size() - 1 - i) % 6] % 13;

			for (k = 0; k < 13; k++)
			{
				ll now = (k + rmd) % 13;
				dp[i][now] = (dp[i][now] + dp[i + 1][k]) % MOD;
			}
		}
		else
		{
			for (j = 0; j < 10; j++)
			{
				ll rmd = j * cycle[(s.size() - 1 - i) % 6] % 13;

				for (k = 0; k < 13; k++)
				{
					ll now = (k + rmd) % 13;
					dp[i][now] = (dp[i][now] + dp[i + 1][k]) % MOD;
				}
			}
		}

	cout << dp[0][5];
	return 0;
}

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

typedef long long ll;

void solve() {
    int N, W, w, v, w1;
    cin >> N >> W;
    vector<int> vs[4];
    cin >> w1 >> v;
    vs[0].push_back(v);
    rep(i, N - 1) {
        cin >> w >> v;
        vs[w - w1].push_back(v);
    }
    vector<int> s[4];
    rep(i, 4) {
        s[i].push_back(0);
        sort(vs[i].begin(), vs[i].end());
        rep(j, vs[i].size()) s[i].push_back(s[i][j] + vs[i][vs[i].size() - j - 1]);
    }
    int ans = 0;
    rep(i, N + 1) {
        if (i > vs[0].size()) break;
        if (i * w1 > W) break;
        int s0 = s[0][i];
        rep(j, N + 1 - i) {
            if (j > vs[1].size()) break;
            if (i * w1 + j * (w1 + 1) > W) break;
            int s1 = s0;
            s1 += s[1][j];
            rep(k, N + 1 - i - j) {
                if (k > vs[2].size()) break;
                if (i * w1 + j * (w1 + 1) + k * (w1 + 2) > W) break;
                int s2 = s1;
                s2 += s[2][k];
                rep(l, N + 1 - i - j - k) {
                    if (l > vs[3].size()) break;
                    if (i * w1 + j * (w1 + 1) + k * (w1 + 2) + l * (w1 + 3) > W) break;
                    int s3 = s2;
                    s3 += s[3][l];
                    ans = max(ans, s3);
                }
            }
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b, c;

signed main() {
	cin >> a >> b >> c;
	if (a + b + c < 22)cout << "win" << endl;
	else cout << "bust" << endl;
}

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

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a = 0;
    cin >> a;
    ans += a - 1;
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int h, w, k;
int a[3010][3010];
ll d[3010][3010][4];

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> h >> w >> k;
	for (int i = 0; i < k; i++) {
		int r, c, v; cin >> r >> c >> v;
		a[r][c] = v;
	}
	for (int i = 1; i <= h; i++)for (int j = 1; j <= w; j++) {
		for (int l = 0; l <= 3; l++)d[i][j][l] = d[i][j - 1][l];
		for (int l = 1; l <= 3; l++)d[i][j][l] = max(d[i][j][l], d[i][j - 1][l - 1] + a[i][j]);
		d[i][j][0] = max(d[i][j][0], max({ d[i - 1][j][0], d[i - 1][j][1], d[i - 1][j][2], d[i - 1][j][3] }));
		d[i][j][1] = max(d[i][j][1], max({ d[i - 1][j][0], d[i - 1][j][1], d[i - 1][j][2], d[i - 1][j][3] }) + a[i][j]);
	}
	ll ans = 0;
	for (int l = 0; l <= 3; l++)ans = max(ans, d[h][w][l]);
	cout << ans << endl;
}


Measured memory_bytes: 321040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c, d;
ll gcd(ll x, ll y){
  if(y == 0)  return x;
  return gcd(y, x%y);
}
int main(){
  cin >> a >> b >> c >> d;
  ll ss = gcd(c,d);
  ll lcm = (c/ss) * d;
  ll P = b - (b/c + b/d - b/lcm);
  ll Q = a - 1 - ((a-1)/c + (a-1)/d - (a-1)/lcm);
  cout << P - Q << endl;
  return 0;
}


Measured memory_bytes: 256
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 c = sc.nextInt();
        int d = sc.nextInt();
        
        if(a * b >= c * d){
            System.out.println(a * b);
        }else{
            System.out.println(c * d);
        }
    }
}

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


int main(){
	int n;
	cin>>n;
	vector<int> d(n);
	set<int> s;
	for(int i=0;i<n;i++){
		cin>>d[i];	}
	vector<int> res;
	for(int i=0;i<n;i++){
		int tmp=0;
		for(int j=0;j<5&&i+j<n;j++){
			tmp*=10;
			tmp+=d[i+j];
			//res.push_back(tmp);
			s.insert(tmp);
		}
	}
	//sort(res.begin(),res.end());
	for(int i=0;i<s.size();i++){
		auto it = s.find(i);
		if(it == s.end()){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}



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

const int INF=-1000000;
typedef long long ll;
typedef pair<int,int> P;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int sx,sy,gx,gy;
char s[30][30];
int d[30][30];
int H,W;

int bfs(){
	queue<P>que;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++)d[i][j]=INF;
	}
	que.push(P(sx,sy));
	d[sx][sy]=0;
	while(que.size()){
		P p=que.front();que.pop();
		if(p.first==gx&&p.second==gy)break;
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i],ny=p.second+dy[i];
			if(0<=nx&&nx<H&&0<=ny&&ny<W&&s[nx][ny]!='#'&&d[nx][ny]==INF){
				que.push(P(nx,ny));
				d[nx][ny]=d[p.first][p.second]+1;
			}
		}
	}
	return d[gx][gy];
}

int main(){
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>s[i][j];
		}
	}	
	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(s[i][j]!='#')sx=i,sy=j;
			for(int k=0;k<H;k++){
				for(int l=0;l<W;l++){
					if(s[k][l]!='#'&&(!(k==sx&&l==sy))){
						gx=k,gy=l;
						ans=max(bfs(),ans);
					}
				}
			}			
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    int N , M , X , Y;
    cin >> N >> M;
    vector V(N , 1) , B(N , 0);
    B.at(0) = 1;
    while(cin >> X >> Y){
        V.at(--X)--, V.at(--Y)++;
        if(B.at(X)){
            B.at(Y) = 1;
        }
        if(!V.at(X)){
            B.at(X) = 0;
        }
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        count += V.at(i) && B.at(i);
    }
    cout << count << "\n";
}

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

using namespace std;

using ll = long long;

int main(void) {
	int k;
	scanf("%d", &k);
	int a, b;
	scanf("%d %d", &a, &b);
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			puts("OK");
			return 0;
		}
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var a = ReadSplitInt().Sum();
            if (a >= 10)
                Println("error");
            else
                Println(a);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e)
        {
            if (e) Println("YES");
            else Println("NO");
        }

        static void YesOrNo(bool e)
        {
            if (e) Println("Yes");
            else Println("No");
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<numeric>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int A, B, C;	cin >> A >> B >> C;
	cout << min(B / A, C) << endl;
	cin >> A;
}

Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
int n;
  cin>>n;
  ll ret = 0;
  for(int i=1;i<n;i++){
    int m = n - i;
    for(int j=1;j*j<=m;j++){
      if(m%j!=0)continue;
      ret++;
      if(j*j<m)ret++;
    }
  }
  cout<<ret<<endl;
  return 0;
}


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

int main() {
 int N;cin >> N;
 vector<int> h(N);
 for (int i = 0; i < N; ++i) cin >> h[i];
  
  // 高さが全部 0 になるまでやる
  int res = 0;
  while(true){
     // 最高高さが 0 だったらおしまい
    if(*max_element(h.begin(),h.end()) == 0) break;
    
    // 区間分割する
    int i =0;
    while(i<N){
      if(h[i] == 0) i++;// 0 なら何もせずに次に進む
      else{
        res++;// 区間の始まり
        while(i <N && h[i] > 0){
          h[i]--;
          i++;// 区間の終わりまで一気に
        }
      }
    }
  }
   cout << res << endl;  
      
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
    ll N,Q,K;
    vector<edge> G[100010];
    ll d[100010];
    ll ans=0;
//辺がたかだかN-1本なので、
void dijkstra(int s){
    std::priority_queue<P,vector<P>,std::greater<P>> que;
    std::fill(d,d+N,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){

        P p =que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<(signed)G[v].size();i++){
            edge e =G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N-1){
        int a,b,c;
        DEB(i)END
        cin>>a>>b>>c;
        edge e;
        e.to=b-1;e.cost=c;
        G[a-1].push_back(e);
        e.to=a-1;
        G[b-1].push_back(e);
    }
    cin>>Q>>K;
    DEB(Q)DEB(K)END
    dijkstra(K-1);
    REP(i,Q){
        DEB(i)
        int a,b;
        cin>>a>>b;
        cout<<d[a-1]+d[b-1]<<endl;
    }
    return 0;
}

//ARC 079 D - Decrease (Contestant ver.)


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

int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int X1, X2, Xa;
  X1 = 60 * H1 + M1;
  X2 = 60 * H2 + M2;
  Xa = X2 - X1 - K;
  cout << Xa << endl;
}

Measured memory_bytes: 3584
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	char b;

	scanf("%c", &b);

	if (b == 'A') {
		putchar('T');
	}
	else if (b == 'T') {
		putchar('A');
	}
	else if (b == 'C') {
		putchar('G');
	}
	else {
		putchar('C');
	}

	return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll h,w,n,sr,sc;
    cin>>h>>w>>n>>sr>>sc;
    string s,t;

    cin>>s>>t;
    map<ll,ll> po_mp;
    string ans = "YES";
    po_mp['D'] = sr;
    po_mp['U'] = sr;
    po_mp['L'] = sc;
    po_mp['R'] = sc;



    FOR(i,0,n){
      if(s[i] == 'D')po_mp['D']++;
      if(s[i] == 'U')po_mp['U']--;
      if(s[i] == 'L')po_mp['L']--;
      if(s[i] == 'R')po_mp['R']++;

      if(po_mp['U'] < 1)ans = "NO";
      if(po_mp['D'] > h)ans = "NO";
      if(po_mp['L'] < 1)ans = "NO";
      if(po_mp['R'] > w)ans = "NO";


      if(t[i] == 'D')po_mp['U'] = min(h, po_mp['U']+1);
      if(t[i] == 'U')po_mp['D'] = max((ll)1, po_mp['D']-1);
      if(t[i] == 'R')po_mp['L'] = min(w, po_mp['L']+1);
      if(t[i] == 'L')po_mp['R'] = max((ll)1, po_mp['R']-1);



/*      s_mp[s[i]]++;
      t_mp[t[i]]++;

      if(s_mp['U'] - t_mp['D'] > u){
        ans = "NO";
      }
      if(s_mp['D'] - t_mp['U'] > d){
        ans = "NO";
      }
      if(s_mp['R'] - t_mp['L'] > r){
        ans = "NO";
      }
      if(s_mp['L'] - t_mp['R'] > l){
        ans = "NO";
      }
*/
  }
    cout<<ans<<endl;


}


Measured memory_bytes: 920
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[200005];

int main(int argc, char* argv[])
{
    int n,q;
    scanf("%d%d", &n, &q);
    scanf("%s", str);

    vector<char> str0, str1;
    int i;
    for(i=0; i<q; i++) {
        char strtmp0[5]={0}, strtmp1[5]={0};
        scanf("%s", strtmp0); str0.push_back(strtmp0[0]);
        scanf("%s", strtmp1); str1.push_back(strtmp1[0]);
    }

    
    int limit[2]={0};    // left, right
    int k;
    for(k=0; k<2; k++) {
        int l=-1, r=n;
        while(r-l>1) {
            int m=(l+r)/2;
            int curr=m;
            int status=0;
            for(i=0; i<q; i++) {
                if(str[curr]==str0[i]) {
                    if(str1[i]=='L') curr--;
                    else             curr++;
                    if(curr<0) {
                        status=-1;
                        break;
                    }
                    else if(curr>=n) {
                        status=1;
                        break;
                    }
                }
            }
            if(k==0) {
                if(status<0) l=m;
                else         r=m;
            }
            else {
                if(status<=0) l=m;
                else          r=m;
            }
        }
        limit[k]=(k==0? l: r);
    }
    
    printf("%d\n", MAX(0, limit[1]-limit[0]-1));
    return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
using vi=vector<int>;
#define pb push_back
int main() {
  ll n;
  cin>>n;
  int x,m;
  scanf("%d%d",&x,&m);
  map<int,int> mp;
  vi a;
  int cnt = 0;
  ll tot = 0;
  while (mp.count(x) == 0) {
    a.pb(x);
    tot += x;
    mp[x] = cnt;
    ++cnt;
    x = (ll)x*x%m;
  }
  if (n <= cnt) {
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout<<ans<<endl;
    return 0;
  }
  ll c = 0;
  int s = cnt-mp[x];
  srep(i,mp[x],cnt) c += a[i];
  ll ans = tot;
  n -= cnt;
  ans += n/s*c;
  n %= s;
  int si = mp[x];
  rep(i,n) ans += a[si+i];
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 6012
import java.util.Scanner;

public class Main {
	public static void main(String [] args)
	{
		int [] a= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		Scanner cin = new Scanner(System.in);
		int k=cin.nextInt();
		System.out.println(a[k-1]);
		cin.close();
	}
}

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

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

	int64_t N, A, B;
	cin >> N >> A >> B;

	vector<int64_t> X( N );
	for( auto& v: X ) { cin >> v; }

	int64_t result = 0;
	for( int64_t i = 0; i < N-1; ++i ) {
		result += min( (X[i+1] - X[i]) * A, B );
	}

	cout << result << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
  int W, H, x, y, r;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if((x + r <= W) && (x >= r) && (y + r <= H) && (y >= r)){
    printf("Yes\n");
    }
    else{
      printf("No\n");
    }

  return 0;
}

Measured memory_bytes: 584
n, k = map(int, input().split())
a = map(int, input().split())
_sum = [0]*41
m, f = 0, 0
for x in a:
  for i in range(41):
    _sum[i] += (x >> i) & 1
for i in range(40, -1, -1):
  s = 0 if _sum[i] > n//2 else 1 << i
  _min = min(_sum[i], n-_sum[i]) << i
  _max = max(_sum[i], n-_sum[i]) << i
  if s:
    m += s
    if m > k:
      m -= s
      f += _min
    else:
      f += _max
  else:
    f += _max
print(f)


Measured memory_bytes: 12200
#include<iostream>
#include<vector>

using namespace std;

void BubbleSort(vector<int>);
void swap(int&, int&);

int main(){
  int i, n, x;
  vector<int> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; i++){
      cin >> x;
      data.push_back(x);
    }

    BubbleSort(data);
    data.clear();
  }

  return 0;
}

void BubbleSort(vector<int> data){
  int i, j, count=0;

  for(i=0; i<data.size(); ++i){
    for(j=0; j<data.size()-i-1; ++j){
      if(data[j] > data[j+1]){
	swap(data[j], data[j+1]);
	++count;
      }
    }
  }

  cout << count << endl;
}

void swap(int& x, int& y){
  int copy;
  copy = x;
  x = y;
  y = copy;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    string X; cin >> X;

    int popbase = 0;
    REP(i,n) if (X[i] == '1') popbase++;
    int mp = 0, mm = 0; // あまり
    int popp = popbase+1, popm = popbase-1;

    REP(i,2) {
        int p = (i == 0) ? popp:popm; 
        if (p == 0) continue;
        ull a = 0;
        int j = 0;
        while(j < X.size()) {
            string s = X.substr(j,32);
            a = (a << s.size()) + bitset<32>(s).to_ullong();
            a %= p;
            j += s.size();
        }
        if (i == 0) mp = a;
        else mm = a;
    }


    auto calc = [](int x,int m){
        int ret = 0;
        do {
            x %= m;
            bitset<32> bs(x);
            m = bs.count();
            ret++;
        } while (x > 0);
        return ret;
    };

    int powp = 1,powm = 1;
    vector<int> ans(n);
    RREP(i,n-1) {
        int a = 0;
        if (X[i] == '0') {
            a = mp + powp;

            ans[i] = calc(a,popp);
        } else {
            if (popm == 0) continue;

            a = mm - powm;
            if (a < 0) a += popm;

            ans[i] = calc(a,popm);
        }

        powp = powp * 2 % popp;
        if (popm != 0) powm = powm * 2 % popm;
    }

    REP(i,n) cout << ans[i] << '\n';

    return 0;
}


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

int main() {
  int N, T, A, H[1010];
  cin >> N >> T >> A; for (int i = 0; i < N; i++) cin >> H[i];
  int minDiff = T * 1000 - H[0] * 6 - A * 1000, correctPlace = 1;
  if (minDiff < 0) minDiff = 0 - minDiff;
  for (int i = 0; i < N; i++) {
    int diff = T * 1000 - H[i] * 6 - A * 1000;
    if (diff < 0) diff = 0 - diff;
    if (diff < minDiff) {
      minDiff = diff;
      correctPlace = i + 1;
    }
  }
  cout << correctPlace << endl;
}

Measured memory_bytes: 256