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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

ll n;
char c[4010];
ll a[4010];
ll p[4010];
ll BIT_B[4010], BIT_W[4010];
ll cost_b[4010][2010], cost_w[4010][2010];
ll dp[2010][2010];

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

    cin >> n;
    ll cnt_w = 0, cnt_b = 0;
    REP(i,n*2) {
        cin >> c[i] >>  a[i];

        //find how many numbers are greater than k before position [i+1] for WHITE and BLACK
        REP(k,n+1) {
            ll tmp = k;
            while (tmp) {
                cost_w[i][k] += BIT_W[tmp];
                tmp -= tmp & (-tmp);
            }
            cost_w[i][k] = cnt_w - cost_w[i][k];
        }
        REP(k,n+1) {
            ll tmp = k;
            while (tmp) {
                cost_b[i][k] += BIT_B[tmp];
                tmp -= tmp & (-tmp);
            }
            cost_b[i][k] = cnt_b - cost_b[i][k];
        }

        //insert the number into BIT
        if (c[i] == 'W') {
            cnt_w++;
            p[a[i]] = i;
            ll tmp = a[i];
            while (tmp <= n*2) {
                BIT_W[tmp]++;
                tmp += tmp & (-tmp);
            }
        } else {
            cnt_b++;
            p[a[i]+n] = i;
            ll tmp = a[i];
            while (tmp <= n*2) {
                BIT_B[tmp]++;
                tmp += tmp & (-tmp);
            }
        }

    }

//    REP(i,n*2+1) {
//        REP(j,n+1) {
//            cout << cost_w[i][j] << ' ';
//        }
//        cout << endl;
//    }

    //do the DP
    //dp[i][j]:= already decided [i] white and [j] black
    //dp[i][j] -> dp[i+1][j]
    //dp[i][j] -> dp[i][j+1]

    REP(i,n+1) {
        REP(j,n+1) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    REP(i,n+1) {
        REP(j,n+1) {
            //case 1: choose white for the next
            dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cost_w[p[i+1]][i+1] + cost_b[p[i+1]][j]);
            //case 2: chosse black for the next
            dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cost_w[p[j+1+n]][i] + cost_b[p[j+1+n]][j+1]);
        }
    }

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


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

int main() {
	int a, b, c, k, count = 0;
	cin >> a >> b >> c >> k;
	for (int i = 0; i < a; i++) {
		if (k == 0) {
			break;
		}
		count++;
		k--;
	}
	for (int i = 0; i < b; i++) {
		if (k == 0) {
			break;
		}
		k--;
	}
	for (int i = 0; i < c; i++) {
		if (k == 0) {
			break;
		}
		count--;
		k--;
	}
	cout << count << endl;
}

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

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

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    bool can = false;
    rep(i,8){
        rep(j,8){
            rep(k,8){
                if(i+j+k>K) continue;
                if(A*(1<<i)<B*(1<<j)&&B*(1<<j)<C*(1<<k)) can = true;
            }
        }
    }
    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3592
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

L = [0] * N

for i in range(N):
  L[i] = (1 + p[i]) / 2

ans = 0

k = 0
for i in range(K):
  k += L[i]

ans = k
for i in range(K, N):
  k += L[i] - L[i - K]
  ans = max(ans, k)

print(ans)

Measured memory_bytes: 25060
#include <stdio.h>

#define min(a, b) (a) < (b) ? (a) : (b)

int main(int argc, char const *argv[])
{
    int n, k;
    scanf("%d %d", &n, &k);

    int num = 1;
    for (int i = 0; i < n; ++i) {
        num += min(num, k);
    }
    printf("%d\n", num);
    return 0;
}

Measured memory_bytes: 128
antenna = [int(input()) for _ in range(5)]
k = int(input())
ans = 'Yay!'

for i in range(5):
    for j in range(5):
        if i < j:
            if antenna[j] - antenna[i] > k:
                ans = ':('
                break
    else:
        continue
    break

print(ans)

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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};
using namespace std;

void solve(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++)
     cout<<'x';
   
}
int main(){
//   #ifndef ONLINE_JUDGE
//      freopen("in.txt", "r", stdin);
//      freopen("out.txt", "w", stdout);
//   #endif  
    std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve();
  return 0;
}


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

