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

int main(){
    using namespace std;
    unsigned long N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<unsigned long> A(N), B(N + 1);
    for(auto& i : A)cin >> i;
    sort(A.begin(), A.end(), greater<>());
    if(V <= P){
        cout << upper_bound(A.begin(), A.end(), A[P - 1] - min(A[P - 1], M), greater<>()) - A.begin() << endl;
        return 0;
    }else{
        auto tmp = M * (V - P), tmp1 = A.back() + M, tmp2 = 0UL;
        for(unsigned long i = P - 1; i + 1 < N; ++i)tmp2 += tmp1 - min(tmp1, A[i]);
        if(A.back() + M >= A[P - 1] && tmp <= tmp2){
            cout << N << endl;
            return 0;
        }
    }
    partial_sum(A.cbegin(), A.cend(), B.begin() + 1);
    const auto& chk = [&N, &M, &V, &P, &A, &B](unsigned long idx) -> bool {
        if(A[P - 1] > A[idx] + M)return false;
        unsigned long rem = V * M - M * (min(V + 1, P + N - idx) - 1), lim = A[idx] + M;
        return lim * (idx - P + 1) + B[P - 1] >= rem + B[idx];
    };
    unsigned long L = P, R = N - 1;
    while(L + 1 < R){
        auto m = (L + R) / 2;
        (chk(m) ? L : R) = m;
    }
    cout << R << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
const int MAX_N = 100000;
const int MAX_V = 1000000000;
int N;
int X[MAX_N];
int L[MAX_N];

void input(){//N組の入力を受けて配列X, Lに格納
    scanf("%d", &N);
    for(int i = 0; i < N; ++i){
        scanf("%d %d", &X[i], &L[i]);
    }
}

P ps[MAX_N];//typedef pair<int, int> P;

int solve(){
    for(int i = 0; i < N; ++i){
        ps[i] = P(X[i] + L[i], X[i] - L[i]);//ps[i].first:腕の届く最大値/ps[i].second:腕の届く最小値
    }
    sort(ps, ps+N);//ps[i].first（＝腕の届く最大値）について、最初の要素から最後の要素までを対象にsort
    int cur = -MAX_V;//確定した腕の届く値の最大値を保持する　これを初期化
    int ans = 0;
    for(int i = 0; i < N; ++i){
        if(cur <= ps[i].second){//ps[i].second:新しい機械の腕の届く最小値が確定した腕の届く値の最大値より大きければそれを採用
        ans++;
        cur = ps[i].first;
        }
    }
    return ans;
}

int main(){
    input();
    int ans = solve();
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		if (("ABC").equals(a)) {
			System.out.println("ARC");
		} else {
			System.out.println("ABC");
		}

	}
}

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


long long calc(std::vector<long long>& v ) {
  long long res  = 0 ;
  for (int i = 1; i < v.size(); ++i)
  {
    res += abs(v[i] - v[i - 1]);
  }
  return res ;

}
int main() {

  int n ;
  cin >> n ;
  long long res = 0 ;
  long long a[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }


  sort(a, a + n);
  std::vector<long long> v;
  for (int i = 0; i < n / 2; ++i)
  {
    v.push_back(a[n / 2 - i - 1 ]);
    v.push_back(a[n - i - 1 ]);
  }
  res = calc(v);
  if ( n % 2 )
    res += max(abs(a[n / 2] - v.front() ), abs(a[n / 2] - v.back() ));


  cout << res << endl;

}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<map<int, int>> v(2);
    for (int i = 1; i <= n; ++i) {
        int k;
        cin >> k;
        if(i%2) v[0][k]++;
        else v[1][k]++;
    }
    using P = pair<int, int>;
    vector<vector<P>> v2(2);
    for (auto &&j : v[0]) {
        v2[0].emplace_back(j.second, j.first);
    }
    v2[0].emplace_back(0, 10000001);
    for (auto &&j : v[1]) {
        v2[1].emplace_back(j.second, j.first);
    }
    v2[1].emplace_back(0, 10000002);
    int a = 0, b = 0;
    sort(v2[0].rbegin(), v2[0].rend());
    sort(v2[1].rbegin(), v2[1].rend());
    while (v2[0][a].second == v2[1][b].second){
        if(v2[0][a].first - v2[0][a+1].first < v2[1][b].first - v2[1][b+1].first){
            a++;
        }else b++;
    }
    cout << n - v2[0][a].first - v2[1][b].first;
    return 0;
}


Measured memory_bytes: 6136
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  vector<int> A(N); rep(i, N) cin >>A[i];
  int res = 1;
  int increasing = 0;
  for (int i=1; i<N; i++){
    if (A[i] == A[i-1]) continue;
    else if (A[i] < A[i-1]){
      if (increasing == -1) continue;
      if (increasing == 0) increasing = -1;
      else{
        res++; increasing = 0;
      }
    }else if (A[i] > A[i-1]){
      if (increasing == 1) continue;
      if (increasing == 0) increasing = 1;
      else{
        res++; increasing = 0;
      }
    }
  }
  cout <<res <<endl;

}


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

