akhauriyash/Code-Regression huggingface dataset:
def kaijo(num):
    a = 1
    for i in range(num, 1, -1):
        a *= i
    return a

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

p_len = 0
for i in range(n - 1):
    a = p[i]
    p_len += (len(list(filter(lambda x: x < a, p[i:]))) - 1) * kaijo(n - i - 1)

for i in range(n - 1):
    b = q[i]
    p_len -= (len(list(filter(lambda x: x < b, q[i:]))) - 1) * kaijo(n - i - 1)

print(abs(p_len))



Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    ll a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}


Measured memory_bytes: 256
import itertools

N, M, Q = map(int, input().split())
data = []
for i in range(Q):
    data.append(list(map(int, input().split())))

ans = 0
for ite in itertools.combinations_with_replacement(range(1,M+1), N):
    val = 0
    for q in data:
        if ite[q[1]-1] - ite[q[0]-1] == q[2]:
            val += q[3]
    ans = max(ans, val)

print(ans)


Measured memory_bytes: 67900
using System;

namespace procon
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 1; i <= 9; i++)
            {
                for (j = 1; j <= 9; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        }
    }
}



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

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S; cin >> S;
    if(S[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    int cnt = 0;
    FOR(i,2,S.size()-1){
        if(S[i] == 'C') cnt++;
    }

    if(cnt != 1){
        cout << "WA" << endl;
        return 0;
    }

    cnt = 0;
    REP(i,S.size()){
        if('a' <= S[i] && S[i] <= 'z') cnt++;
    }

    if(cnt != S.size()-2){
        cout << "WA" << endl;
    }
    else cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
// package agc.agc025;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        char[] c = in.nextToken().toCharArray();
        int sum = 0;
        for (char ci : c) {
            sum += ci-'0';
        }
        if (sum == 1) {
            sum = 10;
        }
        out.println(sum);
        out.flush();
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

Measured memory_bytes: 22612
#include<stdio.h>
int main(){
  int A,B;

  scanf("%d %d",&A,&B);

  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
    printf("Possible");
  }else{
    printf("Impossible");
  }
  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int m,d; scanf("%d%d",&m,&d);
    int cnt=0;
    rep(i,1,m+1)rep(j,11,d+1){
        if(j/10>=2&&j%10>=2&&i==(j/10)*(j%10)){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

int main()
{
    int n;
    string s;
    int cnt = 20000000;

    ci >> n >> s;

    int rb = 0, rw = 0;
    int lb = 0, lw = 0;
    
    for(int i = 0; i < n; i++) {
	if(s[i] == '#') rb++;
	else rw++;
    }
    
    cnt = min(cnt, lb + rw);
    
    for(int i = 0; i < n; i++) {
	if(s[i] == '.') {
	    lw++;
	    rw--;
	} else {
	    lb++;
	    rb--;
	}

	cnt = min(cnt, lb + rw);
    }

    co << cnt << en;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	ll sum=0;
	for(int i=0,a;i<m;i++)	{
		cin>>a;
		sum+=a;
	}
	if(n-sum<0)
	cout<<-1;
	else cout<<n-sum;
	
	}

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

int main(){
	int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++)
    cin>>vec.at(i);
  int count=1;
  int k=0;
  
  for(int i=0;i<N;i++){
  	if(vec.at(k)==2){
      cout<<count<<endl;
      break;
    }
    else{
      k=vec.at(k)-1;
      count++;
    }
  } 
  if(count==N+1)
    cout<<-1<<endl;
}

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

int v[102], w[102];
long long dp[102][100002];

long long solve(int i, int j,int W) {
    if(i==1) {
        if(j>=w[i])
            return v[i];
        else
            return 0;
    }
    if(dp[i][j]!=-1)
        return dp[i][j] ;
    if(j>=w[i])
        return dp[i][j] = max( solve(i-1, j - w[i], W) + v[i] ,solve(i-1, j, W) );
    else
        return dp[i][j] = solve(i-1, j, W);
}
int main() {
    int n, W;
    cin>> n>>W;
    int i, j;
    for(i=1;i<=n;i++)
        for(j=1;j<=W;j++)
            dp[i][j] = -1;
    for(i=1;i<=n;i++)
        cin>>w[i] >> v[i];
            
    long long ans = 0;
    
    for(i=1;i<=W;i++)
        ans = max(ans, solve(n, i, W));
        
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 78336
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()
a = readints()
if 0 in a:
    print(0)
    exit()
ans = 1
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 85124
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int w,a,b;
    cin >> w >>a>>b;
    int res = 0;
    if (a>b) {
        res = max(0,a-(w+b));
    } else {
        res = max(0,b-(a+w));
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	int n;
	cin >> n;
	vector<vector<bool>> f(3, vector<bool>(100));
	int x, y, z;
	cin >> x;
	rep(i, x){
		int tmp;
		cin >> tmp;
		f[0][tmp] = true;
	}
	cin >> y;
	rep(i, y){
		int tmp;
		cin >> tmp;
		f[1][tmp] = true;
	}
	cin >> z;
	rep(i, z){
		int tmp;
		cin >> tmp;
		f[2][tmp] = true;
	}
	
	int ans = 0;
	rep(i, 101){
		if((!f[0][i] && f[2][i]) || (f[1][i] && f[2][i])) ans++;
	}
	
	cout << ans << endl;

}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    ll A, B, C, K; cin >> A >> B >> C >> K;

    if( K % 2 == 0) cout << A - B << endl;
    else cout << B - A << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
pos = [ 0 ] * 64
neg = [ 0 ] * 64
for i in range(32):
    if n >= 0:
        if n & (1 << i):
            pos[i] += 1
    else:
        if (- n) & (1 << i):
            neg[i] += 1
for i in range(32):
    delta = min(pos[i], neg[i])
    pos[i] -= delta
    neg[i] -= delta
    if i % 2 == 1:
        if pos[i]:
            pos[i + 1] += pos[i]
            neg[i] += pos[i]
            pos[i] = 0
        neg[i + 1] += neg[i] // 2
        neg[i] %= 2
    else:
        if neg[i]:
            neg[i + 1] += neg[i]
            pos[i] += neg[i]
            neg[i] = 0
        pos[i + 1] += pos[i] // 2
        pos[i] %= 2
s = ''
for i in reversed(range(64)):
    if pos[i] or neg[i]:
        s += '1'
    else:
        s += '0'
print(s.lstrip('0') or '0')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

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

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<ll>> v(10);
    for (int i = 0; i < n; ++i) {
        ll x, y;
        scanf("%li %li", &x, &y);
        v[y-1].emplace_back(x);
    }
    for (int i = 0; i < 10; ++i) {
        sort(v[i].begin(), v[i].end());
        v[i].emplace_back(0);
        reverse(v[i].begin(), v[i].end());
        for (int j = 1; j < v[i].size(); ++j) {
            v[i][j] = v[i][j-1]+v[i][j]+2*(j-1);
        }
    }
    vector<ll> dp(1, 0);
    for (auto &&genre : v) {
        vector<ll> newdp(dp.size()+genre.size()+1);
        for (int i = 0; i < dp.size(); ++i) {
            for (int j = 0; j < genre.size(); ++j) {
                chmax(newdp[i+j], dp[i]+genre[j]);
            }
        }
        dp = newdp;
    }
    cout << dp[k] << "\n";
    return 0;
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  string s;
  cin >> s;
  if(s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if(s == "Cloudy") {
    cout << "Rainy" << endl;
  } else if(s == "Rainy") {
    cout << "Sunny" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

# 書かれた番号の頻度
Freq = Counter(A)

# 答えの最大値
ans_max = 0
for kv in Freq.items():
  ans_max += kv[1] * (kv[1] - 1) // 2

for a in A:
  # 1個しか存在しない番号は、取り除いても答えに影響しない
  if Freq.get(a) == 1:
    print(ans_max)
    continue

  # x個の場合と、x-1個の場合と、の差分
  x = Freq.get(a)
  diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)

  # そのぶんだけ、答えの最大値から減らす
  ans = ans_max - diff
  print(ans)

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

int main()
{
  int n;
  int i,A,B,C;
  bool f;
  cin>>n;
  while(n-->0){
    B=C=0;
    f=true;
    for(i=0;i<10;i++){
      cin>>A;
      if(B<A)B=A;
      else if(C<A) C=A;
      else f=false;
    }
    puts(f?"YES":"NO");
  }
}

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

using namespace std;

#define ll long long




void solve() {

	string arr[] = {"Sunny", "Cloudy", "Rainy"};
	string s;
	cin >> s;
	auto pos = find(arr, arr + 3, s) - arr;
	cout << arr[(pos + 1) % 3];
	




	
}

int main() {

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

	return 0;
}

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

using namespace std;

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

	int n;
	cin >> n;
	int q=n/1000;
	if(1000*q==n)
        cout << 0 << endl;
    else{
        q++;
        cout << (1000*q)-n << endl;
    }

	return 0;
}


Measured memory_bytes: 3656
S = input()

ans = 0
lists = [0 for i in range(2019)]
lists[0] += 1

num = 0
for i in range(len(S) - 1, -1, -1):
    num += pow(10, len(S) - 1 - i, 2019) * int(S[i])
    lists[num % 2019] += 1

for i in range(2019):
    if lists[i] >= 2:
        ans += (lists[i] * (lists[i] - 1)) // 2

print(ans)


Measured memory_bytes: 68384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    ll n; cin>>n;
    
    multiset<int> m;
    rep(i,0,n){
        ll x; cin>>x;
        auto it=m.lower_bound(x);
        if(it!=m.begin()) m.erase(--it);
        m.insert(x);
    }
    cout<<m.size()<<endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
        int Y = scanner.nextInt();
        int ans = 0;
        if(X == 1) {
            ans += 300000;
        }else if(X ==2) {
            ans += 200000;
        }else if(X == 3) {
            ans += 100000;
        }
        if(Y == 1) {
            ans += 300000;
        }else if(Y ==2) {
            ans += 200000;
        }else if(Y == 3) {
            ans += 100000;
        }
        if(X == Y && X == 1) {
            ans += 400000;
        }

        System.out.println(ans);
    }
}

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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    cout << fixed << setprecision(16);

    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> G(n);
    while(m--) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    vector<ll> idx(n, -1);
    set<ll> cyc;
    {
        ll x = 0;
        auto dfs = [&](auto dfs, ll cur, ll pre) -> ll {
            if(idx[cur] > -1) {
                cyc.insert(cur);
                return cur;
            }
            idx[cur] = x++;

            for(auto &v: G[cur]) {
                ll r = dfs(dfs, v, cur);
                if(r == cur) return -2;
                if(r == -2) return -2;
                if(r > -1) {
                    cyc.insert(cur);
                    return r;
                }
            }
            return idx[cur] = -1;
        };
        for(ll i=0; i<n; i++) {
            fill(idx.begin(), idx.end(), -1);
            if(dfs(dfs, i, -1) == -2) break;
        }
        if(cyc.size() == 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll t = *cyc.begin();
    for(ll i=0; i<n; i++) {
        ll m = -1, mm = -1, s = t;
        for(auto &v: G[s]) {
            if(!cyc.count(v)) continue;
            if(idx[v] < idx[s] && mm < idx[v])
                mm = idx[v], t = v;
            if(mm == -1 && m < idx[v])
                m = idx[v], t = v;
        }
    }

    set<ll> res;
    for(ll i=0; i<n; i++) {
        ll m = -1, mm = -1, s = t;
        for(auto &v: G[s]) {
            if(!cyc.count(v)) continue;
            if(idx[v] < idx[s] && mm < idx[v])
                mm = idx[v], t = v;
            if(mm == -1 && m < idx[v])
                m = idx[v], t = v;
        }
        res.insert(t);
    }

    cout << res.size() << endl;
    for(auto &e: res) cout << e+1 << endl;

}


Measured memory_bytes: 3768
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,M,K; cin>>N>>M>>K;
	rep(i,N+1){
		int cnt = i*M;
		int once = (N-i);
		REP(j,M+1){
			if(cnt + once*j- i*j == K){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 256
A = []
bingo = [False]*9
for _ in range(3):
  A.append(list(map(int, input().split())))
  
n = int(input())

for _ in range(n):
  b = int(input())
  tmp = 0
  for i in range(3):
    for j in range(3):
      tmp += 1
      if A[i][j] == b:
        bingo[tmp-1] = True
        
for i in range(3):
  if all(bingo[i*3:(i+1)*3]):
         print('Yes')
         exit()
for i in range(3):
  if all(bingo[i:9:3]):
         print('Yes')
         exit()
if all(bingo[0:9:4]) or all(bingo[2:7:2]):
  print('Yes')
  exit()
  
print('No')
               

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

int main() {
    ll n;
    string s,t;
    std::cin >> n;
    std::cin >> s>>t;
    
    string res="";
    for (int i = 0; i < n; i++) {
        res += s[i];
        res += t[i];
    }
    std::cout << res << std::endl;
}


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;



int main(){
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math

def isOdd(n):
    return n % 2 == 1

def isPair(n):
    return n % 2 == 0


A, B, C = list(map(int, stdin.readline().rstrip().split()))

l, m, n = sorted([A, B, C], reverse=True)

count = 0


while l > m or l > n:
    if isOdd(l) and isOdd(m) and isPair(n) or isPair(l) and isPair(m) and isOdd(n):
        l += 1
        m += 1
        count += 1
    elif isOdd(l) and isPair(m) and isOdd(n) or isPair(l) and isOdd(m) and isPair(n):
        l += 1
        n += 1
        count += 1
    elif isPair(l) and isOdd(m) and isOdd(n) or isOdd(l) and isPair(m) and isPair(n):
        m += 1
        n += 1
        count += 1
    else:
        if l > m:
            count += (l - m) // 2
            m += (l - m)
        if l > n:
            count += (l - n) // 2
            n += (l - n)

print(count)


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

int main() {
    int h,w, i, j;

    cin >> h >> w;
    while(h!=0 || w!=0){
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(i%2==0){
                    if(j%2==0){
                        cout << "#";
                    }else{
                        cout << ".";
                    }
                }else{
                    if(j%2==0){
                        cout << ".";
                    }else{
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}


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

int main()
{
  int x, n;
  cin >> x >> n;
  
  vector<bool> num(100, false);
  rep(i,n)
  {
    int p;
    cin >> p;
    num[p] = true;
  }
  
  int res = 1e9;
  for(int i = -100; i <= 200; i++)
  {
    if(i >= 0 && num[i]) continue;
    if(abs(x - i) < abs(x - res))
    {
      res = i;
    }
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int a[10];
    int sum1 = 0,sum2,ans = 0;
    for(int i=0; i<3; i++)
        scanf("%d",&a[i]);
    sort(a,a+3);
    sum1=a[2]-a[1];
    ans+=sum1;
    sum2=a[2]-a[0]-sum1;
    if(sum2%2==0)
        ans+=sum2/2;
    else
        ans+=sum2/2+2;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

set<int> st;
vector<int> v;

void dfs(int a){
    int sz = v.size();
    for(int i = 0; i < sz; i++){
        if (st.find(v[i] + a) == st.end()){
            st.insert(v[i]+a);
            v.push_back(v[i]+a);
        }
    }
    v.push_back(a);
}
int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        //if (st.find(a) == st.end()){
            //v.push_back(a);
        //}
        st.insert(a);
        dfs(a);
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int b; cin >> b;
        if (st.find(b) != st.end()){
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    //en;
}
  




Measured memory_bytes: 3156
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

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]
k=gets.to_i
puts a[k-1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int n,m,c=0;
	cin>>n>>m;
	ll h[n+1];
	vector<int> v[n+1];
	for(int i=1;i<=n;i++)cin>>h[i];
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	for(int i=1;i<=n;i++)
	{
		int fl=0;
		for(int j=0;j<v[i].size();j++)
		{
			if(h[i]<=h[v[i][j]])
			{
				fl=1;break;
			}
		}
		if(fl==0)
			c++;
	}
	cout<<c;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

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

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

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> pys;
  vector<int> mp[N + 1];
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    pys.push_back(make_pair(p, y));
    mp[p].push_back(y);
  }

  for (auto &e : mp) {
    sort(e.begin(), e.end());
  }

  for (auto &p : pys) {
    int pi = p.first;
    vector<int> &v = mp[pi];
    auto iter = lower_bound(v.begin(), v.end(), p.second);
    int x = iter - v.begin() + 1;

    cout << setw(6) << setfill('0') << pi;
    cout << setw(6) << setfill('0') << x;
    cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 7796
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (2*10**6+1)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())
r = 0
for j in range(c1, c2+1):
    r = (r + cmb(j+r2+1, r2, mod) - cmb(j+r1, r1-1, mod) ) %mod
print(r)


Measured memory_bytes: 132780
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fi first
#define se second
using namespace std;

typedef long long LL;
char s[100500];
int sz[5];
int mx,mn;
int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%s",s+1);
	int n=strlen(s+1);
	rep(i,1,n) sz[s[i]-'a']++;
	mn=n;
	rep(i,0,2) mx=max(mx,sz[i]),mn=min(mn,sz[i]);
	if (mx-mn<=1) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 384
// Problem : A - Meal Delivery
// Contest : AtCoder - AtCoder Beginner Contest 071
// URL : https://atcoder.jp/contests/abc071/tasks/abc071_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int x,a,b;cin>>x>>a>>b;
if(abst(x-a)<abst(x-b))
cout<<"A";
else
cout<<"B";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    vector<ll> v(26);
    rep(i,N){
        v[S[i]-'a']++;
    }
    ll ans = N*(N-1)/2;
    rep(i,26){
        ans -= v[i]*(v[i]-1)/2;
    }
    cout << ans+1 << endl;
}

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

using lli = int64_t;
using vi = vector<lli>;
using vvi = vector<vi>;

void debug_cnt(vvi& cnt, int n)
{
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
            cout << cnt[i][j] << ' ';

        cout << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n, k; cin >> n >> k;

    vi mp_x(n), mp_y(n);
    vi xs(n), ys(n);

    for(int i = 0; i < n; i++)
    {
        lli x, y; cin >> x >> y;

        xs[i] = x;
        ys[i] = y;

        mp_x[i] = x;
        mp_y[i] = y;
    }

    sort(begin(mp_x), end(mp_x));
    sort(begin(mp_y), end(mp_y));

    map<lli, int> rmp_x, rmp_y;

    for(int i = 0; i < n; i++) rmp_x[mp_x[i]] = i;
    for(int i = 0; i < n; i++) rmp_y[mp_y[i]] = i;

    vvi cnt(n, vi(n));

    for(int i = 0; i < n; i++)
    {
        int ix = rmp_x[xs[i]];
        int iy = rmp_y[ys[i]];

        cnt[ix][iy]++;
    }

    //debug_cnt(cnt, n);

    for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
    {
        lli a = i ? cnt[i - 1][j] : 0;
        lli b = j ? cnt[i][j - 1] : 0;
        lli c = i && j ? cnt[i - 1][j - 1] : 0;

        cnt[i][j] += a + b - c;
    }

    //cout << "####" << endl;
    //debug_cnt(cnt, n);

    lli ans = LLONG_MAX;

    for(int x1 = 0; x1 < n; x1++)
    for(int y1 = 0; y1 < n; y1++)
    for(int x2 = x1; x2 < n; x2++)
    for(int y2 = y1; y2 < n; y2++)
    {
        lli a = x1 ? cnt[x1 - 1][y2] : 0;
        lli b = y1 ? cnt[x2][y1 - 1] : 0;
        lli c = x1 && y1 ? cnt[x1 - 1][y1 - 1] : 0;

        lli sum = cnt[x2][y2] - a - b + c;

        if(sum < k) continue;

        lli dx = mp_x[x2] - mp_x[x1];
        lli dy = mp_y[y2] - mp_y[y1];

        lli area = dx * dy;

        ans = min(ans, area);
    }

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

Measured memory_bytes: 256
use proconio::input;

#[proconio::fastout]
pub fn main() {
    input! {
    a:[isize],
    }
    let mut money = 1000;
    let mut stock = 0;
    a.windows(2)
        .map(|pair| (pair[0], pair[1]))
        .for_each(|(today, tomorrow)| if today < tomorrow {
            stock += money / today;
            money -= money / today * today;
        } else {
            money += stock * today;
            stock = 0;
        });
    let ans = money + stock * a.last().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 2172
N = int(input())
ans = [0]*10050

for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if v < 10050:
        ans[v] += 1
for i in range(N):
  print(ans[i+1])


Measured memory_bytes: 9236
#include <stdio.h>

int main(void)
{
	/*?????°??£?¨?*/
	int m,f,r;
	char g;
	
	/*??????*/
	while(!(m==-1&&f==-1&&r==-1)){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1||f==-1) g='F';
		else if(m+f>=80) g='A';
		else if(m+f>=65&&m+f<80) g='B';
		else if(m+f>=50&&m+f<65) g='C';
		else if(m+f>=30&&m+f<50){
			if(r>=50) g='C';
			else g='D';
		}
		else if(m+f<30) g='F';
		if(m==-1&&f==-1&&r==-1) break;
		printf("%c\n",g);
	}
	return 0;
}

Measured memory_bytes: 600
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      static long MOD = 1000000007L;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         long res = 1L;
         int tempo = M;
         for(int i=0; i < N; i++)
         {
            res *= tempo;
            res %= MOD;
            tempo--;
         } 
         //pie
         long[] fac = new long[500001];
         long[] invfac = new long[500001];
         fac[0] = invfac[0] = 1L;
         for(int i=1; i <= 500000; i++)
         {
            fac[i] = (fac[i-1]*i)%MOD;
            invfac[i] = power(fac[i], MOD-2, MOD);
         }
         long other = 0L;
         for(int c=0; c <= N; c++) 
         {
            long temp = (fac[N]*invfac[c])%MOD;
            temp = (temp*invfac[N-c])%MOD;
            //temp = (temp*fac[M-c])%MOD;
            int leftover = N-c;
            int choices = M-c;
            
            long boof = (fac[choices]*invfac[choices-leftover])%MOD;
            //boof = (boof*invfac[choices-leftover])%MOD;
            temp = (temp*boof)%MOD;
            
            if(c%2 == 1)
               temp *= -1;
            other += temp+MOD;
            other %= MOD;
         }
         res = (res*other)%MOD;
         System.out.println(res);
      }
      public static long power(long x, long y, long p) 
      { 
          long res = 1L;      
          x = x % p;  
          while (y > 0) 
          { 
              if((y & 1)==1) 
                  res = (res * x) % p; 
              y = y >> 1;  
              x = (x * x) % p;  
          } 
          return res; 
      }
   }

Measured memory_bytes: 40552
function Main(arg)
{
  var S = arg.split("\n")[0];
  var Q = arg.split("\n")[1] - 0;
  var query = arg.split("\n").slice(2);

  var f = false;
  for (var i = 0; i < Q; i++){
    var tmp = query[i].split(" ");
    if (tmp[0] === "1") {
      f = !f;
    }
    else {
      if (tmp[1] === "1") {
        if (!f) {
          S = tmp[2] + S;  
        }
        else {
          S = S + tmp[2];
        }
      }
      else {
        if (!f) {
          S = S + tmp[2];
        }
        else {
          S = tmp[2] + S;  
        }
      }
    }
  }
  if (f) S = S.split("").reverse().join("");
  console.log(S);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 76472
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
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; }
const long long mod = 1e9 + 7;


int main() {

	ll N;

	cin >> N;
	
	vector<char> c(N);
	ll r = 0;

	rep(i, N) {
		cin >> c[i];
		if (c[i] == 'R') {
			r++;
		}
	}
	ll w = 0;

	rep(i, r) {
		if (c[i] == 'W') {
			w++;
		}
	}

	cout << w;

	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

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

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    ll r,d,x;
    cin >> r >> d >> x;
    for(int i=1;i<=10;++i) {
        x = r * x - d;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] appears = new int[n];
        for (int i = 0; i < n; i++) appears[i] = sc.nextInt();
        
        boolean[][] bingo = new boolean[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < n; k++) {
                    if (card[i][j] == appears[k]) bingo[i][j] = true;
                }
            }
        }

        for (int i = 0; i < 3; i++) {
            if (bingo[i][0] && bingo[i][1] && bingo[i][2]) {
                System.out.println("Yes");
                return;
            }
        }
        for(int i = 0; i < 3; i++) {
            if(bingo[0][i] && bingo[1][i] && bingo[2][i]) {
                System.out.println("Yes");
                return;
            }
        }
        if(bingo[0][0] && bingo[1][1] && bingo[2][2]) {
            System.out.println("Yes");
            return;
        }
        if(bingo[0][2] && bingo[1][1] && bingo[2][0]) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 23124
while 1 do
    h,w = gets.chomp.split.map(&:to_i)
    if h == 0 && w == 0
        break
    end
    h.times do |i|
        if i == 0 || i == h-1
            puts "#"*w
        else
            puts "#"+ "."*(w-2) +"#"
        end
    end
    puts
end

Measured memory_bytes: 6132