akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
white = [[0]*(K+1) for _ in range(2*K+1)]
black = [[0]*(K+1) for _ in range(2*K+1)]
for _ in range(N):
    str_h, str_w, c = map(str, input().rstrip().split())
    h = int(str_h)%(2*K)
    w = int(str_w)%(2*K)
    if c == "W":
        if w >= K:
            if h >= K:
                white[h-K+1][w-K+1] += 1
            else:
                white[h+K+1][w-K+1] += 1
        else:
            white[h+1][w+1] += 1
    else:
        if w >= K:
            if h >= K:
                black[h-K+1][w-K+1] += 1
            else:
                black[h+K+1][w-K+1] += 1
        else:
            black[h+1][w+1] += 1

for h in range(1, 2*K+1):
    for w in range(1, K+1):
        white[h][w] += white[h][w-1] + white[h-1][w] - white[h-1][w-1]
        black[h][w] += black[h][w-1] + black[h-1][w] - black[h-1][w-1]

ans = 0
for h in range(K+1):
    for w in range(K+1):
        b1 = black[h][w]
        b2 = black[h+K][K] - black[h+K][w] - black[h][K] + black[h][w]
        b3 = black[2*K][w] - black[h+K][w]
        w1 = white[h][K] - white[h][w]
        w2 = white[h+K][w] - white[h][w]
        w3 = white[2*K][K] - white[2*K][w] - white[h+K][K] + white[h+K][w]
        ans = max(ans, b1+b2+b3+w1+w2+w3)

        b1 = white[h][w]
        b2 = white[h+K][K] - white[h+K][w] - white[h][K] + white[h][w]
        b3 = white[2*K][w] - white[h+K][w]
        w1 = black[h][K] - black[h][w]
        w2 = black[h+K][w] - black[h][w]
        w3 = black[2*K][K] - black[2*K][w] - black[h+K][K] + black[h+K][w]
        ans = max(ans, b1+b2+b3+w1+w2+w3)

print(ans)

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

using namespace std;

#define pb push_back
#define eps 1e-9
#define PI acos(-1.0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
const int INF = 1e9 + 5;

bool prime(ll x)
{
    if(x == 2)
        return true;
    for(int i = 2 ; i * i <= x ; i++)
        if(x % i == 0)
            return false;
    return true;
}

bool cmp(int a, int b)
{
    return a > b;
}
int a[int(1e5 + 5)];
int main()
{

    int n;
    cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    std::vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
    {
        for(int j = i + 1; j <= i + 2; j++)
        {
            if(j < n)
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n - 1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template<typename T>
set<T> div_count(T x) {
  set<T> st;
  for (ll i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      st.insert(i);
      st.insert(x/i);
    }
  }
  return st;
}
int main() {
  ll n;
  cin >> n;
  set<ll> st = div_count(n);
  ll ans = 0;
  for (auto itr : st) {
    // debug(itr);
    ll t = itr - 1;
    if (t == 0 or t == 1) continue;
    if (n % t == n / t) ans += itr - 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
int n,k,ans,p;
int f[12][6]= {
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}
};
int main() 
{
    scanf("%d%d",&n,&k);
    ans=((n-2)/11)*5;
    if(n<=2)
    for(int i=0; i<p; i++)
    for(int j=0; j<5; j++) 
	{if(f[i][j]==k)ans++;}
    else
    for(int i=0; i<(n-2)%11; i++)
    for(int j=0; j<5; j++)
    if(f[i][j]==k)ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,K;
    string res;

    cin >> N;

    if(N < 1200)res = "ABC";
    else if(N < 2800)res = "ARC";
    else res = "AGC";
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
const int MOD = 1000000007;
using namespace std;
//template

int d[10];
bool used[10];
int ans;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10,vector<int>(10));
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> c[i][j];
		}
	}
	vector<vector<int>> a(h,vector<int>(w));
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < 10; i++)
	{
		d[i] = MOD;
	}
	d[1] = 0;
	int v;
	while (true)
	{
		v = 10;
		for (int i = 0; i < 10; i++)
		{
		
			if (!used[i] && (v == 10 || d[i] < d[v]))
			{
				v = i;
			}
		}
		if (v == 10)
		{
			break;
		}
		used[v] = true;
		for (int i=0; i < 10; i++)
		{
			d[i] = min(d[i], d[v] + c[i][v]);
		}
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (a[i][j] != -1)
			{
				ans += d[a[i][j]];
			}
		}
	}
	cout << ans<<endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int H,W;
  while(cin >> H >> W && H||W){
    for(int i=0;i<H;i++){
	for(int j=0;j<W;j++)
	cout << "#";
	cout << endl;
      }
    cout << endl;
  }
}


