akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner c = new Scanner(System.in);
        int vertexNum = c.nextInt();
        int edgeNum = c.nextInt();
        int[][] edges = new int[edgeNum][2];
        for (int i = 0; i < edgeNum; i++) {
            edges[i][0] = c.nextInt();
            edges[i][1] = c.nextInt();
        }
        c.close();
        System.out.println(new Main().isCycleExisted(edges, vertexNum) ? 1 : 0);
    }

    public boolean isCycleExisted(int[][] edges, int vertexNum) {
        ArrayList<LinkedList<Integer>> graph = this.getGraph(edges, vertexNum);
        Set<Integer> visited = new HashSet<Integer>();
        for (int entrance = 0; entrance < vertexNum; entrance++) {
            if (isCycleExisted(entrance, graph, new HashSet<Integer>(), visited)) {
                return true;
            }
        }
        return false;
    }

    private boolean isCycleExisted(int vertexIndex, ArrayList<LinkedList<Integer>> graph, Set<Integer> parents,
            Set<Integer> visited) {
        if (visited.contains(vertexIndex)) {
            return false;
        } else if (parents.contains(vertexIndex)) {
            return true;
        }
        parents.add(vertexIndex);
        LinkedList<Integer> dependencies = graph.get(vertexIndex);
        for (Integer dependency : dependencies) {
            if (isCycleExisted(dependency, graph, parents, visited)) {
                return true;
            }
        }
        parents.remove(vertexIndex);
        visited.add(vertexIndex);
        return false;
    }

    /**
     * 
     * @param edges
     * @param vertexNum
     */
    private ArrayList<LinkedList<Integer>> getGraph(int[][] edges, int vertexNum) {
        // initialize graph & set to be not null
        ArrayList<LinkedList<Integer>> graph = new ArrayList<LinkedList<Integer>>(vertexNum);
        for (int i = 0; i < vertexNum; i++) {
            graph.add(new LinkedList<Integer>());
        }
        // create the graph
        for (int i = 0; i < edges.length; i++) {
            graph.get(edges[i][0]).add(edges[i][1]);
        }
        return graph;
    }
}

Measured memory_bytes: 32628
x, y = map(int, input().split())

A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]

if x in A and y in A:
    print("Yes")
elif x in B and y in B:
    print("Yes")
elif x in C and y in C:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;

const int mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}

