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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
using ll = long long;
using vi = vector<int>;

// rank無しなのでlog n
class UnionFind{
public:
  vi data;

  UnionFind(int size){
    data.resize(size,-1);
    //rep(i, size) data[i] = -1;
  }

  bool unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }

  bool find(int x, int y){
    return root(x) == root(y);
  }

  int root(int x){ // どの集合か
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  int size(int x){
    return -data[root(x)];
  }
};

signed main(){
  int n; cin >> n;
  vector<int> x(n), y(n); rep(i,n) cin >> x[i] >> y[i];
  
  #define MAX 100005
  UnionFind ufx(MAX), ufy(MAX);
  vector<vector<int>> sx(MAX), sy(MAX);
  rep(i,n){
    sx[x[i]].push_back(y[i]);
    sy[y[i]].push_back(x[i]);
  }
  rep(i,MAX){
    FOR(j,1,sx[i].size())
      ufy.unite(sx[i][0], sx[i][j]);
    FOR(j,1,sy[i].size())
      ufx.unite(sy[i][0], sy[i][j]);
  }
  vector<int> usedx(MAX);
  int maxv = 0;
  rep(i,n)
    if(usedx[ufx.root(x[i])] == 0){
      maxv += ufx.size(x[i]) * ufy.size(y[i]);
      usedx[ufx.root(x[i])] = 1;
    }
  cout << maxv - n << endl;
}


Measured memory_bytes: 12544
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int A, B;
        cin >> A >> B;

        Int K;
        cin >> K;
        Int turn = 0;
        while (K--) {
            if (turn == 0) {
                if (A % 2) A--;
                A /= 2;
                B += A;
            } else {
                swap(A, B);
                if (A % 2) A--;
                A /= 2;
                B += A;
                swap(A, B);
            }

            turn = 1 - turn;
        }

        cout << A << " " << B << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> V;
    for (int i = 0; i < N; ++i) {
        int v;
        cin >> v;
        V.push_back(v);
    }
    sort(V.begin(), V.end());
    int i = 0;
    double ans = V[i];
    for (int i = 1; i < N; ++i) {
        int v = V[i];
        ans = (ans + v) / 2.0;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    string S;
    cin >> S;
    int len = S.size();
    int count = 0;
    rep(i, len) {
        if (S[i] == '1') count++;
    }
    cout << 2 * min(count, len - count) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int INF = 1000;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    string ans = "";
    rep(i,26){
        char c = 'a' + i;
        int cnt = INF;
        rep(j, n){
            int cnt_c = 0;
            rep(k, s[j].size()){
                if (s[j][k] == c) cnt_c++;
            }
            cnt = min(cnt, cnt_c);
        }
        rep(j, cnt) ans += c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
from itertools import permutations
N, M = list(map(int, input().split(' ')))
ADJ_MAT = [[0 for _ in range(N)] for _ in range(N)]
for _ in range(M):
    a, b = list(map(int, input().split(' ')))
    ADJ_MAT[a - 1][b - 1] = 1
    ADJ_MAT[b - 1][a - 1] = 1
answer = 0
for node_pattern in permutations(range(1, N)):
    # first node is fixed
    node_pattern = [0] + list(node_pattern)
    exists_path = True
    for i in range(N - 1):
        node_from = node_pattern[i]
        node_to = node_pattern[i + 1]
        if ADJ_MAT[node_from][node_to] == 0:
            exists_path = False
            break
    if exists_path:
        answer += 1
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string N;
  lint K;
  cin>>N>>K;
  lint L=N.size();
  lint n[L];
  REP(i,L)n[i]=N[i]-'0';
  lint dp0[L+1][4];
  lint dp1[L+1][4];
  REP(i,L+1)REP(j,4){
    dp0[i][j]=0;
    dp1[i][j]=0;
  }
  dp1[0][0]=1;
  FOR(i,1,L+1){
    FOR(j,1,4)dp0[i][j]+=9*dp0[i-1][j-1];
    REP(j,4)dp0[i][j]+=dp0[i-1][j];
    if(n[i-1]==0){
      REP(j,4)dp1[i][j]=dp1[i-1][j];
    }else{
      FOR(j,1,4)dp1[i][j]=dp1[i-1][j-1];
      REP(j,4)dp0[i][j]+=dp1[i-1][j];
      FOR(j,1,4)dp0[i][j]+=(n[i-1]-1)*dp1[i-1][j-1];
    }
  }
  // REP(i,L+1){
  //   REP(j,4)cerr<<dp0[i][j]<<" "<<dp1[i][j]<<"||";
  //   cerr<<endl;
  // }
  cout<<dp0[L][K]+dp1[L][K]<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
#define INF (INT_MAX)
int main(){
  int v,e,s,t,d;
  int graph[100][100];
  fill_n(*graph,100*100,INF);
  
  scanf("%d %d",&v,&e);
  for(int i=0;i<v;i++) graph[i][i] = 0;
  for(int i=0;i<e;i++){
    scanf("%d %d %d",&s,&t,&d);
    graph[s][t] = d;
  }

  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      for(int k=0;k<v;k++){
	if(graph[j][i]!=INF && graph[i][k]!=INF){
	  graph[j][k] = min(graph[j][k],graph[j][i]+graph[i][k]);
	}
	if(graph[i][i]<0){
	  puts("NEGATIVE CYCLE");
	  return(0);
	}
      }
    }
  }

  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      printf(graph[i][j]==INF?"INF":"%d",graph[i][j]);
      putchar(j==v-1?'\n':' ');
    }
  }

  return(0);
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    ll n;
    cin >> n;
    ll mx;
    cin >> mx;

    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        ll x;
        cin >> x;
        if (x < mx) ans += mx - x;
        mx = max(mx, x);
    }

    cout << ans << endl;

    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            if (s == "Sunny")
                Console.WriteLine("Cloudy");
            else if (s == "Cloudy")
                Console.WriteLine("Rainy");
            else
                Console.WriteLine("Sunny");
        }
    }
}