Measured memory_bytes: 3092
import sys
q, h, s, d = [int(i) for i in sys.stdin.readline().split()]
n = int(input())
if h > q * 2:
    h = q * 2
if s > h * 2:
    s = h * 2
if d > s * 2:
    d = s * 2
_sum = 0
ls = [(0.25, q), (0.5, h), (1, s), (2, d)]
ls.reverse()
ind = 0
while n:
    cur = ls[ind]
    _sum += cur[1] * (n // cur[0])
    n %= cur[0]
    ind += 1
print(_sum)

Measured memory_bytes: 3316
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
map<char,int> ma;
void mainmain(){
	rep(i,10){
		ma[(char)i+'0']=i;
	}
	char a[]={'a','b','c','d','e','f'};
	rep(i,6){
		ma[a[i]]=i+10;
	}
	string s;
	int r[]={0,0,0,0,1,1,1,1};
	int g[]={0,0,1,1,0,0,1,1};
	int b[]={0,1,0,1,0,1,0,1};
	string ans[]={"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	while(cin>>s,s[0]!='0'){
		int rr=0,gg=0,bb=0;
		rr=ma[s[1]]*16+ma[s[2]];
		gg=ma[s[3]]*16+ma[s[4]];
		bb=ma[s[5]]*16+ma[s[6]];
		int c=-1;
		int d=INF;
		rep(i,8){
			int t=(rr-r[i]*255)*(rr-r[i]*255)+(gg-g[i]*255)*(gg-g[i]*255)+(bb-b[i]*255)*(bb-b[i]*255);
			if(t<d){
				d=t;
				c=i;
			}
		}
		cout<<ans[c]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1188
#define _CRT_SECURE_NO_DEPRECATE
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; // 注意必要时改类型
typedef vector<int> vi;
const int N = 1e3;
const int MOD = 1e9 + 7;
int n, m;
int dp[N][N], mp[N][N];
inline int mod(int x) {
	return x % MOD;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef _DEBUG
	int tt = clock();
	// freopen("in.txt", "r", stdin);
#endif 
	cin >> n >> m;
	string str;
	for (Rint i = 0; i < n; ++i) {
		cin >> str;
		for (Rint j = 0; j < m; ++j) {
			if (str[j] == '.') mp[i][j] = 1;
			else mp[i][j] = 0;
		}
	}
	for (Rint i = 0; i < n; ++i) {
		if (mp[0][i]) dp[0][i] = 1;
		else break;
	}
	for (Rint i = 0; i < n; ++i) {
		if (mp[i][0]) dp[i][0] = 1;
		else break;
	}
	for (Rint i = 1; i < n; ++i) {
		for (Rint j = 1; j < m; ++j) {
			if (!mp[i][j]) {
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = mod(dp[i - 1][j] + dp[i][j - 1]);
			
		}
	}
	cout << dp[n - 1][m - 1] << endl;


#ifdef _DEBUG
	cerr << "\nTIME = " << clock() - tt << endl;
	tt = clock();
#endif

	return 0;
}


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
P solve() {
    ll n; cin >> n;
    vector<ll> A(n); cin >> A;
    ll ansl = 2, ansr = 2;
    if (A.back() != 2) return P(-1, -1);
    rrep(i, 1, n) {
        ll l = ansl, r = ansr + A[i]-1;
        ll nl = A[i-1] * ((l + A[i-1]-1) / A[i-1]);
        ll nr = A[i-1] * (r / A[i-1]);
        if (nl > r || nr < l) return P(-1, -1);
        ansl = nl, ansr = nr;
        // cout << ansl << " " << ansr << endl;
    }
    return P(ansl, ansr+A[0]-1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    P ans = solve();
    if (ans.first < 0) cout << -1 << endl;
    else cout << ans.first << " " << ans.second << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

int main(){
    std::string S;

    std::cin >> S;

    char _s = 'A';
    for(auto s:S){
        if(_s==s){
            std::cout << "Bad" << std::endl;
            return 0;
        }
        _s = s;
    }

    std::cout << "Good" << std::endl;

    return 0;
}

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

class Cube{
	public:
		int f[6];
		Cube(){}
		void roll_z(){ roll(1, 2, 4, 3);}
		void roll_y(){ roll(0, 2, 5, 3);}
		void roll_x(){ roll(0, 1, 5, 4);}
		void roll(int i, int j, int k, int l){
			int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
		}
};

bool eq(Cube c1, Cube c2){
	for(int i=0;i<6;i++)
		if(c1.f[i] != c2.f[i]) return false;
	return true;
}

bool equal(Cube c1, Cube c2){
	for(int i=0;i<6;i++){
		for(int j=0;j<4;j++){
			if(eq(c1,c2)) return true;
			c1.roll_z();
		}
		if(i%2==0) c1.roll_y();
		else c1.roll_x();
	}
	return false;
}

int main(){
	Cube c1,c2;

	for(int i=0;i<6;i++) cin >> c1.f[i];
	for(int i=0;i<6;i++) cin >> c2.f[i];

	if(equal(c1,c2)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <utility>

using namespace std;

#define pb push_back
#define ft first
#define sd second
#define mpr make_pair
#define all(x) begin((x)), end((x))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define max3(a, b, c) max((a), max((b), (c)))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min((a), min((b), (c)))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define isz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;

/* <------------------------------------------------------------------------------------> */

int ans[107][107], a[(int)1e4 + 7];

void solve()
{
    int h, w, n;
    scanf("%d%d%d", &h, &w, &n);
    forn (i, n) scanf("%d", a + i);
    int i = 0, j = 0;
    forn (k, n) while (a[k]--)
    {
        ans[i][j] = k + 1;
        if (i & 1)
        {
            --j;
            if (j == -1)
            {
                ++j;
                ++i;
            }
        }
        else
        {
            ++j;
            if (j == w)
            {
                --j;
                ++i;
            }
        }
    }
    forn (i, h)
    {
        forn (j, w) printf("%d ", ans[i][j]);
        puts("");
    }
}

/* <------------------------------------------------------------------------------------> */

// #define LOCAL
// #define FILE_NAME

int main()
{
    #if defined LOCAL
        freopen("input.txt", "r", stdin);
    #elif defined FILE_NAME
        freopen(FILE_NAME".in", "r", stdin);
        freopen(FILE_NAME".out", "w", stdout);
    #endif

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

    solve();

    return 0;
}


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

int main(){
    int A,B;
    string S;
    cin >> A >> B;
    cin >> S;
    int flag = 0;
    if(S[A] == '-'){
        for(int i = 0; i < A; i++){
            if(S[i] >= '0' && S[i] <= '9'){
                flag++;
            }
        }
        for(int i = A+1; i <= A+B; i++){
            if(S[i] >= '0' && S[i] <= '9'){
                flag++;
            }
        }
    }
    if(flag == A+B){
        cout<<"Yes"<<endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" <<endl;
        return 0;
    }else{
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> ii;
typedef vector<int,int> vii;
typedef vector< vector<int> > vvi;

int main()
{
	FIO
	ll q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	ll ans = ((n/2)*min(8*q,min(4*h,min(2*s,d)))) + ((n%2)*min(4*q,min(2*h,s)));
	cout<<ans<<endl;
	return 0;
}

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

int a[2000];
int main() {
	int N, Z, W;
	cin >> N >> Z >> W;
	for (int i=0; i < N; i++) {
		cin >> a[i];
	}
	if (N >= 2) {
		cout << max(max(max(W - a[N - 1], a[N - 1] - W), a[N - 1] - a[N - 2]), a[N - 2] - a[N - 1]) << endl;
	}
	else {
		cout << max(a[N - 1] - W, W - a[N - 1]);
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

def can_match(s, t):
  fs = Counter(S)
  ft = Counter(T)
  
  if len(s) != len(t):
    return False
  
  for cs, ct in zip(s, t):
    # 出現頻度が同じであれば変換可能
    if fs[cs] != ft[ct]:
      return False

  return True


S = input()
T = input()

if can_match(S, T):
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 41804
S = input()

m = [0,]*len(S)

state=[0,0,0,'L']
for i,s in enumerate(S):
	if s=='R':
		state[state[2]]+=1
		state[2]=(state[2]+1)%2
		state[3]='R'
	elif s=='L' and state[3]=='R':
		m[i]=state[state[2]]
		m[i-1]=state[(state[2]+1)%2]
		state=[0,0,0,'L']
state=[0,0,0,'R']	
for i,s in enumerate(reversed(S)):
	if s=='L':
		state[state[2]]+=1
		state[2]=(state[2]+1)%2
		state[3]='L'
	elif s=='R':
		m[len(S)-i-1]+=state[state[2]]
		m[len(S)-(i-1)-1]+=state[(state[2]+1)%2]
		state=[0,0,0,'R']
print(' '.join(map(str,m)))

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi a(n),b(n),c(n);
		rep(i,n) cin>>a[i];
		rep(i,n) cin>>b[i];
		rep(i,n) cin>>c[i];
		sort(all(a)); sort(all(b)); sort(all(c));

		vl bsum(n);
		rep(i,n) bsum[i]=end(c)-upper_bound(all(c),b[i]);
		per(i,n-1) bsum[i]+=bsum[i+1];

		vl asum(n);
		rep(i,n){
			int j=upper_bound(all(b),a[i])-begin(b);
			if(j<n) asum[i]=bsum[j];
		}
		per(i,n-1) asum[i]+=asum[i+1];

		cout<<asum[0]<<endl;
	}
}


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

int main() {
    int k, s;
    cin >> k >> s;

    int sum = 0;
    for (int z = 0; z <= k; z++) {
        int t = s - z;
        if (t < 0) {
            0;
        } else if (t <= k) {
            sum += t + 1;
        } else if (t <= k * 2) {
            sum += k * 2 - t + 1;
        } else {
            0;
        }
    }

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


Measured memory_bytes: 256
r0,w,c,r = gets.split.map(&:to_i)

ans = []
while r0 != 0 && w != 0 && c != 0 && r != 0 
	i = 0
	while (r0/w) != c 
		if (r0/w) > c 
			puts "0"
			break
		end
		i += 1
		#tmp_y = (r0+i*r) / c
		#tmp_y = r0+i*r
		if c <= (r0+i*r)/w
			#ans.push(i)
			puts i
			break
		end
	end
	puts "0" if r0/w == c
	r0,w,c,r = gets.split.map(&:to_i)
end
=begin
for i in ans
	puts i 
end
=end

Measured memory_bytes: 8636
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()

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

int main() {
  int n;
  cin >> n;
  
  long long max=-1e9-1;
  long long min=1e9+1;
  
  rep(i,n){
    long long x;
    cin >> x;
    
    if(i>0){
      if(x-min>max) max=x-min;
    }
    if(x<min) min = x;
  }
  
  cout << max <<endl;
      
  return 0;
}


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

int Digits(long long n){
  int digits = 0;
  while(n>0){
    digits++;
    n /= 10;
  }
  return digits;
}

int main(){
  long long N;
  cin >> N;
  int ans = Digits(N);
  for(long long i=1; i*i<=N; i++){
    if(N%i == 0){
      ans = min(ans, Digits(N/i));
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
typedef long long ll;

int L[100010], R[100010], ord1[100010], ord2[100010], used[100010];

int Abs(int x) {
    return x < 0 ? -x : x;
}
bool cmp1(int x, int y) {
    return R[x] < R[y];
}

bool cmp2(int x, int y) {
    return L[x] > L[y];
}

signed main() {
    int n;
    scanf("%lld", &n);
    for(int i = 1; i <= n; i++) scanf("%lld%lld", &L[i], &R[i]), ord1[i] = i, ord2[i] = i;
    sort(ord1 + 1, ord1 + n + 1, cmp1);
    sort(ord2 + 1, ord2 + n + 1, cmp2);
    int t1 = 1, t2 = 1, ans1 = 0, nw = 0, ans2 = 0;
    while(t1 <= n || t2 <= n) {
        while(t1 <= n && used[ord1[t1]]) t1++;
        if(t1 <= n && R[ord1[t1]] < nw) {
            ans1 += nw - R[ord1[t1]];
            nw = R[ord1[t1]];
            used[ord1[t1]] = 1;
        }
        t1++;
        while(t2 <= n && used[ord2[t2]]) t2++;
        if(t2 <= n && L[ord2[t2]] > nw) {
            ans1 += L[ord2[t2]] - nw;
            nw = L[ord2[t2]];
            used[ord2[t2]] = 1;
        }
        t2++;
    }
    ans1 += Abs(nw);
    memset(used, 0, sizeof used);
    t1 = 1, t2 = 1, ans2 = 0, nw = 0;
    while(t1 <= n || t2 <= n) {
        while(t2 <= n && used[ord2[t2]]) t2++;
        if(t2 <= n && L[ord2[t2]] > nw) {
            ans2 += L[ord2[t2]] - nw;
            nw = L[ord2[t2]];
            used[ord2[t2]] = 1;
        }
        t2++;
        while(t1 <= n && used[ord1[t1]]) t1++;
        if(t1 <= n && R[ord1[t1]] < nw) {
            ans2 += nw - R[ord1[t1]];
            nw = R[ord1[t1]];
            used[ord1[t1]] = 1;
        }
        t1++;
    }
    ans2 += Abs(nw);
    printf("%lld\n", max(ans1, ans2));
    return 0;
}

Measured memory_bytes: 4096
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
vector<ll> eratos(int max){
  vector<ll> res;
  vector<bool> cp_list(max+1,true);
  cp_list[0]=false;
  cp_list[1]=false;
  for(ll i=2;i<=max;i++){
    if(cp_list[i]){
      res.push_back(i);
      for(ll j=2;j*i<=max;j++){
        cp_list[i*j]=false;
      }
    }
  }
  return res;
}
signed main(){
  init_io();
  ll n;
  vector<ll> plist = eratos(55555);
  cin >> n;
  for(auto p:plist){
    if(p%5==1){
      cout << p;
      n--;
      if(n!=0) cout <<" ";
      else{
        cout << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 384
#include <cstdio>
int main(){
	int a, b, d = 0;
	while(scanf("%d%d", &a, &b), a){
		if(d++)puts("");
		int c = 0;
		for(;a<=b;a++){
			if(a % 4 < 1)
				if(a % 100)c++, printf("%d\n", a);
				else 
					if(a % 400 < 1){c++, printf("%d\n", a);}
		}
		if(!c)puts("NA");
	}
}

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

int main(){

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

  sort(a, a+n, greater<int>());

  int Alice=0, Bob=0;
  for(int i=0; i<n; i+=2){
    Alice+=a[i];
    Bob+=a[i+1];
  }

  cout << Alice-Bob << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

const int NMAX=2000100; // we can calculate nCk until n is equal to NMAX
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}



int main()
{
  int k; cin >> k;
  string s; cin >> s;
  int n = k + s.size();
  vector<mint> pow(n),pow2(n);
  pow[0].x = 1;
  pow2[0].x = 1;  
  rep(i,n-1) {
    pow[i+1] = pow[i] * (mint)26;
    pow2[i+1] = pow2[i] * (mint)25;    
  }

  Make_Fact();
  Make_InvFact();
  mint res;
  for(int i = s.size();i <= n;++i) {
    res += pow2[i - s.size()] * Comb(i - 1, s.size() - 1) * pow[n - i];
  }

  cout << res.x << "\n";
  
  return 0;
}


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

/**
 *
 * @author lenovo
 */
public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int w = scanner.nextInt();
        int h = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int r = scanner.nextInt();
        if (y + r <= h && x + r <= w && x > 0 && y > 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

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

template <typename T>
class imos2 {
	int n, m;
	vector<vector<T>> v;
public:
	imos2(int n, int m) : n(n), m(m), v(n + 1, vector<T>(m + 1)) {}
	T& val(int i, int j) { assert(0 <= i && i < n && 0 <= j && j < m); return v[i + 1][j + 1]; }
	void add(int li, int lj, int ri, int rj) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		val(li, lj) += 1;
		if (rj < m) val(li, rj) -= 1;
		if (ri < n) val(ri, lj) -= 1;
		if (ri < n && rj < m) val(ri, rj) += 1;
	}
	void build() {
		for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) v[i][j] += v[i - 1][j];
		for (int i = 0; i <= n; i++) for (int j = 1; j <= m; j++) v[i][j] += v[i][j - 1];
	}
	T sum(int li, int lj, int ri, int rj) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		return v[ri][rj] - v[ri][lj] - v[li][rj] + v[li][lj];
	}
};

void press(vector<int>& v, int& size) {
	auto s = v;
	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());
	for (auto& val : v) {
		val = lower_bound(s.begin(), s.end(), val) - s.begin();
	}
	size = s.size();
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, h, w;
	cin >> N;
	vector<int> x(N * 2), y(N * 2);
	for (int i = 0; i < N * 2; i++) {
		cin >> x[i] >> y[i];
	}
	press(x, h), press(y, w);
	imos2<int> im(h, w);
	for (int i = 0; i < N; i++) {
		im.add(x[i * 2], y[i * 2], x[i * 2 + 1], y[i * 2 + 1]);
	}
	im.build();
	int res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			res = max(res, im.val(i, j));
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 8396
#include <stdio.h>

int main(void)
{
	int N, amari, ans;

	scanf("%d", &N);

	amari = N % 1000;
	if (amari == 0) ans = 0;
	else ans = 1000 - amari;
	
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 1712
#from collections import Counter
import math
N=int(input())
A=list(map(int,input().split()))
l=[]
n=1
for i in A:
    l.append(i-n)
    n+=1
l.sort()
#中央値
#切り捨て
c=int(math.floor(N/2))

ans_l=[]
ans=0
for j in l:
    ans+=abs(j-l[c])

print(ans)

Measured memory_bytes: 26832
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n,m;cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m);
  rep(i,m) {
    cin >> k[i];
    s[i].resize(k[i]);
    rep(j,k[i]) {
      cin >> s[i][j]; s[i][j]--;
    }
  }
  vector<int> p(m);
  rep(i,m) cin >> p[i];

  int res = 0;
  rep(mask,(1 << n)) {
    bool f = true;
    rep(i,m) { // denkyu
      int cnt = 0;
      rep(j,k[i]) { // switch
	if((mask >> s[i][j]) & 1) cnt++;
      }
      if(cnt % 2 != p[i]) f = false;
    }
    if(f) res++;
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 256
// Diagonal String

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

using namespace std;

int main() {
    string res = "";
    for (int i = 0; i < 9; i++) {
        char tmp;
        cin >> tmp;
        if (i == 0 || i == 4 || i == 8) {
            res += tmp;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
c = []
ans = 0
for i in range(h):
    c_i = list(input())
    c.append(c_i)

for i in range(1 << h):
    for j in range(1 << w):
        cnt = 0
        for ii in range(h):
            for jj in range(w):
                if (i >> ii & 1):
                    continue
                if (j >> jj & 1):
                    continue
                if c[ii][jj] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

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

ll dp[1000005][2]={};
//dp[i][0] i桁目までぴったり
//dp[i][1] i桁目で+1枚払う

int main(){
  string n;
  cin>>n;
  dp[0][1]=1;
  for(int i=1;i<=n.size();i++){
    int now=(int)(n[i-1]-'0');
    dp[i][0]=min(dp[i-1][0]+now,dp[i-1][1]+10-now);
    dp[i][1]=min(dp[i-1][0]+now+1,dp[i-1][1]+(10-now-1));
  }
  cout<<dp[n.size()][0]<<endl;
}


Measured memory_bytes: 20048
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, N, M, X);
    auto a = makeV(0, N, M);
    vector<int> C(N);
    rep(i, 0, N) {
        read(C[i]);
        rep(j, 0, M) { read(a[i][j]); }
    }

    int ans = INF;
    rep(b, 0, 1 << N) {
        vector<int> sum(M);
        int costSum = 0;
        rep(i, 0, N) {
            if ((b >> i) & 1) {
                costSum += C[i];
                rep(j, 0, M) sum[j] += a[i][j];
            }
        }

        if (all_of(all(sum), [&](int n) { return n >= X; })) {
            chmin(ans, costSum);
        }
    }

    if (ans == INF) {
        print(-1);
    } else {
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pll pair<ll, ll>
const ll MOD = 1e9 + 7;
pll euclid(ll a, ll b){
    if(a==0)return {0,1};
    pll aux = euclid(b%a, a);
    return { (aux.second - (b/a)*aux.first)%MOD, aux.first%MOD };
}
int main(){
    ll n,k; cin>>n>>k;
    ll ans = 1;//caso zeros = 0
    ll numer = 1;
    ll denom = 1;
    ll anterior = 1;
    for(ll zeros=1; zeros <= min(n-1, k); zeros++){
        //n-zeros variaveis com soma zeros
        //numero de solucoes = n-1 escolhe zeros
        //podemos escolher de n escolhe zeros maneiras = n-1 escolhe zeros + n-1 escolhe zeros -1
        numer = (numer*(n - zeros))%MOD;
        denom = (denom*euclid(zeros, MOD).first)%MOD;
        ll n_esc_z = ((denom*numer)%MOD + anterior)%MOD;
        ans = (ans + (n_esc_z*((denom*numer)%MOD))%MOD)%MOD;
        if(ans < 0)ans+=MOD;
        anterior = (denom*numer)%MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

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

    Int ans = 0, tem = 0;
    bool ok = false;
    for (Int i = 0; i < n; i++) {
        ans++;
        tem = a[tem];

        if (tem == 1) {
            ok = true;
            break;
        }
    }

    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')

def top(x, y):
    return y * ((x + y - 1) // y)

def solve():
    n = int(input())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        x, y = [int(x) for x in input().split()]
        a[i] = x
        b[i] = y

    a.reverse()
    b.reverse()

    ans = 0
    pls = 0
    for i in range(n):
        a[i] += pls
        xd = top(a[i], b[i]) - a[i]
        ans += xd
        pls += xd
    print(ans)

    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

7
3 1
4 1
5 9
2 6
5 3
5 8
9 7 5

"""


Measured memory_bytes: 21708
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n <= 111) {
            System.out.println(111);
        } else if (n <= 222) {
            System.out.println(222);
        } else if (n <= 333) {
            System.out.println(333);
        } else if (n <= 444) {
            System.out.println(444);
        } else if (n <= 555) {
            System.out.println(555);
        } else if (n <= 666) {
            System.out.println(666);
        } else if (n <= 777) {
            System.out.println(777);
        } else if (n <= 888) {
            System.out.println(888);
        } else{
            System.out.println(999);
        }

    }

}

Measured memory_bytes: 22224
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R;
  cin >> R;
  if (R < 1200){
    cout << "ABC" << endl;
  }
  else if (R < 2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	}
	static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	}
	static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	}
}

Measured memory_bytes: 24280
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s;
    cin >> s;

    if(s[0] == s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
card = [v for v in range(1, 2*n+1)]
m = int(input())
for _ in range(m):
    k = int(input())
    if k:
        A, B = card[:k], card[k:]
        card = B + A
    else:
        A, B = card[:n], card[n:]
        card = []
        for a, b in zip(A, B):
            card += [a] + [b]
print('\n'.join(map(str, card)))

Measured memory_bytes: 7696
x, n = map(int, input().split())
p_list = list(map(int, input().split()))

check = x
tansaku = 1
count = 0
while True:
    count += 1
    if not(check in p_list):
        print(check)
        exit()
    
    check -= tansaku
    tansaku = -tansaku
    if tansaku <0:
        tansaku -= 1
    else:
        tansaku += 1
    if count >= 500:
        exit()


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

int main() {
	int N;
	cin >> N;
	int S[30];
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 1; i < N; i++) {
		if (S[0] <= S[i]) {
			cnt++;
			S[0] = S[i];
		}
	}
	cout << cnt+1 << endl;
}

Measured memory_bytes: 256
N, M = map( int, input().split())
A = list( map( int, input().split()))
D = {0:1}
a = 0
ans = 0
for i in range(N):
    a = (a+A[i])%M
    ans += D.get(a,0)
    D[a] = 1 + D.get(a,0)
print(ans)

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

public class Main {

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

        final int N = sc.nextInt();
        int x = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        Arrays.sort(A);

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (x >= A[i]) {
                ans++;
                x -= A[i];
            }
        }

        if (ans == N && x > 0) ans--;

        System.out.println(ans);
    }
}


Measured memory_bytes: 22612
#include <stdio.h>
int a[200000];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = k; i < n; i++) {
		if (a[i - k] >= a[i]) {
			printf("No\n");
		} else {
			printf("Yes\n");
		}
	}
	return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

void swap(int& i, int& j) {
	int tmp = i;
	i = j;
	j = tmp;
}

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

	int n;
	cin >> n;

	vector<int> p(n);
	rep (i, 0, n)
		cin >> p[i];

	int res = 0;
	rep (i, 0, n) {
		if (p[i] == i + 1) {
			if (p[i + 1] == i + 2) {
				i++;
			}
			res++;
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split(' ')))

sum_a = sum(A)

min_diff = sum_a
sum_i = 0
for i in range(N):
    sum_i += A[i]
    diff = (sum_a - sum_i) - sum_i
    # print(sum_a - sum_i, sum_i)
    min_diff = min(min_diff, abs(diff))

print(min_diff)


Measured memory_bytes: 86620
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 18:58:46 2020

@author: naoki
"""
from heapq import heappush, heappop
import sys

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

hq = []
hq_r = []
for i in range(N):
    heappush(hq,a[i])
    heappush(hq_r,-1*a[-1-i])


max_A = [0 for _ in range(N+1)]
max_A[0] = sum(hq)

min_C = [0 for _ in range(N+1)]
min_C[0] = sum(hq_r) * (-1)

for i in range(N):
    heappush(hq, a[N+i])
    heappush(hq_r, -1*a[-N-1-i])
    minus = heappop(hq)
    minus_r = heappop(hq_r)
    max_A[i+1] = max_A[i] + a[N+i] - minus
    min_C[i+1] = min_C[i] + a[-N-1-i] + minus_r
    
max_val = -10e+100
for i in range(N+1):
    kari = max_A[i] - min_C[-1-i]
    if max_val < kari:
        max_val =kari
print(max_val)

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

using namespace std;

int main(void) {
  long long N; cin >> N;
  
  if (N%2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  long long ans = 0;
  long long rdx = 5;
  N /= 2;

  while (rdx <= N) {
    ans += N / rdx;
    rdx *= 5;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int GetMostRightValidNeiberLeft(int iLArg, const string& X) {
	bool isFound = false;
	for (int i = iLArg - 1; i >= 0; --i) {
		if (X[i] == 'S') {
			isFound = true;
			iLArg = i;
			break;
		}
	}
	if (isFound == false) {
		return -1;
	}
	return iLArg;
}

int Work5Core(string X)
{
	int numSt = 0;

	//int indexS = 0;
	int iL0 = -1; // すぐ左の削っていないもっとも右のデータ

	for (int iL = 0; iL <= static_cast<int>(X.size()) - 2; ++iL) {
		if (X[iL] == 'S' && X[iL + 1] == 'T') {
			++numSt;
			X[iL] = 'x';
			X[iL + 1] = 'x';

			if (iL0 < 0) {
				iL0 = GetMostRightValidNeiberLeft(iL,X);
			}

			for (;;) {
				if (X[iL + 2] == 'T') {
					if (iL0 >= 0
						&& X[iL0] == 'S') {
						++numSt;
						X[iL + 2] = 'x';
						X[iL0] = 'x';
						++iL;
						iL0 = GetMostRightValidNeiberLeft(iL0, X);
					}
					else {
						break;
					}
				}
				else {
					iL0 = -1;
					break;
				}
			}
		}
	}

	return X.size() - numSt * 2;
}
int main()
{
	string X;

	cin >> X;

	int result = Work5Core(X);

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 772
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;

long long int N, M, K, W, H, L, R;

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

	cin >> N >> M >> L >> R;
	cin >> K;
	long long int num[2] = {};
	num[0] = min({ N * 4,M * 2,L });
	num[1] = min({ num[0] * 2,R });
	cout << min(K*num[0], K / 2 * num[1] + num[0] * (K % 2)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

bool CheckSymmetry(char a, char b){
	switch (a){
	case 'i':
	case 'w':
		if (b == a)return true;
		break;
	case '(':
		if (b == ')')return true;
		break;
	case ')':
		if (b == '(')return true;
		break;
	default:
		return false;
	}
	return false;
}

int main(){
	char Loader[11];
	cin >> Loader;

	int length = strlen(Loader);
	int cnt = 0;
	for (int i = 0; i < (length + (length % 2)) / 2; ++i){
		if (!CheckSymmetry(Loader[i],Loader[length-i-1]))++cnt;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		if(a>=b+c) System.out.println(0);
		else System.out.println(b+c-a);
		in.close();

	}

}


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

int main(){
  int n,m,Q;
  cin >> n >> m >> Q;
  int l[m],r[m],c[n+1][n+1],x[n+1][n+1];
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n;j++){
      c[i][j] = 0;
      x[i][j] = 0;
    }
  }
  for(int i = 0;i < m;i++){
    cin >> l[i] >> r[i];
    x[l[i]][r[i]]++;
  }
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      c[i][j] = c[i][j-1] + x[i][j];
    }
  }
  for(int i = 0;i < Q;i++){
    int p,q;
    cin >> p >> q;
    int sum = 0;
    for(int j = p;j <= q;j++){
      sum += c[j][q];
    }
    cout << sum << endl;
  }
}

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  bool ok = false;
  if (a + b == c || a + c == b || b + c == a) ok = true;

  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256