akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x,T a,T b){return a<=x&&x<=b;}
template<class T> void amin(T &a,T v){if(a>v) a=v;}
template<class T> void amax(T &a,T v){if(a<v) a=v;}
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<=EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<=EPS*max(1.0,max(fabs(x),fabs(y))); }
double SQSUM(double x,double y) { return x*x+y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


#if 1 // C
int main()
{
	int H, W;
	cin >> H >> W;
	vector <string> a(H);
	for (int i = 0; i < H; ++i)
	{
		cin >> a[i];
	}

	vector < vector <int> > red(H, vector <int>(W));
	vector < vector <int> > blue(H, vector <int>(W));

	for (int y = 0; y < H; ++y)
	{
		for (int x = 0; x < W; ++x)
		{
			if (a[y][x] == '#')
			{
				red[y][x] = 1;
				blue[y][x] = 1;
			}

			if (x == 0)
			{
				red[y][x] = 1;
			}
			else if (x == W - 1)
			{
				blue[y][x] = 1;
			}
			else
			{
				if (y % 2)
				{
					blue[y][x] = 1;
				}
				else
				{
					red[y][x] = 1;
				}
			}
		}
	}

	for (int y = 0; y < H; ++y)
	{
		for (int x = 0; x < W; ++x)
		{
			if (red[y][x])
			{
				printf("#");
			}
			else
			{
				printf(".");
			}
		}
		printf("\n");
	}
	printf("\n");

	for (int y = 0; y < H; ++y)
	{
		for (int x = 0; x < W; ++x)
		{
			if (blue[y][x])
			{
				printf("#");
			}
			else
			{
				printf(".");
			}
		}
		printf("\n");
	}

	return 0;
}


#elif 1 // B


int main()
{
	int N;
	ll x;
	cin >> N >> x;

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

	ll best = BIGLL;


	for (int mv = 0; mv <= N - 1; mv++)
	{
		ll total = accumulate(a.begin(), a.end(), mv*x);
		amin(best, total);

		vector <ll> nexta(N);
		for (int i = 0; i < N; ++i)
		{
			nexta[i] = min(a[(i-1+N)%N], a[i]);
		}
		a = nexta;
	}

	cout << best << endl;

	return 0;
}

#else
int main()
{
	ll a, b, c;
	cin >> a >> b >> c;

	ll ret = 0;

	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
	{

	}
	else
	{
		ret = min(a*b, min(b*c, c*a));
	}

	cout << ret << endl;

}

#endif

Measured memory_bytes: 2944
from bisect import bisect_left
N = int(input())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        t = l[i] + l[j]
        idx = bisect_left(l, t)
        res += idx-j-1
print(res)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define INF 2e9
#define int ll
#define vi          vector<int>
#define de          deque<int>
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()//全範囲指定を簡略化
typedef long long ll;
using namespace std;
//配列の要素数は　sizeof(ar)/sizeof(ar[0]) で求める
signed main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int H, N;
    cin >> H >> N;
    vi v(N);
    int sum = 0;

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

    if(sum >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 


struct team{
	int no,ac,t,miss[10];
	team(int no): no(no){
		ac=0,t=0;
		rep(i,10) miss[i]=0;
	}
	team(const team &x): no(x.no),ac(x.ac),t(x.t){
		rep(i,10) miss[i]=x.miss[i];
	}
	bool operator <(team a){
		if(ac!=a.ac) return ac<a.ac;
		if(t!=a.t) return t>a.t;
		return no<a.no;
	}
	void write(){
		cout<<no<<" "<<ac<<" "<<t<<endl;
	}
};

bool cmp(team a,team b){
	return a<b;
}

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R){
		if(M==0&&T==0&&P==0&&R==0) break;
		vector<team> t;
		rep(i,T) t.pb(i+1);
		int m,n,p,j;
		rep(i,R){
			cin>>m>>n>>p>>j;
			n--,p--;
			if(j==0){
				t[n].ac++;
				t[n].t += t[n].miss[p]*20+m;
			}
			else t[n].miss[p]++;
		} 
		//rep(i,T) t[i].write();
		sort(all(t),cmp);
		reverse(all(t));
		int a=t[0].ac,b=t[0].t;
		cout<<t[0].no;
		for(int i=1; i<T; i++){
			if(a==t[i].ac && b==t[i].t) cout<<"=";
			else cout<<",";
			a=t[i].ac,b=t[i].t;
			cout<<t[i].no;
		}
		cout<<endl;
	}
	
}