Measured memory_bytes: 11092
def main():
    N=int(input())
    a=list(map(int, input().split()))
    c = 0
    for i in range(N):
        if a[i] == c + 1:
            c += 1
    if c == 0:
        print(-1)
    else:
        print(N-c)

if __name__ == '__main__':
    main()

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


using namespace std;

typedef pair<int, int> pii;
#define lp(i, s, e) for (int i = s; i < e; ++i)
#define lpi(i, s, e) for (int i = s;i <= e; ++i)
typedef long long ll;

int main() {
	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	if (k == 1) {
		int cnt = 0;
		int last = 0;
		int ans = 0;
		lp(i, 1, n) {
			if (s[i] != s[i - 1]) {
				ans += (i - last) / 2;
				last = i;
			}
		}
		ans += (n - last) / 2;
		cout << ans;
		return 0;
	}
	int last = n - 2;
	while (last >= 0 && s[last] == s[last + 1]) {
		--last;
	}
	++last;
	if (!last) {
		// cout << "Kek\n";
		cout << 1LL * k * n / 2;
		return 0;
	}
	int first = 0;
	while(s[first] == s[n - 1]) {
		++first;
	}
	ll ans = 0;
	ans += (n - last + first) / 2 * 1LL * (k - 1);
	// cout << ans << '\n';
	int cnt = 0;
	int last_pos = first;
	lp(i, first + 1, last) {
		if (s[i] != s[i - 1]) {
			cnt += (i - last_pos) / 2;
			last_pos = i;
		}
	}
	cnt += (last - last_pos) / 2;
	ans += 1LL * k * cnt;
	ans += first / 2 + (n - last) / 2;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000) 
H, N = map(int, input().split())
List = list(map(int, input().split()))
A = 0

for i in range(N):
    A += List[i]


def calc_atack(H, A, counter =0):
    if H - A <= 0:
        return('Yes')
    else:
        return('No')

print(calc_atack(H, A))