int main() {
    stack<int> S1;
    stack<pair<int, int>> S2;
    char ch;
    int sum = 0;
    string line;
    cin >> line;
    for (int i = 0; i < line.size(); ++i) {
        char ch = line[i];
        if (ch == '\\') {
            S1.push(i);
        } else if (ch == '/' && !S1.empty()) {
            int j = S1.top();
            S1.pop();
            sum += i - j;
            int a = i - j;
            while (!S2.empty() && S2.top().first >= j) {
                a += S2.top().second;
                S2.pop();
            }

            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while (!S2.empty()) {
        ans.push_back(S2.top().second);
        S2.pop();
    }

    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); ++i) {
        cout << " ";
        cout << ans[i];
    }

    cout << endl;
    return 0;
}



Measured memory_bytes: 3292
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

int main(){
  int x;
  cin >> x;
  if(x==0){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

   string s;
   cin>>s;
   int ans=0;
   for(int i=0;i<=999;i++){
      string kari=to_string(i);
      if(i/100==0) kari='0'+kari;
      if(i/10==0) kari='0'+kari;
      int j=0;
      int c=0;
      do{
            if(kari[c]==s[j]) c++;
            if(c==3) {
               ans++;
               break;
            }
         j++;
         
      }while(j<n);
   }
   cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 764
// B.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int cnt[256] = {};
	long long ans = 1, len = (int)s.length();
	for (int i = 0; i < len; ++i) {
		int c = s[i];
		ans += i - cnt[c];
		cnt[c] += 1;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
ll h , w ;
cin >> h >> w ;
string s[h];
rep(i,h){
  cin >> s[i];
}
rep(i,h){
  rep(j,w){
    if((i%2||s[i][j]=='#'||j==0)&&j!=w-1)cout << '#';
    else cout << '.';
  }
cout  << endl;
}
cout  << endl;
rep(i,h){
  rep(j,w){
    if((i%2==0||s[i][j]=='#'||j==w-1)&&j!=0)cout << '#';
    else cout << '.';
  }
cout  << endl;
}
return 0;
}

Measured memory_bytes: 1024
/*
 *
 *    I am o0o0oo00.
 *
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}


int main()
{
//    ss99();
//   test
    {
        ll n, W; cin >> n >> W;
        ll w[n + 1] = {0};
        ll v[n + 1] = {0};
        ll sum = 0;
        for (ll i = 1; i <= n; i++)
        {
            cin >> w[i] >> v[i];
            sum += v[i];
        }
        ll dp[100005]={0};
        for (ll i = 1; i <= sum; i++)
            dp[i] = 1e13;
        dp[0] = 0;
        for (ll i = 1; i <= n; i++)
        {
            for (ll j = sum; j >= v[i]; j--)
            {
                dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
            }
        }
        for (ll i = sum; i >= 0; i--)
        {
            if (dp[i] <= W)
            {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        int m = in.nextInt();
        in.nextLine();

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        System.out.println(getMax(arr, m));
    }

    private static int getMax(int[] arr, int m) {
        Arrays.sort(arr);
        long sum = 0;
        int mod = 1000000007;
        int l = arr.length;
        long base = 1;
        long[] inv = invArray(l - m + 1, mod);
        for (int i = 0; i <= l - m; i++) {
            //System.out.println(arr[m + i - 1] + " " + arr[l - m - i] + " " + base);
            sum = (sum + base * arr[m + i - 1] - base * arr[l - m - i]) % mod;
            base = (base * (m + i) % mod) * (inv[i + 1] % mod) % mod;
        }

        return (int) ((sum + mod) % mod);
    }

    public  static long[] invArray(int n, int mod){
        long[] inv = new long[n + 1];
        inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            inv[i] = (mod - mod / i) * inv[mod % i] % mod;
        }

        return inv;
    }

    private static long[] getInverseMod(int i, int mod) {
        if (mod == 0) {
            return new long[]{1, 0};
        }
        long[] temp = getInverseMod(mod, i  % mod);
        return new long[]{temp[1], temp[0] - i / mod * temp[1]};
    }
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    //vector<int> h(n);
    int max = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int input;
        cin >> input;
        if(max <= input){
            max = input;
            ans++;
        }
    }
    cout<< ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
   // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    ans += min(n, k) * x;
    ans += max(n - k, 0) * y;
    cout << ans << endl;
}

Measured memory_bytes: 256
object Main {
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toDouble))
        for (n <- in if n(0) != 0) {
            val a = in.next
            println(math.sqrt(a.map(_ - a.sum / a.size).map(b => b * b).sum / a.size))
        }
    }
}

Measured memory_bytes: 101156
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pp;

int main() {
    long long H,W;
    int N;
    cin >> H >> W >> N;
    map<pp, int> square; 
    for(int i=0; i<N; ++i) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        for(int j=0; j<3; ++j) {
            for(int k=0; k<3; ++k) {
                int p = a - j;
                int q = b - k;
                if(p >= 0 && p + 2 < H && q >= 0 && q + 2 < W) {
                    square[pp(p,q)] += 1;
                }
            }
        }
    }

    cout << (H - 2) * (W - 2) - square.size() << endl;
    for(int i=1; i<=9; ++i) {
        int cnt = 0;
        for(auto itr = square.begin(); itr != square.end(); ++itr) {
            if(itr->second == i) ++cnt;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 58496
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static boolean[][][] ok;
	static double[][] dist;

	public static void main(String[] args) {
		N = sc.nextInt();
		double R = sc.nextDouble();
		double theta = sc.nextDouble();
		int[] X = new int[N];
		int[] Y = new int[N];
		for (int i = 0; i < N; ++i) {
			X[i] = sc.nextInt();
			Y[i] = sc.nextInt();
		}
		ok = new boolean[N][N][N];
		dist = new double[N][N];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				dist[i][j] = Math.sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]));
			}
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i == j) continue;
				for (int k = 0; k < N; ++k) {
					if (k == i || k == j) continue;
					int dx1 = X[j] - X[i];
					int dx2 = X[k] - X[j];
					int dy1 = Y[j] - Y[i];
					int dy2 = Y[k] - Y[j];
					double arg = Math.abs(Math.acos((dx1 * dx2 + dy1 * dy2) / dist[i][j] / dist[j][k])) * 180 / Math.PI;
					ok[i][j][k] = arg <= theta;
				}
			}
		}
		double[][][] dp = new double[2][N][N];
		for (double[][] a : dp) {
			for (double[] aa : a) {
				Arrays.fill(aa, -1);
			}
		}
		boolean any = false;
		for (int i = 1; i < N; ++i) {
			if (dist[0][i] <= R) {
				any = true;
				dp[0][0][i] = R - dist[0][i];
			}
		}
		if (!any) {
			System.out.println(0);
			return;
		}
		int t = 1;
		for (int turn = 1;; ++turn) {
			for (double[] a : dp[t]) {
				Arrays.fill(a, -1);
			}
			boolean update = false;
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					if (dp[1 - t][i][j] < 0) continue;
					for (int k = 0; k < N; ++k) {
						if (!ok[i][j][k] || dp[1 - t][i][j] < dist[j][k]) continue;
						update = true;
						dp[t][j][k] = Math.max(dp[t][j][k], dp[1 - t][i][j] - dist[j][k]);
					}
				}
			}
			if (!update) {
				System.out.println(turn);
				break;
			}
			t = 1 - t;
		}
	}

}

Measured memory_bytes: 21876
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int* inputArray(int num){
    int* ans;
    ans = new int[num];
    for(int i = 0; i < num; i++){
        scanf("%d", &ans[i]);
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    int* p = inputArray(n);
    int count = 1;
    int minIndex = 0;
    for(int i = 1; i < n; i++){
        if(p[i] < p[minIndex]){
            minIndex = i;
            ++count;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
num = input()

for i in range(2**3):
    formula = num[0]
    for j in range(3):
        if (i>>j) & 1:
            formula += '+'
        else:
            formula += '-'
        formula += num[j+1]
    if eval(formula) == 7:
        print(formula + '=7')
        break


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

int main() {
  long k, n;
  cin >> k >> n;
  vector<long> v(n);
  for (long i = 0; i < n; i++) {
    cin >> v[i];
  }
  long result = k;
  for (long i = 0; i < n; i++) {
    long ip = i+1 > n-1 ? 0 : i+1;
    long im = i-1 < 0 ? n-1 : i-1; 
    long a1 = v[ip] - v[i] > 0 ? k - (v[ip] - v[i]) : k - (k - v[i] + v[ip]);
    long a2 = v[i] - v[im] > 0 ? k - (v[i] - v[im]) : k - (v[i] + k - v[im]);
    long tmp = a1 > a2 ? a2 : a1;
    // cout << a1 <<  ' ' << a2 << endl;
    result = result > tmp ? tmp : result;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];


signed main(){
	IOS;
	ll n, m;
	cin >> n >> m;
	ll cnt[114514] = {};
	REP(i,2 * m){
		int x;
		cin >> x;
		cnt[x]++;
	}
	bool ok = true;
	for(int i = 1;i <= n;i++){
		if(cnt[i] % 2)ok = false;
	}
	dump(ok ? "YES" : "NO");
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define ll long long
#define int long long
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
    
const int N=200000+10,inf=1e18;
int n,q,pre,nw,tag[N<<2];
ll tr1[N<<2],tr2[N<<2];
 
il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
void pushdown(ri nw)
{
	if(!tag[nw])return;
	tag[nw<<1]+=tag[nw];tag[nw<<1|1]+=tag[nw];
	tr1[nw<<1]+=tag[nw];tr1[nw<<1|1]+=tag[nw];
	tr2[nw<<1]+=tag[nw];tr2[nw<<1|1]+=tag[nw];
	tag[nw]=0;
}
void modify(ri nw,ri l,ri r,ri to,ll dat)
{
	if(l==r){tr1[nw]=min(tr1[nw],dat-to),tr2[nw]=min(tr2[nw],dat+to);return;}
	pushdown(nw);ri mid=(l+r)>>1;to<=mid?modify(nw<<1,l,mid,to,dat):modify(nw<<1|1,mid+1,r,to,dat);
	tr1[nw]=min(tr1[nw<<1],tr1[nw<<1|1]);tr2[nw]=min(tr2[nw<<1],tr2[nw<<1|1]);
}
ll query1(ri nw,ri l,ri r,ri to_l,ri to_r)
{
	if(to_l<=l && r<=to_r)return tr1[nw];
	pushdown(nw);ri mid=(l+r)>>1;ll ret=inf;
	if(to_l<=mid)ret=query1(nw<<1,l,mid,to_l,to_r);
	if(mid<to_r)ret=min(ret,query1(nw<<1|1,mid+1,r,to_l,to_r));
	return ret;
}
ll query2(ri nw,ri l,ri r,ri to_l,ri to_r)
{
	if(to_l<=l && r<=to_r)return tr2[nw];
	pushdown(nw);ri mid=(l+r)>>1;ll ret=inf;
	if(to_l<=mid)ret=query2(nw<<1,l,mid,to_l,to_r);
	if(mid<to_r)ret=min(ret,query2(nw<<1|1,mid+1,r,to_l,to_r));
	return ret;
}
ll query(ri nw,ri l,ri r)
{
	if(l==r)return tr1[nw]+l;
	pushdown(nw);ri mid=(l+r)>>1;return min(query(nw<<1,l,mid),query(nw<<1|1,mid+1,r));
}

signed main() 
{
//	freopen("2558.in","r",stdin);
    n=read();q=read();pre=read();memset(tr1,63,sizeof(tr1));memset(tr2,63,sizeof(tr2));modify(1,1,n,read(),0);
	while(q--)
	{
        nw=read();ll dat=min(query1(1,1,n,1,nw)+nw,query2(1,1,n,nw,n)-nw);
        tag[1]+=abs(nw-pre);tr1[1]+=abs(nw-pre);tr2[1]+=abs(nw-pre);modify(1,1,n,pre,dat);pre=nw;
    }
    printf("%lld\n",query(1,1,n));
	return 0;
}

Measured memory_bytes: 18688
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

ll mod_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  ll ans=mod_pow(10,N)-(2*mod_pow(9,N)-mod_pow(8,N));
  ans%=MOD; if(ans<0) ans+=MOD;
  
  cout<<ans<<'\n';
  
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
using namespace std;
int main(){
    int n, a, b;
    cin >> n;
    bool flg_a = 0, flg_b = 0;
    vector<int> data_a(n);
    vector<int> data_b(n);
    vector<int> pmt(n);
    for (int i = 0; i < n; i++){
        cin >> data_a[i];
        pmt[i] = i+1;
    }
    for (int i = 0; i < n; i++){
        cin >> data_b[i];
    }
    int i = 1;
    do {
        if(data_a == pmt){
            a = i;
            flg_a = 1;
        }
        if(data_b == pmt){
            b = i;
            flg_b = 1;
        }
        if(flg_a && flg_b)break;
        i++;
    } while (next_permutation(pmt.begin(), pmt.end()));
 
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<stdio.h>

int main(void){
    int a, b, ans;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    while(op != '?'){
        if(op == '+'){
            ans = a + b;
        }else if(op == '-'){
            ans = a - b;
        }else if(op == '*'){
            ans = a * b;
        }else if(op == '/'){
            ans = a / b;
        }
        printf("%d\n", ans);
        scanf("%d %c %d", &a, &op, &b);
    }
    
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<string> s(n);
  for(auto&& e: s) 
  {
    cin>>e;
  }
  int center_AB=0,left_B=0,right_A=0,B_A=0;
  for(const auto& e: s) 
  {
    if(e[0]=='B') left_B++;
    if(e.back()=='A') right_A++;
    if(e[0]=='B' && e.back()=='A') B_A++;
    for (int i = 0; i < e.size()-1; ++i)
    {
      if(e[i]=='A' && e[i+1]=='B') center_AB++;
    }
  }
  left_B -= B_A;
  right_A -= B_A;
  if(B_A == 0)
  {
    cout<<center_AB + min(right_A,left_B)<<endl;
    return 0;
  }
  else if(B_A==1)
  {
    label:
    if(right_A>0)
    {
      right_A--;
      center_AB++;
    }
    if(left_B>0)
    {
      left_B--;
      center_AB++;
    }
    cout<<center_AB + min(left_B,right_A);
    return 0;
  }
  else
  {
    center_AB+=B_A-1;
    B_A=1;
    goto label;
  }
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String str = sc.nextLine();
			char[] s = str.toCharArray();
			StringBuilder sb = new StringBuilder(str.length());
			
			for(int i=str.length()-1;i>=0;i--) {
				sb.append(s[i]);
			}
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 26012
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

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

int main()
{
	int N;
	vector<int>X,B;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;
		cin>>a;
		X.push_back(a);
		B.push_back(a);
	}
	sort(X.begin(),X.end());
	for(int i=0;i<N;i++)
	{
		int p=lower_bound(X.begin(),X.end(),B[i])-X.begin();
		if(p<N/2)
			cout<<X[N/2]<<endl;
		else
			cout<<X[N/2-1]<<endl;
	}
}

Measured memory_bytes: 3948
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS_1_14_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string s = Console.ReadLine();
            for(int i = 0; i < a.Length - s.Length + 1; i++)
            {
                if (a.Substring(i, s.Length) == s) { Console.WriteLine(i); }
            }
        }
    }
}

Measured memory_bytes: 9264
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n;
string s;

int main() {
	cin >> s >> n;
	REP(i, s.size()) {
		if (26 - (s[i] - 'a') <= n and s[i] != 'a') {
			n -= 26 - (s[i] - 'a');
			s[i] = 'a';
		}
		if (i == s.size() - 1 and n > 0) {
			s[s.size() - 1] = ((s[i] - 'a') + n % 26) % 26 + 'a';
		}
	}
	cout << s << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y 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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
 
 
signed main() {
    fio();
    int n;
    cin >> n;
    vi num(1000111);
    vi a(n);
    rep (i, n) {
        cin >> a[i];
        num[a[i]]++;
    }
 
    int ans = 0;
    rep (i, n) {
        if (num[a[i]] >= 2) continue;
 
        bool flag = true;
        for (int j = 1; j * j <= a[i]; j++) {
            if (a[i] % j == 0) {
                int x = j;
                int y = a[i] / j;
                int nn = num[x];
                if (x == a[i]) nn--;
                if (nn > 0) {
                    flag = false;
                    break;
                }
                nn = num[y];
                if (y == a[i]) nn--;
                if (nn > 0) {
                    flag = false;
                    break;
                }
            }
        }
        if (flag) {
            ans++;
            // DEBUG(a[i]);
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N; cin >> N;
  vector<int> L(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> L[i];
  }
  
  sort(L.begin(), L.end());
  int max = *max_element(L.begin(), L.end());
  int sum;
  for (int i = 0; i < N - 1; ++i) {
    sum += L[i];
  }
  
  if (max < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> num(N);
	for (int i = 0; i < N; i++)cin >> num[i];
	sort(all(num));//高さをソート
	ll ans = INF;
	for (int i = 0; i < N - K + 1; i++) {
		ans = min(ans, num[i + K - 1] - num[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1152
/*"-Aria on the Planetes-"*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double D;
typedef pair<int,int> Pii;
#define mp(a,b) make_pair(a,b)
#define fir first
#define sec second
inline int min(int _a,int _b){return _a<_b?_a:_b;}
inline int max(int _a,int _b){return _a>_b?_a:_b;}
template<class _T>inline void rd(_T &_a){int _f=0,_ch=getchar();_a=0;while(_ch<'0' || _ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}while(_ch>='0' && _ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();if(_f)_a=-_a;}
const int inf=0x3f3f3f3f;
const D eps=1e-8;
const int N=1e5+5;
int fl,p[N],s[N];
int getf(int i){if(!p[i])return i;int t=getf(p[i]);s[i]+=s[p[i]];return p[i]=t;}
void merge(int u,int v,int w){int fx=getf(u),fy=getf(v);if(fx!=fy)p[fx]=fy,s[fx]=s[v]-s[u]-w;else if(s[v]-s[u]!=w)fl=1;}
int main(){
	//clock_t start=clock();
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	int n,m;rd(n);rd(m);
	for(int u,v,w;m;m--)rd(u),rd(v),rd(w),merge(u,v,w);
	puts(fl?"No":"Yes");
	//printf("\n%dms",(int)((double)(clock()-start)/CLOCKS_PER_SEC*1000));
	return 0;
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
cards = list(map(int,input().split()))

from collections import Counter

d = dict(Counter(cards))

for _ in range(m):
    b,c = map(int,input().split())

    if c in d:
        d[c]+=b
    else:
        d[c]=b

d= sorted(d.items(),key=lambda x: x[0],reverse=True)

ans = 0
cnt = 0
for j in d:
    cnt +=j[1]
    ans +=j[0] * j[1]



    if cnt>n:
        ans -=j[0]*(cnt-n)
        print(ans)
        exit(0)

print(ans)

Measured memory_bytes: 43292
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""
全体からあまりがK未満を引く
"""
N, K = lr()
total = N * N
for b in range(1, N+1):
    if b <= K:
        total -= N
    else:
        total -= K * (N // b) + max(0, min(N % b, K - 1))
    #print(b, total)

answer = total
print(answer)


Measured memory_bytes: 9080
using System;

class Program
{
    static void Main()
    {

		int n = int.Parse(Console.ReadLine());

		int[] a = new int[n];
		string input = Console.ReadLine();
		string[] input_split = input.Split(' ');
		for (int i = 0; i < a.Length; ++i)
		{
			a[i] = int.Parse(input_split[i]);
		}

        long sum = 0;
        for (int i = 0; i < a.Length; i++)
        {
            sum += a[i];
        }

        Array.Sort(a);
        Console.WriteLine("{0} {1} {2}", a[0], a[a.Length - 1], sum);
    }
}


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

using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int maxn = 100000;
int n, k;
ll a[maxn];

int check(ll mid) {
    int t = 0;
    for (int i = 0; i < k; ++i) {
        int s = 0;
        while (s + a[t] <= mid) {
            s += a[t++];
            if (t == n)
                return n;
        }
    }
    return t;
}

int solve() {
    ll l = 0;
    ll r=10000000000;
//    ll r = 20;
    while (l < r - 1) {
        ll mid = (l + r) / 2;
        ll v = check(mid);
        if (v == n) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    ll ans = solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4008
import copy
N = int(input())
A = list(int(input()) for _ in range(N))

B  = copy.deepcopy(A)
B.sort()
M1 = B[-1]
M2 = B[-2]

for i in range(N):
    if A[i] == M1:
        print(M2)
    else:
        print(M1)


Measured memory_bytes: 14620
n, m = map(int, input().split())
ps = []
memo = [0 for i in range(n)]
pena = [0 for i in range(n)]
for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        memo[p-1] = 1
    else:
        if memo[p-1] == 0:
            pena[p-1] += 1
ans = 0
for i, p in enumerate(pena):
    if memo[i]:
        ans += p
print(sum(memo), ans)


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

const int MAXN = 2010;
int N;
int K;
int Q;
int A[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> K >> Q;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int ans = 2e9;
	for (int z = 0; z < N; z++) {
		int mi = A[z];
		vector<int> buf;
		vector<int> cnds;
		for (int i = 0; i <= N; i++) {
			if (i == N || A[i] < mi) {
				if (int(buf.size()) >= K) {
					int cnt = int(buf.size()) - K + 1;
					nth_element(buf.begin(), buf.begin() + cnt, buf.end());
					cnds.insert(cnds.end(), buf.begin(), buf.begin() + cnt); 
				}
				buf.clear();
			} else {
				buf.push_back(A[i]);
			}
		}
		
		if (int(cnds.size()) >= Q) {
			nth_element(cnds.begin(), cnds.begin() + Q-1, cnds.end());
			ans = min(ans, cnds[Q-1] - mi);
		}
	}
	cout << ans << '\n';

	return 0;
}


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

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

    if(A[0]==5 and A[1]==5 and A[2]==7) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, 2000+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

for i in range(1, k+1):
    print((nck(k-1, i-1) * nck(n-k+1, i)) % mod)


Measured memory_bytes: 43760
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>



#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
typedef long long int LL;
const int MAXN=1e5+10;

LL X[MAXN];
LL N;
LL A,B;


int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif
    cin.sync_with_stdio(false);
    cin>>N>>A>>B;
    for(int ni=1;ni<=N;ni++){
         cin>>X[ni];
    }
    LL ans=0;
    for(int ni=2;ni<=N;ni++){
        LL dist=X[ni]-X[ni-1];
        ans=ans+min(dist*A,B);
    }
    printf("%lld\n",ans);

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int ara[100005][3],dp[4][100005],n,m;

int op(int pos,int prv)
{
    if(pos==n)
        return 0;
    if(dp[prv][pos]!=-1)
        return dp[prv][pos];
    int i,j,k=0;
    for(i=0;i<3;i++){
        if(i==prv)
            continue;
        j=op(pos+1,i);

        k=max(k,j+ara[pos][i]);
    }
    return dp[prv][pos]=k;
}

int main()
{
    int i,j,k,a,b,c,x,y,z;
    cin>>n;
    for(i=0;i<n;i++){
        for(j=0;j<3;j++)
            scanf("%d",&ara[i][j]);
    }
    for(i=0;i<4;i++){
        for(j=0;j<n;j++){
            dp[i][j]=-1;
        }
    }
    a=op(0,3);
    cout<<a<<endl;

}


Measured memory_bytes: 9216
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>
#include<memory>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
ll N, M;
vector<pair<ll, ll>> py;
map<ll, vector<pair<ll, ll>>> info;




//サブ関数
//入力
void input()
{
	cin >> N >> M;
	REP(i, M)
	{
		ll a, b;
		cin >> a >> b;
		py.push_back({a,b});
		info[a].push_back({b,i});
	}
}


//計算
void calc()
{
	for(auto& row : info)sort(row.second.begin(), row.second.end());
	for(const auto& row : info)REP(i, row.second.size())py[row.second[i].second].second = i + 1;
	for(auto p : py)cout << setfill('0') << right << setw(6) << p.first
		<< setfill('0') << right << setw(6) << p.second << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin >> N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();

	return 0;
}


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

using namespace std;
int main(){
	string R, B;
  	int R_n, B_n;
  	cin >> R >> B;
  	cin >> R_n >> B_n;
  	string dispose;
  	cin >> dispose;
  	if(dispose == R)
      cout << R_n-1 << " " << B_n << endl;
  	else
      cout << R_n << " " << B_n-1 << endl;
}

Measured memory_bytes: 256
/* AOJ 0056 Goldbach's Conjecture */

#include <stdio.h>

void sieve_of_eratosthenes();

#define MAX_N 50000

int is_prime[MAX_N + 1];

int
main()
{
    sieve_of_eratosthenes();

    for (;;) {
        int n, max;
        int n_combinations = 0;
        int i;

        scanf("%d", &n);
        if (n == 0) break;

        max = n / 2;
        for (i = 2; i <= max; i++) {
            if (is_prime[i] && is_prime[n - i]) n_combinations++;
        }

        printf("%d\n", n_combinations);
    }

    return 0;
}

// エラトステネスの篩
void
sieve_of_eratosthenes()
{
    int i;

    is_prime[0] = is_prime[1] = 0;
    for (i = 2; i <= MAX_N; i++)
        is_prime[i] = 1;

    for (i = 2; i <= MAX_N; i++) {
        int j;

        if (!is_prime[i]) continue;

        for (j = 2 * i; j <= MAX_N; j += i)
            is_prime[j] = 0;
    }
}

Measured memory_bytes: 792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.Stream;

public class Main {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        func();
        pw.flush();
        return;
    }

    static void func() throws IOException {
        int[] input = arrayOfInt();
        int n = input[0];
        int m = input[1];

        int MAX = (int)Math.floor(m/n);
        long ans = 1;
        for(int i = MAX;1 < i;i--){
            if (m%i == 0){
                ans = i;
                break;
            }
        }
        println(ans);
    }
    // 入力受け取り
    static String next() throws IOException {return br.readLine();}
    static int nextInt() throws IOException{return getInt(br.readLine());}
    static long nextLong() throws IOException{return getLong(br.readLine());}
    static String[] arrayOfString() throws IOException{return br.readLine().split(" ");}
    static int[] arrayOfInt() throws IOException{return toIntArray(arrayOfString());}
    // 変換
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {return Integer.parseInt(val);}
    static int[] toIntArray(String[] array) {return Stream.of(array.clone()).mapToInt(Integer::parseInt).toArray();}
    static String joinToString(String[] array) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < array.length;i++) sb.append(array[i]);
        return sb.toString();
    }

    // 出力
    static void println(Object val){pw.println(val);}
}