Measured memory_bytes: 1208
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,K;
    cin >> N >> K;
    ll A = N%K;
    ll B = abs(A-K);
    ll out = min(A,B);
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n'
#define pe(x) cout<<x<<" "
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
int MOD = 1e9+7;

const int MAX = 200060;
const double pi = acos(-1);
const double EPS = 1e-12;


void solve(){
	int N; cin >> N;
	ll ans = 1e18;
	for (int i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			int pa = N / i;
			ans = min(ans, i - 1 + pa - 1);
		}
	}
	print(ans);
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


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

const static double pi = 4*atan(1.0);
int main(){
	double r;
	cin >> r;
	printf("%.7f\n",r*r*pi);
	printf("%.7f\n",2*pi*r);
	return 0;
}

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

int N;//Number of items
int W;//Capacity of Knapsack
int w;//weights of item
int v;//values of item
vector <long long> ks;//best knapsack of given weight

int main(){
	cin>>N>>W;
	ks.resize(W+1,0);

	for(int i=1;i<=N;i++){
		cin>>w>>v;
		//we will update all relavent knapsacks for taking this item or not
		for(int j=W;j>=w;j--){
			ks[j] = max( ks[j] , ks[j-w]+v );
		} 
		//this is from W to w because it will take care that are not considering same item twice
	}

	//Is ks[W] the solution??
	//Nooooooooooooo
	//We have cosidered only relevant knapsacks for that update : W-w to w
	//There can be a maximum in : W to W-w+1
	//But we should consider all the knapsacks to get max value 
	
	long long MaxValue = 0;
	for(int i=1;i<=W;i++)
		MaxValue = max( MaxValue , ks[i] );

	cout<<MaxValue<<endl;
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	int a,b,c,d;
	cin >> a >> b >> c >> d;

	int beat_t = a/d;
	if(a%d != 0) beat_t++;
	int beat_a = c/b;
	if(c%b != 0) beat_a++;

	if(beat_a <= beat_t){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

}

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

Measured memory_bytes: 3660
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
using namespace std;
 
 
 
int main()
{
	
	string a;
	cin>>a;
	if(a[a.length()-1]=='s'){
		a+="es";
	}else{
		a+="s";
	}
 
 	cout<<a;
	
	return 0;
}

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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define eb emplace_back
#define pb push_back
#define lli long long int
#define modn 1000000007
#define NL '\n'

using namespace std;

typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< bool > vb;
typedef vector< string > vs;
typedef vector< lli > vli;
typedef vector< vector< char > > vvc;
typedef vector< vector< int > > vvi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef pair< lli, int> pli;
typedef pair< lli, lli> pll;
typedef set< int > si;
typedef set< ii > sii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	#ifdef LOCAL_TEST
		clock_t z = clock();
    	ifstream h("in");
	    ofstream g("out");
	#else
	    #define h cin
	    #define g cout
	#endif // LOCAL_TEST
	
	char c;
	h >> c;
	g << char(c + 1);
	
	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif // LOCAL_TEST
}



Measured memory_bytes: 256
A,B = map(int,input().split())

def calc(n,k):
  n += 1
  return (n//(2**k))*(2**(k-1))+max(n-(n//(2**k))*(2**k)-(2**(k-1)),0)

ans = ['' for _ in range(40)]
for i in range(40):
  ans[39-i] = str((calc(B,i+1)-calc(A-1,i+1))%2)
print(int(''.join(ans),2))


Measured memory_bytes: 38384
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] # 2 5 4 3 nsew
        self.nowkey = 0
        self.nowval = li[0]
    def operate(self, s):
        c_key = abs(5 - self.nowkey)
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]

v = list(map(int, input().split()))
s = input()
dice = DICE(v)
for i in s:
    dice.operate(i)
print(dice.nowval)



Measured memory_bytes: 5604
#include <algorithm>
#include <queue>
#include <cstdio>

using namespace std;

const int INF=1e9+5;

struct seg_t{
    int X;
    int Y;
    int Z;//level
};

int vertLen=0,horLen=0;
int N,M;
seg_t vert[1010],hor[1010];
int vertP[3010],horP[3010];
bool grid[3030][3030][4],visited[3030][3030];

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