int n;
long INF = 1LL << 60;
int dp[100010];
int c[100010];

int main()
{
  cin >> n;

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

  for (int i = 0; i < 10010; i++)
  {
    dp[i] = INF;
  }

  dp[0] = 0;
  dp[1] = dp[0] + abs(c[1] - c[0]);
  
  for (int i = 2; i < n; i++) {
    int step1 =  dp[i - 1] + abs(c[i] - c[i - 1]);
    int step2 =  dp[i - 2] + abs(c[i] - c[i - 2]);
    if (step1 < step2) {
      dp[i] = step1;
    } else {
      dp[i] = step2;
    }
  }

  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
ll A,B;
int main()
{
	cin>>A>>B;
	cout<<(ll)ceill((B-1)/(ld)(A-1))<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
#define vvv vector<vector<vector<long long int>>>
#define vvvl(a, b, c, d) vector<vector<vector<long long int>>>(a, vector<vector<long long int>>(b, vector<long long int> (c, d)));

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  map<string, ll> mp;
  re(i, n){
    string s;std::cin >> s;
    if(mp.find(s)==mp.end()) mp.emplace(s, 1);
    else{
      ll tmp = mp.at(s);
      mp.erase(s);
      mp.emplace(s, tmp+1);
    }
  }
  ll m = 0;
  for(auto itr = mp.begin();itr!=mp.end();itr++){
    m = max(m, (*itr).second);
  }
  vector<string> ans;
  for(auto itr = mp.begin();itr!=mp.end();itr++){
    if((*itr).second==m) ans.push_back((*itr).first);
  }
  sort(all(ans));
  for(int i=0;i<ans.size();i++) std::cout << ans[i] << '\n';
  return 0;
}


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

int a,b,c,arr[11];

int main(){
	cin>>a>>b>>c;
	arr[a]++;
	arr[b]++;
	arr[c]++;
	if((arr[5] == 2) && (arr[7] == 1)){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}	
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int q;
  cin >> q;
  int rev = 1;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1)
      rev = -rev;
    else {
      int f;
      cin >> f;
      string c;
      cin >> c;
      if ((f == 1 && rev == 1) || (f == 2 && rev == -1)) {
        s.insert(0, c);
      } else {
        s.append(c);
      }
    }
  }
  if (rev == -1) reverse(s.begin(), s.end());
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 3812
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a == 0 || b == 0) {
            System.out.println("Zero");
            return;
        }

        if (a > 0) {
            System.out.println(b > 0 ? "Positive" : "Zero");
        } else {
            if (b > 0) {
                System.out.println( "Zero");
            } else {
                System.out.println(Math.abs(a - b) % 2 == 1 ? "Positive" : "Negative");
            }
        }
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define N 500005
#define int long long
using namespace std;
int n,m,top,b[N],f[N],ans[N];
signed main(){
	scanf("%lld%lld",&n,&m);
	b[++top]=n;
	for (int i=1;i<=m;i++){
		scanf("%lld",&b[++top]);
		while (top>1&&b[top]<=b[top-1]) b[top-1]=b[top],top--;
	}
	f[top]=1;
    for (int i=top-1;~i;i--){
    	int len=b[i+1];
    	while (len>b[1]){
    		int pos=upper_bound(b+1,b+i+1,len)-b-1;
    		f[pos]+=len/b[pos]*f[i+1];
    		len%=b[pos];
    	}
    	ans[len]+=f[i+1];
    }
    for (int i=b[1];i;i--) ans[i]+=ans[i+1];
    for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

PII p[3010];
ll dp[3010],f[201000];
int h,w,n;
ll go(ll x,ll y) {
	assert(x>=0&&y>=0);
	return f[x+y]*powmod(f[x]*f[y],mod-2)%mod;
}
int main() {
	scanf("%d%d%d",&h,&w,&n);
	f[0]=1;
	rep(i,1,200001) f[i]=f[i-1]*i%mod;
	rep(i,0,n) scanf("%d%d",&p[i].fi,&p[i].se);
	p[n]=mp(h,w); p[n+1]=mp(1,1); n+=2;
	sort(p,p+n); 
	dp[0]=1;
	rep(i,1,n) {
		dp[i]=go(p[i].fi-1,p[i].se-1);
		rep(j,1,i) if (p[j].fi<=p[i].fi&&p[j].se<=p[i].se)
			dp[i]=(dp[i]-go(p[i].fi-p[j].fi,p[i].se-p[j].se)*dp[j])%mod;
	}
	(dp[n-1]+=mod)%=mod;
	printf("%I64d\n",dp[n-1]);
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 50;
ll p[64];
int st[64];
int tot = 0;
void ins(ll x){
    for(int i = 0; i < tot; ++i){
        if((x>>st[i])&1){
            if(p[i]) x^=p[i];
            else {p[i] = x;
            break;}
        }
    }
}
int n;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    ll sum = 0;
    for(int i = 0; i < n ; ++i) cin>>a[i], sum^=a[i];
    for(int i = 60; i >= 0; --i) if(!((sum>>i)&1)) st[tot++] = i;
    for(int i = 0; i < n; ++i) ins(a[i]);
    ll res = 0;
    for(int i = 0; i < tot; ++i)
        if(!((res>>st[i])&1)) res ^= p[i];
    cout<< res + (sum^res)<<endl;
}
/*
4
23 36 66 65
*/


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
ll a[114514], cnt[114514]; ll n, m, memo = 0, ans = 0;
map<ll, ll>mp;
signed main() {
	cin >> n >> m;
	rep(i, n)cin >> a[i];
	cnt[0] = a[0];
	for (int i = 1; i < n; i++)cnt[i] = cnt[i - 1] + a[i];
	rep(i, n)cnt[i] = cnt[i] % m;
	rep(i, n) {
		if (!cnt[i])memo++;
	}
	rep(i, n)mp[cnt[i]]++;
	for (auto x : mp)ans += x.second*(x.second - 1) / 2;
	cout << ans + memo << endl;
	getchar(); getchar(); return 0;
}

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

vector<int> graph[200001];
vector<bool> visited(200001, false);
int diameter;
int v0;

void visit(const int vertex, int d)
{
  visited[vertex] = true;
  if (diameter < d) {
    diameter = d;
    v0 = vertex;
  }
  for (auto&& v : graph[vertex]) {
    if (!visited[v])
      visit(v, d + 1);
  }
  visited[vertex] = false;
}

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

  for (int i = 0; i < n - 1; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    graph[v1].push_back(v2);
    graph[v2].push_back(v1);
  }
  visit(1, 0);
  visit(v0, 0);
  cout << (diameter % 3 == 1 ? "Second" : "First") << endl;
}


