akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  ll N, K;
  cin >> N >> K;
  ll sum = 0;
  for(int i = 0; i <= N - 2; i++) sum += i;
  sum = max(sum, 0LL);

  // //cerr << sum << " " << K << " " << sum - K << endl;
  if(sum < K) {
    cout << -1 << endl;
    return 0;
  }

  vector<string> ans;
  for(int i = 2; i <= N; i++) {
    ans.push_back("1 " + to_string(i));
  }
  
  int cnt = 0;
  for(int i = 2; i <= N; i++) {
    for(int j = i + 1; j <= N; j++) {
      if(cnt == sum - K) break;
      ans.push_back(to_string(i) + " " + to_string(j));
      cnt++;
    }
  }
  
  cout << ans.size() << endl;
  for(auto m : ans) {
    cout << m << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n,k; cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    int ans=0;
    rep(i,k) ans+=p[i];
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename Container>
ostream &pprint(const Container &a, string_view sep = " ",
                string_view ends = "\n", ostream *os = nullptr) {
  if (os == nullptr) os = &cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  return pprint(a, ",", "", &(os << "[")) << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &a) {
  return pprint(a, ",", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int x = 0;
  REP(i, s.size()) {
    int d = s[i] - '0';
    x = (x + d) % 9;
  }
  cout << (x == 0 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3768
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] di = new int[7];
		
		for(int i = 1; i < 7; i++){
			di[i] = scan.nextInt();
		}
		
		int q = scan.nextInt();
		for(int i = 0; i < q; i++){
			int ue  = scan.nextInt();
			int mae = scan.nextInt();
		
			if((ue==di[1]&&mae==di[2])||(ue==di[2]&&mae==di[6])||(ue==di[6]&&mae==di[5])||(ue==di[5]&&mae==di[1])){
				System.out.println(di[3]);
			}
			if((ue==di[1]&&mae==di[5])||(ue==di[5]&&mae==di[6])||(ue==di[6]&&mae==di[2])||(ue==di[2]&&mae==di[1])){
				System.out.println(di[4]);
			}
			if((ue==di[1]&&mae==di[3])||(ue==di[3]&&mae==di[6])||(ue==di[6]&&mae==di[4])||(ue==di[4]&&mae==di[1])){
				System.out.println(di[5]);
			}
			if((ue==di[2]&&mae==di[4])||(ue==di[4]&&mae==di[5])||(ue==di[5]&&mae==di[3])||(ue==di[3]&&mae==di[2])){
				System.out.println(di[6]);
			}
			if((ue==di[2]&&mae==di[3])||(ue==di[3]&&mae==di[5])||(ue==di[5]&&mae==di[4])||(ue==di[4]&&mae==di[2])){
				System.out.println(di[1]);
			}
			if((ue==di[1]&&mae==di[4])||(ue==di[4]&&mae==di[6])||(ue==di[6]&&mae==di[3])||(ue==di[3]&&mae==di[1])){
				System.out.println(di[2]);
			}
		}
	}
}



Measured memory_bytes: 25924
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int i,j,k,N;
  long long ans,Rn=0,Gn=0,Bn=0;
  cin >> N >> str;
  for (i=0;i<N;i++){
    if (str.at(i)=='R')Rn++;
    if (str.at(i)=='G')Gn++;
    if (str.at(i)=='B')Bn++;
  }
  ans=Rn*Gn*Bn;
  
  for(j=0;j<N;j++){
    for(i=0;i<j;i++){
      k=j+j-i;
      if(k<N){
        if(str.at(i)==str.at(j))continue;
        if(str.at(j)==str.at(k))continue;
        if(str.at(k)==str.at(i))continue;
        ans--;
      }
    }
  }
      
  cout << ans <<endl;
}  

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#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(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector] size: " << A.size() << endl;
    
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N;
    cin >> N;

    vector<ll> x(N);
    vector<ll> y(N);
    
    FOR(i, 0, N){
        cin >> x.at(i);
        y.at(i) = x.at(i);
    }

    sort(ALL(y));

    if(y[N/2] == y[N/2 - 1]){
        ll answer = y[N/2];
        FOR(i, 0, N){
            p(answer);
        }        
    }else{
        // 切り捨てが起こっていることに注意
        ll left = y[N/2 - 1];
        ll right = y[N/2];
        ll center = (left + right) / 2;
        FOR(i, 0, N){
            if(x[i] <= center){
                p(right);
            }else{
                p(left);
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 5376
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
      	int s = a-2*b;
      
      if (s <= 0) {
        System.out.println(0);
      } else {
		System.out.println(s);
      }
	}
}

Measured memory_bytes: 22740
#include<iostream>
#include<cstdlib>
#include<vector>
#include<algorithm>

#define INF (1<<29)

using namespace std;

template<class T>
struct treap{
  struct node_t{
    T val;             //値
    T sum;             //部分木の値の和
    T Min;             //部分木の値の最小値(RMQのため)
    bool rev;          //部分木が反転していることを表すフラグ
    node_t *lch, *rch; //={左,右}
    int pri;           //優先度
    int cnt;           //部分木のサイズ
    node_t(T v, int p):val(v),pri(p),cnt(1),Min(v){
      lch=rch=NULL;
    }
  };
  node_t *root;
  treap():root(NULL){}

  int count(node_t *t){return t?t->cnt:0; }
  T   Minimum(node_t *t){return t?t->Min:INF;}
  T   sum(node_t *t){return !t?0:t->sum;}
  int size(){return count(root);}

  node_t *update(node_t *t){
    t->cnt=count(t->lch)+count(t->rch)+1;
    t->Min=min(min(Minimum(t->lch),Minimum(t->rch)),t->val);
    return t;
  }
  node_t *merge(node_t *l, node_t *r){
    if(!l||!r) return l?l:r;
    if(l->pri>r->pri){
      l->rch=merge(l->rch,r);
      return update(l);
    }
    else{
      r->lch=merge(l,r->lch);
      return update(r);
    }
  }
  pair<node_t*,node_t*> split(node_t *t,int k){
    if(!t) return make_pair((node_t*)NULL,(node_t*)NULL);
    if(k<=count(t->lch)){
      pair<node_t*,node_t*>s=split(t->lch,k);
      t->lch=s.second;
      return make_pair(s.first,update(t));
    }
    else{
      pair<node_t*,node_t*>s=split(t->rch,k-count(t->lch)-1);
      t->rch=s.first;
      return make_pair(update(t),s.second);
    }
  }
  node_t *insert(node_t *t,int k,T val,int pri){
    pair<node_t*, node_t*>s=split(t,k);
    t=merge(s.first, new node_t(val,pri));
    t=merge(t,s.second);
    return update(t);
  }
  node_t *erase(node_t *t,int k){
    pair<node_t*, node_t*>s1,s2;
    s2=split(t,k+1);
    s1=split(s2.first,k);
    t=merge(s1.first,s2.second);
    return update(t);
  }

  node_t *find(node_t *t,int k){
    int c=count(t->lch);
    if(k<c)return find(t->lch, k);
    if(k==c)return t;
    return find(t->rch,k-c-1);
  }

  void insert(int k,T val){root=insert(root,k,val,rand());}
  void erase(int k){root=erase(root,k);}
  node_t *find(int k){return find(root,k);}

  void shift(int l,int r){
    pair<node_t*,node_t*>a,b,c;
    c=split(root,r);
    b=split(c.first,r-1);
    a=split(b.first,l);
    root=merge(a.first,b.second);
    root=merge(root,a.second);
    root=merge(root,c.second);
  }

  int query(int l,int r,node_t *t){
    int sz=count(t);
    if(sz<=l || r<=0)return INF;
    if(l<=0 && sz<=r)return Minimum(t);

    int c=count(t->lch);
    int vl=query(l,r,t->lch);
    int vr=query(l-c-1,r-c-1,t->rch);
    int res=min(vl,vr);
    if(l<=c && c<r)res=min(res,t->val);
    return res;
  }
};

int main(void){

  srand(time(NULL));
  int n,q;
  treap<int> t;

  cin >> n >> q;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    t.insert(i,a);
  }

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

    if(x==0)t.shift(y,z+1);
    else if(x==1)cout << t.query(y,z+1,t.root) << endl;
    else if(x==2){
      t.erase(y);
      t.insert(y,z);
    }
  }

  return 0;
}