int main(){
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&vert[i].X,&vert[i].Y,&vert[i].Z);
        vertP[vertLen++]=vert[i].X;
        vertP[vertLen++]=vert[i].Y;
        horP[horLen++]=vert[i].Z;   
    }

    for(int i=0;i<M;i++){
        scanf("%d%d%d",&hor[i].Z,&hor[i].X,&hor[i].Y);
        horP[horLen++]=hor[i].X;
        horP[horLen++]=hor[i].Y;
        vertP[vertLen++]=hor[i].Z;   
    }
    
    vertP[vertLen++]=INF;
    vertP[vertLen++]=0;
    vertP[vertLen++]=-INF;

    horP[horLen++]=INF;
    horP[horLen++]=0;
    horP[horLen++]=-INF;

    sort(horP,horP+horLen);
    sort(vertP,vertP+vertLen);
    horLen=unique(horP,horP+horLen)-horP-1;
    vertLen=unique(vertP,vertP+vertLen)-vertP-1;

    for(int i=0;i<N;i++){
        int l=lower_bound(vertP,vertP+vertLen,vert[i].X)-vertP;
        int r=lower_bound(vertP,vertP+vertLen,vert[i].Y)-vertP;
        int level=lower_bound(horP,horP+horLen,vert[i].Z)-horP;

        for(int j=l;j<r;j++){
            grid[j][level-1][0]=true;
            grid[j][level][2]=true;
        }
    }

    for(int i=0;i<M;i++){
        int l=lower_bound(horP,horP+horLen,hor[i].X)-horP;
        int r=lower_bound(horP,horP+horLen,hor[i].Y)-horP;
        int level=lower_bound(vertP,vertP+vertLen,hor[i].Z)-vertP;

        for(int j=l;j<r;j++){
            grid[level-1][j][1]=true;
            grid[level][j][3]=true;
        }
    }

    queue<pair<int,int>> q;
    auto sx=lower_bound(vertP,vertP+vertLen,0)-vertP,sy=lower_bound(horP,horP+horLen,0)-horP;
    q.push({sx,sy});
    visited[sx][sy]=true;
    bool closed=true;

    long long ans=0;

    while(!q.empty()){
        auto x=q.front().first,y=q.front().second;
        q.pop();

        
        if (x==0||x==vertLen-1||y==0||y==horLen-1){
            closed=false;
            break;
        }

        ans+=1ll*(vertP[x+1]-vertP[x])*(horP[y+1]-horP[y]);

        for(int k=0;k<4;k++){
            if (!grid[x][y][k]){
                auto px=x+dx[k],py=y+dy[k];
                if (px < 0 || px >= vertLen || py < 0 || py >= horLen || visited[px][py]) continue;
                q.push({px,py});
                visited[px][py]=true;
            }
        }
    }

    if (!closed) {
        puts("INF");
        return 0;
    }

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 45096
H, W = map(int, input().split())
l = list(map(list, [input() for i in range(H)]))
b = []
for i in range(H):
    for j in range(W):
        if l[i][j] == '#':
            b.append([i+1, j+1])

for i in range(H):
    for j in range(W):
        if l[i][j] == '.':
            l[i][j] = 0
            for k in range(len(b)):
                if int(b[k][0]) - 1 <= i+1 <= int(b[k][0]) + 1 and int(b[k][1]) - 1 <= j+1 <= int(b[k][1]) + 1:
                    l[i][j] = l[i][j] + 1
        print(l[i][j], end="")
    print('')

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

