akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;

const ll base = 998244353;

ll n, m, k, ans = 0;

ll mul(ll x, ll y) { return (x * y) % base; }

void add(ll &x, ll y) { (x += y) %= base; }

ll bin_pow(ll x, ll st) {
    ll res = 1;

    while (st > 0) {
        if (st & 1)
            res = mul(res, x);

        x = mul(x, x);
        st >>= 1;
    }

    return res;
}

int main() {
    fast_io;

    cin >> n >> m >> k;

    ll cur = 1;

    //cerr << bin_pow(m - 1, n - 1) << "\n";
    ans = mul(m, bin_pow(m - 1, n - 1));
    //cerr << ans << "\n";

    for (ll i = 1; i <= k; ++i) {
        cur = mul(cur, n - i);
        cur = mul(cur, bin_pow(i, base - 2));

        add(ans, mul(m, mul(cur, bin_pow(m - 1, n - 1 - i))));

        //cerr << ans << "\n";
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) = for(int i = 0;i<n;i++)
using namespace std;
typedef long long ll;
 
int main(){
  ll n;
  cin >> n;
  ll ans = n * (n-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 100100;
ll w[MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,m,v,p;
	cin >> n >> m >> v >> p;
	for(int i=0;i<n;i++) {
		cin >> w[i];
	}
	sort(w,w+n);
	ll st = 0,ed = n-1;
	ll ls = n-1;
	while(st <= ed) {
		ll md = (st+ed)/2;
		ll go = w[md]+m;
		ll sm = 0;
		for(int i=0;i<n;i++) {
			ll val = min(go-w[i],m);
			if(i > n-p) {
				val = m;
			}
			val = max(val,0LL);
			sm += val;
		}
		if(sm >= m*v && w[md]+m >= w[n-p]) {
			ed = md-1;
			ls = md;
		} else {
			st = md+1;
		}
	}
	cout << n-ls << '\n';
}


Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        int ab = scn.nextInt();  
        int aNum = scn.nextInt();
        int bNum = scn.nextInt();
        int aTotal  = aNum*a;
        int bTotal = bNum*b;
        int abUp = 0;
        int abDown = 0;
        if(aNum>bNum){
            abUp = aNum*ab*2;
            abDown = bNum*ab*2+a*(aNum-bNum);
        }else{
            abUp = bNum*ab*2;
            abDown = aNum*ab*2+b*(bNum-aNum);
        }
        int min = aTotal+bTotal;
        min = Math.min(min,abUp);
        min = Math.min(min,abDown);
        System.out.println(min);
    }
}

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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] h = new int[N];
    for (int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }

    sc.close();

    Arrays.sort(h);

    int min = h[N - 1];
    for (int i = 0; i < N - K + 1; i++){
      int a = 0;
      a = h[i + K - 1] - h[i];
      min = Math.min(a, min);
      if (min == 0){break;}
    }

    System.out.println(min);
    
  }
}


Measured memory_bytes: 49088
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  if((N+1)/2 >= K || N/2 >=K) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def make_graph(m):
    matrix = np.zeros([m + 1, m + 1, m + 1])
    for k in range(1, m + 1):
        for s in range(k, m + 1):
            matrix[k, s, s % k] = 1
    return matrix


def is_disable(matrix, subset, aaa, bbb):
    if subset:
        sub_matrix = matrix[list(subset)].max(axis=0)
    else:
        sub_matrix = matrix[0]
    sp = floyd_warshall(sub_matrix)
    return any(sp[a, b] > 50 for a, b in zip(aaa, bbb))


def solve(aaa, bbb):
    for a, b in zip(aaa, bbb):
        if a < b:
            return -1
    m = max(aaa)
    matrix = make_graph(m)
    subset = set(range(1, m + 1))
    if is_disable(matrix, subset, aaa, bbb):
        return -1

    for k in range(m, 0, -1):
        subset.remove(k)
        if is_disable(matrix, subset, aaa, bbb):
            subset.add(k)
    return sum(1 << k for k in subset)


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(aaa, bbb))