int main(void){
    ll I, O, T, J, L, S, Z; cin >>I>>O>>T>>J>>L>>S>>Z;
    ll ans = O;
    if(I == 0){
        cout << ans + J/2*2 + L/2*2 << endl;
        return 0;
    }
    if(J == 0){
        cout << ans + I/2*2 + L/2*2 << endl;
        return 0;
    }
    if(L == 0){
        cout << ans + J/2*2 + I/2*2 << endl;
        return 0;
    }
    if(I%2+J%2+L%2 == 3){
        cout << ans + I+J+L << endl;
        return 0;
    }
    if(I%2+J%2+L%2 == 2){
        cout << ans + I/2*2 + J/2*2 + L/2*2 + 1 << endl;
        return 0;
    }
    cout << ans + I/2*2 + J/2*2 + L/2*2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	sort(begin(s),end(s));
	sort(begin(t),end(t));
	reverse(begin(t),end(t));
	if(s<t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
int add(int a,int b){
	return (a + b)%mod;
}
int sub(int a,int b){
	return add(a,mod - 1);
}
int mul(int a,int b){
	return (a*b)%mod;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    int x = k - a%k;
    bool done = false;
    for(int i = 1;i*k <= b; ++i){
    	if(i*k >= a){
    		done = true;
    		// cout << i*k;
    		break;
    	}
    }
    if(done){
    	cout << "OK";
    }else{
    	cout << "NG";
    }
}

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

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  int s1 = a*b;
  int s2 = c*d;
  if(s1>=s2) cout << s1 << endl;
  else if(s1<s2) cout << s2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int n;
  int num = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int l, r;
    std::cin >> l >> r;
    num += r - l + 1;
  }
  std::cout << num << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,p;
  cin >> N;
  int count;
  for (int i = 0; i < N; i++){
    cin >> p;
    if (i + 1 != p) count++;
  }
  cout << (count == 0 || count == 2 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
const int N=1<<21,MOD=1e9+7;
ll dp[N];
int a[21][21];
int main(){
	cin>>n;
	for (int i=0;i<n;i++) for (int j=0;j<n;j++) scanf ("%d",&a[i][j]);
	dp[0]=1;
	for (int i=0;i<(1<<n);i++){
		int c=0;
		for (int j=0;j<n;j++) if (i&(1<<j)) c++;
		for (int j=0;j<n;j++) if (~i&(1<<j)) if (a[c][j]) dp[i+(1<<j)]=(dp[i+(1<<j)]+dp[i])%MOD;
	}
	cout<<dp[(1<<n)-1];
}

Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#define move move1
#define int long long
using namespace std;
const int N=4e5+2;
const int inf=1e18;
vector<int> lis[N],damn;
int ar[N],move[N][65];
bool cnt[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k=0,l=0,num;
	cin>>n>>num;
	for(i=0;i<n;i++){
		cin>>ar[i];
		lis[ar[i]].push_back(i);		
	}
	for(i=1;i<=2e5;i++){
		for(j=0;j<lis[i].size();j++){
			if(j==lis[i].size()-1){
				move[lis[i][j]][0]=lis[i][0]+n-lis[i][j]+1;
			}
			else{
				move[lis[i][j]][0]=lis[i][j+1]-lis[i][j]+1;
			}
		}
	}
	for(i=1;i<=60;i++){
		for(j=0;j<n;j++){
			move[j][i]=move[j][i-1]+move[(j+move[j][i-1])%n][i-1];
			if(move[j][i]>inf){
				move[j][i]=inf;
			}
		}
	}
	for(i=60;i>=0;i--){
		if(k+move[k%n][i]<num*n){
			k+=move[k%n][i];
		}
	}
	k%=n;
	for(i=k;i<n;i++){
		if(!cnt[ar[i]]){
			cnt[ar[i]]=true;
			damn.push_back(ar[i]);
		}
		else{
			while(true){
				j=damn.back();
				cnt[j]=false;
				damn.pop_back();
				if(j==ar[i]){
					break;
				}
			}
		}
	}
	for(i=0;i<damn.size();i++){
		cout<<damn[i]<<' ';
	}
}

Measured memory_bytes: 124916
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=100000;

int main(){
    
    int n;
    int m;
    int ans=0;
    P p[maxn];
    cin >> n>>m;
    
    rep(i,m){
        cin >> p[i].second >> p[i].first;
        p[i].second--;p[i].first--;
    }
    
    sort(p,p+m);
    ans++;
//    rep(i,m){
//        cout << p[i].first << ' '<<p[i].second<<endl;
//    }
    int mostr=p[0].first;
    for(int i=1;i<m;i++){
        int r = p[i].first,l = p[i].second;
        if(mostr<=l){
            ans++;
            mostr= r;
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  int N;    // input
  int x;    // input
  int ans;  // output

  int i;    // subscript
  int count;


  /* Input, Array_Proclamation */
  cin >> N >> x;
  vector<int> a(N);


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


  /* Initialize */
  ans = 0;
  count = 0;


  /* Calculation */
  sort( all(a) );

  for(i=0; i<N; i++)
  {

    x -= a.at(i);
    count++;
    
    if(x < 0)
    {
      break;
    }

  }
  
  if(x != 0)
  {
    count--;
  }

  /* Output */
  cout << count << endl;


  return 0;

}


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

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=1000+5,U=5000+5;
int fa[N],x1[N],x2[N];
vector<int>lk[N];
int dp[U];

int main()
{
	//freopen("1.in","r",stdin);
	int n;
	cin>>n;
	rep(i,2,n){cin>>fa[i];lk[fa[i]].push_back(i);}
	rep(i,1,n)cin>>x1[i];
	per(x,n,1)
	{
		int u=x1[x];
		rep(i,0,u)dp[i]=0;
		int sum=0;
		for(auto y:lk[x])sum+=min(x1[y],x2[y]);
		if(sum>u)
		{
			puts("IMPOSSIBLE");
			exit(0);
		}
		for(auto y:lk[x])
		{
			int a=x1[y],b=x2[y];
			if(a<b)swap(a,b);
			per(i,u,a)dp[i]=min(dp[i-a]+b,dp[i-b]+a);
			per(i,a-1,b)dp[i]=dp[i-b]+a;
			per(i,b-1,0)dp[i]=U;
		}
		x2[x]=min(U,dp[u]);
	}
	puts("POSSIBLE");
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
const int INF2=1e9+5;
int main()
{
    int n;
   cin>>n;
    vector<int> h(n),dp(n,INF2);
    rep(i,0,n)cin>>h[i];
  dp[0]=0;
    rep(i,0,n)
    {
        for(int j: {i+1,i+2}){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long n;
  cin >> n;
  long t;
  vector<long> v;
  long long ans = 0;
  long minus = 0;
  long minn = powl(10 , 9) ;
  for ( int i = 0; i < n ; i++){
      cin >> t;
      if (t < 0){
        minus += 1;
        ans -= t;
        minn = min(minn , -t);
      }else{
        ans += t;
        minn = min(minn , t);
      }
  }
  if (minus % 2 == 1){
    ans -= (minn * 2);
  }
  cout << ans <<  endl;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cstring>
using namespace std;

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

int main() {
  int n; scanf("%d", &n);
  char a[110], b[110], c[110]; scanf("%s %s %s", a, b, c);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i] && b[i] == c[i]) ans += 0;
    else if (a[i] == b[i]) ans++;
    else if (a[i] == c[i]) ans++;
    else if (b[i] == c[i]) ans++;
    else ans += 2;
  }
  printf("%d\n", ans);
  return 0;
}
	

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    double n, k;
    cin >> n >> k;

    int up = k, dn;
    int t = 1;
    double wariai = 0;

    if (n >= k) wariai += double(n - k + 1) / n;

    while (up != 1) {
        dn = (up + 1) / 2;
        int cnt = 0;
        For(i, dn, up - 1) {
            if (i <= n)
                cnt++;
            else
                break;
        }
        wariai += double(cnt) / n * pow(0.5, t);

        up = dn;
        t++;
    }
    cout << setprecision(12) << wariai << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
x=1
for i in range(n):
    x*=(i+1)
    if x>10**9+7:
        x=x%(10**9+7)

print(x)
#import numpy as np
#n=int(input())
#print(np.prod([i+1 for i in range(n)]))
#print(np.prod([i+1 for i in range(n)])%((10**9)+7))

#オーバーフロー？


Measured memory_bytes: 2940
#include <stdio.h>

int main(){
    
    int n, m, x;
    
    scanf("%d %d %d", &n, &m, &x);
    
    int vet[n];
    
    for(int i = 0; i < n; i++){
        vet[i] = 0;
    }
    
    int aux;
    
    for(int i = 0; i < m; i++){
        scanf("%d", &aux);
        vet[aux] = 1;
    }
    
    int soma_esq = 0;
    
    for(int i = x; i > 0; i--){
        soma_esq = soma_esq + vet[i];
    }
    
    int soma_dir = 0;
    
    for(int i = x; i <n; i++){
        soma_dir = soma_dir + vet[i];
    }
    
    if(soma_dir > soma_esq){
        printf("%d", soma_esq);
    }
    else{
        printf("%d", soma_dir);
    }
    

    return 0;
}

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

int N,Q;
string s;
vector<char> td;

bool vanish_l(int x)
{
	int pos=x;
	for(int i=0; i<Q; i++)
	{
		char t=td[2*i],d=td[2*i+1];
		if(s[pos]==t)
		{
			if(d=='L')pos--;
			else pos++;
		}
		if(pos==-1)return true;
		if(pos==N)return false;
	}
	return false;
}

bool vanish_r(int x)
{
	int pos=x;
	for(int i=0; i<Q; i++)
	{
		char t=td[2*i],d=td[2*i+1];
		if(s[pos]==t)
		{
			if(d=='L')pos--;
			else pos++;
		}
		if(pos==-1)return false;
		if(pos==N)return true;
	}
	return false;
}

int main()
{
	cin >> N >> Q >> s;
	for(int i=0; i<2*Q; i++)
	{
		char tmp;
		cin >> tmp;
		td.push_back(tmp);
	}
	int left,right,ok,ng;
	ok=-1;
	ng=N;
	while(abs(ng-ok)>1)
	{
		int mid=(ok+ng)/2;
		if(vanish_l(mid))ok=mid;
		else ng=mid;
	}
	left=ok;
	ok=N;
	ng=-1;
	while(abs(ng-ok)>1)
	{
		int mid=(ok+ng)/2;
		if(vanish_r(mid))ok=mid;
		else ng=mid;
	}
	right=ok;
	cout << right-left-1 << endl;
	return 0;
}

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

int h, w, m, a, b, maxH, maxW;
set<pair<int, int>> S;
vector<int> VmaxH, VmaxW;


int main() {
    cin >> h >> w >> m;
    vector<pair<int, int>> Vh (300005);
    vector<pair<int, int>> Vw (300005);
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        S.insert({a, b});
        Vh[a].second = a;
        Vw[b].second = b;
        Vh[a].first++;
        Vw[b].first++;
    }

    sort(Vh.begin(), Vh.end());
    reverse(Vh.begin(), Vh.end());
    sort(Vw.begin(), Vw.end());
    reverse(Vw.begin(), Vw.end());

    maxH = Vh[0].first;
    maxW = Vw[0].first;

    for (auto e : Vh) {
        if (e.first == maxH) {VmaxH.push_back(e.second);}
        else {break;}
    }

    for (auto e : Vw) {
        if (e.first == maxW) {VmaxW.push_back(e.second);}
        else {break;}
    }

    int sol = maxH + maxW - 1;

    for (int i = 0; i < VmaxH.size(); i++) {
        for (int j = 0; j < VmaxW.size(); j++) {
            a = VmaxH[i];
            b = VmaxW[j];
            if (S.count({a, b}) == 0) {
                cout << sol + 1 << endl;
                return 0;
            }
        }
    }

    cout << sol << endl;
}


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

int main(){
	int n,ans=0,cnt;
	string a,b,c;
	cin>>n>>a>>b>>c;
	for(int i=0; i<n; i++){
		cnt=0;
		if(a[i]==b[i])cnt++;
		if(b[i]==c[i])cnt++;
		if(c[i]==a[i])cnt++;
		
		if(cnt==3);
		if(cnt==1)ans++;
		if(cnt==0)ans+=2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
int main(){
  ll n;
  cin>>n;
  ll a1=1;
  ll a2=1;
  ll a3=1;
  while(n--){
  	a1 = (a1*10)%M; 
  	a2 = (a2*9)%M;
  	a3 = (a3*8)%M;
  }
  ll ans = (a1+a3)%M;
  ans = ans - ((2*a2)%M);
  if(ans<0){
  	ans = ans + M;
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int flag =0;
    while(flag!=1 && n!=0){
        int r = n%10;
        n= n/10;
        if(r==7){
            flag =1;
            break;
        }
    }
    if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

typedef long long ll;

#define MAX_N 10000

struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P;

Graph G;
void dfs(int v, vector<bool>& seen, int& res)
{
    bool end = true;
    for (int i = 0; i < seen.size(); i++)
        if (!seen[i] && i != v) // iにまだ行ってない&&次のvがiではない
            end = false;
    if (end) {
        ++res;
        return;
    }

    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv])
            continue;
        dfs(nv, seen, res);
    }
    seen[v] = false;
}
int main()
{
    int N, M;
    cin >> N >> M;
    G.assign(N, vector<int>());
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<bool> seen(N, false);
    int res = 0;
    dfs(0, seen, res);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 X;
  cin >> X;
  cout << 10 - X / 200 << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

int main() {

	long N;
	cin >> N;

	long h;
	cin >> h;

	long min = h;
	bool jdg = true;
	for (int i = 1; i < N; i++) {
		cin >> h;
		if (min <= h) {
			min = max(min, h - 1);
		}
		else {
			jdg = false;
		}
	}

	if (jdg == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

func main() {
	m := map[string]int{
		"maerd":   1,
		"remaerd": 2,
		"esare":   3,
		"resare":  4,
	}

	var s string
	fmt.Scan(&s)
	s2 := reverse(s)

	for i := 0; i < len(s2); {
		found := false
		for k, _ := range m {
			if len(s2) < i+len(k) {
				continue
			}
			if s2[i:i+len(k)] == k {
				found = true
				i += len(k)
				break
			}
		}
		if !found {
			fmt.Printf("NO\n")
			return
		}
	}
	fmt.Printf("YES\n")
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000001
#define VMAX 20000

int main() {

	unsigned short *A, *B;

	int C[VMAX + 1], n, i;
	scanf("%d", &n);

	A = (unsigned short*)malloc(sizeof(short) * n + 1);
	B = (unsigned short*)malloc(sizeof(short) * n + 1);

	for (i = 0; i <= VMAX; i++) C[i] = 0;

	for (i = 0; i < n; i++) {
		scanf("%hu", &A[i+1]);
		C[A[i+1]]++;
	}

	for (i = 1; i <= VMAX; i++) C[i] += C[i-1];

	for (i = 1; i <= n; i++) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

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

	free(A);
	free(B);

	return 0;
}


Measured memory_bytes: 10248
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; ++i)
#define per(i, a, n)  for(int i=n-1; i>=a; --i)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007
using namespace std;
typedef long long ll;

int dp[101][4][4][4];

int main(){
  int N;  cin >> N;
  dp[0][3][3][3] = 1;

  rep(len, 0, N){
    rep(c1, 0, 4){
      rep(c2, 0, 4){
        rep(c3, 0, 4){
          if(dp[len][c1][c2][c3] == 0)  continue;
          rep(a, 0, 4){
            if(a==2 and c1==1 and c2==0) continue;
            if(a==2 and c1==0 and c2==1) continue;
            if(a==1 and c1==2 and c2==0) continue;
            if(a==2 and c1==1 and c3==0) continue;
            if(a==2 and c2==1 and c3==0) continue;

            dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
            dp[len+1][a][c1][c2] %= INF;
          }
        }
      }
    }
  }

  int ans = 0;
  rep(c1, 0, 4){
    rep(c2, 0, 4){
      rep(c3, 0, 4){
        ans += dp[N][c1][c2][c3];
        ans %= INF;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int ans = 0;
  string S,T;
  cin >> S >> T;
  for(int i=0;i<S.size();++i){
    if(S.at(i) != T.at(i)){
      ans += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<ll > vecll;
typedef vector<vector<int > > vec2int;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  int n; cin >> n;
  vecll a(n,0);
  REP(i,n){
    cin >> a[i];
    a[i] -= (ll)(i + 1);
  }
  sort(all(a));
  ll med;
  if(n%2 == 1){
    med = a[n/2];
  }else{
    med = a[n/2 - 1] + a[n/2];
    med /= 2;
  }
  ll a1 = med - 1;
  ll a3 = med + 1;
  ll ans1, ans2, ans3;
  ans1 = ans2 = ans3 = 0;
  REP(i,n){
    ans1 += abs(a[i] - a1);
    ans2 += abs(a[i] - med);
    ans3 += abs(a[i] - a3);
  }
  cout << min(ans1, min(ans2, ans3)) << endl;
}


Measured memory_bytes: 1792
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
  exit()
if (w-w//3-1)%2==0 or h%2==0:
  x=h*(w//3 +1)-h*(w-w//3-1)//2
else:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1)-min((w-w//3-1),h))//2
if (w-w//3)%2==0 or h%2==0:
  x2=h*(w-w//3)//2-h*(w//3)
else:
  x2=(h*w-h*(w//3)+min((w+w//3),h))//2-h*(w//3)
if (h-h//3-1)%2==0 or w%2==0:
  y=w*(h//3 +1)-w*(h-h//3-1)//2
else:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1)-min((h-h//3-1),h))//2
if (h-h//3)%2==0 or w%2==0:
  y2=w*(h-h//3)//2-w*(h//3)
else:
  y2=(h*w-w*(h//3)+min((h-h//3),h))//2-w*(h//3)
print(min(x,y,x2,y2))



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

string pls(int i){ return ( i==1 ? "+" : "-" ); }

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

    string eq;
    cin >> eq;

  	vector<int> num(4);
  	rep(i,4) num[i] = eq[i]-'0';
  	vector<int> res(3);
  
  	rep(i,1<<3){
      int temp = num[0];
      rep(j,3){
        if(i>>j&1){ res[j] = 1; temp += num[j+1]; }
        else{ res[j] = 0; temp -= num[j+1]; }
      }
      if(temp == 7) break;
    }
  	

  	string ans;
  	rep(i,3) ans = ans + eq[i] + pls(res[i]);
    ans = ans + eq[3] + "=7";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, x float64
	fmt.Scan(&a, &b, &x)
	if a*a*b <= x*2 {
		c := 2 * (b - x/(a*a))
		fmt.Println(math.Atan2(c, a) / math.Pi * 180)
	} else {
		c := x * 2 / (a * b)
		h := x * 2 / (a * math.Sqrt(b*b+c*c))
		w := math.Sqrt(c*c - h*h)
		fmt.Println(math.Atan2(h, w) / math.Pi * 180)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1836
#include<bits/stdc++.h>
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
 
using namespace std;

int main(){
	int a,b,c;
	sccc(a,b,c);
	if(a+b+c>21){
		cout<<"bust";
	}
	else{
		cout<<"win";
	}
 
 
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

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


bool visit(const Graph &g, int v, vector<int> &order, vector<int> &color) {
  color[v] = 1;
  FOR(e, g[v]) {
    if (color[e->dst] == 2) continue;
    if (color[e->dst] == 1) return false;
    if (!visit(g, e->dst, order, color)) return false;
  }
  order.push_back(v); color[v] = 2;
  return true;
}
bool topologicalSort(const Graph &g, vector<int> &order) {
  int n = g.size();
  vector<int> color(n);
  REP(u, n) if (!color[u] && !visit(g, u, order, color))
    return false;
  reverse(ALL(order));
  return true;
}

int main() {
  int N, M; cin>>N>>M;
  Graph g(N), gr(N);
  REP(i,N-1+M) {
    int A, B; cin>>A>>B;
    A--, B--;
    g[A].push_back(Edge(A, B, 1));
    gr[B].push_back(Edge(B, A, 1));
  }
  vector<int> order(N), rev(N), ans(N);
  topologicalSort(g, order);
  REP(i,N) {
    rev[order[i]] = i;
    //    cout << i << " " << order[i] << endl;
  }
  REP(i,N) {
    int p = order[i];
    if(gr[p].empty()) ans[p] = -1;
    else {
      int idx = -10000, val = -10000;
      REP(j, gr[p].size()) {
	int q = gr[p][j].dst;
	if(rev[q] > val) {
	  val = rev[q]; idx = q;
	}
      }
      ans[p] = idx;
    }
  }
  REP(i,N) {
    //    cout << i << " " << ans[i] << endl;
    cout << ans[i]+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 17520
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B;
	cin>>A>>B;
	if (B==1){
		cout<<0<<endl;
		return 0;
	}
	if (A>=B){
		cout<<1<<endl;
		return 0;
	}
	int ans=1;
	int i=A;
	while (i<B){
		ans++;
		i+=A-1;
	}

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

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

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> p(n, vector<int>(d));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < d; j++)
            cin >> p[i][j];
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int tmp = 0;
            for(int k = 0; k < d; k++) {
                tmp += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
            }
            for(int k = 1; k <= tmp; k++) {
                if (k * k == tmp) {
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll dp[200010][5];

int main(){
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i, n){
        rep(j, 5) {
            if (s[i] != '?') dp[i+1][j] += dp[i][j];
            else dp[i+1][j] += dp[i][j] * 3;
            dp[i+1][j] %= MOD;
        }
        if (s[i] == 'A' || s[i] == '?') dp[i+1][1] += dp[i][0];
        if (s[i] == 'B' || s[i] == '?') dp[i+1][2] += dp[i][1];
        if (s[i] == 'C' || s[i] == '?') dp[i+1][3] += dp[i][2];
        dp[i+1][1] %= MOD, dp[i+1][2] %= MOD, dp[i+1][3] %= MOD;
    }
    cout << dp[n][3] << endl;
    return 0;
}


Measured memory_bytes: 7628
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int main() {
	char c; cin >> c;
	cout << (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ? "vowel" : "consonant") << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
H = gets.split.map &:to_i

dp = []

dp[0] = 0
dp[1] = (H[1] - H[0]).abs

def min(a,b)
  a < b ? a : b
end

2.upto(N-1) do |i|
  a = (H[i] - H[i-2]).abs + dp[i-2]
  b = (H[i] - H[i-1]).abs + dp[i-1]
  dp[i] = min(a, b)
end

p dp.last


Measured memory_bytes: 8908
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    A = list(map(int,input().split()))

    res = 'APPROVED'

    for i in range(N):
        temp = A[i]
        if temp % 2 == 0:
            if (temp%3!=0) & (temp%5!=0):
                res = 'DENIED'
                break

    print(res)



main()


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=998244353;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

const int MAX_N = 300010;

ll modpow(ll a, ll b){
    if(b==0) return 1;
    else if(b%2==0){
        ll d=modpow(a, b/2)%MOD;
        return (d*d)%MOD;
    }
    else{
        return (a*modpow(a, b-1))%MOD;
    }
}

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n<r || r<0) return 0;
    return fact[n]*finv[n-r]%MOD*finv[r]%MOD;
}

ll calc(int n){
    fact[0]=finv[0]=1;
    for(int i=1; i<=n; i++){
        fact[i]=(fact[i-1]*i)%MOD;
        finv[i]=modpow(fact[i], MOD-2);
    }
}

int main(){
    int n, R, B; cin>>n>>R>>B;
    ll k; cin>>k;
    vector<P> usecnt;

    calc(n+5);

    ll ans=0;

    for(ll i=0; i<=n; i++){
        ll sum=k;
        sum -= i*R;
        if(sum % B == 0){
            ans += comb(n, i) * comb(n, sum/B);
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int n,m,a[2*MAXN],b[MAXN],c[2*MAXN],d[MAXN],nx[MAXN],bl[MAXN],ans[MAXN];
int main () {
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {scanf("%d",&a[i]);}
    for (int i=1;i<=n;i++) {scanf("%d",&b[i]);}
    for (int i=n+1;i<=n+n;i++) {a[i]=a[i-n];}
    m=n;
    n=m+m;
    for (int ii=0;ii<30;ii++) {
        memset(bl,0,sizeof(bl));
        int tmp1=0,tmp2=0,flg=0;
        for (int j=1;j<=n;j++) {c[j]=((a[j]>>ii)&1);tmp1+=c[j]*(j<=m);}
        for (int j=1;j<=m;j++) {d[j]=((b[j]>>ii)&1);tmp2+=d[j];}
        if (tmp1==tmp2) {
            nx[1]=0;
            for (int i=2,j=0;i<=m;i++) {
                while (j>0&&d[i]!=d[j+1]) {j=nx[j];}
                if (d[i]==d[j+1]) {j++;}
                nx[i]=j;
            }
            for (int i=1,j=0;i<=n;i++) {
                if (j==m) {j=nx[j];}
                while (j>0&&c[i]!=d[j+1]) {j=nx[j];}
                if (c[i]==d[j+1]) {j++;}
                if (i>=m&&j!=m) {bl[i-m]++;}
            }
            flg=1;
        }
        if (m-tmp1==tmp2) {
            for (int j=1;j<=m;j++) {d[j]^=1;}
            nx[1]=0;
            for (int i=2,j=0;i<=m;i++) {
                while (j>0&&d[i]!=d[j+1]) {j=nx[j];}
                if (d[i]==d[j+1]) {j++;}
                nx[i]=j;
            }
            for (int i=1,j=0;i<=n;i++) {
                if (j==m) {j=nx[j];}
                while (j>0&&c[i]!=d[j+1]) {j=nx[j];}
                if (c[i]==d[j+1]) {j++;}
                if (i>=m&&j!=m) {bl[i-m]++;}
            }
            flg=1;
        }
        if (!flg) {
            return 0;
        }
        if (tmp1==tmp2&&m-tmp1==tmp2) {
            for (int j=0;j<=m;j++) {
                if (bl[j]==2) {ans[j]=1;}
            }
        } else {
            for (int j=0;j<=m;j++) {
                if (bl[j]==1) {ans[j]=1;}
            }
        }
    }
    for (int i=0;i<m;i++) {
        if (!ans[i]) {printf("%d %d\n",i,a[i+1]^b[1]);}
    }
    return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <set>
//#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[200010];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int b[200010] = { 0 };

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

	int cnt = 0;

	int variety = 0;
	for (int i = 0; i <= n; i++) {
		if (b[i])
			variety++;
	}

	int head = 0;
	int sum = 1;
	
	while (variety > k) {
		for (int i = head; i <= n; i++) {
			if (b[i] == sum) {
				b[i] = 0;
				cnt += sum;
				variety--;
				head = i;
				break;
			}
			if (i == n) {
				sum++;
				head = 0;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict
import itertools
d = defaultdict(int)

N, M, X = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])

for i in range(N):
    for j in range(1, M + 1):
        d[j] += L[i][j]

for i in range(M):
    if (d[i + 1] < X):
        print('-1')
        exit()

n = []
for i in range(N):
    n.append(i)

p = []
for i in range(1, N + 1):
    p.append(itertools.combinations(n, i))

ans = []
for v in p:
    for i in v:
        d2 = defaultdict(int)
        for j in range(len(i)):
            for k in range(0, M + 1):
                if (k == 0):
                    d2[0] += L[i[j]][0]
                else:
                    d2[k] += L[i[j]][k]
        count = 0

        for p, q in d2.items():
            if(p == 0):
                continue
            else:
                if(q >= X):
                    count += 1

        if (count == len(d2) - 1):
            ans.append(d2[0])

print(min(ans))


Measured memory_bytes: 9580
#include<stdio.h>


int main(){
	
	int n,m;
	int input[100000];
	int cont;
	int now;
	int max;
	int i;
	
	while(1){
		
		scanf("%d%d",&n,&m);
		if(n==0 && m ==0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf("%d",&input[i]);
		}
		
		now = 0;
		
		for(i=0;i<m;i++){
			now += input[i];
		}
		max=now;
		
		cont = m;
		
		for(i=m;i<n;i++){
			now-=input[i-m];
			now+=input[i];
			
			if(now>max){
				max=now;
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
int N;
int a[100005];
int C[100005];

int geta = 1;

int main(void) {
	cin >> N;

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

	for (int i = 1; i <= N; i++) {
		C[a[i] - 1 + geta]++; C[a[i] + geta]++; C[a[i] + 1 + geta]++;
	}

	int ans = 0;
	for (int i = 0; i <= 100003; i++) {
		if (C[i] > ans) { ans = C[i]; }
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

D = dict()
for i in range(N):
    if A[i] not in D:
        D[A[i]] = 1 
    else:
        D[A[i]] += 1

res = 0
for v in D.values():
    res += v % 2
print(res)

Measured memory_bytes: 16268
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e,f,g;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>b>>c>>d>>e;
    f=b*d+c*e;
    if(d<5) d=5;
    if(e<2) e=2;
    g=b*d+c*e;
    g=g*8;
    g=g/10;
    if(f>g) cout <<g<<'\n';
    else cout <<f<<'\n';
  }
  return (0);
}



Measured memory_bytes: 3208
#include <iostream>
#include <bits/stdc++.h>
#include <string.h>

using namespace std;

const int N=1e9+7;
int a[10000];

int main()
{
    long long int n,i,j,o,r,num=1;
    scanf("%lld",&n);
    o=sqrt(n)+1;
    bool*pr=(bool*)calloc(n+10,sizeof(bool));
    pr[0]=false;pr[1]=false;
    for(i=2;i<=n;i++)
    {
        pr[i]=true;
    }
    for(i=2;i<o;i++)
    {
        if(pr[i])
        {
            for(j=i*i;j<=n;j+=i)
            {
                pr[j]=false;
            }
        }
    }
    for(i=0;i<=n;i++)
    {
        a[i]=1;
    }
    for(i=2;i<=n;i++)
    {
        for(j=0;j<=i;j++)
        {
            if(pr[j])
            {
                r=i;
                while(!(r%j))
                {
                    r/=j;
                    a[j]++;
                }
            }
        }
    }
    for(i=0;i<=n;i++)
    {
        num=num*a[i]%N;
    }
    printf("%lld",num);
    return 0;
}

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

int main(){

 int x;
 cin>>x;

 int h = x / 3600;
 int m = (x / 60) % 60;
 int s = x % 60;
 cout<<h<<":"<<m<<":"<<s<<endl;

 return 0;
}


Measured memory_bytes: 3096
def read_input():
    n, ma, mb = map(int, input().split())

    medicines = []
    for i in range(n):
        a, b, c = map(int, input().split())
        medicines.append((a, b, c))

    return n, ma, mb, medicines


def submit():
    n, ma, mb, medicines = read_input()

    dp = [[[float('inf') for _ in range(400 + 1)] for _ in range(400 + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 0

    for i in range(1, n + 1):
        # 薬品iを足す場合と足さない場合をそれぞれのa, bについて計算
        m = medicines[i - 1]
        for ca in range(401 - m[0]):
            for cb in range(401 - m[1]):
                # 足さない場合
                dp[i][ca][cb] = min(dp[i][ca][cb], dp[i - 1][ca][cb])

                # 足す場合
                dp[i][ca + m[0]][cb + m[1]] = min(dp[i][ca + m[0]][cb + m[1]], dp[i - 1][ca][cb] + m[2])


    cost = float('inf')
    for ca in range(1, 401):
        for cb in range(1, 401):
            if ca*mb == cb*ma:
                if cost > dp[n][ca][cb]:
                    cost = dp[n][ca][cb]

    if cost == float('inf'):
        print(-1)
    else:
        print(cost)
    return



if __name__ == '__main__':
    submit()


Measured memory_bytes: 143452
import sys
import heapq

readline = sys.stdin.readline
n, m = map(int, readline().split())
a = list(map(int, readline().split()))
bc = [list(map(int, readline().split())) for _ in range(m)]
heapq.heapify(a)
bc.sort(key=lambda x: x[1], reverse=True)

for b, c in bc:
    for _ in range(b):
        if a[0] < c:
            x = heapq.heappop(a)
            heapq.heappush(a, c)
        else:
            break
print(sum(a))


Measured memory_bytes: 32920
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename ARR, typename U> void fill_all(ARR& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T>auto&operator<<(ostream&s,const unordered_set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const unordered_map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1LL<<60;
const int MOD = 1e9+7;

signed main()
{
   int N; cin >> N;
   auto a = make_v<int>(N), b = make_v<int>(N);
   for (int i = 0; i < N; ++i) {
      cin >> a[i];
   }
   for (int i = 0; i < N; ++i) {
      cin >> b[i];
   }

   int asum = accumulate(a.begin(), a.end(), 0LL),
       bsum = accumulate(b.begin(), b.end(), 0LL);

   if (bsum < asum) {
      cout << "No" << endl;
      return 0;
   }

   int num = bsum - asum;
   for (int i = 0; i < N; ++i) {
      num -= max((b[i] - a[i] + 1) / 2, 0LL);
   }

   if (num >= 0) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }

   return 0;
}


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

using namespace std;

#define OnlineJudge1

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
#define debug(x) cerr << #x << " = " << (x) << '\n'
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("input.in","r",stdin);
    freopen("output.in","w",stdout);
#endif
}

const int N = 1e4 + 9, M = 105, OO = 0x3f3f3f3f;
const ll llOO = 1e18;


int main(){
    init();

    int n, k;  cin >> n >> k;
    double a[n];
    double sum = 0;
    for(int i = 0;i < n;i++){
        int x;  cin >> x;
        a[i] = x * (x + 1) / 2 * (1.0 / x);
        if(i < k)   sum += a[i];
    }

    double best = sum;
    for(int i = k;i < n;i++){
        sum -= a[i - k];
        sum += a[i];
        best = max(best, sum);
    }

    cout << fixed << setprecision(10) << best;
}




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

int main() {
  long n;
  string ans="Three";
  cin >> n;
  vector<char> s(n);
  for(int i=0;i<n;i++) {
    cin >> s[i];
    if(s[i]=='Y') ans="Four";
  }

  cout << ans << endl;
}

Measured memory_bytes: 256