typedef long long ll;

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

	int n, a;
	cin >> n;

	map<int, int> sub;
	for (int i=2; i<=n; i++) {
		cin >> a;
		sub[a]++;
	}
	for (int i=1; i<=n; i++) {
		cout << sub[i] << "\n";
	}

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[N-1]-a[0];
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int gcd(int a, int b) {
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main()
{
	int K, ans = 0;

	cin >> K;

	repc(a, 1, K) repc(b, 1, K) repc(c, 1, K) {
		ans += gcd(a, gcd(b, c));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3540
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = [I() for _ in range(n)]
print('second' if all(a%2 == 0 for a in A) else 'first')


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

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

    unsigned int n, h, w;
    cin >> n >> h >> w;

    unsigned int res = 0;
    rep(i, n){
        unsigned int a, b;
        cin >> a >> b;

        if(a>=h && b>=w) ++res;
    }

    cout << res << endl;

    return 0;
}

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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

typedef long long ll;
const int SZ=100005;
const ll MD=(ll)1e9+7;
ll arr[SZ];
ll inv[SZ];
ll pre[SZ];
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    inv[0]=inv[1]=1;
    for(ll i=2;i<=n;i++) inv[i]=(MD-(inv[MD%i]*(MD/i))%MD)%MD;
    ll nfac=1;
    for(ll i=2;i<n;i++) nfac=(nfac*i)%MD;
    pre[0]=pre[1]=nfac;
    for(int i=2;i<=n;i++) pre[i]=(pre[i-1]+nfac*inv[i])%MD;
    ll ans=0;
    for(int i=1;i<n;i++){
        ans=(ans+(arr[i+1]-arr[i])*pre[i])%MD;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
s = input()

x,y = map(int,input().split())

now = 0
angle = 0 #0なら水平方向,1なら垂直方向
length = 0 

if s[0] == "F":
    while now < len(s) and s[now] == "F":
        length += 1
        now += 1
    x -= length


xlst = []
ylst = []

length = 0 

while now < len(s): #最初にTから始まる状態にしておく
    while now < len(s) and s[now] == "T":
        angle = 1 - angle
        now += 1
    while now < len(s) and s[now] == "F":
        length += 1
        now += 1
    if angle == 0:
        xlst.append(length)
    else:
        ylst.append(length)
    length = 0

now_x = 0
now_y = 0
xlst.sort(reverse=True)
ylst.sort(reverse=True)
for i in xlst:
    if x - now_x >= 0:
        now_x += i
    else:
        now_x -= i

for i in ylst:
    if y - now_y >= 0:
        now_y += i
    else:
        now_y -= i

if now_x == x and now_y == y:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 40688
N = int(input())
A = list(map(int, input().split()))
A.sort()

ans = 0

check = [True] * (10 ** 6 + 1)
for i in range(N):
    a = A[i]
    if not check[a]:
        continue
    if (i >= 1 and A[i] != A[i - 1]) or i == 0:
        tmp = a
        while tmp <= 10 ** 6:
            check[tmp] = False
            tmp += a
    else:
        continue
    if i + 1 < N and A[i] == A[i + 1]:
        continue
    # print (a)
    ans += 1

print (ans)


Measured memory_bytes: 32368
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
  int n,W;
  cin>>n>>W;
  int wt[n],val[n];
  for(int i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
  }
  int dp[n+1][W+1];
  for(int i=0;i<=W;i++)
    dp[0][i]=0;
  for(int j=0;j<=n;j++)
    dp[j][0]=0;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=W;j++)
    {
      if(j>=wt[i-1])
        dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);
      else
        dp[i][j]=dp[i-1][j];
    }
  }
  cout<<dp[n][W]<<"\n";
}


