akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from heapq import heappop, heappush
h, w = map(int, input().split())
d = []
for i in range(h):
    d.append(input())
# [d1, d2, d3, ..., dN]
s = [str(m) for m in d]
#移動ベクトル
dd = ((0, -1), (-1, 0), (0, 1), (1, 0))
dist = []
dotcount = 0
sharpcount = 0
for j in range(h):
    for i in range(w):
        if s[j][i] == ".":
            dotcount += 1
            for dx, dy in dd:  # 下、左、上、右の四方向から生物種が流れこむ、もしくは流れ出る（濃度の違いによって決定される、濃度が高いほうから低いほうに流れる）
                nx = i + dx
                ny = j + dy
                if 0 <= nx < w and 0 <= ny < h:  # L*Lの幅に収まっているときのみ
                    if s[ny][nx] == ".":
                        dist.append([i + j * w, nx + ny * w, 1])
        else:
            sharpcount += 1

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
# (src, dst, weight)
inputs = dist

g = Graph()
for src, dst, weight in inputs:
    g.add_edge(src, dst, weight)
    g.add_edge(dst, src, weight)

d = Dijkstra(g, h * w - 1)
sp = format(d.shortest_distance(0))
#print('最短経路: {}'.format(d.shortest_path(1)))
#print('最短距離: {}'.format(d.shortest_distance(1)))
if sp != "inf":
    needcount = int(sp) + 1
    ans = dotcount - needcount
else:
    ans = -1

print(ans)

Measured memory_bytes: 6900
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var n = parseInt(input[0], 10);
    var l = new Array(n);
    var r = new Array(n);
    for (var i = 0; i < n; i++) {
        var values = input[i + 1].split(' ');
        l[i] = parseInt(values[0], 10);
        r[i] = parseInt(values[1], 10);
    }

    var audience = 0;
    for (var i = 0; i < n; i++) {
        audience += r[i] - l[i] + 1;
    }

    console.log(audience);

    return 0;
}



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