Measured memory_bytes: 13704
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  cout << P + Q + R - max({P, Q, R}) << endl;
  return 0;
}


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

void solve(std::string s) {
string rick;
  for(int i = 1;i<=s.size();i++){
    if(i%2)rick+=s[i-1];
  }
  cout<<rick;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
	int p, q, r, min;
	scanf("%d %d %d", &p, &q, &r);
	min = p + q;
	if (min > p + r) {
		min = p + r;
	}
	if (min > q + r) {
		min = q + r;
	}
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long st[3]={127,131,137};
long long mod[3]={(long long)(1e7+7),(long long)(1e7+9),123457};
vector<long long>de[3];
void init(int n)
{
	int i,j;
	for(i=0;i<3;i++)
	{
		de[i].resize(n+1);
		de[i][0]=1;
		for(j=1;j<n+1;j++)
			de[i][j]=(de[i][j-1]*st[i])%mod[i];
	}
}
struct hash3
{
	long long h[3];
	hash3()
	{
		h[0]=h[1]=h[2]=0;
	}
	hash3 add_back(char c)
	{
		int i;
		hash3 ans;
		for(i=0;i<3;i++)
			ans.h[i]=(h[i]*st[i]+c)%mod[i];
		return ans;
	}
	hash3 remove_front(hash3 x,int size)
	{
		int i;
		hash3 ans;
		for(i=0;i<3;i++)
		{
			ans.h[i]=h[i]-(de[i][size]*x.h[i])%mod[i];
			if(ans.h[i]<0)ans.h[i]+=mod[i];
		}
		return ans;
	}
	hash3 operator=(hash3 const &x)
	{
		for(int i=0;i<3;i++)
			h[i]=x.h[i];
		return *this;
	}
	bool operator==(hash3 const &a)
	{
		int i;
		for(i=0;i<3;i++)
			if(this->h[i]!=a.h[i])return 0;
		return 1;
	}
};
vector<hash3>m[123457];
bool fi(hash3 x)
{
	int i;
	for(i=0;i<(int)m[x.h[2]].size();i++)
		if(m[x.h[2]][i]==x)return 1;
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j;
	string s;
	cin>>n>>s;
	init(n+1);
	vector<hash3>v(n+1);
	for(i=0;i<n;i++)
	{
		v[i+1]=v[i].add_back(s[i]);
	}
	for(i=1;i<n;i++)
	{
		for(j=i;j+i-1<=n;j++)
		{
			if(fi(v[j+i-1].remove_front(v[j-1],i)))break;
			hash3 x=v[j].remove_front(v[j-i],i);
			m[x.h[2]].push_back(x);
		}
		if(j+i-1>n)break;
	}
	cout<<i-1<<'\n';
}


Measured memory_bytes: 157568
"use strict"

const { SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER } = require("constants");

const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let s = next()
    let a = 0
    let b = 0
    let c = 0
    for(let i = 0; i<s.length;i++){
        if(s[i] == "a") a++
        if(s[i] == "b") b++
        if(s[i] == "c") c++
    }
    if(Math.abs(a - b) > 1 || Math.abs(b-c) > 1|| Math.abs(c-a) > 1){
        console.log("NO")
    } else {
        console.log("YES")
    }
}
Main()



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