Measured memory_bytes: 82424
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    double a,b,c,d;cin>>a>>b>>c>>d;
    while(true) {
        c-=b;
        if(c<=0) {
            puts("Yes");
            return 0;
        }
        a-=d;
        if(a<=0) {
            puts("No");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
n=int(input())
s=input()
alphabet=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ans=""
for i in range(len(s)):
    x=alphabet.index(s[i])
    ans+=alphabet[(x+n)%26]
print(ans)    
    
    
    

Measured memory_bytes: 3064
main(m,d){for(;scanf("%d%d",&m,&d)*m;printf("%sday\n","Wednes\0Thurs\0 Fri\0   Satur\0 Sun\0   Mon\0   Tues"+7*(((m>2)*2+((m+9)%12*13+47)/5+d)%7)));}

Measured memory_bytes: 596
from collections import Counter

N, M = map(int, input().split())
*X, = map(int, input().split())
*l, = map(lambda x:x%M, X)
c1 = Counter(l)
c2 = Counter(X)
c3 = Counter()

for i, j in c2.items():
    c3[i%M] += j//2

ans = c1[0]//2
for i in range(1, M):
    if i>M-i:break
    elif i==M-i:
        ans += c1[i]//2
    else:
        ans += min(c1[i], c1[M-i])        
        ans += min(abs(c1[i]-c1[M-i])//2, c3[i] if c1[i]>c1[M-i] else c3[M-i])

print(ans)


Measured memory_bytes: 34264
#include <stdio.h>
#include <cmath>
#include <algorithm>

struct Info{
	int number,order;
};

void func(int num,int digit){

	int checkTable1[10],checkTable2[10],max_num,min_num,S,tmp,index,ans_j;
	Info info[21];
	bool FLG;

	info[0].number = num;
	info[0].order = 0;
	index = 1;

	for(int i = 1; i <= 21; i++){

		for(int k = 0; k < 10; k++){
			checkTable1[k] = 0;
			checkTable2[k] = 0;
		}
		S = pow(10,digit-1);
		tmp = num;
		for(int k = 0; k < digit; k++){
			checkTable1[tmp/S]++;
			checkTable2[tmp/S]++;
			tmp %= S;
			S /= 10;
		}
		max_num = 0;
		S = pow(10,digit-1);

		for(int k = 9; k >= 1; k--){
			while(checkTable1[k] > 0){
				max_num += S*k;
				checkTable1[k]--;
				S /= 10;
			}
		}

		S = 1;
		min_num = 0;
		for(int k = 9; k >= 1; k--){
			while(checkTable2[k] > 0){
				min_num += S*k;
				checkTable2[k]--;
				S *= 10;
			}
		}

		num = max_num-min_num;

		FLG = false;
		for(int k = 0; k < index; k++){
			if(info[k].number == num){
				ans_j = info[k].order;
				FLG = true;
				break;
			}
		}

		if(FLG){
			printf("%d %d %d\n",ans_j,num,i-ans_j);
			break;
		}else{
			info[index].number = num;
			info[index].order = i;
			index++;
		}
	}
}

int main(){

	int first_num,digit;

	while(true){
		scanf("%d %d",&first_num,&digit);
		if(first_num == 0 && digit == 0)break;

		func(first_num,digit);
	}

	return 0;
}

Measured memory_bytes: 2760
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io, flush := NewIO()
	defer flush()

	n := io.ScanInt()
	a := io.ScanInts(n)
	b := io.ScanInts(n)
	c := io.ScanInts(n)

	sort.Ints(a)
	sort.Ints(b)
	sort.Ints(c)

	var count int
	for i := 0; i < n; i++ {
		aCount := SearchLeft(a, b[i])+1
		cCount := n - SearchRight(c, b[i])
		count += aCount * cCount
	}

	fmt.Println(count)
}

// SearchLeft returns the index of the highest value in the values lower than x
func SearchLeft(a []int, x int) int {
	return sort.SearchInts(a, x)-1
}

// SearchRight returns the index of the lowest value in the values higher than x
func SearchRight(a []int, x int) int {
	return sort.Search(len(a), func(i int) bool { return a[i] > x })
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        printf("a < b\n");
    } else if (a > b) {
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 1e6 + 239;
const int ALP = 26;

int pnt = 0;
int root;
int go[N][ALP];
int sm[N][ALP];

int new_node() {
	fill(go[pnt], go[pnt] + ALP, -1);
	fill(sm[pnt], sm[pnt] + ALP, 0);
	pnt++;
	return pnt - 1;
}

void init() {
	root = new_node();
}

void add(string s) {
	vector<int> path = {root};
	int cur = root;
	for (auto t : s) {
		if (go[cur][t - 'a'] == -1) {
			go[cur][t - 'a'] = new_node();
		}
		cur = go[cur][t - 'a'];
		path.push_back(cur);
	}
	vector<int> any(ALP);
	reverse(path.begin(), path.end());
	reverse(s.begin(), s.end());
	for (int i = 1; i < (int)path.size(); i++) {
		any[s[i - 1] - 'a'] = 1;
		for (int j = 0; j < ALP; j++) {
			if (any[j]) {
				sm[path[i]][j]++;
			}
		}
	}
}

int solve(string s) {
	int last = s.back() - 'a';
	s.pop_back();
	int cur = 0;
	for (auto t : s) {
		cur = go[cur][t - 'a'];
	} 
	return sm[cur][last];
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	init();

	int n;
	cin >> n;
	vector<string> a(n);
	for (auto &t : a) {
		cin >> t;
		reverse(t.begin(), t.end());
	}	
	for (auto s : a) {
		add(s);
	}
	int ans = 0;
	for (auto s : a) {
		ans += solve(s) - 1;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 411172
from functools import reduce
import sys
MOD = 1000000007
def culc(min, max):
	if max - min <= 1:
		return 0
	num = max - min - 3
	x = [0, 1]
	y = x[0] + x[1]
	for i in range(num):
		x[i%2] = y
		y = (x[0] + x[1]) % MOD
	return y

n, m = map(int, input().split())
a = [-1]
for i in range(m):
	a.append(int(input()))
a.append(n + 1)
res = []
for i in range(m + 1):
	res.append(culc(a[i], a[i + 1]))
	if(res[i] <= 0):
		print(0)
		sys.exit()
print(reduce(lambda x, y: (x * y) % MOD, res))

Measured memory_bytes: 7572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

 public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int k = Integer.parseInt(br.readLine());
        long ans=0L;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                int gcd = gcd(i,j);
                for(int s = 1;s<=k;s++){
                    int g = gcd(gcd,s);
                    ans+=g;
                }
            }
        }
        System.out.println(ans);
    }
     static int gcd(int a, int b)
     {
         if (b == 0)
             return a;
         return gcd(b, a % b);
     }
 }


Measured memory_bytes: 32708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
  ll r = a % b; // a > b
  if(r == 0) return b;

  ll a1 = b;
  ll b1 = r;
  gcd(a1, b1);
}
bool IsPrime(ll n) {
  if(n == 1) return true;
  else if(n == 2) return true;
  else if(n % 2 == 0) return false;
  double sqrtNum = sqrt(n);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (n % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  ll sum = 0;

  for(ll i = 0; i < N; i++) cin >> A[i];
  priority_queue<ll> q;
  for(ll i = 0; i < N; i++) {
    q.push(A[i]);
  }
  
  for(ll i = 0; i < M; i++) {
     ll s = q.top() / 2; 
     q.pop(); 
     q.push(s);
  }
  ll ans = 0;
  for(ll i = 0; i < N; i++) {
    ans += q.top();
    q.pop();
  }

  cout << ans;
  return 0;

}

Measured memory_bytes: 2168
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
  int N;
  double ans = 0;
  cin >> N;
  if(N%2 == 0){
    ans = 0.5;
  }else {
    ans = ((N+1.0)/2.0)/N;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,f=0;
	while(cin>>n,n){
		if(f)cout<<endl; f=1;
		pair<int,pair<int,string> > team[10];
		int w,l,d;
		rep(i,n){
			cin>>team[i].second.second>>w>>l>>d;
			team[i].first=-w*3-d;
			team[i].second.first=i;
		}
		sort(team,team+n);
		rep(i,n)cout<<team[i].second.second<<","<<-team[i].first<<endl;
	}
	return 0;
}

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

int main()
{
	int x[100];
	int y[100];
	int h[100];

	int n;
	cin >> n;


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

	int i, j; //中心Cx, Cy
	int hmax;
	//マス
	for (i = 0; i <= 100; i++) {
		for (j = 0; j <= 100; j++) {
			int k;
			hmax = -1;
			//最初に高さ候補を一つ探索
			for (k = 0; k < n; k++) {
				if (h[k] <= 0) continue;
				hmax = abs(x[k] - i) + abs(y[k] - j) + h[k];
				break;
			}

			for (k = 0; k < n; k++) {
				int height = max(hmax - abs(x[k] - i) - abs(y[k] - j), 0);
				if (height != h[k]) break;
			}
			if (k == n && hmax > 0) goto ANS; //全部一致
		}
	}

	if (i > 100)
		return 0;

ANS:
	cout << i << " " << j << " " << hmax;
	return 0;
}


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

int main() {
  int n,k,q ;
  cin >>n >>k >>q ;
  vector<int> ans(q);
  vector<int> point(n);
   for(int i=0;i<q;i++){
    cin >> ans.at(i) ;
    ans.at(i) --;
   }
  for(int i=0;i<n;i++){
    point.at(i) = 0;
  }
  for(int i=0;i<q;i++){
    point.at(ans.at(i))++;
  }
  int last_point ;
    for(int i=0;i<n;i++){
     last_point = k - q ;
     last_point+= point.at(i);
      if ( last_point >0){
        cout << "Yes" <<endl;
      }
      else{
        cout << "No"<<endl;
      }
    }
   // for(int i=0;i<n;i++){ 
   // cout <<  point.at(i) << endl;
  //}
}


Measured memory_bytes: 1408
H, W = map(int, input().split())
M = [input() for _ in range(H)]
dp = [[0]*W for _ in range(H)]
dp[0][0] = 1
MOD = 10**9+7
for i in range(H):
    for j in range(W):
        if M[i][j] == "#":
            continue
        if i > 0:
            dp[i][j] += dp[i-1][j]
        if j > 0:
            dp[i][j] += dp[i][j-1]
        dp[i][j] %= MOD
print(dp[H-1][W-1])


Measured memory_bytes: 52080
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int x = stdIn.nextInt();

        int[] c = new int[n];
        int[][] a = new int[n][m];

        for(int i=0; i<n; i++){
            c[i] = stdIn.nextInt();
            for(int j=0; j<m; j++){
                a[i][j] = stdIn.nextInt();
            }
        }

        boolean[] bit = new boolean[n+1];

        int minCost = Integer.MAX_VALUE;
        while(!bit[n]){
            int sumCost = 0;
            int[] skills = new int[m];
            for(int i=0; i<n; i++){
                if(bit[i]){
                    for(int j=0; j<m; j++){
                        skills[j] += a[i][j];
                    }
                    sumCost += c[i];
                }
            }

            if(clear(skills, x)){
                if(sumCost < minCost){
                    minCost = sumCost;
                }
            }

            setNextBit(bit);
        }

        if(minCost < Integer.MAX_VALUE){
            System.out.println(minCost);
        }else{
            System.out.println(-1);
        }
    }

    static boolean clear(int[] skills, int x){
        for(int i=0; i<skills.length; i++){
            if(skills[i] < x){
                return false;
            }
        }
        return true;
    }

    static void setNextBit(boolean[] bit){
        for(int i=0; i<bit.length; i++){
            bit[i] = (bit[i]) ? false : true;
            if(bit[i]){
                return;
            }
        }
    }
}