Measured memory_bytes: 20608
#include <stdio.h>
#include <string.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n, l, i, j, h, k;
   
    char s[101][101];

    char t[101] = {};
   
      
    scanf("%d %d", &n , &l );
   
    for( i = 0 ; i < n ; i = i + 1 ){

        scanf("%s", s[i] );

        }


    for( j = 0 ; j < n ; j = j + 1 ){

        for( h = j + 1 ; h < n ; h = h + 1 ){

            if( strcmp( s[j] , s[h] ) > 0 ){

                strcpy( t , s[j] );

                strcpy( s[j] , s[h] );

                strcpy( s[h] , t );

                }

            }

         }

   
    for( k = 0 ; k < n ; k = k + 1 ){

        if( k == n - 1 ) printf("%s\n", s[k] );

        else printf("%s", s[k] );

        }
       

    return 0;
                                                          
}

Measured memory_bytes: 128
from collections import deque

N = int(input())
S = input()
Q = int(input())
K = list(map(int, input().split()))

for k in K:
    res = 0
    d = 0
    m = 0
    dm = 0
    for i in range(N):
        if S[i] == 'D':
            d += 1
        elif S[i] == 'M':
            dm += d
            m += 1
        elif S[i] == 'C':
            res += dm
        if i + 1 - k >= 0:
            if S[i + 1 - k] == 'D':
                d -= 1
                dm -= m
            elif S[i + 1 - k] == 'M':
                m -= 1

    print(res)

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

int main(){
	LL ans = 0;
	int n;
	cin >> n;
	LL a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a,a+n);
	reverse(a,a+n);
	LL v = 1;
	LL found = 0;
	map<LL, int> c;
	for(int i = 0; i < n; i++) c[a[i]]++;
	for(int b = 0; b < 2; b++){
		for(int i = 0; i < n; i++){
			if(c[a[i]] >= 2){
				c[a[i]]-=2;
				v *= a[i];
				found++;
				break;
			}
		}
	}
	if(found < 2) v = 0;
	cout << v << endl;
}


Measured memory_bytes: 7296
(a,b) = map(int, input().split())
xs = []
if a % 2 == 1:
    xs.append(a)
    a = a+1
if b % 2 == 0:
    xs.append(b)
    b = b-1

if (b-a+1)//2 % 2 == 1:
    xs.append(1)
#print(xs)
ans = 0
for x in xs:
    ans = ans ^ x

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

ll dp[110][10];