Measured memory_bytes: 15400
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	/*int l,ma=0;cin>>l;
	rep(i,1000) rep(j,1000){
		if(i+j>l) continue;
		ma=max(ma,i*j*(l-i-j));
	}
	cout<<ma<<endl;*/
	double l;cin>>l;
	printf("%.12f\n", l*l*l/27.0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 0;
  for (int i=0; i<4; i++) {
    char t;
    cin >> t;
    if (t == '+') {
      a++;
    } else {
      a--;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, i;
    
    scanf("%d %d", &a, &b);
    
    if(a == b){
        for(i = 0; i < a; i++){
            printf("%d", a);
        }
    }else if(a > b){
        for(i = 0; i < a; i++){
            printf("%d", b);
        }
    }else if(a < b){
        for(i = 0; i < b; i++){
            printf("%d", a);
        }
    }
    
}


Measured memory_bytes: 1732
#include <stdio.h>
 
int main(void){
    int N, K, x, i;
    char S[100005];
    scanf("%d%d", &N, &K);
    scanf("%s", S);
    x=1;
    for (i=0; i<N-1; i++) {
        if (S[i]!=S[i+1]) x++;
    }
    x-=2*K;
    if (x<=0) x=1;
    printf("%d", N-x);
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
V = list(map(int, input().split()))
Ans = -float('inf')
for a in range(K+1):
    for b in range(K+1):
        if a + b > min(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans)
print(Ans)





Measured memory_bytes: 73360
import java.util.Scanner;
import java.util.TreeSet;
import java.util.Arrays;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
       while(true){
           int h,w;
           h=sc.nextInt();
           w=sc.nextInt();
           if(h==0&&w==0)break;
           for(int i=0;i<h;i++){
               for(int j=0;j<w;j++){
                   System.out.print("#");
               }
               System.out.println("");
           }
           System.out.println("");
       }
}
}



Measured memory_bytes: 32992
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

int main(){

  int n, ans = 0;
  vector<int> d(100);
  
  cin >> n;
  
  rep(i, n){
    cin >> d[i];
  }
  
  sort(d.begin(), d.end(), greater<int>());
  
  int pre = 0;
  rep(i, n){
    if(pre != d[i]){
      ans++;
      pre = d[i];
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define true 1
#define false 0

char s[51];
char origin[10] = "AKIHABARA";
int origin_num = 0;

int main() {
	for (int i = 0; i < 51; i++) {
		s[i] = '0';
	}
	scanf("%s", s);
	for (int i = 0; i < 50 && origin_num <= 9; i++) {
		//同じの場合
		if (s[i] == origin[origin_num]) {
			origin_num++;
		}
		//Aをひとつ飛ばしたら同じの場合
		else if (origin[origin_num] == 'A' && origin_num <= 8 && origin[origin_num + 1] == s[i]) {
			origin_num += 2;
		}
		else {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

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

using namespace std;

int main()
{
  int N = 0;
  cin >> N;
  for(int i = 1; i < 10; i++){
    if(N % i == 0 && int(N/i) < 10){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rer(i, a, b) for(ll i=a-1; i>=b; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m, parent[MAX_N], h[MAX_N]; //入次数を管理
vector<ll> e[MAX_N], ev[MAX_N];

signed main(){
    cin >> n >> m;
    rep(i, 0, MAX_N) h[i] = 0;
    rep(i, 0, n+m-1){
        ll a, b; cin >> a >> b;
        a--; b--;
        e[a].pb(b);
        ev[b].pb(a);
        h[b]++;
        parent[b] = a;
    }

    // 入次数が0の頂点集合
    stack<ll> st;

    // 入次数が0の頂点があればstに追加
    rep(i, 0, n) if(h[i]==0) st.push(i);

    vector<ll> v;
    while(!st.empty()){
        // rep(i, 0, n) cout << h[i] << " ";
        cout << endl;
        ll t = st.top(); st.pop();
        v.pb(t);
        rep(i, 0, e[t].size()){
            h[e[t][i]]--;
            if(h[e[t][i]]==0) st.push(e[t][i]);
        }
    }

    // rep(i, 0, v.size()) cout << v[i] + 1 << " ";
    // cout << endl;

    ll d[MAX_N];
    rep(i, 0, n) d[v[i]] = i;
    rep(b, 0, n){
        rep(j, 0, ev[b].size())
            if(d[ev[b][j]] > d[parent[b]]) parent[b] = ev[b][j];
    }
    rep(i, 0, n){
        if(i == v[0]) cout << "0" << endl;
        else cout << parent[i] + 1<< endl;
    }
    return 0;
}

Measured memory_bytes: 15096
#include <stdio.h>

int main() 
{
    int h, m, s;
    int S;
	
    scanf("%d", &S);
	
    s = S % 60;
    h = S / 3600;
    m = (S - 3600 * h - s) / 60;
	
    printf("%d:%d:%d\n", h, m, s);
	
    return 0;
}

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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 1e9
#define MOD 1000000007

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

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

void solve() {
  int n;
  string s;
  cin >> n >> s;
  string ans = "";
  rep(i, s.size()) {
    char temp = s[i] + n;
    if (temp > 'Z') {
      temp -= 26;
    }
    ans += temp;
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int num;
    int sum = 0;
    while(cin >> num)
    {
        sum = (num / 500) * 2 *500;
        num = num % 500;
        sum += (num / 5) * 5;
        
        cout << sum <<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
   int n;
   cin>>n;
   
   if(n>=400&&n<=599)
   cout<<"8";
   else if(n>=600&&n<=799)
   cout<<"7";
   else if(n>=800&&n<=999)
   cout<<"6";
   else if(n>=1000&&n<=1199)
   cout<<"5";
   else if(n>=1200&&n<=1399)
   cout<<"4";
   else if(n>=1400&&n<=1599)
   cout<<"3";
   else if(n>=1600&&n<=1799)
   cout<<"2";
   else
   cout<<"1";
   
   return 0;
}

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

const int MAX=1000000;

int func_num(int n){
  
  int count=0;

  while(1){
    int x=0;
    if(0<=n&&n<=9) break;
    for(int i=10;i<=MAX;i*=10){
      if(n/i==0) break;
      x=max(x,(n/i)*(n%i));
    }
    n=x;
    count++;
  }
  return count;
}

int main(){
  int Q,N;
  int ans;
  
  cin>>Q;
  for(int i=0;i<Q;i++){
    cin>>N;
    ans=func_num(N);
    cout<<ans<<endl;
  }
  
  return 0;
}

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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

const ll MAX_N = 100, MAX_W = 1e9, MAX_V = 1e3;
ll N, W;
ll wt[MAX_N], vl[MAX_N];
ll dp[MAX_N + 1][MAX_V * MAX_N + 1];
int main(){
  //input
  cin >> N >> W;
  REP(i, N){
    cin >> wt[i] >> vl[i];
  }
  REP(i, N + 1){
    dp[i][0] = 0;
    FOR(v, 1, MAX_V * MAX_N + 1){
      dp[i][v] = INF;
    }
  }
  REP(i, N){
    FOR(v, 1, MAX_V * N + 1){
      if(v >= vl[i]){
        dp[i+1][v] = min(dp[i][v-vl[i]] + wt[i], dp[i][v]);
      }
      else{
        dp[i+1][v] = min(wt[i], dp[i][v]);
      }
    }
  }
  ll ans = upper_bound(dp[N], dp[N] + MAX_V * MAX_N + 1, W) - dp[N] - 1;
  cout << ans << endl;
}


Measured memory_bytes: 79104
from fractions import gcd
import math
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    a, b =map(int, input().split())
    if a <= 0 <= b:
        print('Zero')
        return
    if 0 < a:
        print('Positive')
        return
    if (b - a) % 2 == 1:
        print('Positive')
        return
    print('Negative')
main()


Measured memory_bytes: 5076
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 500 + 10;
typedef long long int ll;
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % b)
        cout << (a / b + 1) * c << endl;
    else
        cout << a / b * c << endl;
    return 0;
}
/*
3 4
1 0 0 0
0 0 0 0
0 0 0 2
*/

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

typedef long long ll;

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

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	int x;
	cin >> x;

	for(int i = x; ; i++) {
		if(isPrime(i)) {
			cout << i << endl;
			return 0;
		}
	}
}



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

using namespace std;

int max(int a, int b)
{
	return (a > b) ? a : b;
}

int main()
{
	int a, b, k;

	cin >> a >> b >> k;

	int last = -1;
	for (int i = a, count = 1; i <= b; i++, count++)
	{
		if (count > k) break;
		cout << i << endl;
		last = i;
	}

	for (int i = max(max(a, b - k + 1), last + 1); i <= b; i++)
	{
		cout << i << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
t, x, y = 0, 0, 0 # current, default(0, 0, 0)
ans = "Yes"
for i in range(1, n+1):
  ti, xi, yi = map(int, input().split())
  dist = abs((xi - x) + (yi - y))
  dt = ti - t
  if dt >= dist and (dt - dist) % 2 == 0:
    t, x, y = ti, xi, yi  # update
  else:
    ans = "No"
    break
 
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  string a,b;
  cin>>a>>b;
  string ans="D";
  if(a==b) ans="H";
  cout<< ans  <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int n,m; cin >> n >> m;
  if(n==m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
/*
author : seryu
title : NOMURA programming contest 2020
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int h[2],m[2],k;
	cin >> h[0] >> m[0] >> h[1] >> m[1] >> k;
	int t = (h[1]-h[0])*60+(m[1]-m[0]);
	int ans = t-k;
	cout << ans << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main(){
	int a, b;

	scanf("%d %d",&a, &b);

	int mul = a*b;

	if(mul<(a+b)){
		mul=a+b;
	}
	if (mul<(a-b)){
		mul=a-b;
	}
	printf("%d\n",mul);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	char a,b;
	int cup[3] = {1,0,0};
	while(~scanf("%c,%c ",&a,&b)){
		a -= 'A'; b -= 'A';
		swap(cup[a],cup[b]);
	}
	if( cup[0]==1 ){
		puts("A");
	}else if( cup[1]==1 ){
		puts("B");
	}else{
		puts("C");
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i=0; i<n; i++){
        cin >> p[i]; p[i]--;
    }
    int a[n],b[n];
    for(int i=0; i<n; i++){
        a[i] = i+1;
        b[i] = n-i;
    }
    for(int i=0; i<n-1; i++){
        int q = p[i];
        for(int j=0; j<q; j++) b[j] += n-i;
        for(int j=q+1; j<n; j++) a[j] += n-i;
    }
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
    for(int i=0; i<n; i++){
        cout << b[i] << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A, Q, B, C;
  
  std::cin >> N;

  std::map<int, long long> map;

  for (int i = 0; i < N; i ++) {
    std::cin >> A;

    map[A] ++;
  }

  long long S = 0;

  for (const auto& kv : map)
    S += 1LL * kv.first * kv.second;

  std::cin >> Q;

  for (int i = 0; i < Q; i ++) {
    std::cin >> B >> C;

    long long c = map[B];

    S -= B * c;
    S += C * c;

    map[B]  = 0;
    map[C] += c;

    std::cout << S << std::endl;
  }

  return 0;
}


Measured memory_bytes: 9400
#include<stdio.h>

const int mod = 1e9 + 7;

int main(){
  int N;
  scanf("%d", &N);
  char S1[N]; 
  char S2[N];
  scanf("%s", S1);
  scanf("%s", S2);
  
  long long color = 1;
  if(S1[0] == S2[0]) color = 3;
  else color = 6;
  for(int i = 1; i < N; i++){
    if(S1[i] == S1[i - 1]) continue;
    if(S1[i - 1] == S2[i - 1]){
      color *= 2;
    }else{
      if(S1[i] != S2[i]) color *= 3;
    }
    color %= mod;
  }
  
  printf("%d\n", color);
  
  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    string t = "2019/04/30";
    if(s>t)
    {
       cout << "TBD" << "\n";
    }
    else
    {
    cout << "Heisei" << "\n";
    }
   
 
}



Measured memory_bytes: 3092
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int a, b, P;
int bit[100010];
int sum(int i){
	int res = 0;
	for(; i; i -= i & -i) (res += bit[i]) %= P;
	return res;
}
void add(int i, int x){
	for(; i < 100010; i += i & -i) (bit[i] += x) %= P;
}

int main(){
	while(cin >> a >> b >> P, a){
		memset(bit, 0, sizeof(bit));
		vector<string> v;
		for(int i = a; i <= b; i++){
			char buf[20];
			sprintf(buf, "%d", i);
			v.pb(buf);
		}
		sort(all(v));
		
		int ans = 0;
		rep(i, v.size()){
			int d, t;
			sscanf(v[i].c_str(), "%d", &d);
			d -= a - 1;
			t = sum(d) + 1;
			(ans += t) %= P;
			add(d, t);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 7164
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N, M; cin >> N >> M;
	vector<int>anss(N);
	if (N % 2) {
		for (int i = 0; i < N / 2; ++i) {
			anss[i] = 0;
		}
		for (int i = N / 2; i < N; ++i) {
			anss[i] = M;
		}
	}
	else {
		for (int i = 0; i < N / 2+1; ++i) {
			anss[i] = 0;
		}
		for (int i = N / 2+1; i < N; ++i) {
			anss[i] = M;
		}
	}
	for (int i = 0; i < anss.size(); ++i) {
		cout << anss[i];
		if (i == anss.size() - 1)cout << endl;
		else cout << " ";
	}
	
	return 0;
}

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

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;

const int N=100010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;

int n;

int main()
{
#ifdef local
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    int ans=-n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        ans+=x;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  string s;
  cin >> s;
  string a="AKIHABARA";
  if(s.size()==5) {
    if(s=="KIHBR") {
      cout << "YES" << endl;
      return 0;
    }
  }
  if(s.size()==6) {
    if(s=="AKIHBR"||s=="KIHABR"||s=="KIHBAR"||s=="KIHBRA") {
      cout << "YES" << endl;
      return 0;
    }
  }
  if(s.size()==7) {
    if(s=="AKIHABR"||s=="AKIHBAR"||s=="AKIHBRA"||s=="KIHABAR"||s=="KIHABRA"||s=="KIHBARA") {
      cout << "YES" << endl;
      return 0;
    }
  }
  if(s.size()==8) {
    if(s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="KIHABARA") {
      cout << "YES" << endl;
      return 0;
    }
  }
  if(s==a) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt =0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
	int out[5]={0,6000,4000,3000,2000};
	rep(i,4){
		int a,b;
		cin>>a>>b;
		cout<<out[a]*b<<endl;;
	}

}

Measured memory_bytes: 1160
IDENTIFICATION DIVISION.
      PROGRAM-ID. 135A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(100).
      01 A   PIC 9(10).
      01 B   PIC 9(10).
      01 SHO PIC 9(10).
      01 AMA PIC 9(1).
      01 ANS PIC 9(11).
      01 DISP PIC ZZZZZZZZZ9.

      PROCEDURE DIVISION.
      ACCEPT INP.
      UNSTRING INP DELIMITED BY " "
      INTO A B.
      COMPUTE ANS = A + B
      DIVIDE ANS BY 2 GIVING SHO REMAINDER AMA.
      MOVE SHO TO DISP.
      IF AMA = 1
      	DISPLAY "IMPOSSIBLE"
      ELSE
        DISPLAY DISP
      END-IF.
      STOP RUN.
      

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 500000;
int lb[N], rb[N], lc[N], rc[N], mx[N], tag[N], tot;
int ans;
vector <int> V[N];
void upd(int t)
{
    mx[t] = max(mx[lc[t]], mx[rc[t]]);
}
void psdw(int t)
{
    tag[lc[t]] += tag[t];
    mx[lc[t]] += tag[t];
    tag[rc[t]] += tag[t];
    mx[rc[t]] += tag[t];
    tag[t] = 0;
}
int build(int l, int r)
{
    int t = ++ tot;
    lb[t] = l; rb[t] = r;
    if (l != r)
    {
        lc[t] = build(l, (l + r) / 2);
        rc[t] = build((l + r) / 2 + 1, r);
        upd(t);
    }
    else
    {
        mx[t] = -(m + 1 - l);
    }
    return t;
}
void modify(int t, int l, int r, int v)
{
    if (l <= lb[t] && rb[t] <= r)
    {
        mx[t] += v;
        tag[t] += v;
        return;
    }
    psdw(t);
    if (l <= rb[lc[t]]) modify(lc[t], l, r, v);
    if (r >= lb[rc[t]]) modify(rc[t], l, r, v);
    upd(t);
}
int query(int t, int l, int r)
{
    if (l <= lb[t] && rb[t] <= r) return mx[t];
    psdw(t);
    int v = 0;
    if (l <= rb[lc[t]]) v = max(v, query(lc[t], l, r));
    if (r >= lb[rc[t]]) v = max(v, query(rc[t], l, r));
    return v;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        V[l].push_back(r);
    }
    build(0, m + 1);
    ans = max(n - m, 0);
    for (int i = 0; i <= m; ++ i)
    {
        for (int j = 0; j < V[i].size(); ++ j)
            modify(1, 0, V[i][j], 1);
        ans = max(ans, query(1, i + 1, m + 1) - i);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 26880
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<vector<int>> g(n);
    rep(i,n-1) {
        int a,b; cin>>a>>b; --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<ll> x;
    vector<ll> dp(n+10,LINF);
    vector<ll> ans(n);
    auto dfs = [&] (auto &&f, int v, int p) -> void {
        auto itr = lower_bound(dp.begin(), dp.end(), a[v]);
        int idx = itr-dp.begin();
        ll pre = *itr;
        *itr = a[v];
        ans[v] = lower_bound(dp.begin(), dp.end(), LINF)-dp.begin();

        for (auto &&e: g[v]) {
            if (p==e) continue;
            f(f, e, v);
        }

        dp[idx] = pre;
        return;
    };

    dfs(dfs,0,-1);

    for (auto &&e: ans) cout << e << '\n';
    return 0;
}

Measured memory_bytes: 33112
s=input()
if s[0]=='0' or s[-1]=='1' or s[:-1]!=s[:-1][::-1]:
    print(-1)
    exit(0)
e=[]
bi=0
for i,j in enumerate(s[:-1]):
    e.append([bi,i+1])
    if j=='1':
        bi=i+1
for i,j in e:
    print(i+1,j+1)

Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int,int>
#define VS vector<string>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define FST first
#define SEC second
int main(){
  int n;
  cin>>n;
  VI V(n);
  REP(i,n)cin>>V[i];
  sort(ALL(V));
  int mi=1e9;
  REP(i,n-3){
    mi=min(mi,V[i+1]-V[i]);
  }
  double ans=(double)(V[n-1]+V[n-2])/(double)mi;
  double d=(double)(V[n-3]+V[n-4])/(double)(V[n-1]-V[n-2]);
  ans=max(ans,d);
  d=(double)(V[n-1]+V[n-4])/(double)(V[n-2]-V[n-3]);
  ans=max(ans,d);
  printf("%.5f\n",ans);
  return 0;
}

Measured memory_bytes: 3260
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


h, w, k = LI()
C = SR(h)
ans = 0
for i in range(2 ** (h + w)):
    ret = 0
    for y in range(h):
        for x in range(w):
            if i >> y & 1 and i >> (h + x) & 1 and C[y][x] == "#":
                ret += 1
    if ret == k:
        ans += 1

print(ans)

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

#define pb push_back
#define f first
#define s second
using namespace std;


int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    long long int x=a+b;
    long long int y=n%x;
    long long int z=n/x;

    if(y>a)cout<<a+z*a;
    else cout<<y+z*a;

return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,L;
string s[110];
int main() {
	scanf("%d %d",&n,&L);
	for (int i=1;i<=n;i++)
		cin>>s[i];
	sort(s+1,s+(n+1));
	for (int i=1;i<=n;i++)
		cout<<s[i];
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define pi acos(-1)
#define P pair<int,int>
#define fi first
#define se second
#define si signed
#define sc(x) scanf("%lld",&(x));
int n;
int A[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main()
{
    int m;
    sc(n)sc(m)
    if(n==1||m==1){
        cout<<1<<'\n';
        return 0;
    }
    int ans = (n/2)*m;
    if(n%2!=0){
        ans+=(m+1)/2;
    }
    cout<<ans<<'\n';
    //cout<<A[n-1]<<'\n';
}


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

int main() {
  ll a, b, n, x;
  cin >> a >> b >> n;
  x = min(b - 1, n);
  cout << (a * x) / b - a * (x / b) << endl;

}


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

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while (n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
xyh = sorted(xyh, key = lambda x: -x[2])
tx, ty, th = xyh[0]
for Cx in range(101):
  for Cy in range(101):
    H = th + abs(tx - Cx) + abs(ty - Cy)
    if(all(h == max(H - abs(x - Cx) - abs(y - Cy), 0) for x,y,h in xyh)):
      print(Cx, Cy, H)
      exit()

Measured memory_bytes: 3064
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

C = input()

al = string.ascii_lowercase

print(al[al.index(C)+1])



Measured memory_bytes: 5808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		int cnt = 1;
		long tmp = x;
		while (true) {
			tmp *= 2;
			if (tmp > y) {
				break;
			}
			cnt++;
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 23764
def cmb(n, r, mod):
    if r < 0 or n < r:
        return 0
    r = min(r, n-r)
    numerator, denominator = 1, 1
    for i in range(1, r + 1):
        numerator = (numerator * (n + 1 - i)) % mod
        denominator = (denominator * i) % mod
    return numerator * pow(denominator, mod - 2, mod) % mod


def solve():
    MOD = 10**9+7
    X, Y = map(int, input().split())

    if (X + Y) % 3 != 0:
        print(0)
        exit()
    
    n = (2 * Y - X) // 3
    m = (X - n) // 2
    
    if n < 0 or m < 0:
        print(0)
        exit()
    
    ans = cmb(n + m, n, MOD)
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
import sys
s = input()
z = True
for i in range(len(s)):
    if not z:
        break
    try:
        if s[i] == s[i + 1]:
            print(i + 1, i + 2)
            z = False
            sys.exit()
        if s[i] == s[i + 2]:
            print(i + 1, i + 3)
            z = False
            sys.exit()
    except:
        pass
if z:
    print(-1, -1)


Measured memory_bytes: 3188
program main

  implicit none

  integer :: a, N, i, j, k, pn, qn, tmp
  integer,allocatable :: P(:), Q(:)
  
  read(*,*) N
  allocate( P(N) )
  allocate( Q(N) )
  read(*,*) P
  read(*,*) Q
  
  pn = 0 
  qn = 0 

  do i = 1, N
    ! kaijou
    tmp = 1
    do j = 1, N - i
      tmp =  tmp * j  
    end do
    a = 0
    do k = 1, i 
      if ( P(k) < P(i) ) a = a + 1
    end do
    pn = pn + ( P(i) - a - 1 ) * tmp
  end do
    pn = pn + 1 

  do i = 1, N 
    ! kaijou
    tmp = 1
    do j = 1, N - i
      tmp =  tmp * j  
    end do
    a = 0
    do k = 1, i
      if ( Q(k) < Q(i) ) a = a + 1
    end do
    qn = qn + ( Q(i) - a - 1 ) * tmp
  end do
    qn = qn + 1

  tmp = pn - qn  
  print*, abs( tmp )
  
end program main


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   ll n;
   cin >> n;
   string s;
   cin >> s;
   ll j = n - 1;
   ll cnt = 0;
   for(ll i = 0; i < n; i++) {
       while(s[j]=='W') {
           j--;
       }
       if(i>=j) {
           cout << cnt << endl;
           return 0;
       }
       if(s[i] == 'W') {
           char store = s[i];
           s[i] = s[j];
           s[j] = store;
           cnt++;
       }

   }
   cout << cnt << endl;
}

Measured memory_bytes: 3716
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  char S[100];
  cin>>S;
  int N=strlen(S),i;
  for(i=0;i<(N-1)/2;i++){
    if(S[i]!=S[N-i-1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cerr<<"1_passed."<<endl;
  for(i=0;i<(N-1)/4;i++){
    if(S[i]!=S[(N-1)/2-i-1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cerr<<"2_passed."<<endl;
  for(i=0;i<(N-1)/4;i++){
    if(S[i+(N+3)/2-1]!=S[N-1-i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int flag=0;
    for (int i=1;i<=s.size();i++) {
        if (i%2==1) {
            if (s.at(i-1)!='R'&&s.at(i-1)!='U'&&s.at(i-1)!='D') {
                flag=1;
                cout<<"No"<<endl;
                break;
            }
        } else {
            if (s.at(i-1)!='L'&&s.at(i-1)!='U'&&s.at(i-1)!='D') {
                flag=1;
                cout<<"No"<<endl;
                break;
            }
        }
    }
    if (flag==0) {
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b<c+d){
    cout<<"Right"<<endl;
  }else if(a+b>c+d){
    cout<<"Left"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const ll MOD = 1000000007;
    ll N,sum=0,ans,c;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    ll MAX=sqrt((double)N);
    EREP(i,MAX){
        if(N%i==0){
            ll temp=max(N/(ll)i,(ll)i);
            c=0;
            ans=log10(temp)+1;
 
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1152
x = []
count = 0
x.append(int(input()))
x.append(int(input()))
x.append(int(input()))
x.append(int(input()))
x.append(int(input()))
k = int(input())
for i in range(len(x)):
     for j in range(i, len(x)):
          if abs(x[i] - x[j]) <= k:
               count += 0
          else:
               count += 1
if count == 0:
     print('Yay!')
else:
     print(':(')

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

using namespace std;
int main(void) {
	int X = 0,ans = 1;
	scanf("%d", &X);
	while ((ans * ans++) <= X) {}
	printf("%d\n", (ans - 2) * (ans - 2));
	return 0;
}

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

int main(){
  int m,d;
  cin >> m >> d;
  int ans = 0;
  for(int i = 1;i <= m;i++){
    for(int j = 1;j <= d;j++){
      int d10 = j/10;
      int d1 = j%10;
      if(d1 >= 2 && d10 >= 2){
        if(i == d1*d10){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>

using namespace std;
int main(void){
    // Your code here!
vector<int> vec(110);
int a,b,c;
cin >> a >> b >> c;
for(int i = 1; i < 110; i++){
    int S = i * a % b;
    if(S == c){
        cout  << "YES" << endl;
        break;
    }
    else if(vec.at(S) == 0){
        vec.at(S) = 1;
    }
    else{
        cout << "NO" << endl;
        break;
    }
    
    
}






}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <limits>
#include <string>
#include <stack>
#include <queue>

#define INT_MAX 2147483647
#define INT_MIN -2147483647
using namespace std;

void print(vector<pair<char, int> > &data)
{
	for (int i = 0; i < data.size() - 1; ++i)
		cout << data[i].first << data[i].second << " ";

	cout << data.back().first << data.back().second << endl;
}

int main()
{
	int num, timeSpan;
	cin >> num >> timeSpan;

	string name;
	int t;
	queue<pair<string, int>> q;
	while (cin >> name >> t)
	{
		q.push(make_pair(name, t));
	}
	int curTime = 0;
	while (!q.empty())
	{
		pair<string, int> pa = q.front();
		q.pop();
		if (pa.second <= timeSpan)
		{
			curTime += pa.second;
			cout << pa.first << " " << curTime << endl;
		}
		else
		{
			pa.second -= timeSpan;
			curTime += timeSpan;
			q.push(pa);
		}
	}
	return 0;
}

Measured memory_bytes: 6196
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define int long long

double dist(int x, int y, int d) {
    return sqrt(x * x + y * y) * 1.0;
}

signed main() {   
    int n, d;
    cin >> n >> d;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];

    int ans = 0;
    for(int i = 0; i < n; i++) {
        double dt = dist(x[i], y[i], d);
        if(dt <= d) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6284
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll R, G, B, N;
  cin >> R >> G >> B >> N;

  ll ans = 0;
  rep(r, N/R+1)
    rep(g, N/G+1)
      if((N-r*R-g*G) >= 0 && (N-r*R-g*G) % B == 0) ans++;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

int main(){
  int n; cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }

  int i = 1;
  int ans = 0;
  bool ok = false;
  rep(j,n) {
    if(a[j] == i){
      i++;
      ok = true;
    }
    else{
      ans++;
    }
    //printf("%d %d\n", j, ans);
  }

  cout << (ok ? ans : -1) << endl;
}

Measured memory_bytes: 1152