Measured memory_bytes: 37756
cards = {
        'S': [0 for _ in range(13)],
        'H': [0 for _ in range(13)],
        'C': [0 for _ in range(13)],
        'D': [0 for _ in range(13)],
}
n = int(input())
for _ in range(n):
    (s, r) = input().split()
    cards[s][int(r) - 1] = 1
 
for s in ('S', 'H', 'C', 'D'):
    for r in range(13):
        if cards[s][r] == 0:
            print(s, r + 1)

Measured memory_bytes: 7744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long long l,r;
  long long sum=0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum = sum + r - l + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int saidai = 0;
	rep(i, S.size()) {
		int OK = 0;
		for (int j = i; j < S.size(); j++) {
			if (S[j] == 'A' || S[j] == 'T' || S[j] == 'C' || S[j] == 'G') OK++;
			else break;
		}
		saidai = max(saidai, OK);
	}

	co(saidai);

	Would you please return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
    int i, j, k, n;
    long *l, cnt=0;
    scanf("%d", &n);
    l = calloc(n, sizeof(long));
    for(i=0; i<n; i++) scanf("%ld", &l[i]);

    for(i=0; i<n-2; i++){
        for(j=i+1; j<n-1; j++){
            for(k=j+1; k<n; k++){
                if(l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j] && l[i] != l[j] && l[j] != l[k] && l[k] != l[i])
                   cnt++;
            }
        }
    }

    printf("%ld", cnt);
    free(l);
    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
