akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n;
char s[300010];
int a[300010], b[300010], ans, t1, t2;


int main(){
    while(cin>>n){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));

        cin>>s[0];
        if(s[0]=='W')
            a[0] = 1;
        else
            b[0] = 1;

        for(int i=1; i<n; i++){
            cin>>s[i];
            if(s[i]=='W'){
                a[i] = a[i-1]+1;
                b[i] = b[i-1];
            }
            else if(s[i]=='E'){
                b[i] = b[i-1]+1;
                a[i] = a[i-1];
            }
        }

        ans = b[n-1]-b[0];

        for(int i=1; i<n; i++){
            t1 = a[i-1];
            t2 = b[n-1]-b[i];
            ans = min(ans, t1+t2);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        string s;
        cin>>s;
        int n=s.size();
        for(int l=0;l<n;l++)
        {
                for(int r=l;r<n;r++)
                {
                        string a;
                        for(int i=0;i<l;i++)
                        {
                                a+=s[i];
                        }
                        for(int i=r+1;i<n;i++)
                        {
                                a+=s[i];
                        }
                        if(a=="keyence")
                        {
                                cout<<"YES\n";
                                return  0;
                        }
                }
        }
        if(s=="keyence")
        {
                cout<<"YES\n";
                return 0;
        }
        cout<<"NO";
        return 0;
}
/**


**/


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M,ans=0;
  cin>>N>>M;
 vector<int> A(3),s(M),c(M),B(3);
  for(int i=0;i<3;i++){
  	A[i]=0;
    B[i]=0;
  }
  for(int i=0;i<M;i++){
  	cin>>s[i]>>c[i];
  }
  for(int i=0;i<M;i++){
  	if(B[s[i]-1]==0) A[s[i]-1]=c[i],B[s[i]-1]=1;
    else if(A[s[i]-1]!=c[i]) ans=-1;
  }  
  if(N==1){
    if(ans!=-1) ans=A[0];
  }else if(N==2){
  	if(A[0]==0){
    	if(B[0]==1) ans=-1;
        else A[0]=1;
    }  
    if(ans!=-1) ans=A[0]*10+A[1];
  }else if(N==3){
  	if(A[0]==0){
    	if(B[0]==1) ans=-1;
        else A[0]=1;
    }
    if(ans!=-1) ans=A[0]*100+A[1]*10+A[2];
  }
cout<<ans<<endl;
}  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
signed main() {
	int n, m;
	cin >> n >> m;
	bitset<32>bita(n), bitb(m);
	cout << (bita & bitb) << endl;
	cout << (bita | bitb) << endl;
	cout << (bita ^ bitb) << endl;
	return 0;
}


Measured memory_bytes: 3144
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int  N = sc.nextInt();
       int  K = sc.nextInt();
       int max=0;
       for (int i=0 ; i<K; i++) {
    	   max=Math.max(max, sc.nextInt());
       }
       int ans=0;
	   ans=2*max-1-N;
	   if(ans<0)ans=0;
       System.out.println(ans);
       
   }
}

Measured memory_bytes: 21844
N, M = map(int, input().split())
L = 1
R = N
for i in range(M):
  Li, Ri = map(int, input().split())
  if Li > L:
    L = Li
  if Ri < R:
    R = Ri
if L <= R:
  print(R - L + 1)
else:
  print(0)


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

int main() {

     int A,B;
    cin >> A >> B;
    
    if ((A + B) > (A - B)) {
        if ((A + B > A * B)) {
            cout << A + B << endl;
        }
        
        else {
            cout << A * B << endl;
        }
    }
    
    else {
        if ((A - B) > (A * B)) {
            cout << A - B << endl;
        }
        
        else {
            cout << A * B << endl;
        }
        
    }
            
 }

Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
#define _USE_MATH_DEFINES
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}

