akhauriyash/Code-Regression huggingface dataset:
// C - Switches
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N,M; cin>>N>>M;

	vi S(M);
	for(int m=0; m<M; ++m){
		int k; cin>>k;
		while(k--){ int s; cin>>s; S[m] |= 1<<(s-1); }
	}

	vi P(M); for(int p=0; p<M; ++p) cin>>P[p];

	int all = 1<<N, match_count = 0;
	for(int s=0; s<all; ++s){//s: sw all pattern
		int m;
		for(m=0; m<M; ++m){//S[m]: sw data matching
			int sw = s & S[m];
			int b = 0; while(sw){ if(sw&1) ++b; sw/=2; }//count bit '1'
			if(b%2!=P[m]) break;
		}
		if(m>=M) ++match_count;
	}
	cout<< match_count <<endl;
}

Measured memory_bytes: 256
mod=1000000
n,m=map(int,input().split())
dp=[[0]*5 for _ in range(n)]
dp[0]=[1,1,1,1,0]
a=1
if m==1:print((a<<n)%mod)
else:
    for i in range(1,n):
        dp[i][0]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2]+dp[i-1][4])%mod
        dp[i][1]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2])%mod
        dp[i][2]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2]+dp[i-1][3])%mod
        dp[i][3]=(dp[i-1][0]+dp[i-1][3])%mod
        dp[i][4]=(dp[i-1][2]+dp[i-1][4])%mod
    print(sum(dp[n-1][:4])%mod)

Measured memory_bytes: 7820
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader scan = new BufferedReader (new InputStreamReader(System.in));
        int n = Integer.parseInt(scan.readLine());
        Map<String, String> seq = new HashMap<>();
        for(int x = 0; x < n; x++){
            String check = scan.readLine();
            if(check.startsWith("insert")){
                seq.put(check.substring(7), check.substring(7));
            }
            else{
                if(seq.containsKey(check.substring(5))){
                    System.out.println("yes");
                }
                else{
                    System.out.println("no");
                }
            }
        }
    }
}


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

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int dp[n+5][n+5];
    int a[n+5];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            dp[i][j]=1e18;
    for(int i=0;i<n;i++)
        cin>>a[i],dp[i][i]=a[i];
    int sum[n+5][n+5];
    memset(sum,0,sizeof(sum));
    for(int i=0;i<n;i++)
        for(int j=i;j<n;j++)
            for(int k=i;k<=j;k++)
                sum[i][j]+=a[k];
    for(int i=1;i<n;i++)
        for(int j=0;j+i<n;j++)
            for(int k=j;k<i+j;k++)
            dp[j][i+j]=min(dp[j][i+j],dp[j][k] + dp[k+1][i+j] + sum[j][k] + sum[k+1][i+j]);
    cout<<dp[0][n-1]-sum[0][n-1];
}


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

#define ll long long

ll a[3001][3001], dp[3001][3001][4];

int main()
{
    ll i, j, n, m, k, x, y, v, p, ans;

    cin >> n >> m >> k;

    memset(a, 0, sizeof(a));
    for(i=0; i<k; i+=1)
    {
        cin >> x >> y >> v;
        a[x][y]=v;
    }

    memset(dp, 0, sizeof(dp));

    // for(i=1; i<=n; i+=1)
    // {
    //     for(j=1; j<=m; j+=1)
    //         cout << a[i][j] << " ";
    //     cout << endl;
    // }

    for(i=1; i<=n; i+=1)
    {
        for(j=1; j<=m; j+=1)
        {
            // 0
            for(p=0; p<4; p+=1)
                dp[i][j][0]=max(dp[i][j][0], dp[i-1][j][p]);
            dp[i][j][0]=max(dp[i][j][0], dp[i][j-1][0]);

            // 1
            if(a[i][j]!=0)
            {
                for(p=0; p<4; p+=1)
                    dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][p]+a[i][j]);

                dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][0]+a[i][j]);
            }
            dp[i][j][1]=max(dp[i][j][1], dp[i][j-1][1]);

            // 2
            if(a[i][j]!=0 && dp[i][j-1][1]!=0)
                dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][1]+a[i][j]);

            dp[i][j][2]=max(dp[i][j][2], dp[i][j-1][2]);

            // 3
            if(a[i][j]!=0 && dp[i][j-1][2]!=0)
                dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][2]+a[i][j]);

            dp[i][j][3]=max(dp[i][j][3], dp[i][j-1][3]);
        }
    }

    ans=0;
    for(i=0; i<4; i+=1)
        ans=max(ans, dp[n][m][i]);

    cout << ans << endl;

    // for(p=0; p<4; p+=1)
    // {  
    //     cout << p << endl;
    //     for(i=1; i<=n; i+=1)
    //     {
    //         for(j=1; j<=m; j+=1)
    //             cout << dp[i][j][p] << " ";
    //         cout << endl;
    //     }
    // }
}