string s;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> s;
	int cnt = 0;
	for (int i = 0; i < n; i++)if (s[i] == 'R')cnt++;
	int cnt2 = 0;
	for (int i = 0; i < cnt; i++)if (s[i] == 'R')cnt2++;
	cout << cnt - cnt2 << endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,a,amax=0,amin=1000;
    cin >> n;
    rep(i,n){
        cin >> a;
        amax=max(amax,a);
        amin=min(amin,a);
    }
    cout << amax-amin;
    return 0;
}

Measured memory_bytes: 3520
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll x;
int main()
{scanf("%lld",&x);
    for(int i=1;i<=100000;i++)
        if(i+i*i-2*x>=0)
        {
            printf("%d\n",i);
            return 0;
        }
}


Measured memory_bytes: 256
# coding : utf-8

N, M = list(map(int, input().split()))
arr = list(map(int, input().split()))

border = sum(arr) / (4*M)

count = 0
for arr_i in arr:
    if(arr_i >= border):
        count+=1

if(count >= M):
    print('Yes')
else:
    print('No')

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

#define INF (1LL << 63)
struct edge{
    size_t to;
    size_t weight;
};

vector<size_t> dijkstra(vector<vector<edge>>& Graph, int& startPoint, int& vertexNum){
    vector<size_t> minimumWeight(vertexNum,INF);

    priority_queue<vector<pair<size_t,size_t>>, vector<pair<size_t,size_t>>, greater<pair<size_t,size_t>>> priorityQueue;
    priorityQueue.push({0,startPoint});
    minimumWeight[startPoint] = 0;

    while(!priorityQueue.empty()){
        pair<size_t,size_t> tmp = priorityQueue.top();

        edge Edge;
        Edge.to = tmp.second;
        Edge.weight = tmp.first;

        priorityQueue.pop();

        if(minimumWeight[Edge.to] < Edge.weight) continue;
        for(edge& edge : Graph[Edge.to]){
            if(minimumWeight[edge.to] < minimumWeight[Edge.to] + edge.weight) continue;
            minimumWeight[edge.to] = minimumWeight[Edge.to] + edge.weight;
            priorityQueue.push({minimumWeight[edge.to],edge.to});
        }
    }
    return minimumWeight;
}