int main()
{
  int H, W, K;
  cin >> H >> W >> K;

  dp[0][0] = 1;
  REP(i, H) {
    REP(b, 1 << (W-1)) {
      bool flag = true;

      REP(j, W-1) {
        if (((b >> j) & 1) && ((b >> (j + 1)) & 1)) {
          flag = false;
          break;
        }
      }
      if (!flag) continue;

      REP(j, W) {
        if ((b >> j) & 1) 
          (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
        else if (j >= 1 && ((b >> (j - 1)) & 1))
          (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
        else 
          (dp[i + 1][j] += dp[i][j]) %= MOD;
      }
    }
  }
  cout << dp[H][K-1] << endl;

	return 0;
}

Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = nextIntArray();
  list.sort(function(a,b){
  	return a - b;
  });
  var diff = new Array(M - 1);
  for(var i = 1; i < M; i++){
    diff[i - 1] = Math.abs(list[i - 1] - list[i]);
  }
  diff.sort(function(a,b){
  	return b - a;
  });
  myerr(diff);
  var output = 0;
  for(var i = N - 1; i < M - 1; i++){
    output += diff[i];
  }
  myout(output);
}


Measured memory_bytes: 54816
#include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(auto s=t.begin();s!=t.end();s++)for(auto S=s;++S!=t.end();v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=1;i<=n/2;i++)printf("%d\n",v[i]);}}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
 
#define FORu(i, start, n) for (ll i = start; i < (ll)(n); i++)
#define FORd(i, start, n) for (ll i = start; i > (ll)(n); i--)
#define FORa(vec) for (auto x : vec) cout << x << " ";
#define pb push_back
#define pf pop_front
#define mp make_pair
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
 
//==============================================================================
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x; cin >> x;
    (x >= 30) ? cout << "Yes" << endl : cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
uint64_t Lucas(int &N){
  uint64_t x0=2,x1=1,x2=1;
  for(int i=0;i<N-1;i++){
    x2=x0+x1;
    x0=x1;
    x1=x2;
  }
  return x2;
}
int main(){
  int N;cin>>N;
  cout<<Lucas(N)<<endl;
}

Measured memory_bytes: 256
"""
problem statment url: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B
"""

from __future__ import division
from sys import stdin, maxint

# Based on the solution you choose,
def knapsack(N, W, infos):
	dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
	for i in range(1, N + 1):
		for j in range(W + 1):
			if j >= infos[i - 1][1]:
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - infos[i - 1][1]] + infos[i - 1][0])
			else:
				dp[i][j] = dp[i - 1][j]


	return dp[N][W]


if __name__ == '__main__':
    N, W = map(int, stdin.readline().strip().split())
    infos = []
    for _ in range(N):
    	v, w = map(int, stdin.readline().strip().split())
    	infos.append((v, w))
    print(knapsack(N, W, infos))

Measured memory_bytes: 24024
#include <bits/stdc++.h>
#define sp ' '
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;
const string nyan("(=^・ω・^=)");

int N, Q, a[200000], b[200000], p, x, y;
bool u[200000];
set<pair<int, int>>st[2];
ll res;