Measured memory_bytes: 355424
#include <iostream>
#include<bits/stdc++.h>
#define ll long long

using namespace std;


int main()
{
  ll n,sum=1;
  cin>>n;
  
  vector<ll> v(n);
  for(ll i=0;i<n;i++)
   cin>>v[i];
   if(n==1)
    cout<<sum<<endl;
    else
    {
        ll min=v[0];
        for(ll i=1;i<n;i++)
        {
            if(v[i]<=min)
            {
                sum++;
                min=v[i];
            }
        }
        cout<<sum<<endl;
    }
   
   return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int larger(int a,int b){
 return (a<=b)? b:a;}

int main(){
 int n;
 scanf("%d",&n);
 int a[n],x[n][n-1],y[n][n-1];
 int l,m;
 for(l=0;l<n;l++){
  scanf("%d ",&a[l]);
  for(m=0;m<a[l];m++){
   scanf("%d%d ",&x[l][m],&y[l][m]);
  }}
  
  int b,sb,sc,cnt=0,ans=0,ok=1;
  for(b=0;b<(1<<n);b++){ //正直者の数を仮定
   cnt=0;ok=1;
   for(sb=0;sb<n&ok;sb++){
    if(b&(1<<sb)){//正直者とされたsb人目の証言について吟味
     //printf("b=%d a[sb]=%d\n",b,a[sb]);
     cnt++;
     for(sc=0;sc<a[sb];sc++){//sc個目の証言について吟味
      //printf("b=%d sb=%d sc=%d cnt=%d\n",b,sb,sc,cnt);
     //printf("x[sb][sc]=%d y[sb][sc]=%d\n",x[sb][sc],y[sb][sc]);
      if((b&(1<<(x[sb][sc]-1)))!=(y[sb][sc]<<(x[sb][sc]-1))){
       ok=0;/*puts("NG");*/break;}
     }}}
  
  if(ok==1){
   //printf("b=%d cnt=%d\n",b,cnt);
   ans=larger(ans,cnt);} }
  printf("%d\n",ans);
    
return 0;}

Measured memory_bytes: 128
import sys
from collections import defaultdict

H, W, N = map(int,input().split())
if N ==0:
  print((H-2)*(W-2))
  for i in range(9): print(0)
  sys.exit()
  
ans =[(H-2)*(W-2)]+[0]*9
blacks = defaultdict(int)
for i in range(N):
  a, b = map(int,input().split())
  for dx in [-1,0,1]:
    for dy in [-1,0,1]:
      if 2 <= a+dx <H and 2 <= b+dy <W:
        ans[blacks[(a+dx,b+dy)]]-=1
        ans[blacks[(a+dx,b+dy)]+1]+=1
      blacks[(a+dx,b+dy)]+=1
        
for i in range(10): print(ans[i])

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

int main() {
  int N;
  cin >> N;
  vector<double> a(N);
  int i,k;
  for(i=0;i<N;i++){
    cin >> a.at(i);
  }
  
  double save;
  
  for(i=1;i<N;i++){
    save=a.at(i);
    for(k=i;k>0 && a.at(k-1)>save;k--){
      a.at(k)=a.at(k-1);
      a.at(k-1)=save;
    }
  }
  
  for(i=0;i<N-1;i++){
    a.at(i+1)=(a.at(i)+a.at(i+1))/2.0;
  }
  
  cout << a.at(N-1) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
require 'rational'
while(n=gets.to_i)>0
	a=n.times.map{gets.split.map(&:to_i)}
	l=1;n.times{|i|l*=a[i][0]/l.gcd(a[i][0])}
	b=n.times.map{|i|a[i][1]*l/a[i][0]}
	g=b[0];n.times{|i|g=g.gcd b[i]}
	n.times{|i|p b[i]/g}
end

Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int a,b,k;
  cin>>a>>b>>k;
  REP(i,k){
    if(i%2==0){
      if(a%2==1){
        a--;
      }
      a = a/2;
      b += a;
    }else{
      if(b%2==1){
        b--;
      }
      b = b/2;
      a += b;
    }
  }
  cout<<a<<" "<<b<<endl;

    return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

// ------------------------------------------------------------------------------------------

int N, K;
vec<int> A;
int dp[100][5];

signed main() {
  cin >> N >> K;
  A.resize(N);
  rep (i, N) {
    cin >> A[i];
  }

  int LIM = 45;
  fill(dp[0], dp[100], -1);
  dp[LIM][0] = 0;
  for (int digit = LIM-1; digit >= 0; digit--) {
    int mask = 1LL << digit;

    int flgNum = 0;
    rep (i, N) {
      if (mask & A[i]) flgNum++;
    }

    // ビットを立てない時
    int score0 = flgNum * mask;
    // ビットを立てる時
    int score1 = (N - flgNum) * mask;

    // 1 -> 1
    if (dp[digit+1][1] != -1) {
      int hoge = dp[digit+1][1] + max(score0, score1);
      chmax(dp[digit][1], hoge);
    }

    // 0 -> 1
    if (dp[digit+1][0] != -1) {
      if (mask & K) {
        chmax(dp[digit][1], dp[digit+1][0] + score0);
      }
    }

    // 0 -> 0
    if (dp[digit+1][0] != -1) {
      if (mask & K) {
        chmax(dp[digit][0], dp[digit+1][0] + score1);
      } else {
        chmax(dp[digit][0], dp[digit+1][0] + score0);
      }
    }
  }

  cout << max(dp[0][1], dp[0][0]) << endl;

  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int64 N, L;
  cin >> N >> L;
  int64 res = 0, mini = INF_LL;
  FOR(i, L, L+N) {
    res += i;
    if (abs(i) < abs(mini)) mini = i;
  }
  cout << res-mini << endl;
}


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

    auto clk=clock();
    typedef long long ll;
    typedef long double ld;
    typedef vector<int> vi;
    typedef pair<int,int> pi;
    #define F first
    #define S second
    #define PB push_back
    #define MP make_pair
    #define Mod 1000000007
    #define REP(i,a,b) for (int i = a; i <= b; i++)
    #define all(x) x.begin(),x.end()

    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n; cin>>n;
        int sum=0,ans=0;
        for(int i=0;i<n;i++) {
            int x; cin>>x;
            ans+=(sum*x);
            sum+=x;
        }
        cout<<ans;
        cerr<<"\n"<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<"\n";
        return 0;
    }


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    vector<int> d(26);
    vector<int> dd(26);
    for(int i = 0; i < s.size(); i++)
    {
        char cs = s[i];
        char ts = t[i];
        if(d[cs-97] == 0)
        {
            d[cs - 97] = ts;
        }
        else if(d[cs -97] != ts) 
        {
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = 0; i < s.size(); i++)
    {
        char cs = t[i];
        char ts = s[i];
        if(dd[cs -97] == 0)
        {
            dd[cs - 97] = ts;
        }
        else if(dd[cs -97] != ts) 
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



Measured memory_bytes: 900
#include <stdio.h>

int partition(int *,int p,int r);

int main(){
    int n,i,A[100000],q;

    scanf("%d",&n);

    for(i=0;i<n;i++) scanf("%d",&A[i]);

    q = partition(A,0,n-1);

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

    printf("%d\n",A[i]);
    return 0;
}

int partition(int *A,int p,int r){
    int x,i,j,tmp;
    x=A[r];
    i=p-1;

    for(j=p; j<=r-1;j++){
        if(A[j]<=x){
            i++;
            tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    return i+1;
}


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

using namespace std;

typedef long long LL;
#define M 10000500
#define N 5200

const LL mod=1000000007;
LL n,m,ans,f[N][N],fac[M],ifac[M];

void upd(LL &x,LL y){
	x=(x+y)%mod;
}

LL pw(LL x,LL k){
	if (!k) return 1;
	LL tmp=pw(x*x%mod,k>>1);
	return k&1?tmp*x%mod:tmp;
}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL C(LL x,LL y){
	return x<y||y<0?0:fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

void calc(LL i,LL j){
	LL k=n-i-j;
	upd(ans,f[i][j]*C(m-n+k-1,k-1)%mod*fac[m-n]%mod*(i?fac[i-1]:1));
}

int main(){
	scanf("%lld%lld",&m,&n);
	fac[0]=1; for (LL i=1;i<=m;++i) fac[i]=fac[i-1]*i%mod;
	ifac[m]=inv(fac[m]); for (LL i=m-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	f[n][0]=1;
	for (LL i=n-1;~i;--i){
		for (LL j=0;j<=n-i;++j){
			f[i+1][j]=(f[i+1][j]*fac[i]%mod+f[i+2][j])%mod;
		}
		for (LL j=0;j<=n-i;++j){
			f[i][j]=f[i+1][j]*ifac[i]%mod;
			if (j) upd(f[i][j],-(f[i+1][j-1]-f[i+2][j-1])*ifac[i]);
			calc(i,j);
		}
	}
	upd(ans,mod);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 277028
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
ans = R * G * B
for d in range(1, N):
  for i in range(N):
    j = i + d
    k = i + d + d
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      ans -= 1
print(ans)

Measured memory_bytes: 73616
package main

import (
   "fmt"
)

func solution(n, m int, s, t []string) int {
   memo := make(map[string]int)

   for _, v := range s {
        memo[v]++

   }
   for _, v := range t {
        memo[v]--
   }

   out := 0
   for _, n := range memo {
        out = max(out, n)
   }
   return out
}

func max(x, y int) int {
   if x > y {
        return x
   }
   return y
}
func main() {
   var n int
   fmt.Scan(&n)
   s := make([]string, n)
   for i := range s {
        fmt.Scan(&s[i])
   }
   var m int
   fmt.Scan(&m)
   t := make([]string, m)
   for i := range t {
        fmt.Scan(&t[i])
   }
   fmt.Println(solution(n, m, s, t))
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if ( a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std ;
using namespace  __gnu_pbds ;
using namespace __gnu_cxx ;

typedef long long ll ;
typedef long double ld ;

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

typedef vector<int> vi ;
typedef vector<ll>  vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl ;
typedef vector<vi>  vvi ;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define per(i,b,a) for (int i = (b); i >= (a); i--)

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int MOD1 = 1000000007 ;
const int MOD2 = 998244353 ;
const ll INFL = 1e18 ;
const int INFI = 2e9 ;
const int MAXN = 500005 ;
const int MAXM = (1 << 18) ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

ll modpow(ll a, ll b, int MOD) {
    ll res = 1 ;
    while(b) {
        if(b&1) {
            res = res*a ;
            res %= MOD ;
        }
        a *= a ;
        a %= MOD ;
        b >>= 1 ;
    }
    return res ;
}
void upmin(int &a, int b) {
    if(a < b) {
        a = b ;
    }
}
void relax(int &a, int b) {
    if(a > b) {
        a = b ;
    }
}
ll add(ll a, ll b, int MOD) {
    a += b ;
    if(a >= MOD) {
        a -= MOD ;
    }
    return  a ;
}
ll subtract(ll a, ll b, int MOD) {
    a -= b ;
    if(a < 0) {
        a += MOD ;
    }
    return a ;
}
int n ;
int l[MAXN] ;
int main() {
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n ;
    rep(i,0,n-1) {
        cin >> l[i] ;
    }
    sort(l,l+n) ;
    ll res = 0 ;
    rep(i,0,n-1) {
        rep(j,i+1,n-1) {
            int a = l[i] ;
            int b = l[j] ;
            int bound = a + b ;
            int pbound = lower_bound(l,l+n,bound) - l - 1;
            if(pbound > j) {
                res +=  pbound - j ;
            }
        }
    }
    cout << res << endl ;
    return 0 ;
}


Measured memory_bytes: 256
#include<cstdio>//AT3959
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=200010;

struct B{
	int u,id;
	bool operator<(const B&rhs)const{
		return u<rhs.u;
	}
};

B b[N];

int n,a[N],aans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i].u=a[i];
		b[i].id=i;
	}
	if(n==1){
		printf("0\n");
		return 0;
	}
	sort(b+1,b+1+n);
	int cnt=1;
	for(int i=2;i<=n;i++){
		if(b[i].id>b[i-1].id){
			cnt++;
		}
		else{
			aans=max(cnt,aans);
			cnt=1;
		}
	}
	aans=max(cnt,aans);
	printf("%d\n",n-aans);
	return 0;
}


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

//Containers
typedef long long int lng;
#define vint vector<int>
#define vtwod vector<vector<int>>
#define vlng vector<long long int>
#define vstr vector<string>
#define vvint vector<int,int>
#define pint pair<int,int>
#define lint list<int>
#define qint queue<int>
#define dqint deque<int>
#define pq priority_queue<int>
#define rpq priority_queue<int,vector<int>,greater<int>>
#define fl forward_list<int>
#define st stack<int>
#define sint set<int>
#define msint multiset<int>


//Methods of containers:-
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define binsear binary_search
#define popf pop_front
#define popb pop_back
#define empb emplace_back
#define empf emplace_front
#define emp emplace
#define emt empty
#define ins insert
#define insaft insert_after
#define emplaft emplace_after
#define ersaft erase_after
#define swp swap
#define splicaft splice_after

//LOOPS
#define f(i,a,b) for(int i=a;i<b;i++)
#define rf(i,a,b) for(int i=a;i>b;i--)
#define optarray(arr,a,b)  for(int i=a;i<b;i++) cout<<arr[i]<<endl;
#define optarray1(arr,a,b) for(int i=a;i<b;i++){cout<<arr[i]<<" ";} cout<<endl;
#define optarray2d(arr,a,b) for(int i=0;i<a;i++){for(int j=0;j<b;j++){cout<<arr[i][j]<<" ";} cout<<endl;}

//FUNCTIONS
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int max3(int a,int b,int c)
{
    return max(max(a,b),c);
}
void gcd(int a,int b)
{
    cout<<__gcd(a,b)<<endl;
}

/*******************************************************************CODE**************************************************************/
void doit()
{
    string s;
    string t;
    int ct=0;
    cin>>s>>t;
    for(size_t i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            ct++;
        }
    }
    cout<<ct<<endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("error.txt","w",stderr);
        freopen("output.txt","w",stdout);
    #endif
    doit();
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}



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

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

  ll ans = LLONG_MAX;
  for (int y = -100; y <= 100; y++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      sum += pow(a[i] - y, 2);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  int k; cin >> k;
  string s; cin >> s;
  if(s.size() <= k)
  cout << s << endl;
  else{
    string g = s.substr(0, k);
    g += "...";
    cout << g << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  int cnt = 0;
  rep(i, n) {
    if (a[a[i]] == i) {
      cnt++;
    }
  }
  cout << cnt/2 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll n, m, ans;

int main(){
    cin >> n >> m;
    vector<ll> x(m), l(m - 1);
    for (int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    for (int i = 0; i + 1 < m; i++){
        ll d = abs(x[i] - x[i + 1]);
        ans += d;
        l[i] = d;
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    for (int i = 0; i < min(n - 1, m - 1); i++){
        ans -= l[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
    int y,m,d,t=0;
    char c;
    cin >> y >> c >> m >> c >> d;
    if(y<2019)
        t=1;
    else if(y==2019 && m<5)
        t=1;
    if(t)
        cout << "Heisei\n";
    else
        cout << "TBD\n";
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations
 
N, M, X = list(map(int,input().split()))
A = []
for i in range(N):
  A.append(list(map(int,input().split())))
sum = []
subsets=[]
for i in range(len(A) + 1):
    for c in combinations(A, i):
        subsets.append(list(c))
 
for i in subsets:
  tmp = [0]*(M+1)
  if len(i) == 1:
    sum.append(i[0])
  elif len(i) == 0:
    sum.append([0]*(M+1))
  else:
    for j in i:
      tmp = list(map(lambda a,b: a + b, tmp,j))
    sum.append(tmp)
    
min_price = 10000000000
 
for i in sum:
  t = 0
  for j in range(len(i)):
    if j==0:
      pass
    elif X > i[j]:
      t = 1
      break
  if t == 0:
    min_price = min(min_price, i[0])
 
if min_price == 10000000000:
  print(-1)
else:
  print(min_price)

Measured memory_bytes: 11796
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x = int(input())

for a in range(-120, 121):
    for b in range(-120, 121):
        if (a ** 5) - (b ** 5) == x:
            print(a, b)
            exit()

Measured memory_bytes: 9388
#include <iostream>
using namespace std;
int main(void){
    int h1,h2,k1,k2,a,b,c,d,H,K;
    cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
     
    H = h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d;
    K = k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d;
     
    if(H > K){
        cout << "hiroshi";
    }
    else if(H < K){
        cout << "kenjiro";
    }
    else{
        cout << "even";
    }
    cout << endl;
}


Measured memory_bytes: 3104
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, m;
        while (true) {
            n = sc.nextInt();
            m = sc.nextInt();
            int arr[] = new int[n];
            if (n == 0 && m == 0) break;
            for (int i = 0; i < n; ++i) {
                arr[i] = 0;
            }
            int mm = m;
            boolean f = true;
            while (f) {
                for (int i = 0; i < n; ++i) {
                    if (m > 0) {
                        m--;
                        arr[i]++;
                    }
                    else if (m == 0) {
                        if (arr[i] > 0) {
                            m += arr[i];
                            arr[i] = 0;
                        }
                    }
                }
                for (int i = 0; i < n; ++i) {
                    if (mm == arr[i]) {
                        System.out.println(i);
                        f = false;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 27608
#include<bits/stdc++.h>
#define PI 3.14159265
using namespace std;

int main(){

  double d, a;
  double r = 90.0;
  double x = 0, y = 0;

  while(true){
    scanf(" %lf,%lf", &d, &a);

    if(!d && !a) break;
    y += d*sin((r*PI)/180.0);
    x += d*cos((r*PI)/180.0);
    r -= a;
  }

  printf("%d\n%d\n", (int)x, (int)y);

}



Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    string s,t;
    cin >> s >> t;
    ll n=s.size();
    string ans="Yes";
    for(ll i=0;i<n;i++){

        if(s.c_str()[i]!=t.c_str()[i]){
            
            ans="No";
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> d(N);
    rep(i, N) cin >> d[i];
    sort(all(d));
    if (d[N / 2 - 1] == d[N / 2])
        cout << 0 << endl;
    else
        cout << d[N / 2] - d[N / 2 - 1] << endl;
}


Measured memory_bytes: 1024
import sys

def dfs(n, ans, op, idx):
    if idx == 3 and ans == 7:
        tmp = ""
        for i in range(3):
            tmp += n[i] + op[i]
        tmp += n[3] + '=7'
        print tmp
        sys.exit()
    elif idx < 3:
        # +
        op[idx] = '+'
        tmp = ans + int(n[idx + 1])
        dfs(n, tmp, op, idx + 1)
        # -
        op[idx] = '-'
        tmp = ans - int(n[idx + 1])
        dfs(n, tmp, op, idx + 1)
    else:
        return 

if __name__ == '__main__':
    n = raw_input()
    op = ['' for i in range(3)]
    dfs(n, int(n[0]), op, 0)

Measured memory_bytes: 2692
N, M = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
processes = A.map! { |a| [1, a] }
M.times { processes << gets.chomp.split.map(&:to_i) }
processes = processes.sort_by { |a| a[1] }

num = 0
ans = 0
while num < N
  process = processes.pop
  process[0] = N - num if process[0] > N - num
  ans += process[0] * process[1]
  num += process[0]
end

puts ans


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



int main(void) {

	double ans;
	double W, H, x, y;

	cin >> W >> H >> x >> y;

	ans = W * H / 2.0;

	printf("%.10f ", ans);

	if (W / 2 == x && H / 2 == y) cout << 1 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t


int main(void){
    int N,A,B;
    
    cin >> N >> A >> B;
    
    int count = 0 ;
    int temp;
    
    for(int i = 0 ; i < N ; i++ ){
        cin >> temp;
        if( A <= temp && temp < B )
            count += 0;
        else
            count++;
    }
    
    
    cout << count << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())

i = 1
q = []

while True:
    q.append(i)
    a = i * (i+1) // 2
    if N <= a:
        break
    i += 1

b = a % N
for j in range(len(q)):
    if q[j] != b:
        print(q[j])

Measured memory_bytes: 3572
# Problem - 文字列変換

# input
in_str = list(input())
n = int(input())

# string process
for i in range(n):
    p = input().split()

    if p[0]=='replace':
        a = int(p[1])
        b = int(p[2])
        q = p[3]
        for j in range(len(q)):
            in_str[j+a] = q[j]
    elif p[0]=='reverse':
        a = int(p[1])
        b = int(p[2])
        tmp = in_str[a:b+1]
        tmp = tmp[::-1]
        for j in range(len(tmp)):
            in_str[j+a] = tmp[j]
    elif p[0]=='print':
        a = int(p[1])
        b = int(p[2])
        ans = in_str[a:b+1]
        print("".join(ans))



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

int main() {
	int k;
	while (scanf("%d", &k) != EOF) {
		if (k <= 5) {
			printf("%d\n", k);
			for (int i = 1; i <= k; ++i) for (int j = 1; j <= k; ++j)
					printf("%d%c", i, " \n"[j == k]);
		} else {
			int n = (k + 3) / 4 * 2;
			printf("%d\n", n);
			for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) {
					int x;
					if (i & 1) x = (i + j) % n;
					else x = n + (i + j) % n;
					if (x >= k) x -= n;
					printf("%d%c", x + 1, " \n"[j == n]);
				}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    int A[41], B[41], C[41];
    rep(i,N) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        A[i] = a;
        B[i] = b;
        C[i] = c;
    }
    int H1 = N / 2;
    int H2 = N - H1;
    int mi = INT32_MAX;

    // (MbA0−MaB0)+(MbA1−MaB1)=0
    // MbA0 - MaB0 = MaB1 - MbA1
    
    unordered_map<int,int> M1;
    for (int bit = 1; bit < pow(2,H1); bit++) {
        int a = 0, b = 0, c = 0;
        for (int i = 0; i < H1; i++) {
            if (bit & (1 << i)) {
                a += A[i];
                b += B[i];
                c += C[i];
            }
        }
        int s = Mb * a - Ma * b;
        if (M1[s] == 0) M1[s] = c; // Can't be zero
        else M1[s] = min(M1[s], c);
        if (s == 0) mi = min(mi, c);
    }

    unordered_map<int,int> M2;
    for (int bit = 1; bit < pow(2,H2); bit++) {
        int a = 0, b = 0, c = 0;
        for (int i = 0; i < H2; i++) {
            if (bit & (1 << i)) {
                a += A[H1 + i];
                b += B[H1 + i];
                c += C[H1 + i];
            }
        }
        int s = Ma * b - Mb * a;
        if (M2[s] == 0) M2[s] = c;
        else M2[s] = min(M2[s], c);
        if (s == 0) mi = min(mi, c);
    }

    for (auto x : M1) {
        if (M2.count(x.first) > 0) {
            mi = min(mi, x.second + M2[x.first]);
        }
    }

    if (mi == INT32_MAX) {
        cout << -1 << endl;
    } else {
        cout << mi << endl;
    }
}


Measured memory_bytes: 384
N=int(input())
s=[]
for i in range(N):
    s.append(input())
M=int(input())
t=[]
for j in range(M):
    t.append(input())

temp = 0

for i in range(N):
    numN = 0
    numM = 0
    for j in range(N):
        if s[i]==s[j]:
            numN = numN + 1
    for k in range(M):
        if s[i]==t[k]:
            numM = numM + 1
    if temp <= numN-numM:
        temp=numN-numM

print(temp)
    

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define inf (1LL<<61)
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define int long long
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >  
#define N 200001
#define mod 1000000007
#define ll long long


int32_t main()
{
    IOS;
    
    int n;
    cin>>n;
    int a[n+2];
    a[0] = 0;
    a[n+1] = 0; 
    for(int i = 1;i <=n ;i++)
        cin>>a[i];
    int dp[405][405];
    int cost[405][405];
    for(int i = 0 ;i<=n+1;i++)
    {
        for(int j =0;j<=n+1;j++)
            {dp[i][j] = inf;cost[i][j] = inf;}
        cost[i][i] = 0;
    }

    for(int i = 0;i <=n+1;i++)
        dp[i][i]=a[i];
    for(int i = 1;i<=n;i++)
    {
        dp[i][i+1] = a[i] + a[i+1];
        cost[i][i+1] = dp[i][i+1];

    }

    for(int len =3;len <= n;len++)
    {
        for(int i = 1;i + len -1<=n;i++)
        {
            for(int j = i;j<=i+len - 2;j++)
            {
                if(cost[i][i+len-1] > cost[i][j] + cost[j+1][i+len-1] + dp[i][j]+dp[j+1][i+len-1])
                {
                    dp[i][i+len-1] =dp[i][j]+dp[j+1][i+len-1];
                    cost[i][i+len-1] = cost[i][j] + cost[j+1][i+len-1] + dp[i][j]+dp[j+1][i+len-1];
                }
                
            }
        }
    }
    cout<<cost[1][n];

    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define double long double
const ll N = 1e5 + 5, MOD = 1e9+7;

double n,k;
double ans;

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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>k;

    for( double i=1; i<=n; i++ ){
        double p=1.0;
        double q=i;
        while(q<k){
            q*=2;
            p*=0.5;
        }
        ans+=p;
    }
    cout<<fixed<<setprecision(12)<<ans/n<<endl;
    return 0;
}




Measured memory_bytes: 256
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        nums: [usize;2],
    };

    println!("{}", solve(nums[0], nums[1]));
}

fn solve(a: usize, b: usize) -> usize {
    return a * b - (a) - (b) + 1;
}

macro_rules! tests {
    ($($name:ident:[$( $args:expr ),*] => $output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output,super::solve($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:[2,2]=>1,
    test2:[5,7]=>24,
}


Measured memory_bytes: 4352
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

ll val[1003];
ll wt[1003];
ll dp[110][120000];

ll knapsack(ll w,ll n){
    if(wt<=0 || n<=0){
        return 0;
    }

    if(dp[n][w]!=-1){
        return dp[n][w];
    }

    if(wt[n-1]<=w){
        return dp[n][w] =  max(knapsack(w,n-1), val[n-1]+knapsack(w-wt[n-1],n-1));
    }else{
        return dp[n][w] = knapsack(w,n-1);
    }
}

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

    ll n,w;
    cin>>n>>w;

    for(ll i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;

        wt[i] = a;
        val[i] = b;
    }   

    memset(dp,-1,sizeof(dp));

    ll val = knapsack(w,n);

    cout<<dp[n][w]<<"\n";

    return 0;
}

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

using namespace std;

int main()
{
  int n; cin >> n;
  map<string, int> mapp;
  vector<string> print;
  int maxi = 0;
  for(int i= 0; i < n; i++)
  {
    string s; cin >> s;
    mapp[s]++;
    maxi = max(maxi, mapp[s]);
  }
  for(auto it = mapp.begin(); it != mapp.end(); it++)
    if(it->second == maxi) print.push_back(it->first);
  sort(print.begin(), print.end());
  for(int i = 0; i < print.size(); i++)
    cout << print[i] << endl;

  return 0;
}

Measured memory_bytes: 26868
a, b = map(int, input().split())

# 0.08 と 0.1 の最小公倍数
# 8と10　//100

# x = a / 0.08
# x_2 = int(x)
# print(x_2)
# y = b / 0.1
# y_2 = int(y)
# print(y_2)

# if x_2 == y_2:
#     print(int(x_2))
# else:
#     print(-1)

for i in range(1, 1009, 1):
    # print(i)
    x = i * 0.08
    # x = i * 8
    x_2 = int(x)
    y = i * 0.1
    # y = i * 10
    y_2 = int(y)
    # print(x)
    # print(y)
    if x_2 == a and y_2 == b:
        # continue
    # if x == y:
        ans = i
        break
    else:
        ans = -1

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){


int W,H,x,y,r;


scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


if(x+r<=W&&x-r>=0&&y+r<=H&&y-r>=0){


printf("Yes\n");}


else{printf("No\n");}


return 0;


}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N), B(N), C(N);
    REP(i,0,N) cin >> A[i];
    REP(i,0,N) cin >> B[i];
    REP(i,0,N) cin >> C[i];

    ASC(A); ASC(B); ASC(C);
    vec D(N), csum(N+1, 0);
    ll cnt = 0;
    REP(i,0,N) D[i] = C.end() - upper_bound(ALL(C), B[i]);
    REP(i,0,N) csum[i+1] = csum[i] + D[i];
    REP(i,0,N) {
        ll k = upper_bound(ALL(B), A[i]) - B.begin();
        cnt += csum[N] - csum[k];
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 7216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(all(s));
  vector<vi> dp(n + 1, vi(2, 1e8));
  dp[0][0] = 0;
  rep(i, n) {
    int d = s[i] - '0';
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + d);
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + 10 - d);
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + d + 1);
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 9 - d);
  }
  cout << min(dp[n][0], dp[n][1] + 1) << endl;
}

Measured memory_bytes: 55940
#include <stdio.h>

int main()
{
    int a, b;
    int d, r;
    double f;
    
    scanf("%d %d", &a, &b);

    d = a / b;
    r = a % b;
    f = (double)a / (double)b;

    printf("%d %d %lf\n", d, r, f);
}



Measured memory_bytes: 2084
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f

int main()
{
    char c;
    scanf("%c",&c);
    printf("%c\n",c+1);
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#define N 1e13
using namespace std;
long long n,res;
int main(){
	cin>>n;
	res=N;
	for (long long i=1;i<=sqrt(n);i++)
		if (n%i==0)	res=min(res,i+n/i-2);		
	cout<<res;
	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int M, D;
    std::cin >> M >> D;

    int ans = 0;
    for(int i = 1; i <= M; i++) {
        for(int j = 1; j <= D; j++) {
            auto d1 = (j % 10);
            auto d2 = (j / 10);
            if(d1 < 2 || d2 < 2) {
                continue;
            }
            else if(d1 * d2 == i) {
                ans++;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<double> vec(n);
    for(int i=0;i<n;i++) cin >> vec[i];
    sort(vec.begin(),vec.end());

    double ans = vec[0];
    for(int i=1;i<n;i++){
        ans = (ans+vec[i])/2.0;
    }

    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n;
string str;

int main(){
	cin >> n;
	ll c = 0;
	ll p;
	for(ll i = 1; i <= n; i++){
		cin >> p;
		if(p != i){c++;}
	}
	if(c == 0 || c == 2){cout << "YES" << endl;}
	else{cout << "NO" << endl;}
	return 0;
}

Measured memory_bytes: 256
from copy import deepcopy
import itertools


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


N = read()
A = []
for _ in range(N):
    A.append(read())

ans = 0
if A[-1] >= N:
    print(-1)
    quit()
ans += A[-1]
for i in reversed(range(N-1)):
    if A[i] < A[i+1] - 1:
        print(-1)
        quit()
    elif A[i] >= A[i+1]:
        if A[i] > i:
            print(-1)
            quit()
        else:
            ans += A[i]

print(ans)

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

struct abcd {
	int a;
	int b;
	int c;
	int d;
};
vector<abcd> que;
int max_score = 0;

int calc_score(vector<int>& vec) {
	int score = 0;
	for (int i = 0; i < que.size(); i++) {
		if ((vec.at(que.at(i).b-1) - vec.at(que.at(i).a-1)) == que.at(i).c) { score += que.at(i).d; }
	}
	return score;
}

void make_seq(vector<int>& vec, int index, int max) {
	if (index > 0) { vec.at(index) = vec.at(index - 1); }

	for (; vec.at(index) <= max; vec.at(index)++) {
		if (index == (vec.size() - 1)) {
			int temp_score = calc_score(vec);
			if (temp_score > max_score) { max_score = temp_score; }
			continue;
		}
		make_seq(vec, index + 1, max);
	}

}

int main(void) {
	int num, upper, query, total = 0;
	cin >> num >> upper >> query;
	vector<int> seq(num, 1);

	int temp_a, temp_b, temp_c, temp_d;
	for (int i = 0; i < query; i++) {
		cin >> temp_a >> temp_b >> temp_c >> temp_d;
		abcd temp = { temp_a,temp_b,temp_c,temp_d };
		que.push_back(temp);
	}
	make_seq(seq, 0, upper);

	cout << max_score << endl;

	return 0;
}

Measured memory_bytes: 3180
import itertools

N = int(input())
S = [input() for _ in range(N)]

cnt = [0 for _ in range(5)]
for s in S:
    if s[0] == "M":
        cnt[0] += 1
    elif s[0] == "A":
        cnt[1] += 1
    elif s[0] == "R":
        cnt[2] += 1
    elif s[0] == "C":
        cnt[3] += 1
    elif s[0] == "H":
        cnt[4] += 1

ans = 0
for i, j, k in itertools.combinations(cnt, r=3):
    ans += i * j * k

print(ans)


Measured memory_bytes: 16112