int main(){
    int vertexNum, edgeNum, startPoint;
    cin >> vertexNum >> edgeNum >> startPoint;

    vector<vector<edge>> Graph(vertexNum);
    for(int i=0;i<edgeNum;i++){
        size_t from,to,weight;
        cin >> from >> to >> weight;
        Graph[from].push_back({to, weight});
    }

    vector<size_t> minimumWeight = dijkstra(Graph,startPoint,vertexNum);

    for(int i=0;i<vertexNum;i++){
        if(minimumWeight[i] == INF) cout << "INF" << '\n';
        else cout << minimumWeight[i] << '\n';
    }

}


Measured memory_bytes: 19392
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll a;
    cin>>a;
    cout<<a + a*a + a*a*a;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            long long temp = (i*j);
            if(temp >= n) break;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
char grid[1005][1005];
#define mod 1000000007
int solve(int H,int W)
{
  int dp[1005][1005];
  memset(dp,1,sizeof dp);
  dp[H][W]=1;
  for(int i=H;i>=1;i--)
  {
    for(int j=W;j>=1;j--)
    {
      if(i==H && j==W)
        continue;
      if(grid[i][j]=='#')
        dp[i][j]=0;
     
      else
      	dp[i][j]=(((i==H)?0:dp[i+1][j])+((j==W)?0:dp[i][j+1]))%mod;
      
    }
  }
 return dp[1][1]; 
}
int main()
{
	int h,w;
  cin>>h>>w;
  for(int i=1;i<=h;i++)
  {
    for(int j=1;j<=w;j++)
    {
      cin>>grid[i][j];
    }
  }
  
  cout<<solve(h,w);
  
  return 0;
}
  

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<bool>> v(h, vector<bool>(w));
    REP(i, h){
        REP(j, w){
            char c;
            cin >> c;
            v[i][j] = (c == '1');
        }
    }

    int ans = inf;

    REP(bit, (1 << (h-1))){
        vector<int> group(h, 0);
        int g = 0;
        REP(i, h-1){
            if((bit >> i) & 1) g++;
            group[i+1] = g;
        }
        int sum = g;
        vector<int> cnt(g+1, 0);
        REP(i, w){
            vector<int> cnt2(g+1, 0);
            bool cut = false;
            REP(j, h){
                cnt2[group[j]] += (v[j][i] ? 1 : 0);
            }
            REP(j, g+1){
                if(cnt2[j] > k){
                    sum = inf;
                }
                if(cnt[j] + cnt2[j] > k){
                    cut = true;
                }
            }
            if(cut){
                sum++;
                cnt = cnt2;
            }else{
                REP(j, g+1) cnt[j] += cnt2[j];
            }
            
        }
        chmin(ans, sum);
    }

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


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

flag = 1
count = 0
while flag:
    flag = 0
    for i in range(n-1, 0, -1):
        if A[i-1] > A[i]:
            A[i-1], A[i] = A[i], A[i-1]
            flag = 1
            count += 1
print(*A)
print(count)


Measured memory_bytes: 5608