int main(){
  string s;
  int n;
  cin >> n >> s;
  int g;
  g = 0;
  for(int i = 0; i < s.size() - 2; i++){
    if(s[i] == 'A'){
      if(s[i + 1] == 'B' && s[i + 2] == 'C')
        g++;
    }
  }
  cout << g << endl;
}


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

int main() {
	vector<int> array, num(101, 0), out;
	int inp, MAX = 0;
	int flag = 0;
	
	while (cin>>inp)
	{
		array.push_back(inp);
	}
	for (int i = 0; i < array.size(); i++)
	{
		int cnt = 0;
		for (int j = i; j < array.size(); j++)
		{
			if (array[i] == array[j])num[i]++;
		}
	}

	for (int i = 0; i < array.size(); i++)
	{
		for (int j = 0; j < array.size(); j++)
		{
			if (num[i] < num[j]) {
				flag = 1;
				break;
			}
		}
		if (flag != 1) out.push_back(array[i]);		
		flag = 0;
	}
	sort(out.begin(), out.end());
	for (int i = 0; i < out.size(); i++)
	{
		cout << out[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
const char a[3]={'a','b','c'};
int main()
{
	string s;
	bool f;
	cin>>s;
	for(int i=0;i<=2;i++)
	{
		for(int j=0;j<=2;j++)
		if(a[i]==s[j]) f=1;
		if(f==0) 
		{
			cout<<"No";
			return 0;
		}
		f=0;
	}
	cout<<"Yes";
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  set<int> P, M;
  int ans = 0;
  for(int i = 0; i < N; ++i){
    int x, y;
    cin >> x >> y;
    if(i > 0){
      int p_max = *P.rbegin();
      int p_min = *P.begin();
      int m_max = *M.rbegin();
      int m_min = *M.begin();
      ans = max({ans,abs(x+y-p_max),abs(x+y-p_min)});
      ans = max({ans,abs(x-y-m_max),abs(x-y-m_min)});
    }
    P.emplace(x+y);
    M.emplace(x-y);
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 22284
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;

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

    int N, M;
    while (1)
    {
        cin >> N >> M;
        if (N == 0)
            break;
        vector<P> v(N);
        rep(i, N) cin >> v[i].second >> v[i].first;
        sort(all(v)), reverse(all(v));
        int cost = 0, ans = 0;
        rep(i, N)
        {
            int D = v[i].second, P = v[i].first;
            if (cost + D <= M)
            {
                cost += D;
                continue;
            }
            int d = M - cost;
            D -= d;
            ans += D * P;
            cost = M;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3280
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		String[] suit = {"S", "H", "C", "D"};
		int[][] cards = new int[4][13];
		int n =Integer.parseInt(input());

		for (int i = 0; i < n; i++) {

			String pattern = input();
			int number = Integer.parseInt(input());

			for (int j = 0; j < cards.length; j++) {

				if (pattern.equals(suit[j])) {

					cards[j][number - 1] = number;

				}
			}
		}

		for (int k = 0; k < cards.length; k++) {

			for (int l = 0; l < cards[0].length; l++) {

				if (cards[k][l] == 0) {

					System.out.print(suit[k]);
					System.out.print(" ");
					System.out.println(l + 1);

				}
			}
		}

		close();

	}

	public static String input() {

		return scanner.next();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26096
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	 	int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a + b >= c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
  }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"



  
  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
    int a;
    cin >> a;
    if(a%10 == 2 || a%10 == 4 || a%10 == 5 || a%10 == 7 || a%10 == 9){
		cout << "hon";
		
	}
	
	else if(a%10 == 0 || a%10 == 1 || a%10 == 6 || a % 10 == 8){
		cout << "pon";
		
	}
	
	else{
		cout << "bon";
	}
    
	
 }


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int p[100][11];

int bitcount(int x)
{
    x = (x & 0x55555555) + (x >> 1 & 0x55555555);
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = (x & 0x0F0F0F0F) + (x >> 4 & 0x0F0F0F0F);
    x = (x & 0x00FF00FF) + (x >> 8 & 0x00FF00FF);
    x = (x & 0x0000FFFF) + (x >> 16 & 0x0000FFFF);

    return x;
}

int main()
{
    int n;
    cin >> n;

    int shop[100];

    rep(i, n)
    {
        bitset<10> a;
        rep(j, 10)
        {
            int d;
            cin >> d;
            a[j] = d;
        }
        stringstream ss;
        ss << a;
        string s = ss.str();
        shop[i] = stoi(s, 0, 2);
    }
    rep(i, n) rep(j, 11) cin >> p[i][j];

    int ans = -10e8;

    for (int i = 1; i <= 1023; i++)
    {
        int sum = 0;
        rep(j, n)
        {
            int cnt = bitcount(shop[j] & i);
            sum += p[j][cnt];
        }
        ans = max(ans, sum);
    }

    OP(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin >> s;

    map<char,int> cnt;

    for(int i = 0;i < s.size();i++){
        cnt[s[i]]++;
    }

    int a = cnt['a'];
    int b = cnt['b'];
    int c = cnt['c'];

    if(s.size() == 2 && cnt.size() == 2)cout << "YES" << endl;
    else if(s.size() == 1)cout << "YES" << endl;
    else{
        if(cnt.size() == 3 && max({a,b,c}) - min({a,b,c}) <= 1)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int m = n/2;

    int v[n];
    rep(i, n) {
        cin >> v[i];
    }

    int e[m], o[m];     //v[n]の偶数番目(0-index)の項がe[m],奇数番目(0-index)の項がo[m]
    rep(i, m) {
        e[i] = v[2*i];
        o[i] = v[2*i+1];
    }
    sort(e, e+m);
    sort(o, o+m);

    int te = e[0];
    int ke = 0;
    vector<int> ce(m);
    rep(i, m) {
        if(te < e[i]) {
            te = e[i];
            ke++;
            ce[ke]++;
        } 
        else {
            ce[ke]++;
        }
    }

    int to = o[0];
    int ko = 0;
    vector<int> co(m);
    rep(i, m) {
        if(to < o[i]) {
            to = o[i];
            ko++;
            co[ko]++;
        } 
        else {
            co[ko]++;
        }
    }

    sort(ce.begin(), ce.end());
    reverse(ce.begin(), ce.end());
    sort(co.begin(), co.end());
    reverse(co.begin(), co.end());

    int modeE = e[0];  //modeEにはeの最頻値(eにce[0]個ある数)が入る
    int be = 0;
    rep(i, m) {
        if(modeE < e[i]) {
            if(be == ce[0]) {
                break;
            }
            modeE = e[i];
            be = 0;
        }
        be++;
    }

    int modeO = o[0];  //modeOにはoの最頻値(oにco[0]個ある数)が入る
    int bo = 0;
    rep(i, m) {
        if(modeO < o[i]) {
            if(bo == co[0]) {
                break;
            }
            modeO = o[i];
            bo = 0;
        }
        bo++;
    }

    int ans;
    if(modeE != modeO) {  //最頻値が異なる数の場合
        ans = n - (ce[0] + co[0]);
    }
    else {  //最頻値が同じ数の場合
        int u = ce[0] + co[1];
        int v = ce[1] + co[0];
        ans = n - max(u, v);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=924844033;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
int mul(int a,int b){return (ll)a*b%mod;}
int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
const int N=4010;
int n,k;
int vis[N];
int g[N][2];
int f[N];
int fac[N];
int main()
{
	f[0]=1;
	scanf("%d%d",&n,&k);
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	for(int i=1;i<=n;i++)if(!vis[i]){
		//cout<<i<<endl;
		if(i+k>n&&i-k<=0)continue;
		vector<int> pi(1,0);
		int t=i;
		while(t<=n){
			pi.push_back(t);
			vis[t]=1; t+=2*k;
		}
		for(size_t j=0;j<=pi.size();j++)g[j][0]=g[j][1]=0;
		g[0][0]=1;
		for(size_t j=1;j<pi.size();j++){
			int x=pi[j];
		//	cout<<x<<" ::"<<endl;
			for(int p=j;p;p--){
				g[p][0]=add(g[p][0],g[p][1]);//not choosing
				g[p][1]=0;
		//		cout<<p<<": "<<g[p][1]<<" "<<g[p][0]<<endl;
				if(x+k<=n) g[p][1]=add(g[p][1],add(g[p-1][0],g[p-1][1]));
				if(x-k>0) g[p][0]=add(g[p][0],g[p-1][0]);
		//		cout<<p<<": "<<g[p][1]<<" "<<g[p][0]<<endl;
			}
		//	cout<<endl;
		}
//		puts("");
		// cout<<"---< >---"<<endl;
		// cout<<" "<<g[2][1]<<" "<<g[2][0]<<endl;
		for(int i=n;i;i--){
			for(size_t j=1;j<pi.size();j++)if(i-j>=0){
				f[i]=add(f[i],mul(f[i-j],add(g[j][0],g[j][1])));
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++){
//		cout<<f[i]<<" "<<endl;
		f[i]=mul(f[i],fac[n-i]);
		if(i&1){
			ans=sub(ans,f[i]);
		}else{
			ans=add(ans,f[i]);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
using System;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate {
    class Program {
        static void Main (string[] args) {
            string str = Console.ReadLine();         
            char[] cs=str.ToCharArray();

            int sum = 0;

            for(int i=0; i < cs.Length;i++){
                sum += int.Parse(cs[i].ToString());
            }

            Console.WriteLine(sum);
        }
    }

    class MyLibrary {
    
    }
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n;
  cin >> n;
  vll p(n);
  ll count = 0;
  REP(i, n) {
    ll p;
    cin >> p;
    if (p != i + 1) {
      count++;
    }
  }

  if (count == 2 or count == 0) {
    COUT("YES");
  }
  else {
    COUT("NO");
  }
    
}


int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
using namespace std;
long long a[3],ans=1;
int main(){
    cin>>a[0]>>a[1]>>a[2];
    for(int i=0;i<3;i++){
        if(a[i]%2==0){
            cout<<0;
            return 0;
        }
    }sort(a,a+3);
    cout<<a[0]*a[1];
    return 0;
}

Measured memory_bytes: 256
#define E 0.001
#define zero(n)(fabs(n)<E)
main(n,a,b,c,d,p,q,r,D,f){
	for(scanf("%d",&n);n;n--){
		scanf("%d%d%d%d",&a,&b,&c,&d);//fx=ax3+bx2+cx+d
		if(a<0)a=-a,b=-b,c=-c,d=-d;   //won't lose generality
		p=3*a,q=2*b,r=c,D=q*q-4*p*r;  //f'x=3ax2+2bx+c D: f'x=0?
		if(D>0){
			double x1=(-q-sqrt(D))/p/2,x2=(-q+sqrt(D))/p/2;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
			if(!zero(y1)&&!zero(y2)>E&&y1*y2>0)goto one;
			puts(
				zero(x1)?(
					d==0?"1 0":
					"2 1"
				):zero(x2)?(
					d==0?"0 1":
					"1 2"
				):x1>0?(
					d>0?"2 1":
					d<0?"3 0":
					"2 0"
				):x2<0?(
					d>0?"0 3":
					d<0?"1 2":
					"0 2"
				):(
					d>0?"2 1":
					d<0?"1 2":
					"1 1"
				)
			);
		}else if(D==0)puts(
			d>0?"0 1":
			d<0?"1 0":
			"0 0"
		);else{one:
			puts(d>0?"0 1":d<0?"1 0":"0 0");
		}
	}
	exit(0);
}

Measured memory_bytes: 580
#include<stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int prim(void);

int main(){
  int i, j, e;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d", &e);
      if(e == -1)M[i][j] = INFTY;
      else M[i][j] = e;
    }
  }
  printf("%d\n", prim());

  return 0;
}

int prim(){
  int i, j, u, minv, sum=0, d[MAX], p[MAX], color[MAX];

  for(i=0; i<n; i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;
    for(i=0; i<n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(j=0; j<n; j++){
      if(color[j] != BLACK && M[u][j] != INFTY){
	if(d[j] > M[u][j]){
	  d[j] = M[u][j];
	  p[j]=u;
	  color[j] = GRAY;
	}
      }
    }
  }
  for(i=0; i<n; i++){
    if(p[i] != -1)sum += M[i][p[i]];
  }
  return sum;
}



Measured memory_bytes: 2084
#include<stdio.h>
int main()
{
	int const MAXV=100000;
	int input=0;
	do{scanf("%d",&input);}while(input<2||input>100000);
	int buttons[MAXV]={0};
	int times=1;int num=0;
	for(int i=0;i<input;i++)
	{
		do{scanf("%d",&num);}while(num<1||num>input);
		buttons[i]=num;
	}
	int i=buttons[0];
	while(times<input)
	{
		if(i==2)
			break;
		i=buttons[i-1];
		times++;
	}
	if(times<input)
		printf("%d",times);
	else
		printf("-1");
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep3(i, k, n) for (int i = k; i < n; i++)
#define sz(s) (int)s.size()
#define F first
#define S second

int main() {
    int s, t; cin >> s >> t;
    int p, q, M; cin >> p >> q >> M;
    int y; cin >> y;
    cout << (y ^ s ^ t) << endl;
    return 0;
}


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

int main()
{
    string s;
    map<string,int>m;
    map<string,int>:: iterator itr;
    int n,chk1=0,chk2=0;
    cin>>n;
    cin>>s;
    char last=s[s.length()-1];
    m[s]=1;
    for(int i=1; i<n; i++)
    {
        cin>>s;
        m[s]++;
        if(chk1==0)
        {
            if(s[0]==last)
            {
                chk1=0;
            }
            else if(s[0]!=last)
            {
                chk1=1;
            }
            last=s[s.length()-1];
        }
        }
        if(chk1==1)
            cout<<"No";
        else
        {
            for(itr=m.begin();itr!=m.end();itr++){
               if(itr->second>1){
                    chk2=1;
                    break;
                }
            }
            if(chk2==0) cout<<"Yes";
            else cout<<"No";
            }
        return 0;
    }


Measured memory_bytes: 3512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 20000
#define pi M_PI

int main(){
  int n,q,k=0;
  int a[N],b[N];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(int j=0;j<q;j++){
      scanf("%d",&b[j]);
      for(int i=0;i<n;i++){
          if(b[j]==a[i]){
              k++;
              break;
          }
      }
  }
  printf("%d\n",k);
  return 0;
}


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

void solve() {
  string s; cin >> s;
  if(s.size() == 3) swap(s[0], s[2]);
  cout << s << endl;
}

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


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <array>

using namespace std;
using ll = long long;

bool check1(string s){
  if(s=="0")return true;
  else if(s[0]=='0'&& s.size()!=1)return false;
  else if(s.size()>3) return false;
  else {
    if(stoi(s)<=255)return true;
    else return false;
  }
}

int main(){
  string s;
  cin>>s;
  int len=s.size();
  int ans=0;
  for(int i=1;i<len;++i){
    for(int j=i+1;j<len;++j){
      for(int k=j+1;k<len;++k){
        string s1=s.substr(0,i),s2=s.substr(i,j-i), s3=s.substr(j,k-j), s4=s.substr(k,len-k);
        if(check1(s1) &&check1(s2) &&check1(s3) &&check1(s4) )ans++;
        //cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<" "<<endl;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3208
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	}

}

Measured memory_bytes: 22540
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    string s;
    cin>>n>>s;
    int count=0;
    int countmax=0;
    rep(i,n){
        if(s[i]=='I')count++;
        if(s[i]=='D')count--;
        countmax=max(countmax,count);
    }
    cout<<countmax<<endl;
    return 0;
}

Measured memory_bytes: 3584
def main():
    from collections import Counter
    n = int(input())
    A = sorted(list(map(int, input().split())))
    c = Counter(A)
    result = 0
    flag = [True] * (A[-1] + 1)
    for i in A:
        if flag[i]:
            result += 1
            for j in range(2*i, A[-1] + 1, i):
                flag[j] = False
    for k, v in c.items():
        if v > 1:
            if flag[k]:
                result -= v
    print(result)
main()

Measured memory_bytes: 135180
#include<stdio.h>

#define MAX 500000
#define SENTINEL 2000000000
void merge(int A[],int n,int left,int mid,int right);
void mergeSort(int A[],int n,int left,int right);

int L[MAX/2+2],R[MAX/2+2];
int count;

int main(void){
  int A[MAX],n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  mergeSort(A,n,0,n);

  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);

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




void merge(int A[],int n,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  for(int i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
    }
  }

}

void mergeSort(int A[],int n,int left,int right){
  if(left+1<right){
    int mid = (left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}




Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;

int n,m,d[1000],c[1000];
int dp[2000];

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>d[i];
    for(int i=0;i<m;i++)cin>>c[i];

    fill_n(dp,n+1,INF);
    dp[0]=0;

    for(int i=0;i<m;i++){
        for(int j=n-1;j>=0;j--){
            dp[j+1]=min(dp[j+1],dp[j]+d[j]*c[i]);
        }
    }

    cout<<dp[n]<<endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int n,m,h,k;
    while(scanf(" %d %d %d %d", &n, &m, &h, &k),n)
    {
        vector<int> s(n);
        rep(i,n) scanf(" %d", &s[i]);

        vector<pi> e(m);
        rep(i,m)
        {
            scanf(" %d %d", &e[i].se, &e[i].fi);
            --e[i].se;
        }
        sort(all(e));

        vector<int> f(n);
        rep(i,n) f[i]=i;

        vector<pi> sw(m);
        rep(i,m)
        {
            int a=e[i].se;

            sw[i] = pi(f[a],f[a+1]);
            swap(f[a],f[a+1]);
        }

        vector<int> F(n);
        rep(i,n) F[f[i]]=i;

        int sum=0;
        rep(i,k) sum+=s[F[i]];

        int ans=sum;
        rep(i,m)
        {
            int a=sw[i].fi, b=sw[i].se;
            if(a>b) swap(a,b);

            if(a<k && k<=b) ans=min(ans,sum-s[F[a]]+s[F[b]]);
        }

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

Measured memory_bytes: 4428
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))
INF = 1 << 29


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()
K = int_raw()
dp = {}

def rec(ss):
    return 0

def main():
    return re.sub("[^"+S[K-1]+"]","*",S)



print(main())



Measured memory_bytes: 3316
/*
time:
from:
question:
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		if(a%2==0 && a%3!=0 && a%5!=0)
			cout<<"DENIED",exit(0);
	}
	cout<<"APPROVED"; 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,sum=0;
        cin>>n;
        vector<ll>v(n);
        for(int i=0;i<n-1;i++)
        {
            ll a;
            cin>>a;
            v[a-1]++;
        }
        for(int i=0;i<n;i++)
        {
            cout<<v[i]<<" ";
        }
    }
}



Measured memory_bytes: 4764
import sys
sys.setrecursionlimit(10**6)
N, A, B = map(int, input().split())
h = []
for _ in range(N):
    h.append(int(input()))


def check(m):
    cnt = 0
    for i in range(N):
        cnt += max(-(-(h[i]-m*B)//(A-B)), 0)
    return cnt <= m

l = 0
r = 10**9+1
while r-l != 1:
    c = (l+r)//2
    if check(c):
        r = c
    else:
        l = c
print(r)


Measured memory_bytes: 7076
#include<stdio.h>
int main(void) {
	char s[30];
	scanf("%s", s);
	for (int i = 0; s[i] != 0; i++)
	{
		for (int j = i - 1; j >= 0; j--)
		{
			if (s[j] == s[i])
			{
				printf("no");
				goto end;
			}
		}
	}
	printf("yes");
end:
	return 0;
}

Measured memory_bytes: 128
a=list(input())
b=list(input())
frag="EQUAL"
if len(a)!=len(b):
  if len(a)>len(b):
    frag="GREATER"
  else:
    frag="LESS"
else:
  for i in range(len(a)):
    if a[i]>b[i]:
      frag="GREATER"
      break
    elif a[i]<b[i]:
      frag="LESS"
      break
      
print(frag)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace std;
const int N=1e5+3;
int v[N];
int main()
{
#ifdef ONLINE_JUDGE
    FAST;
#endif
    int n,st=-1,l;
    cin>>n>>l;
    lp(i,1,n)
    cin>>v[i];
    lp(i,1,n-1)
    {
        int sum=v[i]+v[i+1];
        if (sum>=l)
            st=i;
    }
    if (st==-1)
        f("Impossible");
    cout<<"Possible\n";
    lp(i,1,st-1)
    cout<<i<<"\n";
    lp2(i,n-1,st+1)
    cout<<i<<"\n";
    cout<<st;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int ans=0;
int cal(int n){
	if(n%2==0){
		ans++;
		n/=2;
		cal(n);
	}
	else return ans;
}
int a[10004];
int main(){
	int n,res=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		res+=cal(a[i]);
		ans=0;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n,k = mi()
#a^-1 (mod P)
mod = 10 ** 9 +7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

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

'''
ここは任意
'''

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

#  これは計算量rでncr mod p を求められる。
def combination2(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

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

def main():
    if k >= n -1:
        ans = combination2(2*n -1,n-1)
        print(ans)
    else:
        ans = 1
        for i in range(1,k+1):
            zero_comb = combination(n,i)
            cou = combination(n-1,n-i-1) * zero_comb % mod
            #print(cou)
            ans = (ans +cou) % mod
        print(ans)
main()


Measured memory_bytes: 81008
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int stand_duration;
  int sleep_duration;
  int cost;
  while(~scanf("%d %d %d",
               &stand_duration,
               &sleep_duration,
               &cost)){
    int current = 0;
    int res = -1;

    int count = 0;
    for(int round = 0; round < 100000 + cost; round++){
      int prev = current;

      current += stand_duration;

      for(int time = prev; time <= current; time++){
        if(time == cost){
          res = count * 60 + cost;
          goto found;
        }
      }

      current += sleep_duration;
      if(current >= 60){
        count++;
        current -= 60;
      }
    }

  found:;
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1188
import sys
N = int(input())
ls = [list(map(int, input().split())) for i in range(N)]
ls.insert(0, [0, 0, 0])
# print(ls)
for i in range(N):
    dist = abs(ls[i+1][1] - ls[i][1]) + abs(ls[i+1][2] - ls[i][2])
    time = ls[i+1][0] - ls[i][0]
    if dist > time or (time - dist) % 2 != 0:
        print("No")
        sys.exit()
print("Yes")

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

using namespace std;

#define lint long long

int main(){
    int N, K;
    cin >> N >> K;
    
    vector<lint> h(N);
    
    for(int i = 0; i < N; ++i){
        cin >> h[i];
    }
    
    sort(h.begin(), h.end());
    
    lint ans = 1000000000;
    
    for(int i = 0; i < N - K + 1; ++i){
        ans = min(ans, h[i + K - 1] - h[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll c = 0;
vector<ll> a(300000), b;
set<ll> p;
ll z;

void dfs(ll x)
{
    if (p.find(x) != p.end() && c > 0)
    {
        z = x;
        return;
    }

    p.insert(x);
    b.push_back(x);
    c++;
    dfs(a[x]);
}

int main(void)
{
    ll n, k;

    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }

    dfs(0);

    ll t = 0;

    for (int i = 0; i < c; i++)
    {
        if (b[i] == z)
        {
            t = i;
            break;
        }
    }

    if (k - t <= 0)
    {
        cout << b[k] + 1 << endl;
        return 0;
    }

    cout << b[((k - t) % (c - t)) + t] + 1 << endl;
}


Measured memory_bytes: 22488