bool m[1100][1100];
Vi g[1001000];

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

  int mod = 1e9 + 7;

  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = k; i < n + 2; i++){
    ans += (i * (2 * n - (i - 1)) / 2 - ((i - 1) * i / 2) + 1) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 27140
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

enum {
    kNotVisited,
    kVisitedOnWay,
    kVisitedNotOnWay,
};

bool dfs(const vector<vector<int64_t>>& links, vector<int64_t>& state,
         vector<int64_t>& loop, int64_t current) {
    if (state[current] == kVisitedOnWay) {
        loop.push_back(current);
        return true;
    } else if (state[current] == kVisitedNotOnWay) {
        return false;
    }

    state[current] = kVisitedOnWay;
    for (auto v : links[current]) {
        auto tmp = dfs(links, state, loop, v);
        if (tmp) {
            if (loop.size() == 1 || loop.front() != loop.back()) {
                loop.push_back(current);
            }

            return true;
        }
    }
    state[current] = kVisitedNotOnWay;

    return false;
}

main() {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int64_t>> links(n);
    for (auto _ : irange(0L, m)) {
        int64_t a, b;
        cin >> a >> b;
        --a;
        --b;

        links[a].push_back(b);
    }

    vector<int64_t> state(n);
    vector<int64_t> loop;
    bool has_loop = false;
    for (int64_t i = 0; i < n && !has_loop; ++i) {
        has_loop = dfs(links, state, loop, i);
    }
    if (!has_loop) {
        cout << -1 << endl;
        return 0;
    }

    loop.pop_back();
    reverse(loop.begin(), loop.end());
    vector<int64_t> next;
    next.reserve(loop.size());
    while (true) {
        vector<int64_t> idx(n, -1);
        for (auto i : irange(0uL, loop.size())) {
            idx[loop[i]] = i;
        }

        next.clear();
        for (auto i : irange(0uL, loop.size())) {
            auto u = loop[i];
            for (auto v : links[u]) {
                if (!(idx[v] == -1 || idx[v] == (i + 1) % loop.size())) {
                    if (idx[u] < idx[v]) {
                        for (auto j : irange(0L, idx[u] + 1)) {
                            next.push_back(loop[j]);
                        }
                        for (auto j : irange(idx[v], (int64_t)loop.size())) {
                            next.push_back(loop[j]);
                        }
                    } else {
                        for (auto j : irange(idx[v], idx[u] + 1)) {
                            next.push_back(loop[j]);
                        }
                    }
                    break;
                }
            }

            if (!next.empty()) {
                break;
            }
        }

        if (next.empty()) {
            break;
        }
        loop = std::move(next);
    }

    cout << loop.size() << endl;
    for (auto v : loop) {
        cout << v + 1 << "\n";
    }
}

Measured memory_bytes: 384
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
4 2
5 2
2 1
8 3

output:
13
"""

import sys
from collections import namedtuple


# def solve():
#     for i, item in enumerate(item_list, 1):
#         for cp in range(1, real_cp + 1):
#             # capacity allows putting in, calculate value
#             if item.w <= cp:
#                 values[i][cp] = max(values[i - 1][cp], values[i - 1][cp - item.w] + item.v)
#             # can't put in, skip current item
#             else:
#                 values[i][cp] = values[i - 1][cp]
#
#     return values[c_items][real_cp]


def solve_2():
    dp = [0] * (real_cp + 1)
    for item in item_list:
        v, w = item.v, item.w
        for cp in range(real_cp - w, -1, -1):
            dp[cp + w] = max(dp[cp + w], dp[cp] + v)

    return dp.pop()


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_items, real_cp = map(int, _input[0].split())
    items = map(lambda x: x.split(), _input[1:])

    Item = namedtuple('Item', ('v', 'w'))
    item_list = [Item(int(v), int(w)) for v, w in items]

    # values = [[0] * (real_cp + 1) for _ in range(c_items + 1)]
    ans = solve_2()
    print(ans)

Measured memory_bytes: 8324
<?php
class Dice{
  public $label=[1,2,3,4,5,6];#index+1????????¢?????????
  public $pos=[0,1,2];#?????¢,?????¢,??\??¢???index ???????????¢???5-index
  function __construct($sLabel){$this->label=explode(' ',$sLabel,6);}
  function move($s){
    $x=$this->pos[0];
    if($s=='E'){
      $this->pos[0]=5-$this->pos[2];
      $this->pos[2]=$x;
    }
    elseif($s=='W'){
      $this->pos[0]=$this->pos[2];
      $this->pos[2]=5-$x;
    }
    elseif($s=='N'){
      $this->pos[0]=$this->pos[1];
      $this->pos[1]=5-$x;
    }
    elseif($s=='S'){
      $this->pos[0]=5-$this->pos[1];
      $this->pos[1]=$x;
    }
  }
  function spin($s){
    $x=$this->pos[1];
    if($s=='L'){
      $this->pos[1]=$this->pos[2];
      $this->pos[2]=5-$x;
    }
    elseif($s=='R'){
      $this->pos[1]=5-$this->pos[2];
      $this->pos[2]=$x;
    }
  }
  function toTop($label){
    for($j=0;$j<4;$j++){
      if($this->top()==$label) return 1;
      $this->move('N');
    }
    for($j=0;$j<2;$j++){
      $this->move('E');
      if($this->top()==$label) return 1;
      $this->move('E');
    }
    return 0;
  }
  function toSpin($label){
    for($j=0;$j<4;$j++){
      if($this->front()==$label) return 1;
      $this->spin('L');
    }
    return 0;
  }
  function isSame($dice){
    $move=array('','N','W','W','W','N');#1 2 3 5 4 6
    $end=[];
    for($i=0;$i<6;$i++){
      $this->move($move[$i]);
      $top=$this->top();
      if(isset($end[$top])) continue;
      $end[$top]=1;
      if(!$dice->toTop($top)) continue;
      if(!$dice->toSpin($this->front())) continue;
      if($dice->right()!=$this->right()) continue;
      if($dice->bottom()!=$this->bottom()) continue;
      if($dice->back()!=$this->back()) continue;
      if($dice->left()!=$this->left()) continue;
      return 1;
    }
    return 0;
  }
  function top(){return $this->label[$this->pos[0]];}
  function front(){return $this->label[$this->pos[1]];}
  function right(){return $this->label[$this->pos[2]];}
  function bottom(){return $this->label[5-$this->pos[0]];}
  function back(){return $this->label[5-$this->pos[1]];}
  function left(){return $this->label[5-$this->pos[2]];}
}

$d1=new Dice(trim(fgets(STDIN)));
$d2=new Dice(trim(fgets(STDIN)));

echo ($d1->isSame($d2))?'Yes':'No';
?>

Measured memory_bytes: 15620
#include<stdio.h>
int main(void)
{
	int n,i,x=100000;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++)
	{
		x=x*1.05;
		if(x%1000!=0)
			x=(x/1000+1)*1000;
	}
	printf("%d\n",x);
	return 0;
}

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

int main(){
  int N;
  vector<int64_t> A(100010);
  int64_t sum = 0;

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

  vector<int64_t> ans(100010);
  ans[0] = sum;
  for(int i=0; 2*i+1<N; i++) ans[0] -= 2*A[2*i+1];

  for(int i=1; i<N; i++) ans[i] = 2*A[i-1]-ans[i-1];

  for(int i=0; i<N; i++) cout << ans[i] <<" ";
  cout << endl;
  
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
int C[4040], A[4040];
int dp[2020][2020];
int c0[4040][2020], c1[4040][2020];
int loc0[2020], loc1[2020];

void update(int& a, int x)
{
	a = min(a, x);
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < 2 * N; ++i) {
		char in[2]; int x;
		scanf("%s%d", in, &x);

		C[i] = (in[0] == 'B' ? 0 : 1);
		A[i] = --x;

		(C[i] == 0 ? loc0 : loc1)[A[i]] = i;
	}

	for (int i = 0; i <= N; ++i) c0[2 * N][i] = c1[2 * N][i] = 0;
	for (int i = 2 * N - 1; i >= 0; --i) {
		for (int j = 0; j <= N; ++j) {
			c0[i][j] = c0[i + 1][j];
			c1[i][j] = c1[i + 1][j];
		}
		for (int j = A[i] + 1; j <= N; ++j) {
			(C[i] == 0 ? c0 : c1)[i][j]++;
		}
	}

	for (int i = 0; i <= N; ++i) for (int j = 0; j <= N; ++j) dp[i][j] = 1001001001;
	dp[0][0] = 0;

	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= N; ++j) {
			if (i < N) {
				update(dp[i + 1][j], dp[i][j] + c1[loc0[i]][j]);
			}
			if (j < N) {
				update(dp[i][j + 1], dp[i][j] + c0[loc1[j]][i]);
			}
		}
	}

	int base = 0;

	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			if (loc0[i] > loc0[j]) ++base;
			if (loc1[i] > loc1[j]) ++base;
		}
	}

	printf("%d\n", dp[N][N] + base);

	return 0;
}


Measured memory_bytes: 79872
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int dy[2] = {1,0};
int dx[2] = {0,1};
int h,w;
vector<string>s(10);

int main(){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    ll res;
    if(k%2==0)res = a-b;
    else res = b-a;
    cout<<res<<endl;
}



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

using namespace std;

int N, M;
int A[100005];
vector<int> odd, even;
vector<int> ans;

int main(void)
{
	cin >> N >> M;
	for(int i = 0; i < M; i++) cin >> A[i];
	
	if(M == 1){
		if(A[0] > 1) ans.push_back(A[0]-1);
		ans.push_back(1);
		
		cout << A[0] << endl;
		cout << ans.size() << endl;
		for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl;
		return 0;
	}
	
	for(int i = 0; i < M; i++){
		if(A[i] % 2) odd.push_back(A[i]);
		else even.push_back(A[i]);
	}
	
	if(odd.size() >= 3){
		cout << "Impossible" << endl;
		return 0;
	}
	
	if(odd.size() >= 1) even.insert(even.begin(), odd[0]);
	if(odd.size() >= 2) even.push_back(odd[1]);
	
	for(int i = 0; i < even.size(); i++) cout << even[i] << " "; cout << endl;
	
	ans.push_back(even[0]+1);
	for(int i = 1; i < even.size()-1; i++){
		ans.push_back(even[i]);
	}
	if(even.back() > 1) ans.push_back(even.back()-1);
	
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

int main(){
  long long int N=0,M=0;
  long long int i=0;
  long long int  sum=0;
  std::cin >> N >> M;
  std::vector <long long int> a(N,0);
  std::vector <long long int> b(N,0);  
  std::vector <std::pair<long long int,long long int> > ab(N);
  
  for(int i=0;i<N;i++){
    std::cin >> a[i] >> b[i];
    ab[i] = std::make_pair(a[i],b[i]);
    //    std::cout <<" "<< ab[i].first<< " " << ab[i].second<< std::endl;
  }
  
   std::sort(ab.begin(),ab.end());
   
   for(i=0;i<N;i++){
    if(M-ab[i].second < 0){
      sum = sum + ab[i].first*M;
      break;
    }
    else if(M-ab[i].second == 0){
      sum = sum + ab[i].first*ab[i].second;
      break;
    }else if(M-ab[i].second>0){
      M = M-ab[i].second;
      sum = sum+ab[i].first*ab[i].second;
    }
  }
  std::cout<<sum<<std::endl;
  return 0;
}


Measured memory_bytes: 3328
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    var m = sc.nextInt
    val pq = collection.mutable.PriorityQueue[Long]()
    for (i <- 0 until n) {
      pq.enqueue(sc.nextLong())
    }

    var sum = pq.toList.sum
    while (m > 0) {
      val max = pq.dequeue()
      val tmp = max / 2
      sum -= max - tmp
      pq.enqueue(tmp)
      m -= 1
    }

    println(sum)
  }
}


Measured memory_bytes: 70924
N, L = map(int, input().split())
full = sum(range(1, N+1)) + N * (L - 1)
diff = 1000

for i in range(1, N+1):
    if abs(diff) > abs(L + i - 1):
        diff =  - (L + i - 1) 
print(full + diff)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const long long MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin>>n;
    vector<int> t(n+1,0),x(n+1,0),y(n+1,0);
    for(int i=1;i<n+1;i++)cin>>t[i]>>x[i]>>y[i];
    bool ok = true;
    for(int i=1;i<n+1;i++){
        int dt = abs(t[i]-t[i-1]);
        int dx = abs(x[i]-x[i-1]);
        int dy = abs(y[i]-y[i-1]);
        if(dt%2!=(dx+dy)%2)ok=false;
        if(dt<dx+dy)ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';

ll dist[100010]={0}, ord[100010], N;

void dfs1(vector<vector<ll> > &g, vector<bool> &vs, ll u){
    if(vs[u]) return;
    vs[u]=true;
    for(auto v:g[u])
        dfs1(g,vs,v);
    ord[N--]=u;
}

void solve(){
    ll i,j,k,l,m,n,u,v;
    cin>>n>>m;
    N=n-1;
    vector<vector<ll> > g(n+1);
    vector<bool> vs(n+1,false);
    for(i=0;i<m;i++){
        cin>>u>>v;
        g[u].push_back(v);
    }
    for(i=1;i<=n;i++){
        if(!vs[i]) dfs1(g,vs,i);
    }

//    for(i=0;i<n;i++) cout<<ord[i]<<" ";cout<<nl;

    for(i=0;i<n;i++){
        u=ord[i];
        for(auto v:g[u]){
            dist[v]=max(dist[v],dist[u]+1);
        }
    }

    ll ans=0;
    for(i=1;i<=n;i++) ans=max(ans,dist[i]);
    cout<<ans<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 12112
import math

def factorize(n):
    p = n
    while True:
        if p % 2 == 0:
            p //= 2
            yield 2
        else:
            break

    r = 3
    while r < int(math.sqrt(p)+1):
        if p % r == 0:
            p //= r
            yield r
        else:
            r += 2

    if p != 1:
        yield p

n = int(input())
l = factorize(n)

print(str(n)+":",*list(l))

Measured memory_bytes: 7772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		int foo = 0;
		String s;
		String b;
		String a;
		int max = 0;
		n = sc.nextInt();
		s = sc.next();
		
		for(int i = 1; i < n; i++){
			b = s.substring(0,i);
			a = s.substring(i,n);
			foo = 0;
			while(b.length() > 0){
				if(!a.replaceAll(b.substring(0, 1),"").equals(a)){
				foo++;
				}
				b = b.replaceAll(b.substring(0, 1),"");
			}
			max = Math.max(max, foo);
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
int main () {
	int a,b,k,x;
	cin>>a>>b;
	set <int> s;
	while (b--){
		cin>>k;
		while(k--){
			cin>>x;
			s.insert(x);
		}
	}
	cout<<a-s.size();
	return 0;
}


Measured memory_bytes: 3636
s = 0
N, K = map(int, input().split())
if K == 0:
  print(N*N)
else:
  for b in range(K+1, N+1):
    q = N//b
    r = N%b
    s += q*(b-K)
    if r >= K:
      s += r-K+1
  print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int main() {
  ll s = in();
  ll x1 = 1e9, x2 = 1;
  ll y2 = dup(s,x1), y1 = x1*y2-s;
  vl ans;
  ans.pb(0); ans.pb(0);
  ans.pb(x1); ans.pb(y1);
  ans.pb(x2); ans.pb(y2);
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

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

	int lon = s.size();
	int fir = -1, las = -1;

	for (int i = 0; i < lon-1; i++)
	{
		//二文字連続で同じ文字ならアンバランス
		//tはi < lon-1
		string t = s.substr(i, 2);
		if(t[0] == t[1])
		{
			fir = i+1;
			las = i+2;
			break;
		}

		//三文字のうち二文字等しいのならアンバランス
		//uはi < lon-2
		if(i < lon-2)
		{
			string u = s.substr(i, 3);
			if(u[0] == u[2])
			{
				fir = i+1;
				las = i+3;
				break;
			}
		}
	}
	cout << fir << " " << las << endl;
	return 0;
}

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

#define ll long long
#define ull unsigned long long

int l, r, d;

void solve() {
    cin >> l >> r >> d;
    int ans=0;
    for(int i=d; i<=r; i+=d) {
        if(l<=i)
            ans++;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

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

int main() {
	int x;
	cin >> x;
	if (x < 1200) cout << "ABC";
	else cout << "ARC";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

アルゴリズムは悩む要素ないね
あ、ちなみにC問題が楽に解けてD問題もある程度正答できるなら、レート1200未満でもARC出た方が良いよ
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define F first 
#define S second 

using namespace std;

void test(){
	ll n;
	cin>>n;
	ll sum = (n*(n+1))/2;
	ll x = n/3;
	ll s1 = (x*(x+1))/2;
	s1 = s1*3;
	x = n/5;
	ll s2 = (x*(x+1))/2;
	s2 = s2*5;
	x = n/15;
	ll s3 = (x*(x+1))/2;
	s3 = s3*15;
	ll tot = s1+s2-s3;
	cout<<sum-tot<<"\n";
}

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

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

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

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

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

int main() {
  int n, s;

  while(cin >> n >> s, n+s) {
    bool b[10];
    REP(i, 10) {
      if(i < 10-n) b[i] = false;
      else b[i] = true;
    }

    int cnt = 0;
    do {
      int S = 0;
      REP(i, 10) {
	if(b[i]) S += i;
      }
      if(S == s) cnt++;
    } while(next_permutation(b, b+10));

      cout<< cnt << endl;
  }
}

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

using namespace std;

int main(){
  string g[100];
  int y[100], m[100], d[100];
  int cnt_in = 0;

  for(;;){
    cin >> g[cnt_in];
    if(g[cnt_in] == "#"){
      break;
    }

    cin >> y[cnt_in] >> m[cnt_in] >> d[cnt_in];
    cnt_in++;
  }

  for(int i = 0; i < cnt_in; i++){
    if((y[i] > 31) || (y[i] == 31) && (m[i] >= 5)){
      cout << "?" << " " << y[i] - 30 << " " << m[i] << " " << d[i] << endl;
    }
    else{
      cout << g[i] << " " << y[i] << " " << m[i] << " " << d[i] << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3168
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

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

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int N, M;
const int MAX_N = 8;
VI tree[MAX_N + 1];

bool visit[MAX_N + 1];

int ans = 0;
void dfs(int u) {
    visit[u] = true;
    for (auto v : tree[u]) {
        if (!visit[v]) {
            dfs(v);
        }
    }
    ans += 1;
    for (int i = 1; i <= N; i++) {
        if (!visit[i]) {
            ans -= 1;
            break;
        }
    }
    visit[u] = false;
}

int main(int argc, char const* argv[])
{
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        tree[a].PB(b);
        tree[b].PB(a);
    }
    dfs(1);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
c(int*l,int*r){return *r-*l;}a[1<<17];i;f;s;main(j){for(;~scanf("%d",a+i++););for(qsort(a+1,*a,4,c);!s&j<*a;i-a[j]?:(f?s=i:(f=i),j++))i=a[j++];printf("%ld",(long)f*s);}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main (void)
{
  int a,b,c,d,p;
  int X,Y=0;
  cin>>a>>b>>c>>d>>p;
  X=p*a;

  if(p-c>0)
    Y=(p-c)*d+b;

  else if(c>=p)
    Y+=b;


  if(X<Y)
    cout<<X<<endl;

  else
    cout<<Y<<endl;


  return 0;


}



Measured memory_bytes: 3080
import numpy as np
import sys
from collections import Counter
input = sys.stdin.buffer.readline
N = int(input())
A = sorted(list(map(int, input().split())))

B = np.ones(10**6 + 1, np.bool)
S = set()
for a in A:
    if B[a]:
        B[a * 2::a] = 0
        S.add(a)
# print('S', S)
# print('B', B[:20])

c = Counter(A)
# print('c', c)
for key, value in zip(c.keys(), c.values()):
    if value >= 2 and key in S:
        S.remove(key)
# print('S', S)
ans = len(S)
print(ans)


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

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

int main()
{
    long long n;
    long long a, b;

    int amari_blue;

    cin >> n >> a >> b;

    long long total_ball = a + b;

    long long ans = a * (n / total_ball);
    //cout << num << endl;

    //cout << amari << endl;

    ans += min(n % (a + b), a);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = [input() for i in range(N)]

ac = 0
wa = 0
tle = 0
re = 0

for item in P:
  if item == "AC":
    ac += 1
  elif item == "WA":
    wa += 1
  elif item == "TLE":
    tle += 1
  else:
    re += 1
    
print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))

Measured memory_bytes: 16332
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int s[5];
  int ans=0;
  int min=10;
  int count=0;
  for(int i=0;i<5;i++){
    scanf("%d",&s[i]);
    if(s[i]%10==0){
      ans+=s[i];
    }else{
      ans+=s[i]+(10-s[i]%10);
    }
    if(s[i]%10!=0){
      count++;
      chmin(&min,s[i]%10);
    }
  }
  if(count==0){
    printf("%d\n",ans);
  }else{
    printf("%d\n",ans-(10-min));
  }
  return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int n;cin >> n;
    set<int> st;
    rep(i,n){
        int a;cin >> a;
        st.insert(a);
    }
    cout << (st.size()==n?"YES":"NO") << endl;
    return 0;
}

Measured memory_bytes: 9600
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		in.close();
		int A = Integer.parseInt(tokens[0]);
		int B = Integer.parseInt(tokens[1]);
		int K = Integer.parseInt(tokens[2]);
		Set<Integer> vals = new HashSet<>();
		for (int i = A; i < A + K; ++i) {
			if (i > B) {
				break;
			}
			vals.add(i);
		}
		for (int i = B; i > B - K; --i) {
			if (i < A) {
				break;
			}
			vals.add(i);
		}
		List<Integer> results = new ArrayList<>(vals.size());
		results.addAll(vals);
		Collections.sort(results);
		for (Integer result : results) {
			System.out.println(result);
		}

	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
using namespace std;

int main(){
    string s;
    cin >> s;
    string ans = "Yes";
    int size = s.length();
    int min = 0;
    int max = size-1;
    while(min <= max){
        if(s[min] != s[max]){
            ans = "No";
            break;
        }
        min ++;
        max --;
    }
    if(ans == "Yes"){
        min = 0;
        max = (size-3)/2;
        while(min <= max){
        if(s[min] != s[max]){
            ans = "No";
            break;
        }
        min ++;
        max --;
    }
    }
    if(ans == "Yes"){
        min = (size+1)/2;
        max = size-1;
        while(min <= max){
        if(s[min] != s[max]){
            ans = "No";
            break;
        }
        min ++;
        max --;
    }
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
char a[10000],i;
while(scanf("%s",a)!=EOF){
for(i=0;a[i];i++){
    a[i]=a[i]-3;
    if(a[i]<'A'){
        a[i]=a[i]+26;
    }
}
printf("%s\n",a);
}
return 0;
}

Measured memory_bytes: 956
#include <iostream>

using namespace std;

int a[1000000],n;

int binarysearch(int key)
{
    int left = 0;
    int right = n;
    int mid;

    while(left<right)
    {
        mid = (left + right)/2;

        if(key == a[mid])  //keyを発見
        {
            return 1;
        }

        else if(key > a[mid])   //後半を探索
        {
            left = mid + 1;
        }

        else if(key < a[mid])      //前半を探索
        {
            right = mid;
        }
    }
    return 0;
}

int main()
{
    int key,sum = 0,q;

    cin >> n;
    for(int i = 0;i<n;i++){
    cin >> a[i];
    }
    cin >> q;
    for(int i = 0;i<q;i++)
    {
        cin >> key;
        sum += binarysearch(key);

    }

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


Measured memory_bytes: 3500
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] in = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		
		in[0] = in[0] == 1 ? 14 : in[0];
		in[1] = in[1] == 1 ? 14 : in[1];
				
		String res = (in[0] > in[1]) ? "Alice" : in[0] < in[1] ? "Bob" : "Draw"; 
		
		System.out.println(res);		
	}
}


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

int main() {
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int N, M, K=0;
	cin>>N>>M;
	vector<string> A(N+1);
	vector<vector<int>> B(N, vector<int>(M));
	vector<vector<int>> C(N, vector<int>(M));
	rep(i, 0, N) cin>>A[i], A[i]+='#';
	rep(i, 0, M+1) A[N]+='#';
	rep(i, 0, N) {
		int p=0;
		rep(j, 0, M+1) if(A[i][j]=='#') {
			rep(k, p, j) B[i][k]=j-p;
			p=j+1;
		}
	}
	rep(i, 0, M) {
		int p=0;
		rep(j, 0, N+1) if(A[j][i]=='#') {
			rep(k, p, j) C[k][i]=j-p, K=max(K, B[k][i]+j-p-1);
			p=j+1;
		}
	}
	cout<<K;
}

Measured memory_bytes: 39424
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]){
  int x, y, X, Y;
  std::cin >> x >> y >> X >> Y;
  int xt,yt,xf,yf;
  xt = y + X - Y;
  yt = X + Y - x;
  xf = x + xt - X;
  yf = y + (yt - Y);
  std::cout << xt <<" "<< yt <<" "<< xf << " "<<yf << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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



int main() {
    int n;
    while(cin >> n, n){
        array<int, 11> cnt{};
        for (int i = 0; i < n; ++i) {
            int x; cin >> x;
            cnt[x]++;
        }
        int ans = 0;
        while(cnt[1] && cnt[9]) cnt[1]--, cnt[9]--, ans++;
        while(cnt[2] && cnt[8]) cnt[2]--, cnt[8]--, ans++;
        while(cnt[3] && cnt[7]) cnt[3]--, cnt[7]--, ans++;
        while(cnt[4] && cnt[6]) cnt[4]--, cnt[6]--, ans++;
        while(cnt[5] >= 2) cnt[5] -= 2, ans++;
        vector<pair<int, int>> v;
        for (int i = 1; i < 9; ++i) if(cnt[i]) v.emplace_back(cnt[i], i);
        while(v.size() < 5) v.emplace_back(0, 0);
        using A = array<char, 5>;
        A x;
        for (int i = 0; i < v.size(); ++i) x[i] = v[i].first;
        vector<A> ok;
        for (char i = 0; i <= v[0].first; ++i) {
            for (char j = 0; j <= v[1].first; ++j) {
                for (char k = 0; k <= v[2].first; ++k) {
                    for (char l = 0; l <= v[3].first; ++l) {
                        for (char m = 0; m <= v[4].first; ++m) {
                            if(i*v[0].second+j*v[1].second+k*v[2].second+l*v[3].second+m*v[4].second == 10) ok.emplace_back(A{i, j, k, l, m});
                        }
                    }
                }
            }
        }
        map<A, int> dp;
        auto dfs = [&](A x, int dep, auto &&f) -> int {
            if(dp.count(x)) return dp[x];
            int ret = dep;
            for (int i = 0; i < ok.size(); ++i) {
                A y;
                for (int j = 0; j < 5; ++j) y[j] = x[j]-ok[i][j];
                if(*min_element(y.begin(),y.end()) >= 0) ret = max(ret, f(y, dep+1, f));
            }
            return dp[x] = ret;
        };
        cout << dfs(x, ans, dfs) << "\n";
    }
    return 0;
}


Measured memory_bytes: 6268
<?php
list($all_types, $buy_types) = explode(' ', trim(fgets(STDIN)));
$price_array = explode(' ', trim(fgets(STDIN)));

sort($price_array);

$price = 0;
for ($i = 0; $i < (int)$buy_types; $i++) {
    $price += (int)$price_array[$i];
}

echo $price;

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

int BubbleSort(int A[], int N){
	int sw = 0;
	bool flag = 1;
	for(int i = 0; flag; i++){
		flag = 0;
		for(int j = N-1; j >= i +1; j--){
			if(A[j] < A[j-1]){
				swap(A[j], A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;	
}

int main(){
	int N,sw;
	int A[100];
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];
	sw = BubbleSort(A, N);
	for(int i = 0; i < N; i++){
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int
main(int argc, char *argv[])
{
  int n, a[100];
  scanf("%d", &n);
  rep(i, n) scanf("%d", &a[i]);

  int cnt = 0, temp, min;

  for(int i = 0; i < n; i++){
    min = i;
    for(int j = i; j < n; j++){
      if(a[j] < a[min]) min = j;
    }
    if(min != i){
      temp = a[i];
      a[i] = a[min];
      a[min] = temp;
      cnt++;
    }
  }
  rep(i, n) {
    printf("%d", a[i]);
    if(i < n - 1) printf(" ");
  } endl;
  printf("%d", cnt); endl;

  return 0;
}



Measured memory_bytes: 2128
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
n, m = lr()
X = np.array(lr())
Y = np.array(lr())
coef_x = np.arange(n)*2 - (n-1)
xsum = (X * coef_x % MOD).sum() % MOD
coef_y = np.arange(m)*2 - (m-1)
ysum = (Y * coef_y % MOD).sum() % MOD
answer = xsum * ysum % MOD
print(answer)


Measured memory_bytes: 24044
a, b, c = map(int, input().split())
hist = []

ans = 'NO'
for i in range(1, b+1):
  mod = (a*i) % b
  if mod == c:
    ans = 'YES'
    break
  elif mod in hist:
    break
  hist.append(mod)
    
print(ans)

Measured memory_bytes: 9044
import math
import collections
import bisect
from copy import copy, deepcopy


def main():
    H, W, K = map(int, input().split())
    c = [None] * H
    for i in range(H):
        c[i] = list(input())

    ans = 0
    for i in range(2**(H)):
        c_ = deepcopy(c)
        for j in range(H):
            if((i >> j) & 1):
                for k in range(W):
                    c_[j][k] = "."
        for j in range(2**(W)):
            c__ = deepcopy(c_)
            for k in range(W):
                if((j >> k) & 1):
                    for l in range(H):
                        c__[l][k] = "."
            if K == sum(list(map(lambda x: x.count("#"), c__))):
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9632
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int H=in(),W=in();
	int white = 0;
	vector<vector<int>> M(H,vector<int>(W,0));
	REP(i,H){
		REP(j,W){
			char c = in<char>();
			if(c=='.'){
				M[i][j] = 1;
				white++;
			}
		}
	}
	queue<pair<int,int>> q;
	set<int> flag;
	q.emplace(0,0);
	flag.insert(0);

	int dist=-1;
	while(!q.empty()){
		auto p = q.front();
		q.pop();
		int u = p.first%W,v = p.first/W;
		if(u>0 && M[v][u-1]){
			if(v==H-1 && u-1==W-1){
				dist = p.second+1;
				break;
			}
			int w = u-1+v*W;
			auto res = flag.emplace(w);
			if(res.second){
				q.emplace(w,p.second+1);
			}
		}
		if(u<W-1 && M[v][u+1]){
			if(v==H-1 && u+1==W-1){
				dist = p.second+1;
				break;
			}
			int w = u+1+v*W;
			auto res = flag.emplace(w);
			if(res.second){
				q.emplace(w,p.second+1);
			}
		}
		if(v>0 && M[v-1][u]){
			if(v-1==H-1 && u==W-1){
				dist = p.second+1;
				break;
			}
			int w = u+(v-1)*W;
			auto res = flag.emplace(w);
			if(res.second){
				q.emplace(w,p.second+1);
			}
		}
		if(v<H-1 && M[v+1][u]){
			if(v+1==H-1 && u==W-1){
				dist = p.second+1;
				break;
			}
			int w = u+(v+1)*W;
			auto res = flag.emplace(w);
			if(res.second){
				q.emplace(w,p.second+1);
			}
		}
	}
	
	cout << (dist==-1 ? -1 : white-dist-1) << endl;
	return 0;
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;

    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }

    sort(d.begin(), d.end());

    int middle1 = d.size() / 2 - 1; 
    int middle2 = middle1 + 1;

    if(d.at(middle1) != d.at(middle2)){
        cout << d.at(middle2) - d.at(middle1) << endl;
    }
    else {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/agc043/tasks/agc043_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

VL dx = {0, 1};
VL dy = {1, 0};

void solve() {
  ll H, W;
  cin >> H >> W;

  char BL = '#';
  char WH = '.';

  V<string> mat(H);
  rep(i, H) cin >> mat[i];

  VVL black_acc_ct_mat(H, VL(W, INF));
  black_acc_ct_mat[0][0] = mat[0][0] == BL ? 1 : 0;

  rep(h, H) rep(w, W) {
    rep(i, dx.size()) {
      ll nw = w + dx[i];
      ll nh = h + dy[i];
      unless(nw < W && nh < H) continue;

      chmin(black_acc_ct_mat[nh][nw],
            black_acc_ct_mat[h][w] +
                (mat[h][w] == WH && mat[nh][nw] == BL ? 1 : 0));
    }
  }

  cout << black_acc_ct_mat[H - 1][W - 1] << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

using namespace std;

#define pb push_back

int n, l, ans, mn = 9999;
vector<int> v;
char c[205];
string s;

int main(){

    cin >> s;

    for(char i = 'a'; i <= 'z'; ++i){
        v.clear();
        n = 0;
        for(int j = 0; j < s.size(); ++j){
            if(s[j] == i) {v.pb(n); n = 0; l = j;}
            else n++;
        }
        l = s.size() - l - 1;
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        n = l;
        ans = l;
        for(int r = 0; r < v.size(); ++r){
            ans = max(v[r], ans);
        }
        if(s.find(i) < s.size()) mn = min(mn, ans);
    }

    //whbrjpjyhsrywlqjxdbrbaomnw
    
    cout << mn;

    return 0;

}


Measured memory_bytes: 256
// --------------
// Tejas Pandey  |
// 24 - 11 - 19  |
// ABC #146      |
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		int n;
		cin >> n;
		char wd[26];
		for(int i = 0;i < 26;i++)
			wd[i] = (char)('A' + i);
		string s;
		cin >> s;
		for(int i = 0;i < s.size();i++){
			int f = (s[i] - 'A');
			f += n;
			f %= 26;
			s[i] = wd[f];
		}
		cout << s << "\n";
	}
	return 0;
}

Measured memory_bytes: 256