#define PB push_back
#define X first
#define Y second
#define ws asdnasdkns
#define LL long long
#define PI acos(-1.0)
const LL mod = 1000 * 1000 * 1000 + 7;
const LL MAX = 200005;
int a[100005];
int b[100005];
int N , Q;
LL pref[100005];
LL pref2[100005];
LL sum(int l , int r)
{
	return pref2[r] - (l ? pref2[l - 1] : 0);
}
int f(int l , int r)
{
	if(l > r)
		return 0;
	return upper_bound(a , a + N , r) - lower_bound(a , a + N , l);
}
bool good(int l , int r)
{
	int suma = f(l , r);
	int de = upper_bound(a , a + N , r) - a;
	int cnt = N - de;
	return suma <= cnt;
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  //	freopen("In.txt" , "r" , stdin);
	srand(time(NULL));

	cin >> N >> Q;
	for(int i = 0; i < N; i++)
	{
		cin >> a[i];
		pref[i] = a[i] + ((i > 1) ? pref[i - 2] : 0);
		pref2[i] = a[i] + (i ? pref2[i - 1] : 0);
	}
	//reverse(b , b + N);
	while(Q--)
	{
		int x;
		cin >> x;
		int suma = -1;
		for(int j = 29; j >= 0; j--)
		{
			if(good(x - suma - (1 << j) , x + suma + (1 << j)))
				suma += 1 << j;
		}

		int cnt = f(x - suma , x + suma);

		int posR = upper_bound(a , a + N , x + suma) - a - 1;
		int posL = lower_bound(a , a + N , x - suma) - a;

		int cntZliva = (posR - posL + 1);
		int cntSprava = N - (posR + 1);
		assert(cntSprava - cntZliva >= 0 && cntSprava - cntZliva <= 2);
		if(cntSprava - cntZliva == 2)
		{
			LL ans = sum(N - cntSprava , N - 1);
			if(posL - 3 >= 0)
				ans += pref[posL - 3];
			cout << ans << endl;
		}
		else if(cntSprava - cntZliva == 1)
		{
			LL ans = sum(N - cntSprava ,  N - 1);
			if(posL - 2 >= 0)
				ans += pref[posL - 2];
			cout << ans << endl;
		}
		else
		{
			LL ans = sum(N - cntSprava , N - 1);
			
			if(posL - 1 >= 0)
				ans += pref[posL - 1];
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<vector<int>> g(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> d1(n,-1),d2(n,-1);
  queue<int> q1,q2;
  d1[0]=0,d2[n-1]=0;
  q1.push(0),q2.push(n-1);
  while(!q1.empty()){
    int now=q1.front();
    q1.pop();
    for(auto itr:g[now]){
      if(d1[itr]==-1){
        d1[itr]=d1[now]+1;
        q1.push(itr);
      }
    }
  }
  while(!q2.empty()){
    int now=q2.front();
    q2.pop();
    for(auto itr:g[now]){
      if(d2[itr]==-1){
        d2[itr]=d2[now]+1;
        q2.push(itr);
      }
    }
  }
  int cnt=0;
  rep(i,n) if(d1[i]<=d2[i]) cnt++;
  if(cnt>n-cnt) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
}

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

// THINK: INT vs LONG LONG?

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

    int d, t, s;
    cin >> d >> t >> s;
    cout << (d <= s * t ? "Yes" : "No");
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
long long f[maxn],s[maxn];
long long ans;
int main()
{
    int n,x;
    scanf("%d",&n);
    f[0]=0,s[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        f[i]=f[i-1]+x;
        s[i]=s[i-1]^x;
    }
    int L=1;
    ans=0;
    for(int R=1;R<=n;R++)
    {
        while((f[R]-f[L-1])!=(s[R]^s[L-1])) L++;
        ans+=R-L+1;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int n,tot=0;
int main(){
//	freopen("a.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i){
		int x=read();if(x&1) tot++;
	}puts(tot&1?"NO":"YES");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <long long> monedas;
long long memoria [100005];
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long c;
    long long res=0;
    memset(memoria,-1,sizeof(memoria));
    cin>>c;
    monedas.push_back(1);
    queue <pair <long long,long long> > que;
    que.push({1,1});
    memoria [0]=0;
    for (long long i=0, a=9,b=6;i<6;++i,a*=9,b*=6)
    {
        if (i==5)
        {
            monedas.push_back(b);
            que.push({b,1});
            continue;
        }
        monedas.push_back(a);
        que.push({a,1});
        monedas.push_back(b);
        que.push({b,1});
    }
    sort(monedas.begin(),monedas.end());
    while (!que.empty())
    {
        long long valor=que.front().first;
        long long costo=que.front().second;
        que.pop();
        if (valor==c)
        {
             printf("%lld\n",costo);
             return 0;
        }
        if (memoria[valor]!=-1)
            continue;
        memoria[valor]=costo;
        for (int i=0;i<monedas.size();i++)
        {
            if (monedas[i]+valor>c)
            {
                break;
            }
            if ( memoria[monedas[i]+valor]==-1)
            {
               que.push({monedas[i]+valor,costo+1});
            }
        }
 
    }
 
    //cout<<memoria[c]<<endl;
    return 0;
}

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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n,ans=0,m=0;
    cin>>n;
    int a[n+1];
    f(i,1,n)    cin>>a[i];
    f(i,1,n)
    {
        if(a[i]>=m)
        {
            m=a[i];
            continue;
        }
        ans+=m-a[i];
        
    }
    cout<<ans;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MOD = 1e9 + 7;

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

int main(void) {
    int P, Q, R;
    cin >> P >> Q >> R;

    int ans;

    ans = P + Q + R - max({P, Q, R});

    cout << ans;

    return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
//#include <string.h>
#include <bits/stdc++.h>
#define INF 999999999
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int vis[1000000]={0};
int hh[1000000];
int main()
{
    boost;
    int n;
    cin >>n;
    for(int i=1;i<=n;i++){
        cin >>hh[i];
    }
    int j=1,sum=0,falg=0,p=1;
    vis[1]=1;
    while(1){
        if(vis[2]==1)
            break;
        else if(vis[j]==2){
            cout<<-1<<endl;
            falg=1;
            break;
        }
        else {
            j=hh[j];
            //cout<<j<<endl;
            vis[j]++;
            //cout<<" "<<vis[j]<<endl;
            sum++;
        }
    }
    if(!falg)
        cout<<sum<<endl;
    return 0;

}


Measured memory_bytes: 4736
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//同じ数を数える
//7 8... 7 -> 間の和が 0

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n);
    vector <ll> souwa(n+1);
    REP(i,n)
    {
        cin >> a[i];
    }
    souwa[0] = 0;

    for(ll i = 1; i <= n; ++i)
    {
        souwa[i] = souwa[i-1] + a[i-1];
    }


    sort(souwa.begin(),souwa.end());
    ll cnt = 0;
    ll cur = souwa[0];
    ll ren = 1;
    for(ll i = 1; i <= n; ++i)
    {

        if(cur == souwa[i])
        {
            cnt += ren;
            ++ren;
        }
        else
        {
            ren = 1;
        }
        
        cur = souwa[i];
    }
    cout << cnt << endl;

    return 0;    
}



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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long n,com[30][30],dp[1<<22]={1},c[1<<22];
vector<int> G[1<<22];
int main()
{
	cin >> n;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin >> com[i][j];
	for(int i=0; i<(1<<n); i++) for(int j=0; j<n; j++) if(i&(1<<j)) G[i].push_back(j),c[i]++;
	//for(int i=0; i<n; i++) dp[1<<i]=com[0][i];
	for(int i=0; i<n; i++)
		for(int j=1; j<(1<<n); j++) if(c[j] == i+1)
			for(auto k:G[j])
				if(com[i][k])
					dp[j]=(dp[j]+dp[j&~(1<<k)])%MOD;
					
	cout << dp[(1<<n)-1];
	return 0;
}

Measured memory_bytes: 286368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    char card = 'a';
    for (int i = 0;; i++)
    {

        if (card == 'a')
        {
            if (sa.empty())
            {
                cout << "A" << endl;
                return 0;
            }
            card = sa[0];
            sa.erase(0, 1);
        }
        else if (card == 'b')
        {
            if (sb.empty())
            {
                cout << "B" << endl;
                return 0;
            }
            card = sb[0];
            sb.erase(0, 1);
        }
        else
        {
            if (sc.empty())
            {
                cout << "C" << endl;
                return 0;
            }
            card = sc[0];
            sc.erase(0, 1);
        }
    }
}

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

int main(void){
    ll A, B;
    cin >> A>> B;
    ll C;
    while(B!=0){
      C = A%B;
      A = B;
      B = C; 
    }
    ll G = A; 
    // dの素数の数を数える
    
    ll N= 1000*1000  ;
    ll prime[N];
    bool is_prime[N+1]; 
    ll p=0;
      
  for(ll i=0; i<=N; i++) is_prime[i]=true;
  is_prime[0] = is_prime[1]=false;
  for(ll i=2; i<=N; i++){
    if(is_prime[i]){
      prime[p++] =i;
      for(ll j=2*i ; j<= N; j+= i ) is_prime[j] = false; 
    }
  }    
  int answer=1; 
  for(int i=1; i< p; i++){
    ll q = prime[i-1]; 
    if(G%q==0){
      answer++;
      while(G%q==0){
        G = G/q;
      }
    }
  }
  if(G!=1) answer++;
  cout<< answer << endl; 
}
    

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	int n, l; cin >> n >> l;
	vector<int> t(n);
	rep(i, n) {
		cin >> t[i];
	}
	ld ansx = 0, ansy = 0;
	rep(i, n) {
		Rep(j, i + 1, n) {
			int num = n-(j-i+1);
			ld mid = (t[i] + t[j]) / 2.0;
			ld midx = cos(2 * pi*mid / (ld)l);
			ld midy = sin(2 * pi*mid / (ld)l);
			//cout << midx << " " << midy << endl;
			ansx += num*midx;
			ansy += num*midy;
			num = j - i - 1;
			mid += l / 2.0;
			midx = cos(2 * pi*mid / (ld)l);
			midy = sin(2 * pi*mid / (ld)l);
			ansx += num * midx;
			ansy += num * midy;
		}
	}
	ll al = (ll)n*(n - 1)*(n - 2) / 6;
	ansx /= (ld)al;
	ansy /= (ld)al;
	cout << ansx << " " << ansy << endl;
}


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



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

constexpr int INF = 1e9+7;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> D(M);
    vector<int> idx(N, -1);
    for(int i=0; i<M; ++i) {
        cin >> D[i];
        D[i]--;
        idx[D[i]] = i;
    }
    vector<vector<int>> v(N, vector<int>(K));
    for(int i=0; i<N; ++i) {
        for(int j=0; j<K; ++j) {
            cin >> v[i][j];
            v[i][j]--;
        }
    }
    vector<int> dp(1 << M, INF);
    dp[(1 << M) - 1] = 0;
    queue<int> que;
    que.push((1 << M) - 1);
    while(!que.empty()) {
        int now = que.front(); que.pop();
        for(int k=0; k<K; ++k) {
            int next = 0;
            for(int i=0; i<M; ++i) {
                if((now >> i) & 1 && idx[v[D[i]][k]] != -1) {
                    next |= (1 << idx[v[D[i]][k]]);
                }
            }
            if(dp[next] != INF) {
                continue;
            }
            dp[next] = dp[now] + 1;
            que.push(next);
        }
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 3448
N = int(input())
L = list(map(int,input().split()))
L.sort()
k = 0
j = 0
v = L[N-1]
if N % 2 == 0:
  if L[0]-v/2 >= 0:
    k = L[0]
  elif L[N-1]-v/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= v/2:
        j = i
        break
    if L[j] == v/2:
      k = L[j]
    else:
      if abs(v/2-L[j-1]) <= abs(v/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
else:
  if L[0]-(v+1)/2 >= 0:
    k = L[0]
  elif L[N-1]-(v+1)/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= (v+1)/2:
        j = i
        break
    if L[j] == (v+1)/2:
      k = L[j]
    else:
      if abs((v+1)/2-L[j-1]) <= abs((v+1)/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
print(v,k)    

Measured memory_bytes: 14428
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e3 + 5;

int main() {
    abdelrahman010
    int n , k , a[1005];
    cin >> n >> k;
    for(int i = 0;i < n;i++)
        cin >> a[i];
    int ans = 0;
    sort(a , a + n);
    for(int i = 0;i < k;i++)
        ans += a[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0) ; cout.tie(0);
#define debug(x) cout << #x << " : " << x << endl;
#define pi 3.14159265359
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using ll = long long int;
using db = double;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
const int MOD = 1e9+9;

void solve()
{
    int n , k;
    cin >> n >> k;
    vi a(n);
    for(auto &i : a) cin >> i;
    sort(a.begin() , a.end());
    int ans = 0;
     for(int i = 0 ; i < k ; i++)
        ans += a[i];
    cout <<ans<< endl;

    
}

int main()
{
//  #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout);
//  #endif
    fastio;

    int t =1;
    while(t--)
       solve();
    return 0;
}

Measured memory_bytes: 3660
import sys
n = int(input())
s = list(input())
t = list(input())

if s == t:
    print(n)
    sys.exit()
can = False
for i in range(n):
    if s[i:n] == t[0:(n-i)]:
        can = True
        break
if can:
    print(n + i )
else:
    print(2*n)


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

int N, K;
string S, ans;
bool fm, fy, bm, by;

int main() {
	cin >> S;
	if ((S[0] == '0' && S[1] != '0') || (S[0] == '1' && S[1] - '0' < 3))
		fm = true;
	if ((S[2] == '0' && S[3] != '0') || (S[2] == '1' && S[3] - '0' < 3))
		bm = true;

	if (fm&&bm)ans = "AMBIGUOUS";
	else if (fm)ans = "MMYY";
	else if (bm)ans = "YYMM";
	else ans = "NA";

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

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, K;
  cin >> N >> K;
  
  if((N+2-1)/2 >= K){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class CARD{
	char mark;
	int num;
	public CARD(String str) {
		char c0,c1;
		int n;
		c0=str.charAt(0);
		c1=str.charAt(1);
		mark=c0;
		n=Character.getNumericValue(c1);
		num=n;
	}
	public void SHOW() {
		System.out.print(mark+""+num);
	}
}

public class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int i,j,n,min,flag=0;
		String str="";
		n=scan.nextInt();
		CARD[] carda=new CARD[n];
		CARD[] cardb=new CARD[n];
		for(i=0;i<n;i++) {
			str=scan.next();
			carda[i]=new CARD(str);
			cardb[i]=carda[i];
		}
		CARD swap=new CARD(str);
		for(i=n;i>0;i--){
            for(j=0;j<i-1;j++){
                if(carda[j].num>carda[j+1].num){
                    swap=carda[j];
                    carda[j]=carda[j+1];
                    carda[j+1]=swap;
                }
            }
        }
		for(i=0;i<n;i++) {
			carda[i].SHOW();
			if(i<n-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println("Stable");
		for(i=0;i<n;i++) {
            min=i;
            for(j=i;j<n;j++) {
                if(cardb[min].num>cardb[j].num) {
                    min=j;
                }
            }
            if(min!=i) {
                swap=cardb[min];
                cardb[min]=cardb[i];
                cardb[i]=swap;
            }
        }
		for(i=0;i<n;i++) {
			cardb[i].SHOW();
			if(carda[i].mark!=cardb[i].mark) {
				flag=1;
			}
			if(i<n-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		if(flag==0) {
			System.out.println("Stable");
		}
		else {
			System.out.println("Not stable");
		}
		scan.close();
	}
}


Measured memory_bytes: 26260
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		double r = scan.nextDouble();

		System.out.println(String.format("%.6f %.6f", r*r*Math.PI, 2*r*Math.PI));
	}
}



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

int main()
{
	int n, m;
	cin >> n >> m;
	if (n >= m) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> x(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	vector<int> dif(m - 1);
	for (int i = 0; i < m - 1; i++) {
		dif[i] = x[i + 1] - x[i];
	}
	sort(dif.begin(), dif.end());
	reverse(dif.begin(), dif.end());
	int mdif = x[m - 1] - x[0];
	int sum = 0;
	for (int i = 0; i < n - 1; i++) {
		sum += dif[i];
	}
	cout << mdif - sum << endl;
}

Measured memory_bytes: 1024
n = int(input())
number_list = []
for i in range(1, n + 1):
    if i % 15 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        number_list.append(i)

print(sum(number_list))

Measured memory_bytes: 30016
#include <stdio.h>

char ch[100001];
char c[3];
int flag;
int a, b;

int main(void)
{
  int i;
  
  scanf("%s", ch);
  c[0] = ch[0];
  c[1] = ch[1];
  flag = (c[0] == c[1]);
  a = b = -1;
  for (i = 2; ch[i]; ++i)
  {
    c[i%3] = ch[i];
    if (flag && c[i%3] == c[(i+1)%3]) continue;
    if (flag == 0 && c[i%3] != c[(i+1)%3] && c[i%3] != c[(i+2)%3]) continue;
    a = i-1;
    b = i+1;
    break;
  }
  if (ch[2] == 0 && flag)
  {
    a = 1;
    b = 2;
  }
  printf("%d %d\n", a, b);
  
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  double a, b, x;
  cin >> a >> b >> x;
  double ans;
  ans = a * a * b / 2.0 <= x ? atan(2 * (a * a * b - x) / (a * a * a)) : M_PI / 2 - atan(2 * x / (a * b * b));
  cout << fixed << setprecision(10) << ans * 180.0 / M_PI << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int fib_mod(int i) {
  int a=1,b=2;
  int j,swap;
  for(j=0; j<i; j++) {
    swap=b,b=swap+a,a=swap;
    if((b>1001)&&(a>1001)) b-=1001,a-=1001;
  }

  return a;
}

int int_comp(const void *_a, const void *_b)
{
  int a = *(int *)_a;
  int b = *(int *)_b;

  if (a < b) {
    return -1;
  } else if (a > b) {
    return 1;
  } else {
    return 0;
  }
}

int main() {

  int V,d,count=0;
  while(scanf("%d%d",&V,&d) != EOF) {
    int i,fib[V];
    for(i=0; i<V; i++) fib[i] = fib_mod(i+1);

    qsort(fib,V,sizeof(int), int_comp);
    for(i=1; i<V; i++)
      if((fib[i] - fib[i-1]) >= d) count++;

    printf("%d\n",++count);
    count=0;
  }

  return 0;
}

Measured memory_bytes: 504
def solve():
    x1, y1, x2, y2 = list(map(int, input().split()))
    dx, dy = x2 - x1, y2 - y1
    x3, y3 = x2 - dy, y2 + dx
    x4, y4 = x3 - dx, y3 - dy
    return " ".join([str(i) for i in [x3, y3, x4, y4]])


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)

void solve(){
	int n;
	cin>>n;
	set<int>s;
	rep(i,0,n){
		int t;
		cin>>t;
		s.insert(t);
	}
	cout<<sz(s)<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  int n = 0;
  for (int i = 1; i <= c; ++i) {
    if (c % i == 0 && a <= i && i <= b) {
      ++n;
    }
  }
  std::cout << n << std::endl;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  string S;
  cin >> S;

  int flag2 = 0;
  FOR(i,'a','z'+1){
    int flag = 0;
    REP(j,S.size()){
      if(S.at(j)==i){
        flag = 1;
        break;
      }
    }
    if(flag == 0){
      cout << char(i) << endl;
      flag2 = 1;
      break;
    }
  }
  if(flag2 == 0){
    cout << "None" << endl;
  }
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
   int n, i, x;
   char s[51];

   scanf("%d%s",&n,s);

   for(i=0;i<n-2;i++)
      if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C'))
         x++;

   printf("%d\n",x);
   return 0;
}

Measured memory_bytes: 128
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll mod = 998244353;
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<pair<ll,ll>> vec;
    rep(i, k){
        ll l, r;
        cin >> l >> r;
        vec.push_back({l, r});
    }
    sort(all(vec));
    ll dp[200100] = {0};
    dp[0] = 1;
    dp[1] = -1;
    ll now = 0;
    rep(i, n){
        now += dp[i];
        while(now < 0) now += mod;
        now %= mod;
        rep(j, vec.size()){
            if(i + vec[j].first < n){
                dp[i + vec[j].first] += now;
                dp[i + vec[j].first] %= mod;
            }
            if(i + vec[j].second + 1 < n){
                dp[i + vec[j].second + 1] -= now;
                while(dp[i + vec[j].second + 1] < 0) dp[i + vec[j].second + 1] += mod;
                dp[i + vec[j].second + 1] %= mod;
            } 
        }
    }
    while(now < 0) now += mod;
    cout << now % mod << endl;
}



Measured memory_bytes: 5116
class RMQ:
    def __init__(self, length, ini_num = float("inf")):
        self.length = 1
        self.ini_num = ini_num
        while self.length < length:
            self.length <<= 1
        self.segtree = [ini_num] * (2 * self.length - 1)

    def update(self, index, n):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = n
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = min(self.segtree[leaf_index * 2 + 1], self.segtree[leaf_index * 2 + 2])

    def find(self, a, b, index, l, r):
        if a <= l <= r <= b:
            return self.segtree[index]
        elif b < l or r < a:
            return self.ini_num
        else:
            return min(self.find(a, b, index * 2 + 1, l, (l + r) // 2), self.find(a, b, index * 2 + 2, (l + r) // 2 + 1, r))

v_num, query = map(int, input().split(" "))
rmq = RMQ(v_num, 2147483647)
for _ in [0] * query:
    com, i, n = map(int, input().split(" "))
    if com == 0:
        rmq.update(i, n)
    else:
        print(rmq.find(i, n, 0, 0, rmq.length - 1))

Measured memory_bytes: 11820
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int, int> P;

const int INF = 1e9;
int h, w;
char s[20][21];
int dp[400][20][20];
int x[4], y[4];

int main() {
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) scanf("%s", s[i]);
    
    for (int i = 0; i < h * w; i++) {
        for (int j = 0; j < h; j++) {
            for (int k = 0; k < w; k++) dp[i][j][k] = INF;
        }
    }
    x[0] = 1; y[0] = 0;
    x[1] = 0; y[1] = 1;
    x[2] = -1; y[2] = 0;
    x[3] = 0; y[3] = -1;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') continue;
            priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> q;
            q.emplace(0, P(i, j));
            while (!q.empty()) {
                int d = q.top().first;
                int k = q.top().second.first;
                int l = q.top().second.second;
                q.pop();
                if (dp[i * w + j][k][l] != INF) continue;
                dp[i * w + j][k][l] = d;
                for (int a = 0; a < 4; a++) {
                    if (k + x[a] < 0 || k + x[a] >= h ||
                        l + y[a] < 0 || l + y[a] >= w ||
                        s[k + x[a]][l + y[a]] == '#') continue;
                    q.emplace(d + 1, P(k + x[a], l + y[a]));
                }
            }
        } 
    }
    
    int ans = 0;
    for (int i = 0; i < h * w; i++) {
        for (int j = 0; j < h; j++) {
            for (int k = 0; k < w; k++) {
                if (dp[i][j][k] == INF) continue;
                ans = max(ans, dp[i][j][k]);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main(){
	int m,f,b;
	cin >> m >> f>> b ;
	if(m>=b)
	{
	    cout<<"0"<<endl;
	}else{
	    if(m+f>=b)
	    {
	       cout<<(b-m)<<endl; 
	    }else{
	       cout<<"NA"<<endl;
	    }   
	
	}
	
}


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

if  A >= 1 and A <= 10 and B >= 1 and B <= 10 and C >= 1 and C <= 10 :
  if A == 5 :
    if B == 7 and C == 5 or B == 5 and C == 7 :
      print("YES")
    else :
      print("NO")
  elif A == 7 :
    if B == 5 and C == 5 :
      print("YES")
    else :
      print("NO")
  else :
    print("NO")
else :
  print("NO")

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

int main(){
    string k;
    cin>>k;
    int s[4];
    for(int i=0;i<4;i++){
        s[i]=k[i]-'0';
    }
    if(s[0]+s[1]+s[2]+s[3]==7)cout<<s[0]<<"+"<<s[1]<<"+"<<s[2]<<"+"<<s[3]<<"=7"<<endl;
    else if(s[0]-s[1]+s[2]+s[3]==7)cout<<s[0]<<"-"<<s[1]<<"+"<<s[2]<<"+"<<s[3]<<"=7"<<endl;
    else if(s[0]-s[1]-s[2]+s[3]==7)cout<<s[0]<<"-"<<s[1]<<"-"<<s[2]<<"+"<<s[3]<<"=7"<<endl;
    else if(s[0]-s[1]-s[2]-s[3]==7)cout<<s[0]<<"-"<<s[1]<<"-"<<s[2]<<"-"<<s[3]<<"=7"<<endl;
    else if(s[0]+s[1]-s[2]+s[3]==7)cout<<s[0]<<"+"<<s[1]<<"-"<<s[2]<<"+"<<s[3]<<"=7"<<endl;
    else if(s[0]+s[1]-s[2]-s[3]==7)cout<<s[0]<<"+"<<s[1]<<"-"<<s[2]<<"-"<<s[3]<<"=7"<<endl;
    else if(s[0]+s[1]+s[2]-s[3]==7)cout<<s[0]<<"+"<<s[1]<<"+"<<s[2]<<"-"<<s[3]<<"=7"<<endl;
    else if(s[0]-s[1]+s[2]-s[3]==7)cout<<s[0]<<"-"<<s[1]<<"+"<<s[2]<<"-"<<s[3]<<"=7"<<endl;
    return 0;
}

Measured memory_bytes: 3592
//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef set <long long> sll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
double pi = 2 * acos(0.0);
int OO = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
const int NMAX = 100010;;
ll n, arr[NMAX], dp[NMAX];
ll solve(ll i)
{
    if(i == n - 1)  return 0;
    if(~dp[i])      return dp[i];
    return dp[i] = min(solve(i + 1) + abs(arr[i + 1] - arr[i]), i + 2 <= n - 1 ? solve(i + 2) + abs(arr[i + 2] - arr[i]) : OO);
}
int main()
{
    IO
    cin >> n;
    REP(i, 0, n)    cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 3328
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
b = [None]*n
c = [None]*n
for i in range(n):
    a[i],b[i],c[i] = map(int, input().split())
    
dpa = [0]*(n+1)
dpb = [0]*(n+1)
dpc = [0]*(n+1)

for i in range(1,n+1):
    aa,bb,cc = a[i-1],b[i-1],c[i-1]
    dpa[i] = max(dpb[i-1]+aa, dpc[i-1]+aa)
    dpb[i] = max(dpa[i-1]+bb, dpc[i-1]+bb)
    dpc[i] = max(dpa[i-1]+cc, dpb[i-1]+cc)
print(max(dpa[n], dpb[n], dpc[n]))
    

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

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

    //write your code here
    int n;
    cin>> n;
    vector<int > v(n,0);
    for(int i=0;i<n;i++)  cin>> v[i];
    vector<int > dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n-1;i++){
      dp[i+1] = min(dp[i+1], dp[i]+ abs(v[i+1]-v[i]));
      if(i<n-2)
        dp[i+2]= min(dp[i+2], dp[i]+abs(v[i+2]-v[i]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    int l = 0, r = n - 1;
    while (l < r) {
        if (s[l] == 'R') {
            ++l;
            continue;
        }
        if (s[r] == 'W') {
            --r;
            continue;
        }
        swap(s[l], s[r]);
        ++cnt;
    }

    cout << cnt << endl;
    dump(s);
}

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

Measured memory_bytes: 3716
#include<iostream>
using namespace std;
int solve(int x) {
	int y=0;
	while(x%100==0) {
		x/=100;
		y++;
	}
return y;
}
int main() {
	int d,n;
	cin>>d>>n;
	int i=0,ct=0;
	while(i<n) {
		ct++;
	   if(solve(ct)==d) 
		   i++;
	}
   cout<<ct<<'\n';
	
}

Measured memory_bytes: 3636
n,k = [int(x) for x in input().split()]
li = [0]*(k+1)
mod = 10**9+7

ans = 0
for i in range(1,k+1)[::-1]:
    x = pow(k//i,n,mod)
    for j in range(i*2,k+1,i):
        if j%i==0:
            x -= li[j]
    li[i] = x
    ans = (ans+(x*i)%mod)%mod
print(ans%mod)

Measured memory_bytes: 70180
#include<bits/stdc++.h>
using namespace std;
int main()
{  int i, j,n,l,ans=0,flav=0,sum=0,min=999999,pos;
	cin>>n>>l;
	int a[n];
for(i=0;i<n;i++)
   {
   	a[i]=l+i;
   	flav=flav+a[i];
   }
   for(i=0;i<n;i++)
   {  sum=0;
   	  for(j=0;j<n;j++)
   	  {
   	  	if(i!=j)
   	  		sum=sum+a[j];
   	  }
   	  ans=abs(sum-flav);
   	  if(ans<min)
   	  {
   	  	min=ans;
   	  	pos=i;
   	  }
   	}
   	sum=0;
   	for(i=0;i<n;i++)
   {  if(i!=pos)
    sum+=a[i];}
    cout<<sum;
}

Measured memory_bytes: 256
S = list(input())
n = len(S)
res = 0
cur = 0
count = [0] * 2020
count[0] = 1
for i, c in enumerate(map(int, S)):
    cur = (cur * 10 + c) % 2019
    temp = (cur * pow(10, (n - i), 2019)) % 2019
    count[temp] += 1
print(sum(c * (c - 1) // 2 for c in count))

Measured memory_bytes: 10476
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <iomanip>

using namespace std;

typedef long long ll;

int main(){
    ll A, B;
    cin >> A >> B;
    
    ll ans;
    ll a_xor, b_xor;
    ll cnt;
    
    if(A == 0){
        a_xor = 0;
    }
    else{
        if((A - 1) % 2 == 0){
            cnt = (A - 1) / 2;
            if(cnt % 2 == 0){
                a_xor = A - 1;
            }
            else{
                a_xor = (A - 1) ^ 1;
            }
        }
        else{
            cnt = (A - 1) / 2 + 1;
            if(cnt % 2 == 0){
                a_xor = 0;
            }
            else{
                a_xor = 1;
            }
        }
    }
    
    if(B % 2 == 0){
        cnt = B / 2;
        if(cnt % 2 == 0){
            b_xor = B;
        }
        else{
            b_xor = B ^ 1;
        }
    }
    else{
        cnt = B / 2 + 1;
        if(cnt % 2 == 0){
            b_xor = 0;
        }
        else{
            b_xor = 1;
        }
    }
    
    ans = a_xor ^ b_xor;
    // cout << bitset<10>(a_xor) << endl << bitset<10>(b_xor) << endl;
    // cout << bitset<10>(ans) << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
int x, y;
int main() {
	x = read(); y = read();
	if (4 * x < y)
		cout << "No" << endl;
	else if (y & 1)
		cout << "No" << endl;
	else {
		y -= 2*x;
		if (y % 2 == 0&&y>=0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const double EPS=1e-6;
const int MAXN=1e6+10;

double a[MAXN];
int main() {
    int n;
    double m;
    cin>>n>>m;
    double sum=0;
    for (int i=0;i<n;i++) {
        cin>>a[i];
        sum+=a[i];
    }
    double b=sum/m/4.0;
    // cout<<b<<endl;
    int cnt=0;
    for (int i=0;i<n;i++) {
        if (a[i]-b>=0) {
            cnt++;
        }
    }
    if (cnt>=m) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    FOR(i,a,b+1){
        if(i-a<k||b-i<k){
            cout<<i<<endl;
        }
    }
    return 0;
}

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


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

struct edge {int to; ll cost; };

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

 
int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.length();
  vector<vector<int>> dp0(n+1, vector<int>(4, 0)), dp1(n+1, vector<int>(4, 0));
  dp1[0][0] = 1;
  for(int i=1; i<=n; i++){
    dp0[i][0] = 1;
  }
  for(int i=1; i<=n; i++){
    for(int j=1; j<=3; j++){
      dp0[i][j] = dp0[i-1][j] + dp0[i-1][j-1]*9;
      if(i==n){
        if(s[i-1]-'0'){
          dp0[i][j] += dp1[i-1][j] + dp1[i-1][j-1]*(s[i-1]-'0');
          dp1[i][j] = dp1[i-1][j-1];
        }else{
          dp0[i][j] += dp1[i-1][j];
          dp1[i][j] = dp1[i-1][j];
        }
      }else{
        if(s[i-1]-'0'){
          dp0[i][j] += dp1[i-1][j] + dp1[i-1][j-1]*(s[i-1]-'0'-1);
          dp1[i][j] = dp1[i-1][j-1];
        }else{
          dp1[i][j] = dp1[i-1][j];
        }
      }
    }
  }
  cout << dp0[n][k] << endl;
  return 0;
}


Measured memory_bytes: 3640