Measured memory_bytes: 14092
#include <iostream>
using namespace std;
int main(){
int a,b;
    while(1){
cin>>a>>b;
if(a==0 && b==0)
break;
if(a<b)
cout<<a<<" "<<b;
else cout<<b<<" "<<a;
cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
int dp[200010];

int dfs(int n) {
    if (dp[n] >= 0) return dp[n];
    if (n == 0) return 0;
    int popcnt = __builtin_popcount(n);
    if (n%popcnt == 0) {
        dp[n] = 1;
        return 1;
    }
    dp[n] = dfs(n%popcnt) + 1;
    return dp[n];
}

long long modpow(long long N,long long K,long long mod = MOD) {
    long long ret = 1;
    while (K > 0) {
        if (K&1) {
            ret *= N;
            ret %= mod;
        }
        K >>= 1;
        N *= N;
        N %= mod;
    }
    return ret;
}
int main() {
    int N; cin >> N;
    rep(i,N + 1) {
        dp[i] = -1;
    }
    string X; cin >> X;
    int cnt = 0;
    rep(i,N) {
        if (X[i] == '1') ++cnt;
    }
    if (cnt == 0) {
        rep(i,N) cout << 1 << '\n';
        return 0;
    }

    vector<ll> modul1(N,0);
    vector<ll> modul2(N,0);
    rep(i,N) {
        if (cnt > 1) modul1[i] = modpow(2,i,cnt - 1);
        modul2[i] = modpow(2,i,cnt + 1);
    }
    int ret1 = 0,ret2 = 0;
    rep(i,N) {
        if (X[N - i - 1] == '1') {
            if (cnt > 1) {
                ret1 += modul1[i];
                ret1 %= (cnt - 1);
            }
            ret2 += modul2[i];
            ret2 %= (cnt + 1);
        }
    }
    
    vector<ll> ans(N,0);
    rep(i,N) {
        if (X[i] == '1') {
            if (cnt == 1) continue;
            ll ret = ret1;
            ret -= modul1[N - i - 1];
            ret += cnt - 1;
            ret %= (cnt - 1);
            ans[i] = dfs(ret) + 1;
        }
        else {
            ll ret = ret2;
            ret += modul2[N - i - 1];
            ret %= (cnt + 1);
            ans[i] = dfs(ret) + 1;
        }
    }
    rep(i,N) cout << ans[i] << '\n';
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int A,B;
  cin>>A>>B;
  int Max=-100;
  Max=max(Max,A+B);
  Max=max(Max,A-B);
  Max=max(Max,A*B);
  cout<<Max<<endl;
  return 0;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
long long n,c;
long long f[101][100001];
long long v[101],w[101];
int main()
{
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&w[i],&v[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=c;j++)
		{
			f[i][j]=f[i-1][j];
			if(j>=w[i])
				f[i][j]=max(f[i][j],f[i-1][j-w[i]]+v[i]);
		}
	printf("%lld",f[n][c]);
}

Measured memory_bytes: 78336
n,m=map(int,input().split())
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
a=[int(input()) for i in range(m)]
isbroken=[1]*(n+1)
for i in range(m):
    isbroken[a[i]]=0
for i in range(n):
    if i-1>=0:
        dp[i+1]=dp[i]*isbroken[i]+dp[i-1]*isbroken[i-1]
    else:
        dp[i+1]=dp[i]*isbroken[i]
    dp[i+1]%=mod
print(dp[n])

Measured memory_bytes: 9592
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <regex>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iterator>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0;i < n;i++)
using namespace std;

int n, m;
string s;
int main() {
	cin >> s;
	rep(i, s.size()) {
		if (i % 2 == 0) cout << s[i];
	}
  cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<string>
#include<queue>
using namespace std;
template<typename T>inline T read(){
	register char c=getchar();register T x=0,b=1;
	for(;!isdigit(c);)b=(c=='-'?-1:1),c=getchar();
	for(;isdigit(c);)x=x*10+c-48,c=getchar();
	return x*b;
}
template<typename T>void put(T x){ //no negative
	if(x>9)put(x/10);
	putchar(x%10+48);
}
priority_queue<double>p;
int main(){
	register int n=read<int>();
	for(register int i=1;i<=n;++i)p.push(-read<int>());
	for(register int i=1;i<n;++i){
		register double x=-p.top();p.pop();
		register double y=-p.top();
		p.pop(),p.push(-(x+y)/2);
	}
	cout<<-p.top();
	return 0;
}




Measured memory_bytes: 256
import numpy as np
n,m,q = [int(i) for i in input().split()]

trains = np.zeros([n+1,n+1],dtype = np.int32)

l,r = np.split(np.array([input().split() for _ in range(m)],dtype = np.int32),2,1)
p,q = np.split(np.array([input().split() for _ in range(q)],dtype = np.int32),2,1)


np.add.at(trains,(l,r),1)
ans_arr = np.cumsum(np.cumsum(trains,axis = 0),axis = 1)

p -= 1
ans = ans_arr[q,q] - ans_arr[p,q] - ans_arr[q,p] + ans_arr[p,p]
print('\n'.join(ans.astype(str).flatten()))


Measured memory_bytes: 77704
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const x = arg[1].split(" ").map(n=>parseInt(n));
    
    const list = [];
    
    for(let i=0; i<=N - K; i++) {
        let left  = x[i];
        let right = x[~~i + K - 1];
        
        if(Math.abs(left) < Math.abs(right)) {
            list.push(Math.abs(left) + Math.abs(right - left));
        } else {
            list.push(Math.abs(right) + Math.abs(right - left));
        }
    }
    
    console.log(Math.min(...list));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
    int n;
    long long k;
    cin >> n >> k;
    
    vector<int> A(n);
    vector<int> Acnt(2001,0);
    for (int i = 0; i < n; i++){
        cin >> A.at(i);
        Acnt[A[i]]++;
    }

    long long ans1=0;
    for (int i = 0; i < n-1; i++){
        for (int j = i+1; j < n; j++){
            if(A[i]>A[j]){
                ans1=(ans1+k)%(7+(long long)1e9);
            }
        }
    }
    long long temp=0;
    long long ans2=0;
    long long kk;

    if(k%2==0){
        kk=((k/2)*(k-1))%(7+(long long)1e9);
    }
    else{
        kk=(k*((k-1)/2))%(7+(long long)1e9);
    }
    for (int i = 1; i < 2001; i++){
        if(Acnt[i]!=0){
            ans2=ans2+temp*Acnt[i];
            temp=temp+Acnt[i];
        }
    }
    ans2=(ans2*kk)%(7+(long long)1e9);
    
    cout << (ans1+ans2)%(7+(long long)1e9) << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
struct Guide{
    string s;
    int num,p;
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<Guide>book(n);
    map<string,vector<int>> A;

    REP(i,n){
        book[i].num= i+1;
        cin >> book[i].s >> book[i].p;
    }
    sort(book.begin(), book.end(), [](const Guide &x, const Guide &y){ return x.p>y.p;});
    REP(i,n){
        A[book[i].s].push_back(book[i].num);
    }
    for(auto itr = A.begin(); itr != A.end(); ++itr) {
   // 値を表示
        REP(i,itr->second.size()){
            cout << itr->second[i] << endl;
        }
    }

}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = []
stair = [1 for i in range(N+1)]
for i in range(M):
    stair[int(input())] = 0

dp = [0 for i in range(N+1)]

dp[0] = 1

MOD = 1000000007

for i in range(1, N+1):
    if stair[i] == 1:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD

print(dp[N])


Measured memory_bytes: 50848
from itertools import product

n, m, x = map(int, input().split())
price = [0] * (n)
AA = []
for i in range(n):
    c, *A = map(int, input().split())
    price[i] = c
    AA.append(A)

kumiawase = list(product([0, 1], repeat=n))

ans = 10 ** 20
flag = 0
for kumi in kumiawase:
    temp = 0
    memo = [0] * (m)
    for i in range(n):
        if kumi[i] == 1:
            temp += price[i]
            for j in range(m):
                memo[j] += AA[i][j]
    for j in range(m):
        if memo[j] >= x:
            continue
        else:
            temp = -1
    if temp > 0:
        flag = 1
        ans = min(ans, temp)

if flag:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 9652
N = int(input())
S = int(input())

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break

if ans == -1:
    for i in range(int(N**.5)+1,0,-1):
        b = (N-S)//i + 1
        if b>1:
            if f(b,N)==S:
                ans = b
                break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = (int)1e9;

template<typename T> struct BinaryIndexedTree {
	vector<T> data;
	BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
	BinaryIndexedTree(vector<T> data) : data(data) {}
	T sum(int k) {
		if (k < 0) return 0;
		T ret = 0;
		for (++k; k > 0; k -= k & -k) ret += data[k];
		return ret;
	}
	void add(int k, T x) {
		for (++k; k < data.size(); k += k & -k) data[k] += x;
	}
	void debug() {
		int sz = (int)data.size() - 1;
		for (int i = 0; i < sz; ++i) {
			cerr << sum(i) - sum(i - 1) << " \n"[i == sz - 1];
		}
	}
};

int N;
vector<int> black, white;

// idx[i][j] := 白がi個, 黒がj個(後ろから)残っているとき, 各色の最小値を一番前に持ってくるための操作回数
vector<vector<int>> black_idx, white_idx;

// dp[i][j] :=	前からi番目までがソート済みで, 内j個が黒いボールのとき,
//				残りをソート済みにするために必要な操作回数の最小値
vector<vector<int>> dp;
int rec(int p, int q) {
	if (dp[p][q] != -1) return dp[p][q];
	int ret = INF;
	if (q < N)		ret = min(ret, black_idx[N - (p - q)][N - q] + rec(p + 1, q + 1));	// 黒を動かす
	if (p - q < N)	ret = min(ret, white_idx[N - (p - q)][N - q] + rec(p + 1, q));		// 白を動かす
	return dp[p][q] = ret;
}

int main() {

	cin >> N;

	black.resize(N);
	white.resize(N);

	for (int i = 0; i < 2 * N; ++i) {
		char c;	int a;
		cin >> c >> a;	--a;
		if (c == 'W')	white[a] = i;
		else 			black[a] = i;
	}
	
	{	// black_idxの前計算
		black_idx.assign(N + 1, vector<int>(N + 1, 0));
		BinaryIndexedTree<int> w(2 * N);
		for (int i = 0; i <= N; ++i) {
			BinaryIndexedTree<int> bit(w.data);
			for (int j = 1; j <= N; ++j) {
				black_idx[i][j] = bit.sum(black[N - j] - 1);
				bit.add(black[N - j], 1);
			}
			if (i < N) w.add(white[N - 1 - i], 1);
		}
	}

	{	// white_idxの前計算
		white_idx.assign(N + 1, vector<int>(N + 1, 0));
		BinaryIndexedTree<int> b(2 * N);
		for (int i = 0; i <= N; ++i) {
			BinaryIndexedTree<int> bit(b.data);
			for (int j = 1; j <= N; ++j) {
				white_idx[j][i] = bit.sum(white[N - j] - 1);
				bit.add(white[N - j], 1);
			}
			if (i < N) b.add(black[N - 1 - i], 1);
		}
	}

	dp.assign(2 * N + 1, vector<int>(N + 1, -1));
	dp[2 * N][N] = 0;

	cout << rec(0, 0) << endl;

	// cerr << "---------" << endl;
	// for (int i = 0; i < 2 * N; ++i) {
	// 	for (int j = 0; j < N; ++j) {
	// 		cerr << i << ", " << j << " : " << dp[i][j] << endl;
	// 	}
	// }
	// cerr << "---------" << endl;
	// for (int i = 0; i < N; ++i) cerr << "黒" << i << " : " << black[i] << endl;
	// cerr << "---------" << endl;
	// for (int i = 0; i < N; ++i) cerr << "白" << i << " : " << white[i] << endl;
	// cerr << "---------" << endl;
	// for (int i = 0; i <= N; ++i) {
	// 	for (int j = 0; j <= N; ++j) {
	// 		cerr << "白" << i << " 黒" << j << " : " << black_idx[i][j] << endl;
	// 	}
	// }

}

Measured memory_bytes: 63360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    string S[N];
    rep(i, N) cin >> S[i];
    int cnt = 0;
    rep(k, N){
        bool same = true;
        rep(i, N) rep(j, N){
            if(S[(i+k)%N][j] != S[(j+k)%N][i]) same = false; 
        }
        if(same) cnt += N;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
const int MAX=1e5+10;



int main(){
	int N;
	cin>>N;
	int h[MAX];
	rep(i,N){
		cin>>h[i];
	}
  	h[N]=0;
	stack<P> st;
	ll ans=0;
	rep(i,N+1){
		while(true){
			if(st.empty()){
				st.push(make_pair(i,0));
				break;
			}
          	else{
				P p=st.top();
				if(h[p.first]<h[i]){
					st.push(make_pair(i, p.first+1));
					break;
				}
				else{
					ans=max(ans, (ll)h[p.first]*(i-p.second));
					st.pop();
                }
			}
		}
	}
	cout<<ans<<endl;
}


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

int main() {
  int n, m;
  cin>>n>>m;
  priority_queue<double> que;
  for (int i=0; i<n; i++) {
    double a;
    cin>>a;
    que.push(a);
  }
  for (int i=0; i<m; i++) {
    double t = que.top();
    que.pop();
    que.push(t / 2);
  }
  long long ans = 0;
  while (!que.empty()) {
    long t = que.top();
    que.pop();
    ans += t;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include <string>
#include <iostream>
#include <vector>
using namespace std;
#define S second
main(){
vector<pair<int,pair<string,int> > >v;
int i,j,n,m,k;
string s;
L:
if(v.clear(),cin>>n>>m,!n)return 0;
for(i=0;i<n;v.push_back(make_pair(k,make_pair(s,j))),i++)
  for(cin>>s>>k,j=0;s[j]=='*';j++);
for(k=0;m;m--)
  for(cin>>s,i=0;i<n;i++)
    if(s.substr(v[i].S.S)==v[i].S.first.substr(v[i].S.S))k+=v[i].first;
cout<<k<<endl;
goto L;
}

Measured memory_bytes: 936
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    int H,W;
    cin>>H>>W;
    char map[H][W];
    unordered_map<int, int> mp_col;
    unordered_map<int, int> mp_row;

    for(int col=0; col<H; col++) {
        int count_col=0;
        for (int row = 0; row < W; row++) {
            cin >> map[col][row];
            if(map[col][row]=='.'){
                count_col++;
            }
        }
        if(count_col==W){
            mp_col[col]=1;
        }
    }

    for(int row=0; row<W; row++) {
        int count_row=0;
        for (int col = 0; col < H; col++) {
            if(map[col][row]=='.'){
                count_row++;
            }
        }
        if(count_row==H){
            mp_row[row]=1;
        }
    }

    for(int col=0; col<H; col++) {
        for (int row = 0; row < W; row++) {
            if(mp_col[col]!=1 and mp_row[row]!=1) {
                cout << map[col][row];
            }
        }
        if(mp_col[col]!=1)
            cout<<endl;
    }

    return 0;

}

Measured memory_bytes: 256
d,g=map(int,input().split())
g=g//100
p_list=[]
c_list=[]
s_list=[]
for i in range(d):
    p,c=map(int,input().split())
    c=c//100
    p_list.append(p)
    c_list.append(c)
    s_list.append(p*(i+1)+c)
Min=1000
for i in range(2**d):
    Sum=0
    Num=0
    for j in range(d):
        if (i>>j)&1==1:
            Sum=Sum+s_list[j]
            Num=Num+p_list[j]
        else:
            M=j
    if Sum>=g:
        if Num<Min:
            Min=Num
    else:
        r=((g-Sum)+M)//(M+1)
        if r<=p_list[M]:
            Num=Num+r
            if Num<Min:
                Min=Num
print(Min)


Measured memory_bytes: 40304
def calc1():
  A=list(map(int,input().split()))
  r=A[0]
  D=A[1]
  x=A[2]
  B=[]
  g=(r*x)-D
  B.append(g)
  for z in range(1,10):
    C=B[z-1]
    g=(r*C)-D
    B.append(g)
  
  for x in range(len(B)):
    print(B[x])
    
if __name__=="__main__":
  calc1()
   
    
    
    
    
  

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

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

	sort(a.begin(), a.end());

	if (n == 2) {
		cout << a[1] - a[0] << endl;
		cout << a[1] << " " << a[0] << endl;
		return 0;
	}

	//元の符号が正は正、負は負でまとめておく
	vector<int> pos;
	vector<int> neg;

	for (int i = 1; i < n - 1; i++) {
		if (a[i] >= 0) {
			pos.push_back(a[i]);
		}
		else {
			neg.push_back(a[i]);
		}
	}

	//手順を記録する配列
	vector<pair<int, int>> res;

	

	//最終的に+にしたい分を一つ残してまとめて-側に突っ込む

	int base = a[n-1] - a[0];

	if (pos.size() > 0) {
		base = -base;
		//右端と左端を核にして、+→-の順でまとめてくっつけたい
		res.push_back(make_pair(a[0], a[n - 1]));

		for (int i = 0; i < pos.size() - 1; i++) {
			res.push_back(make_pair(base, pos[i]));
			base -= pos[i];
		}

		//残しておいた最後の+で-をまとめてひっくり返す
		res.push_back(make_pair(pos[pos.size() - 1], base));
		base = pos[pos.size() - 1] - base;
	}
	else {
		//右端と左端を核にして、+→-の順でまとめてくっつけたい
		res.push_back(make_pair(a[n-1], a[0]));
	}
	

	//-にしたい分を全部くっつける
	for (int i = 0; i < neg.size(); i++) {
		res.push_back(make_pair(base, neg[i]));
		base -= neg[i];
	}

	//出力
	cout << base << endl;
	for (int i = 0; i < res.size(); i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 3828
# -*- coding: utf-8 -*-
"""
Created on Sat May 19 15:10:55 2018
AOJ ITP2_1_B
@author: maezawa
"""
#import numpy as np
q = int(input())
a = [0 for _ in range(8000000)]
start = 4000000
end = 4000001
for i in range(q):
    ops = list(map(int,input().split()))
    if ops[0] == 0:
        if ops[1] == 0:
            a[start] = ops[2]
            start -= 1
        else:
            a[end] = ops[2]
            end += 1
    elif ops[0] == 1:
        print(a[start+ops[1]+1])
    elif ops[0] == 2:
        if ops[1] == 0:
            start += 1
        elif ops[1] == 1:
            end -= 1
#    print(a[start+1:end])


Measured memory_bytes: 80904
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
int n,k;
int ai[500000];
int a,b;
void init(){
    
}

int ans;


void play(){
    ans=0;
    for(int i=1;i<=998;i++){
        if(ai[i]-a==ai[i+1]-b){
            printf("%d\n",ai[i]-a);
            break;
        }
    }
}
void pri(){
  //  printf("%d\n",ans);
}

int main() {
    memset(ai,0,sizeof(ai));
    int bf=0;
    for(int i=1;i<=999;i++){
        bf+=i;
        ai[i]=bf;
    }
   
    while(scanf("%d%d",&a,&b)!=EOF){
        init();
        play();
        pri();
    }
    
    return 0;
}


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

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;

typedef vector<vector<ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll h,w;
ll a[81][81];
ll b[81][81];
ll offset = 81*160;
char dp[81][81][81*160*2];
ll ans = INF;

int main(){
    cin >> h >> w;
    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            cin >> a[i][j];
        }
    }
    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            cin >> b[i][j];
        }
    }
    dp[0][0][(a[0][0]-b[0][0])+offset] = 1;
    dp[0][0][(b[0][0]-a[0][0])+offset] = 1;

    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            if(i+1 < h){
                for(ll k = 0;k < 81*160*2;k++){
                    if(dp[i][j][k] == 1){
                        dp[i+1][j][k+(a[i+1][j]-b[i+1][j])] = 1;
                        dp[i+1][j][k+(b[i+1][j]-a[i+1][j])] = 1;
                    }
                }

            }
            if(j+1 < w){
                for(ll k = 0;k < 81*160*2;k++){
                    if(dp[i][j][k] == 1){
                        dp[i][j+1][k+(a[i][j+1]-b[i][j+1])] = 1;
                        dp[i][j+1][k+(b[i][j+1]-a[i][j+1])] = 1;
                    }
                }
            }
        }
    }

    // for(ll i = 0;i < h;i++){
    //     for(ll j = 0;j < w;j++){
    //         cerr << dp[i][j][offset+0];
    //     }
    //     cerr << endl;
    // }
    for(ll k = 0;k < 81*160*2;k++){
        if(dp[h-1][w-1][k]){
            ans = min(ans,abs(k-offset));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 164992
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	
	char[][] ss;
	foreach(i; 0 .. n) ss ~= read.to!(char[]);
	
	long[char[10]] ucnt;
	foreach(s; ss){
		int[] v = s.map!(to!int).array;
		v.sort();
		char[10] u = v[0 .. 10].map!(to!char).array;
		if(u !in ucnt) ucnt[u] = 0;
		ucnt[u] += 1;
	}
	
	long ans;
	char[10][] uk = ucnt.keys;
	foreach(u; uk){
		long x = ucnt[u];
		ans += x * (x - 1) / 2;
	}
	
	ans.writeln;
}


Measured memory_bytes: 26236
//




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




ll ncr(ll n,ll r) {
    ll val=1,i,j,p=2;
    rfr(i,n-r+1,n+1) {
        val*=i;
        while(val%p==0 && p<=r) {
            val/=p;
            p+=1;
        }
    }
    if(p<r) {
        fr(i,p,r+1) val/=i;
    }
    return val;
}



ll fun(ll h[],ll i,ll n,vector <ll> &dp) {
    if(i>=n-1) return 0;
    if(dp[i]!=-1) return dp[i];
    if(i==n-2) return dp[i]=fun(h,i+1,n,dp)+abs(h[i+1]-h[i]);
    else return dp[i]=min(fun(h,i+1,n,dp)+abs(h[i+1]-h[i]),fun(h,i+2,n,dp)+abs(h[i+2]-h[i]));
}




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        cin>>n;
        ll h[n];
        fr(i,0,n) cin>>h[i];
        vector <ll> dp(n+1,-1);
        cout<<fun(h,0,n,dp)<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


Measured memory_bytes: 8724
/*Bismillahir Rahmanir Rahim */
#include <stdio.h>
#include <string.h>
int main ()
{
    char s[101];
    int n,i;
    while (scanf("%s",s)   !=EOF)
    {
        n=0;
        n=strlen(s);
       for (i=0;i<n;i++)
       {
       }
       printf("%c%d%c\n",s[0],n-2,s[n-1]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, k;
	int v[50];
	long long max = 0;

	cin >> n >> k;

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

	//取り出す操作をi回、入れる操作をk-i回までする
	int max_pop = k;

	if (max_pop > n) {
		max_pop = n;
	}
	for (int i = max_pop; i >= 0; i--) {	

		//左からj個　右からi-j個とる
		for (int j = 0; j <= i; j++) {
			vector<int> hand;
			long long score = 0;

			for (int s = 0; s < j; s++) {
				hand.push_back(v[s]);
			}
			for (int s = n - 1; s > (n - 1) - (i - j); s--) {
				hand.push_back(v[s]);
			}

			//降順にソート
			sort(hand.rbegin(), hand.rend());

			//この地点でのスコアを記録
			for (int s = 0; s < hand.size(); s++) {
				score += hand[s];
			}
			if (score > max) {
				max = score;
			}

			//価値が小さい順にk - i個まで捨てる
			for (int s = 0; s < k - i; s++) {
				if (!hand.empty()) {
					score -= hand[hand.size() - 1];
					hand.pop_back();

					if (score > max) {
						max = score;
					}
				}
				else {
					break;
				}
			}


		}
		
	}

	cout << max << endl;
}

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

typedef long long ll;
int main() {
	int N; cin >> N;
	ll sum = 0;
	for(int i = 1; i <= N; ++i) {
		if(!(i % 3 == 0 || i % 5 == 0)){
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3600
li=list(input())
li_rev=list(reversed(li))
n=len(li)
li_slice=li[0:int((n-1)/2)]
li_slrev=list(reversed(li_slice))
n=len(li)
if li==li_rev:
    if li_slice==li_slrev:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

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

  int ans = 0;
  int active = 0;
  for (int i = 0; i < n; i++)
  {
    if (active >= h[i])
    {
      active = h[i];
    }
    else
    {
      ans += h[i] - active;
      active = h[i];
    }
  }
  cout << ans << endl;
}


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

int main(){
  int n;
  bool f=true;
  while(cin>>n,n){
    if(f){
      f=false;
    }else{
      cout<<endl;
    }
    n*=0.1;
    int c1,c5,c10,c50;
    int max1=0;
    int max5=0;
    int max10=0;
    int max50=0;
    int min=1<<30;

    cin>>c1>>c5>>c10>>c50;
    int num=c1+c5+c10+c50;
    for(int a=0;a<=c1;a++){
      for(int b=0;b<=c5;b++){
	for(int c=0;c<=c10;c++){
	  for(int d=0;d<=c50;d++){
	    int sum = a+b*5+c*10+d*50-n;
	    if(sum>=0){
	      int aa=sum/50;
	      sum%=50;
	      int bb=sum/10;
	      sum%=10;
	      int cc=sum/5;
	      sum%=5;
	      int temp=num-a-b-c-d+aa+bb+cc+sum;
	      if(min > temp){
		min = temp;
		max50=d;
		max10=c;
		max5=b;
		max1=a;
	      }
	    }
	  }
	}
      }
    }
    if(max1!=0){
      cout<<10<<" "<<max1<<endl;
    }
    if(max5!=0){
      cout<<50<<" "<<max5<<endl;
    }
    if(max10!=0){
      cout<<100<<" "<<max10<<endl;
    }
    if(max50!=0){
      cout<<500<<" "<<max50<<endl;
    }

  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<pair<ll, ll> >
#define vl vector<ll>
#define vi vector<int>
#define vii vector<pair<int, int> >
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
using namespace std;

ll power_mod(ll x, ll y, ll p)
{
	ll ans = 1;
	x = x%p;
	if(x==0)
	return p;

	while(y>0)
	{
		if(y&1)
		{
			ans = (ans*x)%p;
		}
		y = y>>1;
		x = (x*x)%p;
	}
	return ans;
} 
ll knapSack(ll W, ll wt[], ll val[], ll n) 
{ 
    ll i, w; 
    ll K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    return K[n][W]; 
} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t;
	ll n,w,i,j,k;
	cin>>n>>w;
	ll val[n], wt[n];
	for(i=0;i<n;i++)
	{
	    cin>>wt[i]>>val[i];
	}
	cout<<knapSack(w, wt, val, n);
	return 0;
}


Measured memory_bytes: 82448
#include <stdio.h>

int main()
{
    int x1,y1,x2,y2,x3,y3,x4,y4,d1,d2;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    d1=x2-x1;
    d2=y1-y2;
    x3=x2+d2;
    y3=y2+d1;
    x4=x1+d2;
    y4=y1+d1;
    
    printf("%d %d %d %d\n",x3,y3,x4,y4);
    

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200];
signed main(){
	int n, ans = 0;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld", &a[i]);
	int t = a[0];
	repi(i,1,n){
		if(a[i] == t){ans++;a[i] = -1;t = -1;}
		else t = a[i];
		//printf("%lld ", t);
	}
	printf("%lld\n", ans);
	return 0;
}




Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if(b <= a) cout << "delicious" << endl;
	else if (b - a <= x) cout << "safe" << endl;
	else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int a[200010];
int b[200010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int D = 0, S = 0;
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    rep(i, N) {
        if (a[i] < b[i]) S += (b[i] - a[i]) / 2;
        if (a[i] > b[i]) D += a[i] - b[i];
    }
    if (D <= S) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
string S,T,U;
 int a,b;
  cin >> S >> T >> a >> b >> U;
  
  if(S==U) cout << a-1 << ' ' << b;
  else cout << a << ' ' << b-1;


return 0;
}

Measured memory_bytes: 3620
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist


N, M = MAP()
L = [LIST() for i in range(M)]
graph = defaultdict(list)

for a, b in L:
    graph[a-1].append((b-1, 1))
    graph[b-1].append((a-1, 1))

ans = 0

for i in range(M):
    a, b = L[i]
    E = deepcopy(graph)
    E[a-1].remove((b-1, 1))
    E[b-1].remove((a-1, 1))
    dist = dijkstra(E, 0)
    if dist.count(INF) > 0:
        ans += 1

print(ans)



Measured memory_bytes: 3956
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	ll cnt[5] = {0};
	cin >> N;
	rep(i, N){
		string s;
		cin >> s;
		if(s[0] == 'M') cnt[0]++;
		if(s[0] == 'A') cnt[1]++;
		if(s[0] == 'R') cnt[2]++;
		if(s[0] == 'C') cnt[3]++;
		if(s[0] == 'H') cnt[4]++;
	}
	ll sum = 0;
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				sum += cnt[i]*cnt[j]*cnt[k];
			}
		}
	}
	cout << sum;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a!=1&&b!=1)
        printf("1\n");
    else{
            if(a!=2&&b!=2)
        printf("2\n");
            else
                printf("3\n");}
return 0;
}



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


int main(){
  int A,B,K,cnt=0;
  vector<int> v;
  cin >> A >> B >> K;
  for(int i=1;i<=100;++i){
    if(!(A%i)&&!(B%i)){
      v.push_back(i);
    }
  }
  reverse(v.begin(),v.end());
  cout << v.at(K-1) << endl;
}


Measured memory_bytes: 256
// code test
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    println(problem169d(n))
}

fun problem169d(n: Long): Long {
    /**
     * 素因数分解
     */
    fun computePrimeFactorList(n: Long): List<Pair<Long, Long>> {
        val p = mutableListOf<Pair<Long, Long>>()
        var primeFactor = n
        for (i in 2..(Math.sqrt(n.toDouble()) + 1).toLong()) {
            var count = 0L
            while (primeFactor % i == 0L) {
                primeFactor /= i
                count++
                if (primeFactor == 1L) break
            }
            p.add(i to count)
        }
        if (primeFactor != 1L) p.add(primeFactor to 1L)
        return p
    }

    val pf = computePrimeFactorList(n)
    var count = 0L
    for (i in 0 until pf.size) {
        var (a, b) = pf[i]
        var j = 1
        while (b > 0) {
            if (b < j) break
            b -= j
            count++
            j++
        }
    }
    return count
}


Measured memory_bytes: 96788
#include <stdio.h>

int main(){
	long long a, x = 1, y = 1, z = 1;
	scanf("%lld", &a);
	for(int i = 0; i<a; i++){
		x = (x*10)%1000000007;
		y = (y*9)%1000000007;
		z = (z*8)%1000000007;
	}
	long long ans = x%1000000007;
	ans = (ans+1000000007-((2*y)%1000000007))%1000000007;
	ans = (ans+z)%1000000007;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1732