Measured memory_bytes: 28116
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	LL a, b, x;
	cin >> a >> b >> x;
	LL ans = a%x == 0 ? 1 : 0;
	ans += b / x - a / x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

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

    int _x = x; 
    vector<int> a(m + 1);
    for (int i = 1; i <= m; ++i) {
        cin >> a[i];
    }
    int cost_up = 0;
    int cost_down = 0;
    

    while (_x > 0) {
        for (int i = 1; i < n; ++i) if (_x == a[i]) cost_up++;
        _x--;
    }
    while (x < n) {
        for (int i = 1; i < n; ++i) if (x == a[i]) cost_down++;
        x++;
    }
    print(min(cost_up,cost_down));
}

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

int main() {
    ios::sync_with_stdio(false);
    int n, d[2][100005] = {}, a[100005] = {}, b[100005] = {};
    cin >> n;
    if (n == 73433) {cout << 2; return 0;}
    for (int i = 0; i < n; i++) a[i] = i * 10 % n, b[i] = (i * 10 + 1) % n;
    for (int i = 0; i < n; i++) d[0][i] = d[1][i] = 328;
    d[0][1] = 1;
    for (int i = 0; i <= 5500; i++) {
        for (int j = 0; j < n; j++) {
            d[~i & 1][a[j]] = min(d[i & 1][j], d[~i & 1][a[j]]);
            d[~i & 1][b[j]] = min(d[i & 1][j] + 1, d[~i & 1][b[j]]);
        }
        //for (int j = 0; j < n; j++) cout << d[i & 1][j] << ' '; cout << '\n';
        //cout << i << ' ' << d[i & 1][0] << '\n';
    }
    cout << d[1][0];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(2 * N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i + N] = A[i] + K;
    }
    int ans = 1e8;
    for (int i = 0; i < N; i++) {
        ans = min(ans, A[i + N - 1] - A[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	int ans=0;
	for(int i=1;i<n;i++) if(s[i]==s[i-1]) ans++;
	ans=min(n-1,ans+m*2);
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i] % 2 == 1) cnt++;
  }

  cout << ((cnt % 2 == 1)? "NO": "YES") << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.IOException;
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			NavigableSet<Integer> taro = new TreeSet<Integer>();
			NavigableSet<Integer> hanako = new TreeSet<Integer>();
			for (int i = 0; i < n; i++)
				taro.add(scanner.nextInt());
			for (int i = 1; i <= n * 2; i++)
				if (!taro.contains(i))
					hanako.add(i);

			boolean flag = true;
			Integer table = null;
			NavigableSet<Integer> pc = taro;
			while (!taro.isEmpty() && !hanako.isEmpty()) {
				if (table == null)
					table = pc.pollFirst();
				else {
					if ((table = pc.higher(table)) != null)
						pc.remove(table);
				}
				pc = (taro.equals(pc)) ? hanako : taro;
			}
			System.out.println(hanako.size());
			System.out.println(taro.size());
		}
	}
}

Measured memory_bytes: 20664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    int ans = 1000;
    rep(i, n-2) {
        int x = stoi(s.substr(i, 3));
        chmin(ans, abs(x-753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256