int main() {
	cin >> N >> Q;
	--Q;
	N *= 2;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> b[i];
	}
	cin >> p >> x >> y;
	--p;
	a[p] = x;
	b[p] = y;
	res = a[0] + a[N - 1];
	for (int i = 1; i < N - 1; ++i) {
		if (a[i] >= b[i]) {
			u[i] = true;
			res += a[i];
			st[1].insert(mkp(a[i] - b[i], i));
		}
		else {
			res += b[i];
			st[0].insert(mkp(b[i] - a[i], i));
		}
	}
	if (st[0].size() & 1) {
		pair<int, int>p1, p2;
		p1 = *st[0].begin();
		p2 = *st[1].begin();
		if (p1.first > p2.first) {
			res -= p2.first;
			u[p2.second] ^= true;
			st[0].insert(mkp(-p2.first, p2.second));
			st[1].erase(p2);
		}
		else {
			res -= p1.first;
			u[p1.second] ^= true;
			st[1].insert(mkp(-p1.first, p1.second));
			st[0].erase(p1);
		}
	}
	cout << res << endl;
	while (Q--) {
		cin >> p >> x >> y;
		--p;
		if (p == 0 || p == N - 1) {
			res += x - a[p];
			a[p] = x;
		}
		else {
			if (u[p]) {
				res += x - a[p];
				st[1].erase(mkp(a[p] - b[p], p));
				st[1].insert(mkp(x - y, p));
				auto it = st[1].begin();
				auto it2 = it;
				++it2;
				pair<int, int> p1 = *it;
				pair<int, int> p2 = *it2;
				if (p1.first < 0 && p2.first < 0 || (!st[0].empty() && p1.first + p2.first < 0 && p2.first < st[0].begin()->first) || (st[0].empty() && it->first + it2->first < 0)) {
					res -= p1.first + p2.first;
					st[0].insert(mkp(-p1.first, p1.second));
					st[0].insert(mkp(-p2.first, p2.second));
					u[p1.second] ^= true;
					u[p2.second] ^= true;
					st[1].erase(p1);
					st[1].erase(p2);
				}
			}
			else {
				res += y - b[p];
				st[0].erase(mkp(b[p] - a[p], p));
				st[0].insert(mkp(y - x, p));
				auto it = st[0].begin();
				auto it2 = it;
				++it2;
				pair<int, int> p1 = *it;
				pair<int, int> p2 = *it2;
				if (p1.first < 0 && p2.first < 0 || (!st[1].empty() && p1.first + p2.first < 0 && p2.first < st[1].begin()->first) || (st[1].empty() && p1.first + p2.first < 0)) {
					res -= p1.first + p2.first;
					st[1].insert(mkp(-p1.first, p1.second));
					st[1].insert(mkp(-p2.first, p2.second));
					u[p1.second] ^= true;
					u[p2.second] ^= true;
					st[0].erase(p1);
					st[0].erase(p2);
				}
			}
			if (!st[0].empty() && !st[1].empty() && st[0].begin()->first + st[1].begin()->first < 0) {
				pair<int, int> p1 = *st[0].begin();
				pair<int, int> p2 = *st[1].begin();
				res -= p1.first + p2.first;
				u[p1.second] ^= true;
				u[p2.second] ^= true;
				st[0].insert(mkp(-p2.first, p2.second));
				st[1].insert(mkp(-p1.first, p1.second));
				st[0].erase(p1);
				st[1].erase(p2);
			}
			a[p] = x;
			b[p] = y;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 12800
n = int(input())
a = list(map(int,input().split()))
sa = [0] * n
nn = n // 2
q = sum(a) // 2

a = a * 3
su1 = 0
su2 = 0
for i in range(nn):
    su1 += a[1+2*i]
    su2 += a[2+2*i]

for i in range(n):
    if i%2 == 0:
        sa[i] = su1
        su1 = su1 - a[1+i] + a[1+i+2*nn]
    if i%2 == 1:
        sa[i] = su2
        su2 = su2 - a[1+i] + a[1+i+2*nn]
        
ans = [0] * n
for i in range(n):
    ans[i] = (q - sa[i]) * 2
    
print(*ans)

Measured memory_bytes: 68196
#include <stdio.h>

int main(void){
	int n,m,i,j;
	long B[100],A[100][100],C[100]={0};
	
	scanf("%d %d",&n,&m);
	
	for(i=0;i<=n-1;i++){
		for(j=0;j<=m-1;j++){
			scanf("%ld",&A[i][j]);
		}
	}
	
	for(i=0;i<=m-1;i++){
		scanf("%ld",&B[i]);
	}
	
	for(i=0;i<=n-1;i++){
		for(j=0;j<=m-1;j++){
			C[i]+=A[i][j]*B[j];
		}
	}
	for(i=0;i<=n-1;i++){
		printf("%ld\n",C[i]);
	}
	return 0;
}

Measured memory_bytes: 676
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
    char s[200000]; scanf("%s", s);
    int min_a = strlen(s), max_z = 0;
    for(int i = 0; i < strlen(s); i++) {
        if(s[i] == 'A' && min_a > i) min_a = i;
        if(s[i] == 'Z' && max_z < i) max_z = i;
    }
    printf("%d\n", max_z - min_a + 1);
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll rsum[100005]={0};
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=m;i++){
    ll l,r;
    cin>>l>>r;
    r++;
    rsum[l]++;
    rsum[r]--;
  }
  for(int i=0;i<=n+2;i++) rsum[i+1]+=rsum[i];
  int ans=0;
  for(int i=1;i<=n;i++) if(rsum[i]==m) ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 100001
using namespace std;
int a[N*2][3],g[N];
long long dis[N];
int n,m,k;
void ins(int x,int y,int z){
	static int sum=1;
	a[++sum][0]=y,a[sum][1]=z,a[sum][2]=g[x],g[x]=sum;
}
void dfs(int x,int fa){
	for (int i=g[x];i;i=a[i][2])
		if (fa!=a[i][0]){
			dis[a[i][0]]=dis[x]+a[i][1];
			dfs(a[i][0],x);
		}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		ins(x,y,z),ins(y,x,z);
	}
	scanf("%d %d",&m,&k);
	dfs(k,0);
	while (m--){
		int x,y;
		scanf("%d %d",&x,&y);
		cout<<dis[x]+dis[y]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1e7+9
using namespace std;

ll solve(vector<ll> v,ll n){
	vector<ll> dp(n+1,0);
	dp[1]=0;dp[2]=abs(v[2]-v[1]);
	for(int i=3;i<=n;i++){
		dp[i] = min(dp[i-1] + abs(v[i]-v[i-1]), dp[i-2] + abs(v[i]-v[i-2]));
	}
	return dp[n];
}

int main()
{
	ll t=1;
	while(t--){
		ll n;
		cin >> n;
		vector<ll> v(n+1,0);
		for(int i=1;i<=n;i++){
			cin >> v[i];
		}
		cout << solve(v,n) << endl;
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> ans(n+1);
  ans.at(0) = 2;
  ans.at(1) = 1;
  for(int i=2; i<n+1; i++){
    ans.at(i) = ans.at(i-1) + ans.at(i-2);
  }
  cout << ans.at(n) << endl;
}

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

using namespace std;

int reg(map<string, int>& tbl, string& name) {
	if (tbl.count(name) == 0) {
		int id = tbl.size();
		tbl[name] = id;
	}
	return tbl[name];
}

int N;
vector< vector<int> > G;
vector<int> power;
vector<int> ps;
vector<int> conv;
vector<int> adjacent;

int ans = 0, p = 0;
bool merge(int n) {
	if (adjacent[n] > 0) return false;
	for (int i = 0; i < G[n].size(); ++i) {
		adjacent[G[n][i]]++;
	}
	return true;
}
bool remove(int n) {
	for (int i = 0; i < G[n].size(); ++i) {
		adjacent[G[n][i]]--;
	}
}
void dfs(int n) {
	if (n == N) {
		ans = max(ans, p);
	}
	else if (p + ps[n] > ans) {
		if ( merge(conv[n]) ) {
			p += power[n];
			dfs(n+1);
			remove(conv[n]);
			p -= power[n];
		}
		dfs(n+1);
	}
}

int main() {
	while ( cin >> N, N ) {
		map<string, int> tbl;
		power.clear(); power.resize(N);
		G.clear(); G.resize(N);
		conv.clear(); conv.resize(N);
		for (int i = 0; i < N; ++i) {
			string A; cin >> A; int a = reg(tbl, A);
			int B, C; cin >> B >> C;
			for (int j = 0; j < C; ++j) {
				string D; cin >> D;
				int d = reg(tbl, D);
				G[a].push_back(d);
			}
			power[i] = B;
			conv[i] = a;
		}
		ps.resize(N+1);
		for (int i = 0; i < N; ++i) {
			ps[i] = power[i];
		}
		for (int i = N-1; i >= 0; --i) {
			ps[i] += ps[i+1];
		}
		adjacent = vector<int>(N, 0);
		ans = 0; p = power[0]; merge(conv[0]);
		dfs(1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1260
from collections import Counter

def is_this_a_beautiful_sentence(sentence):

    letter_count = Counter(sentence)
    for c in letter_count.values():
        if c % 2 == 1:
            return 'No'
    
    return 'Yes'

if __name__=='__main__':
    print(is_this_a_beautiful_sentence(input()))

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

int main(){
  vector<char> S(4);
  for(int i=0;i<4;i++){
    cin >> S.at(i);
  }
  bool a=false;
  for(int i=0;i<3;i++){
    if(S.at(i) == S.at(i+1)){
      a=true;
      break;
    }}
  if(a){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}

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

using ll = long long;

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

    auto indices = vector<int>(N+1);
    for (auto i = 1; i <= N; i++)
    {
        int x; cin >> x;
        indices[x] = i;
    }

    auto result = 0LL;
    auto seen = set<int>({0, N+1});
    for (auto x = 1; x <= N; x++)
    {
        const auto index = indices[x];
        const auto upper_bound = seen.upper_bound(index);
        const auto lower_bound = prev(upper_bound);

        result += ll(index - *lower_bound) * (*upper_bound - index) * x;

        seen.insert(index);
    }

    cout << result << endl;
}


Measured memory_bytes: 10368
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
cnt = 0
now = 0
c=[[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
  iter_w = range(W)
  if h%2:
    iter_w = reversed(iter_w)
  for w in iter_w:
    c[h][w] = now + 1
    cnt += 1
    if cnt == a[now]:
      now += 1
      cnt = 0

for i in range(H):
  print(*c[i])

Measured memory_bytes: 9356
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != 'R') continue;
            int j = i;
            while (j + 1 < s.length() && s.charAt(j + 1) == 'R') j++;
            ans = Math.max(ans, j - i + 1);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35504
#include <stdio.h>

int main(){
    int A,B,C,i;
    int flag=0;
    scanf("%d %d %d",&A,&B,&C);
    if(A<B){
        for(i=A;i<=B;i++){
            // i+=1;
            if(i==C) flag = 1;
            
        }
    }else if(A>B){
        for(i=A;i>=B;i--){
            if(i==C) flag = 1;
        }
    }
    if(flag == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main()
{
  int n,m,sum=0;
  cin>>n>>m;
  int i;
  int a[m];
  for(i=0;i<m;i++)
  {
      cin>>a[i];
      sum+=a[i];
  }
   if(n-sum<0) cout<<"-1";
   else cout<<n-sum;


}


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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(true){
        C-=B;
        if(C<=0){
            cout << "Yes" << endl;
            break;
        }
        A-=D;
        if(A<=0){
            cout << "No" << endl;
            break;
        }
    }
}


Measured memory_bytes: 3632
import fractions
from functools import reduce
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                s=int(n[j]/t)
                if n[j] % t == 0 and s % 2 == 1:
                        n[j] = s
 
                else: return 0
        return int(t//2)
 
def mp(v):
        if v%2==1:v+=1
        return int(v//2)
 
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=sorted(set(n),reverse = True)
bs = n[0]//2
 
if len(n) > 1:
        c = chk(n[-1])
        if  c != 0:
                v = lcm_o()*c
                if v > M: print(0) 
 
                else: print(mp(M//v))
                        
        
        else: print(0)
        
elif len(n)==1: print(mp(M//bs))


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char> > a(h+1,vector<char>(w+1,'0'));
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i <= h+1; i++){
        for(int j = 0; j <= w+1; j++){
            if(i == 0 || j == 0 || i == h+1 || j == w+1){
                cout << '#';
            } else{
                cout << a[i][j];
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i;
  int num;
  int place[4];
  scanf("%d",&num);
  for(i=0;i<4;i++){
   	place[i]=num%10;
    num=num/10;
  }
  for ( i=0;i<2;i++){
    if(place[i]==place[i+1] && place[i+1]==place[i+2]){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int INF = 1e18;
struct SegTree {
    int N;
    vector<Int> A;
    SegTree(int n) {
        N = 1; while (N < n) N *= 2;
        A.resize(2*N, INF);
    }
    Int get(int idx) {
        idx += N;
        Int ans = INF;
        while (idx > 0) {
            ans = min(ans, A[idx]);
            idx /= 2;
        }
        return ans;
    }
    void chmin(int L, int R, Int val) {
        L += N, R += N;
        while (L < R) {
            if (L & 1) {
                A[L] = min(A[L], val);
                L++;
            }
            if (R & 1) {
                R--;
                A[R] = min(A[R], val);
            }
            L /= 2, R /= 2;
        }
    }
};
int main() {
    int N, M; cin >> N >> M;
    vector<tuple<int, int, int>> A(M);
    for (int i = 0; i < M; i++) {
        int l, r, c; cin >> l >> r >> c; l--, r--;
        A[i] = make_tuple(l, r, c);
    }
    sort(begin(A), end(A));
    SegTree st(N);
    st.chmin(0, 1, 0);
    for (int i = 0; i < M; i++) {
        int l, r, c; tie(l, r, c) = A[i];
        st.chmin(l, r + 1, st.get(l) + c);
    }
    Int ans = st.get(N - 1);
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 3456
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    int min = 100001;
    int max = -1;
    int l, r;
    for (int i = 0; i < m; i++) {
        cin >> l >> r;
        if (l > max) {
            max = l;
        }
        if (r < min) {
            min = r;
        }
    }

    //cout << "max: " << max << endl;
    //cout << "min: " << min << endl;

    if (min - max >= 0) {
        cout << min - max + 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

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

int main()
{
	int n;
	string s;
	cin >> n;
	while (n--) {
		int res = 0, O = 0;
		vector<int> r(3);
		while (true) {
			cin >> s;
			if (s == "HIT") {
				res += r[2];
				r[2] = r[1];
				r[1] = r[0];
				r[0] = 1;
			}
			else if (s == "HOMERUN") {
				res += r[0] + r[1] + r[2] + 1;
				r[0] = r[1] = r[2] = 0;
			}
			else {
				O++;
				if (O >= 3) {
					break;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3128
N, K = map(int, input().split())
A = list(map(int, input().split()))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


if max(A) < K:
    print("IMPOSSIBLE")
    exit()
elif K in A:
    print("POSSIBLE")
    exit()

while len(A) > 1:
    A.append(gcd(A.pop(), A.pop()))

if K % A[0] == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



Measured memory_bytes: 14224
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	ll A, B;
	cin >> A >> B;

	ll ans = - A + B;
	if (B % A == 0) {
		ans = A + B;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=210;
int n;
int a[N],p[N];
int main()
{
	int i,j,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=n;i>=1;i--)
	{
		x=0;
		for(j=1;j<=i;j++)
		{
			if(a[j]==j) x=j;
		}
		if(x==0)
		{
			puts("-1");
			return 0;
		}
		p[i]=x;
		for(j=x;j<i;j++) a[j]=a[j+1];
	}
	for(i=1;i<=n;i++) printf("%d\n",p[i]);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define NMAX 200001

vector <int> v[NMAX];
char labels[NMAX];
int nra[NMAX], nrb[NMAX], viz[NMAX];

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

    int n, m;
    // ifstream cin("code.in");
    cin >> n >> m;
    cin >> (labels + 1);
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        if (x != y) {
            v[y].push_back(x);
        }
    }

    for (int i = 1; i <= n; i++) {
        for (const int x : v[i]) {
            if (labels[x] == 'A')
                nra[i]++;
            else
                nrb[i]++;
        }
    }

    queue <int> q;
    for (int i = 1; i <= n; i++) {
        if (nra[i] == 0 || nrb[i] == 0) {
            q.push(i);
            viz[i] = 1;
        }
    }

    while (!q.empty()) {
        int nod = q.front();
        q.pop();
        for (const int x : v[nod]) {
            if (viz[x])
                continue;
            if (labels[nod] == 'A')
                nra[x]--;
            else
                nrb[x]--;
            if (nra[x] == 0 || nrb[x] == 0) {
                q.push(x);
                viz[x] = 1;
            }
        }
    }

    int found = 0;
    for (int i = 1; i <= n; i++) {
        if (viz[i] == 0) {
            found = 1;
            break;
        }
    }

    if (found) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 13184
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n,m;cin>>n>>m;
	vi a(n);
	map<ll,ll> fq;
	set<ll> s;
	rep(i,0,n)
	{
		cin>>a[i];
		fq[a[i]]++;
		s.insert(a[i]);

	} 

	while(m--)
	{
		ll val = *s.rbegin();
		fq[val]--;
		if(fq[val]==0) s.erase(val);
		fq[val/2]++;
		s.insert(val/2);
	}

	ll ans=0;
	all(it,fq) ans+=(it->F)*(it->S); 
	cout<<ans<<"\n";


	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

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

using namespace std;

bool iseven(long long int a)
{
	if ((a%2)==0)
		return true;
	else
		return false;
}

int main()
{
	long long int a,b,num_elements;
	cin >> a >> b;
	num_elements = (b-a+1);
	if (iseven(a))
	{
		if (iseven(num_elements))
			cout << ((num_elements/2)%2) << endl;
		else
			cout << (b ^ (((num_elements - 1)/2)%2)) << endl;
	}
	else
	{
		if(iseven(num_elements))
			cout << (a ^ b ^ (((num_elements - 2)/2)%2)) << endl;
		else
			cout << (a ^ (((num_elements - 1)/2)%2)) << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    ll n,k;
    cin>>n>>k;
    ll d,a;
    map<ll,ll> mp;
    rep(i,n) mp[i];
    rep(i,k){
        cin>>d;
        rep(j,d){
            cin>>a;
            a--;
            mp[a]++;
        }
    }
    ll ans=0;
    for(auto x:mp){
        if(x.second==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 r;
    cin >> r;
    cout << fixed << setprecision(20) << M_PI * r * 2 << endl;
    return 0;
}

Measured memory_bytes: 3804
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let amari = n % 10;
    if amari == 2 || amari == 4 || amari == 5 || amari == 7 || amari == 9 {
        return "hon".to_string();
    }
    if amari == 3 {
        return "bon".to_string();
    }

    return "pon".to_string();
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB 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())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

#define MAX_N 50
int n, m;
bool edge[MAX_N][MAX_N];
bool visited[MAX_N];

bool rf(int v){
  if(visited[v])
    return true;
  
  visited[v] = true;
  REP(i, n){
    if(edge[v][i])
      rf(i);
  }

  REP(i, n){
    //cout << visited[i] << endl;
    if(visited[i] == false)
      return false;
  }

  return true;

}

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

  cin >> n >> m;

  REP(i, n){
    visited[i] = false;
    REP(j, n)
      edge[i][j] = false;
  }

  vector<int> a(m), b(m);
  REP(i, m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    edge[a[i]][b[i]] = true;
    edge[b[i]][a[i]] = true;
  }

  ll ans = 0;
  REP(i, m){
    REP(i, n)
      visited[i] = false;
    edge[a[i]][b[i]] = false;
    edge[b[i]][a[i]] = false;
    if(!rf(0))
      ans++;

    edge[a[i]][b[i]] = true;
    edge[b[i]][a[i]] = true;
  }

  cout << ans << endl;
}


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

int main() {

    int K;
    int N;

    cin >> K >> N ;

    int A[N];

    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    
    int distance[N];
    for (int i = 0; i < N; i++)
    {
        if( i+1 < N){
            distance[i] = A[i+1]-A[i];
        } else {
            distance[i] = A[0]+K-A[i];
        }
    }
    
    sort(distance,distance+N, greater<int>());

    int answer = 0;
    for (int i = 1; i < N; i++){
        answer += distance[i];
    }


    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1792