akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 100050;
long long W, H;
long long p[MAX_N], q[MAX_N];

int main(int argc, char **argv) {
    std::cin >> W >> H;

    for (int i = 0; i < W; i++) {
        std::cin >> p[i];
    }

    for (int i = 0; i < H; i++) {
        std::cin >> q[i];
    }

    std::vector<std::pair<int, int>> vec;

    for (int i = 0; i < W; i++) {
        vec.push_back(std::pair<int, int>({p[i], 0}));
    }
    for (int i = 0; i < H; i++) {
        vec.push_back(std::pair<int, int>({q[i], 1}));
    }

    std::sort(vec.begin(), vec.end());
    int sel_w = 0;
    int sel_h = 0;
    long long ret = 0;
    for (auto p : vec) {
        if (p.second == 0) {
            if (H + 1 - sel_h > 0) {
                ret += (H + 1 - sel_h) * p.first;
            }
            sel_w++;
        } else {
            if (W + 1 - sel_w > 0) {
                ret += (W + 1 - sel_w) * p.first;
            }
            sel_h++;
        }
    }

    std::cout << ret << std::endl;


    return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359



int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A >= C) {
		if (D >= A) {
			if (B >= D) {
				cout << D - A;
			}
			else {
				cout << B - A;
			}
		}
		else {
			cout << "0";
		}
	}
	else {
		if (B >= C) {
			if (D >= B) {
				cout << B - C;
			}
			else {
				cout << D - C;
			}
		}
		else {
			cout << "0";
		}
	}

	return 0;

	
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main()
{
    ll n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> sum(n+1); //左からi文字目まででACがいくつ現れるか
    for(ll i=1;i<n;i++){
        if(s[i]=='C' && s[i-1]=='A'){
            sum[i+1]=sum[i]+1;
        }
        else{
            sum[i+1]=sum[i];
        }
    }
    rep(i,q){
        ll l,r;
        cin >> l >> r;
        l--;
        ll ans=sum[r]-sum[l];
        if(sum[l]!=sum[l+1]) ans--;
        cout << ans << endl;
    }
    return 0;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
struct Data {
  int A, B;
  Data(int A, int B) : A(A), B(B){}
  bool operator< (const Data& d) const {
    return A < d.A;
  } 
};
 
int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  int A, B;
  vector<Data> d;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    d.push_back(Data(A, B));
  }
  sort(d.begin(), d.end());
  int c = 0;
  int idx = 0;
  for (int i = 1; i <= M; i++) {
    while (idx < N && d[idx].A <= i) {
      q.push(d[idx].B);
      idx++;
    }
    if (!q.empty()) {
      c += q.top();
      q.pop();
    }
  }
  cout << c << "\n";
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> Ai,Bi,Ci;
  rep(i,N){
    int tmpAi = 0;
    cin >> tmpAi;
    Ai.push_back(tmpAi);
  }
  rep(i,N){
    int tmpBi = 0;
    cin >> tmpBi;
    Bi.push_back(tmpBi);
  }
  rep(i,N-1){
    int tmpCi;
    cin >> tmpCi;
    Ci.push_back(tmpCi);
  }  
  
  int ans = 0;
  ans = accumulate(Bi.begin(), Bi.end(), 0);
  
  for(int i = 0;i < N-1;i++){
    if((Ai.at(i + 1) - Ai.at(i)) == 1) ans += Ci.at(Ai.at(i) - 1);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
def koyakusu(a, b)
  loop do
    rem = b % a
    return a if rem == 0
    a, b = rem, a
  end
end

def kobaisu(a, b)
  a * b / koyakusu(a, b)
end

while str = gets
  a, b = str.split(' ').map(&:to_i).sort
  puts "#{koyakusu(a, b)} #{kobaisu(a, b)}"
end

Measured memory_bytes: 8584
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


vector<string> vstr;	//checkテ」ツ?凖」ツつ凝ヲツ鳴?・ツュツ療・ツ按?

int check(string &s){
	if(s[0] != 'a') return 0;
	for(int i=0;i<vstr.size();i++){
		if(vstr[i] == s) return 0;
	}
	return 1;
}

bool solve(){
	cout<< "?nyaa"<<endl;
	
	while(1){
		string s;
		cin>> s;
		if(!check(s)){
			cout<< "!OUT"<<endl;
			break;
		}else{
			vstr.push_back(s);
			if(s=="a"){
				cout<< "?aa"<<endl;
				vstr.push_back("aa");
			}else if(s=="aa"){
				cout<< "?a"<<endl;
				vstr.push_back("a");
			}else{
				cout<<"?" << s[s.size()-1]<< "labrysa"<<endl;
			}
		}
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define RREP(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define ALL(vector) vector.begin(), vector.end()
const int K=43;
ll dp[K][2][2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector <ll> _a(n);
    REP(i,n) cin>>_a[i];
    ll x=0;
    REP(i,n) x ^= _a[i];
    ll a = _a[0];
    ll b = _a[1];
    x ^= a^b;
    ll s = a+b;

    REP(i,K)REP(j,2)REP(k,2) dp[i][j][k] = -1;
    dp[0][0][0]=0;
    ll v = 1;
    REP(i,K){
        int cx = x&1;
        int cs = s&1;
        int ca = a&1;
        REP(j,2)REP(k,2){
            if (dp[i][j][k] == -1) continue;
            REP(na,2)REP(nb,2){
                int ni = i+1;
                int nj, nk;
                if ((na^nb) != cx) continue;
                int ns = na+nb+j;
                if (ns%2 != cs) continue;
                nj = 0;
                if (ns >= 2) nj = 1;
                if(ca < na){
                    nk = 1;
                }else if (ca==na){
                    nk = k;
                }else{
                    nk = 0;
                }
                dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k]|(v*na));

            }
        }
        x >>= 1;
        s >>= 1;
        a >>= 1;
        v <<= 1;
    }
    a = dp[K-1][0][0];
    if(a == -1 || a == 0){
        cout<<-1<<endl;
        return 0;
    }
    ll ans = _a[0] - a;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
/* BABA JAGAAAAAA  */  

#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define PI 3.1415926535897932384626
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
int dp[2020];

int main()
{
	int n;
	scanf("%d", &n);
	dp[1] = 0;
	dp[2] = 0;
	dp[3] = 1;
	for (int i = 4; i <= n; i++)
	{
		dp[i] = (dp[i - 1] + dp[i - 3]) % mod;
	}
	printf("%d", dp[n]);
}
  

Measured memory_bytes: 3756
#include<stdio.h>

int main(){

  int input[10],i;
  int no1=0,no2=0,no3=0;

  for(i=0;i<10;i++){
    scanf("%d",&input[i]);
    if(input[i] > no1){
      no3=no2;
      no2=no1;
      no1=input[i];
    }
    else if(input[i] > no2){
      no3=no2;
      no2=input[i];
    }
    else if(input[i] > no3)
      no3=input[i];
  }

  printf("%d\n%d\n%d\n",no1,no2,no3);

  return 0;

}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

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

long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}

int main()
{
   long long a, b;
   cin >> a >> b;

   //cout << "最大公約数:" << gcd(a, b) << endl;
   cout << lcm(a, b) << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

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

  cout << n + n*n + n*n*n << endl;
}


Measured memory_bytes: 3632
C = 3.times.map{gets.split.map(&:to_i)}
r,m = C.flatten.inject(0,&:+).divmod(3)
puts (m == 0 && [0,1,2].permutation.all?{|i,j,k| C[0][i] + C[1][j] + C[2][k] == r}) ? "Yes" : "No"

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(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 sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int r;
        cin >> r;
        cout << r*r;
        
        

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* UnionFind */

struct UnionFind{
  vector<int> data, tree_size;
  UnionFind(int s):data(s,-1),tree_size(s,1) {}
  
  int root(int x){
    if(data[x]==-1) return x;
    return data[x]=root(data[x]);
  }
  
  bool set(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return false;
    data[y]=x;
    tree_size[x] += tree_size[y];
    tree_size[y] = 0;
    return true;
  }
  
  bool check(int x,int y){
    x=root(x);
    y=root(y);
    return x==y;
  }
  
  int size(int x){
    return tree_size[root(x)];
  }
  
};


int main(){
  int n,x[SIZE],y[SIZE];
  vector<pair<int,int> > vec1,vec2;
  
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d%d",x+i,y+i);

    vec1.push_back({x[i],i});
    vec2.push_back({y[i],i});
  }

  sort(vec1.begin(),vec1.end());
  sort(vec2.begin(),vec2.end());

  vector<pair<int,pair<int,int> > > vec;

  for(int i=0;i<vec1.size()-1;i++){
    vec.push_back({vec1[i+1].first - vec1[i].first,{vec1[i].second,vec1[i+1].second}});
  }
  
  for(int i=0;i<vec2.size()-1;i++){
    vec.push_back({vec2[i+1].first - vec2[i].first,{vec2[i].second,vec2[i+1].second}});
  }

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

  UnionFind uf(n);
  ll ans = 0;
  
  for(int i=0;i<vec.size();i++){
    if(uf.set(vec[i].second.first, vec[i].second.second))
      ans += vec[i].first;
  }

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


Measured memory_bytes: 7784
#include<bits/stdc++.h>
using namespace std;
vector<long long> a;
set<long long> b;
long long s=0,x,y;
int main(){
	int n,tmp;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>tmp;
		a.push_back(tmp);
		s+=tmp;
	}
	x=a[0];
	y=s-a[0];
	b.insert(abs(x-y));
	for (int i=1;i<n-1;i++){
		x+=a[i];
		y-=a[i];
		b.insert(abs(x-y));
	}
	cout<<*b.begin()<<endl;
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n, T;
  int c[100];
  int t[100];
  cin >> n >> T;
  REP(i,n) {
    cin >> c[i] >> t[i];
  }

  int result = 1001;
  REP(i,n) {
    if(t[i] <= T) {
      result = min(result, c[i]);
    }
  }
  if (result == 1001) {
    cout << "TLE" << endl;
  } else {
    cout << result << endl;
  }
}


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

int main(void) {
    int N,j=30,sum=0;
    bool flag=false;
      cin >>N;

    int a[N],count[N];

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

    for(int i=0;i<N;i++){
      while(!flag){
        if((a[i]%(int)pow(2,j))==0){
          flag = true;
          count[i] = j;
        }
        j--;
      }
      j=30;
      flag = false;
    }
    for(int i=0;i<N;i++){
      sum += count[i];
    }

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


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, H, W = map(int, input().split())
    ans = 0
    for _ in range(N):
        a, b = map(int, input().split())
        if H <= a and W <= b:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int min(int,int);

int arr[101][101],p[101];
int main(){
  int n,i,j,r,c,l,k;
  scanf("%d",&n);
  if(n>100) exit(2);
  for(i=1;i<=n;i++){
    scanf("%d %d",&r,&c);
    p[i-1]=r;
    p[i]=c;
  }
  for(i=1;i<=n;i++) arr[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      arr[i][j]=10000000;
      for(k=i;k<j;k++){
	arr[i][j] = min(arr[i][j],arr[i][k]+arr[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",arr[1][n]);
  
  return 0;
}

int min(int x,int y){
  if(x>=y) return y;
  else return x;
}



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

void pf(ll n)  
{  
     map<ll,ll> m;
    while (n % 2 == 0)  
    {  m[2]++;
         
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
           m[i]++;
            n = n/i;  
        }  
    }  
  
 
    if (n > 2)  
        m[n]++; 
        
        ll cnt=0;
    for(auto i =m.begin();i!=m.end();i++){
        cnt+= (sqrt((ll)1 + ((ll)8*(ll)(i->second))) - 1)/2 ;
        
    }
    cout<<cnt;
} 

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

    ll n;
	cin>>n;
	pf(n);
   
	


	return 0;
}


Measured memory_bytes: 3556
#include "bits/stdc++.h"
using namespace std;
int  A[200000];//入っている値。
int  B[200000];//Dみたいなもん。
struct Edge {
	int to;
	int id;
	Edge(int to, int id) :to(to), id(id) {}
};
vector<Edge>g[100005];

void dfs(int v, int p = -1) {
	for (Edge e : g[v]) {
		if (p == e.to) {
			continue;
		}
		//訪問済みなら
		if (-1 != B[e.to]) {
			A[e.to] = e.id - A[v];
			B[e.to] = B[v] + 1;
			continue;
		}
		A[e.to] = e.id - A[v];
		B[e.to] = B[v] + 1;
		dfs(e.to, v);
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>X(M);
	vector<int>Y(M);
	vector<int>Z(M);
	for (int n = 0; n < M; ++n) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		X[n] = a;
		Y[n] = b;
		Z[n] = c;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	for (int i = 1; i < N; ++i) {
		A[i] = -1;
		B[i] = -1;
	}
	A[0] = 0;
	B[0] = 0;
	dfs(0);

	bool f = false;
	int t = -1;
	for (int i = 0; i < M; ++i) {
		if ((A[X[i]] + A[Y[i]]) != Z[i]) {
			if ((B[X[i]] % 2) == (B[Y[i]] % 2)) {
				if ((Z[i] % 2) != ((A[X[i]] + A[Y[i]]) % 2)) {
					//cout << 0 << endl;//★★
					//return 0;
				}
				else {
					f = true;
					if (0 == B[X[i]] % 2) {
						t = (Z[i] - A[X[i]] - A[Y[i]]) / 2;
					}
					else {
						t = (A[X[i]] + A[Y[i]] - Z[i]) / 2;
					}
					break;
				}
			}
			else {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	if (f) {
		if (-1 == t) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 0; i < N; ++i) {
			if (0 == (B[i] % 2)) {
				A[i] += t;
			}
			else {
				A[i] -= t;
			}
			if (A[i] <= 0) {
				cout << 0 << endl;
				return 0;
			}
		}
		for (int i = 0; i < M; ++i) {
			if ((A[X[i]] + A[Y[i]]) != Z[i]) {
				cout << 0 << endl;
				return 0;
			}
		}
		cout << 1 << endl;
		return 0;
	}


	int min0 = 1e9;
	int min1 = 1e9;
	for (int i = 0; i < N; ++i) {
		if (0 == (B[i] % 2)) {
			min0 = min(min0, A[i]);
		}
		else {
			min1 = min(min1, A[i]);
		}
	}
	int ans = 0;
	min0 = 1 - min0;
	min1 = min1 - 1;
	if (min0 <= min1) {
		ans = min1 - min0 + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 18432
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int[][] coordinate = new int[number + 1][3];
    for (int i = 1; i < number + 1; i++) {
      for (int j = 0; j < 3; j++) {
        coordinate[i][j] = sc.nextInt();
      }
    }
    int[] deltaT = new int[number];
    int[] deltaX = new int[number];
    int[] deltaY = new int[number];
    int[] deltaXY = new int[number];
    for (int i = 0; i < number; i++) {
      deltaT[i] = Math.abs(coordinate[i + 1][0] - coordinate[i][0]);
      deltaX[i] = Math.abs(coordinate[i + 1][1] - coordinate[i][1]);
      deltaY[i] = Math.abs(coordinate[i + 1][2] - coordinate[i][2]);
      deltaXY[i] = deltaX[i] + deltaY[i];
    }
    int count = 0;
    for (int i = 0; i < number; i++) {
      if (deltaT[i] >= deltaXY[i]) {
        if ((deltaT[i] % 2 == 0 && deltaXY[i] % 2 == 0) || (deltaT[i] % 2 == 1 && deltaXY[i] % 2 == 1)) {
          count++;
        } else {
          System.out.println("No");
          break;
        }
      } else {
        System.out.println("No");
        break;
      }
    }
    if (count == number) {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 92952
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 998244353, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N;
	string s;
	cin>>N>>s;
	int R=0,G=0,B=0,RG=0,GB=0,BR=0;
	int ans = 1;
	REP(i,s.size()){
		if(s[i]=='R'){
			if(GB){
				ans*=GB--;
			}else if(G){
				ans*=G--;
				RG++;
			}else if(B){
				ans*=B--;
				BR++;
			}else R++;
		}else if(s[i]=='G'){
			if(BR){
				ans*=BR--;
			}else if(B){
				ans*=B--;
				GB++;
			}else if(R){
				ans*=R--;
				RG++;
			}else G++;
		}else{
			if(RG){
				ans*=RG--;
			}else if(R){
				ans*=R--;
				BR++;
			}else if(G){
				ans*=G--;
				GB++;
			}else B++;
		}
		ans%=MOD;
	}
	REP(i,N)(ans*=i+1)%=MOD;
	cout<<ans<<endl;
}


Measured memory_bytes: 900
#べき乗(MODあり)(繰り返し２乗法)
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

N = gets.to_i
C = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

C.sort!.reverse!
ans = 0
C.each_with_index{|c, idx|
  ans = (ans + c * (idx + 2)) % MOD
}

puts (ans * pow(4, N - 1, MOD)) % MOD


Measured memory_bytes: 19824
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
W = IL()
num = sum(W)
a = 0

ans = num
for i in range(N):
  a += W[i]
  num -= W[i]
  ans = min(ans,abs(a-num))

print(ans)

Measured memory_bytes: 21460
#include<map>
#include<cstdio>
using namespace std;
int main(){for(int T;~scanf("%d",&T)&&T;puts("")){
	map<pair<int,int>,int>m;
	char C[2];
	int n,k;
	for(;T--;){
		scanf("%s%d",C,&n);
		if(*C=='D'){
			for(auto it=m.begin();it!=m.end();)if(it->second==n)m.erase(it++);else	++it;
		}else if(*C=='R'){
			auto it=m.lower_bound(make_pair(n,2000000000));
			printf("%d\n",it==m.begin()||n<(--it)->first.first||it->first.second<n ? -1 : it->second);
		}else if(*C=='W'){
			int c=!scanf("%d",&k),d;
			for(auto it=m.begin();k&&it!=m.end();++it){
				d=it->first.first-c;
				if(d>k)d=k;
				if(d)m[make_pair(c,c+d-1)]=n;
				k-=d;
				c=it->first.second+1;
			}
			if(k)m[make_pair(c,c+k-1)]=n;
		}
	}
}}

Measured memory_bytes: 1240
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string ans;
	if(s == "Sunny") ans = "Cloudy";
	else if(s == "Cloudy") ans = "Rainy";
	else ans = "Sunny";
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
const int mod = 1000000007;
const int MAX_N = 100005;

ll fact[MAX_N];         // 階乗
ll ifact[MAX_N];        // 階乗の逆元

// x^nを求める繰り返し二乗法(累乗の高速化)
// フェルマーの小定理より、逆元を計算するときに用いる。
ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

    ll res = 1;
    while(n > 0){
        if(n & 1)   res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }

    return res;
}

// 階乗とその逆元テーブルを(0-n)まで埋める
void table(int n){
    fact[0] = 1;    // i^0 = 1;
    for(int i = 1; i <= n; ++i){
        fact[i] = fact[i - 1] * i % mod;
    }

    // フェルマーの小定理を利用して、右端の逆元を求める
    // 階乗の(mod-2)乗
    ifact[n] = mod_pow(fact[n], mod - 2);

    // 逆元の性質を利用して、テーブルを埋める
    for(int i = n; i >= 1; --i){
        ifact[i - 1] = ifact[i] * i % mod;
    }
}

// nCrを求める
ll combination(int n, int r){
    if(n < 0 || r < 0 || n < r)     return 0;

    return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, id1 = 0, id2 = 0;
    cin >> n;
    vector<int> a(n+1), cnt(n+1, 0);
    for(int i = 0; i < n+1; ++i){
        cin >> a[i];
        ++cnt[a[i]];
        
        if(cnt[a[i]] == 2)      id2 = i;   
    }
    for(int i = 0; i < n+1; ++i){
        if(a[i] == a[id2]){
            id1 = i;
            break;
        }
    }
    
    table(n+2);
    
    // 重複している数字をxとして、xの左にある数字の個数
    // a = [...x.....x...]
    int num1 = id1;
    // xの右側にある数字の個数
    int num2 = n - id2;

    // 重複している数字：x
    for(int i = 1; i <= n+1; ++i){        // 数字をi個取る
        ll res = combination(n + 1, i) - combination(num1 + num2, i - 1);
        res = (res + 2 * mod) % mod;
        cout << res << "\n";
    }
}

Measured memory_bytes: 3584
N = int(input())
S = input()
A = [0] * (N + 1)
mn = 1000000 
pos = 0 
for i in range(N):
        if S[i] == "W":
                A[i + 1] = A[i] + 1   
        else:
                A[i + 1] = A[i]
for i in range(1, N + 1): 
        mn = min(mn, A[i - 1] + N - i - (A[N] - A[i]))
print(mn)

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

int main() {
  int n;
  cin >> n;
  int x[n];
  int maxX = 0;
  REP(i,n) {
    cin >> x[i];
    maxX = max(x[i], maxX);
  }

  int ans = 1001001001;

  REP(i,maxX) {
    int sum = 0;
    REP(j,n) {
      sum += pow((x[j] - (i + 1)), 2.0);
      if (sum >= ans) break;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

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

int main(){
	while(true){
		int n, r, p, c;
		cin >> n >> r;
		if ((not n) && (not r)) break;
		int card1[n], card2[n];
		for (int i = 0; i < n; ++i){
			card1[i] = n - i;
			card2[i] = n - i;
		}
		for (int i = 0; i < r; ++i){
			cin >> p >> c;
			for (int j = 0; j < n; ++j){
				if (i % 2){
					if (j < c){
						card1[j] = card2[p-1+j];
					}else if(j < c + p - 1){
						card1[j] = card2[j-c];
					}else{
						card1[j] = card2[j];
					}
				}else{
					if (j < c){
						card2[j] = card1[p-1+j];
					}else if(j < c + p - 1){
						card2[j] = card1[j-c];
					}else{
						card2[j] = card1[j];
					}
				}
			}
		}
		if (r%2) cout << card2[0] << endl;
		else cout << card1[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[55][55][5000];
signed main() {
    string S;
    cin >> S;
    for(int i = 0; i <= 7; i++) {
        if(S.substr(0,i)+S.substr(S.size()-(7-i)) ==  "keyence") {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;

int main(){

    ll N;
    vector<ll > H(N + 1, 0);
    cin >> N;
    H[0] = -1;
    for(ll i = 1; i <= N; i++){
        cin >> H[i];
    } 


    ll mx = 0;
    ll ans = 0;
    for(ll i = N; i >= 0; i--){
        //cout << H[i] << endl;
        if(H[i] <= H[i - 1]){
            ans++;
        }
        if(H[i] > H[i - 1]){
            mx = max(ans, mx);
            ans = 0;
        }
    } 

    cout << mx << endl;

}

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


int main()
{
  int r, D, x;
  int result = 0;
  cin >> r >> D >> x;

  for (int i = 0; i < 10; i++ ) {
    result = r * x - D;
    cout << result << endl;
    x = result;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))



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

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

int main() {
	long long N;
	cin >> N;
	long long A, B;
	vector<pair<long long, long long>> BA(N);
	long long tmpA, tmpB;
	for (long i = 0; i < N; i++) {
		cin >> tmpA >> tmpB;
		BA.at(i) = make_pair(tmpB, tmpA);
	}

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

	long long sumTime = 0;
	for (long i = 0; i < N; i++) {
		sumTime += BA.at(i).second;
		if (sumTime > BA.at(i).first) {
			cout << "No" << endl;
			exit(0);
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3456
N,M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

A.sort()
sm = 0
cnt = 0

i = 0
while sm != M:
	cnt += A[i][0]*min(A[i][1],M-sm)
	sm += min(A[i][1],M-sm)
	i += 1

print(cnt)

Measured memory_bytes: 27756
import copy

def cnt(i, de):
    if i == n:
        for di, dk in enumerate(de):
            if dk % 2 != ps[di]:
                return 0
        return 1
    re = 0
    re += cnt(i+1, de)
    nde = copy.deepcopy(de)
    for di in swtode[i]:
        nde[di] += 1
    re += cnt(i+1, nde)
    return re

n, m = map(int, input().split())
swtode = [[] for _ in range(n)]
for di in range(m):
    k, *ss = map(int, input().split())
    for s in ss:
        swtode[s - 1] += [di]
ps = list(map(int, input().split()))
de=[0] * m
print(cnt(0,de))

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n >> m,n+m){
    vector<pll> v(n);
    rep(i,n){
      cin >> v[i].se >> v[i].fi;
    }
    sort(all(v));
    reverse(all(v));
    ll ans = 0;
    rep(i,n){
      if(m >= v[i].se){
        m -= v[i].se;
      } 
      else{
        v[i].se -= m;
        m = 0;
        ans += v[i].se * v[i].fi;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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

typedef struct tagItemType {
    int weight;
    int value;
} ItemType;

/* item: value, wegiht */
int napsack(vector<ItemType> item, int capa)
{
    int i, j;
    int result[101][10001] = {0};

    for (i = 1; i < item.size(); i++) {
        for (j = 1; j <= capa; j++) {
            result[i][j] = result[i - 1][j];
            if (j < item[i].weight) {
                continue;
            }
            if ((result[i - 1][j - item[i].weight] + item[i].value) > result[i - 1][j]) {
                result[i][j] = (result[i - 1][j - item[i].weight] + item[i].value);
            }
        }
    }

    return result[item.size() - 1][capa];
}


int main(void)
{
    int i;
    int value, weight;
    int itemNum;
    int capa;
    int ret;
    vector<ItemType> item;
    ItemType tmp = {0, 0};

    scanf("%d %d", &itemNum, &capa);
    item.push_back(tmp);
    for (i = 0; i < itemNum; i++) {
        scanf("%d %d", &tmp.value, &tmp.weight);
        item.push_back(tmp);
    }

    ret = napsack(item, capa);
    printf("%d\n", ret);

    return 0;
}

Measured memory_bytes: 5156
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   String[] s = new String[A];
   int[] a  = new int[A];
 
   for(int i =0;i<A;i++)
   {
     s[i] = sc.next();
     a[i] = sc.nextInt();
   }
   String sl = sc.next();
   int ans = 0;
   boolean sleep = false;
   for(int i = 0;i<A;i++)
   {
     if(sleep) ans+= a[i];
     else if(sl.equals(s[i]))
     {
       sleep = true;
     }
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 23508
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INF (ll)1000000007
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long mul_modp(long long a, long long b, long long p){
    // a*b mod p
    return ((a % p) * (b % p)) % p;
}

bool isPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(void){

    ll N;
    cin >> N;

    vector<pair<ll, ll>> fact;

    ll ans = 1;
    if(N == 1) ans = 1;
    else{
        ll n = 2;
        fact.emplace_back(2,0);
        while(n <= N){
            fact.back().second += N/n;
            n *= 2;
        }

        for(ll i=3; i<=N; i+=2){
            if(isPrime(i)){
                fact.emplace_back(i,0);
                n = i;
                while(n <= N){
                    fact.back().second += N/n;
                    n *= i;
                }
            }
        }

        for(auto p : fact){
            ans = mul_modp(ans, p.second+1, INF);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC059ThreeLetter
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s;
            s = Console.ReadLine().Split(' ');
            Console.WriteLine((s[0].Substring(0, 1) + s[1].Substring(0, 1) + s[2].Substring(0, 1)).ToUpper());
        }
    }
}


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

const int maxn = 55;
int stick[maxn];

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    int N,K;
    cin>>N>>K;
    int ans=0;
    for(int i=0;i<N;i++){
        scanf("%d",&stick[i]);
    }
    sort(stick,stick+N,cmp);
    for(int j=0;j<K;j++){
        ans+=stick[j];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int h,w,i,j;
cin>>h>>w;
char s[h][w];
for(i=0;i<h;++i)
for(j=0;j<w;++j)
  cin>>s[i][j];
int k=0,p=0;
for(i=0;i<w+2;++i)
cout<<'#';
cout<<endl;

for(i=0;i<h;++i)
{ cout<<'#';
for(j=0;j<w;++j)
   {
  cout<<s[i][j];
    }
cout<<'#';
cout<<endl;
}
for(i=0;i<w+2;++i)
cout<<'#';
cout<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int pow3[16], c[16];
	int n, m, i, j, k, d, x, y, p;

	pow3[0] = 1;
	for(i = 1; i <= 15; ++i){
		pow3[i] = pow3[i-1] * 3;
	}

	while(scanf("%d%d", &n, &m), n){
		for(i = 0; i < 3; ++i){
			for(scanf("%d", &j); j > 0; --j){
				scanf("%d", &k);
				c[n-k] = i;
			}
		}

		p = 0;
		x = 0;
		for(i = n - 1; i >= 0; --i){
			d = abs(p - c[i]);
			x += pow3[i] * d;
			if(d == 1){
				p = 2 - p;
			}
		}

		y = pow3[n] - 1 - x;
		if(x > y){
			x = y;
		}
		printf("%d\n", x > m ? -1 : x);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
import java.lang.*;

public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int P = Integer.parseInt(inputs[0]);
            int Q = Integer.parseInt(inputs[1]);
            int R = Integer.parseInt(inputs[2]);

            int min1 = Math.min(P,Q);
            int max1 = Math.max(P,Q); 

            if (max1 <=  R) {
                System.out.println(min1 + max1);
            } else {
                System.out.println(min1 + R);
            } 
            
            scanner.close();
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void){
    ll m;
    cin >> m;
    ll ans = 24 * 2;
    cout << ans - m << endl;
    return 0;
}


Measured memory_bytes: 256
a = []
for i in range(3):
    a.append(input().split(" "))
b = [['101', '102', '103'], ['104', '105', '106'], ['107', '108', '109']]
N = input()
suji = []
for i in range(int(N)):
    suji.append(input())
for k in range(int(N)):
    for i in range(3):
        for s in range(3):
            if suji[k] == a[i][s]:
                b[i][s] = 0

judge = 0

for i in range(3):
    if b[i][0] == b[i][1] == b[i][2]:
        judge = 1
        
    if b[0][i] == b[1][i] == b[2][i]:
        judge = 1

if b[0][0] == b[1][1] == b[2][2]:
    judge = 1

if b[0][2] == b[1][1] == b[2][0]:
    judge = 1

if judge == 1:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int d = a+ b+ c ;

    if ( d >= 22 )
    {
        printf("bust");
    }

    else
    {
        printf("win");
    }

    return 0;

}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

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

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <typename T>
struct RMQ {
  using F = function<T(T, T)>;
  T dat[kMax5][20];
  F f;

  RMQ() {}
  RMQ(F f): f(f) {}

  void init(const vector<T> & a) {
    auto n = a.size();
    rep(i, 0, n - 1) { dat[i][0] = a[i]; }
    for (auto j = 1; (1 << j) <= n; ++j) {
      for (auto i = 0; i + (1 << j) - 1 < n; ++i) {
        dat[i][j] = f(dat[i][j - 1], dat[i + (1 << (j - 1))][j - 1]);
      }
    }
  }

  T query(ll l, ll r) {
    if (l > r) {
      return 0;
    }

    auto k = 0;
    while (l + (1 << (k + 1)) - 1 <= r) { ++k; }
    return f(dat[l][k], dat[r - (1 << k) + 1][k]);
  }
};

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

  ll ans = 0;

  int n, m;
  vector<ll> a, b;
  string s, t;

  cin >> n;
  cout << n * n * n << endl;

  return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int N;
	int B[100001] = { 0 };
	int del = 0;

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		if (a > N) {
			del++;
			continue;
		}
		B[a]++;
	}

	
	for (int i = 1; i <= N; i++)
	{
		if (B[i] == 0)
			continue;

		if (i > B[i]) {
			del += B[i];
		}
		else {
			del += (B[i] - i);
		}
	}

	cout << del << endl;

	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a, b;
	vector<ll> sum_a(n + 1, 0), sum_b(m + 1, 0);
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		a.pb(x);
		sum_a[i + 1] = sum_a[i] + x;
	}
	for (int i = 0; i < m; i++) {
		int x; cin >> x;
		b.pb(x);
		sum_b[i + 1] = sum_b[i] + x;
	}
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (sum_a[i] > k) break;
		int j = upper_bound(sum_b.begin(), sum_b.end(), k - sum_a[i]) - sum_b.begin() - 1;
		ans = max(ans, i + j);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8720
import sys
readline = sys.stdin.readline

N,M,X = map(int,readline().split())
data = [None] * N
for i in range(N):
  d = list(map(int,input().split()))
  c = d[0]
  target = d[1:]
  data[i] = [c,target]

ans = 10 ** 9
for i in range(2 ** N):
  cost = 0
  skills = [0] * M
  for j in range(N):
    if (i >> j) & 1:
      cost += data[j][0]
      for k in range(len(data[j][1])):
        skills[k] += data[j][1][k]
  if ans > cost:
    for k in range(len(skills)):
      if skills[k] < X:
        break
    else:
      ans = cost
      
if ans == 10 ** 9:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9240
import itertools
import math

def solve(l):
    r = 0
    for i in range(len(l)-1):
        x_i = l[i][0]
        y_i = l[i][1]
        x_i_1 = l[i+1][0]
        y_i_1 = l[i+1][1]

        r += math.sqrt(pow(x_i_1 - x_i,2) + pow(y_i_1 - y_i,2))

    return r

def main():
    N = int(input())
    xy = [list(map(int,input().split())) for _ in range(N)]

    p = list(itertools.permutations(xy, len(xy)))
    result = 0

    for i in range(len(p)):
        result += solve(list(p[i]))

    print(result/len(p))



if __name__ == "__main__":
    main()

Measured memory_bytes: 7972
#include <stdio.h>
#include <math.h>
int main(){
    int H,W,i,j;
    while(1){
    scanf("%d %d",&H,&W);
        if(H ==0 && W==0){
            break;
        }
        for (i = 0; i < H; i++)
        {
            for (j = 0; j < W; j++)
            {
                printf("#");
            }
            printf("\n");
        }
            printf("\n");
    }
    return 0;
}

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

int main() {
  int n, k, x, s = 0;

  cin >> n >> k;

  for (int i = 0; i < n; ++i){
    cin >> x;
    s += min(x, k - x);
  }

  cout << 2 * s << endl;
  
  return 0;
}


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

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

    vector<long long> A;
    vector<long long> B;
    int a;
    for(int i=0;i<N;i++){
        cin>>a;
        if(a>=0){
            A.emplace_back(a);
        }else{
            B.emplace_back(a);
        }
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    long long ans=1;
    long long mod=1000000007;

    if(A.size()==0){
        if(K%2==1){
            for(int i=1;i<=K;i++){
                ans*=B[N-i];
                ans%=mod;
            }
            if(ans<0){
                ans+=mod;
                ans%=mod;
            }
        }else{
            for(int i=0;i<K;i++){
                ans*=B[i];
                ans%=mod;
            }
            if(ans<0){
                ans+=mod;
            }
        }
        cout<<ans<<endl;
        return 0;
    }

    if(N==K){
        for(auto p:A){
            ans*=p;
            ans%=mod;
        }
        for(auto p:B){
            ans*=p;
            ans%=mod;
        }
        if(ans<0){
            ans+=mod;
            ans%=mod;
        }
        cout<<ans<<endl;

        return 0;
    }

    //cout<<"hoge"<<endl;
    int pta=A.size()-1;
    int ptb=0;

    //cout<<A.size()<<" "<<B.size()<<endl;
    for(int i=0;i<K;i++){
        //cout<<pta<<" "<<ptb<<endl;
        if(pta==-1){
            ptb++;
        }else if(ptb==B.size()){
            pta--;
        }else if(A[pta]>=(-B[ptb])){
            pta--;
        }else{
            ptb++;
        }

    }
    /*
    for(auto p:A){
        cout<<p<<" ";
    }
    cout<<endl;

    for(auto p:B){
        cout<<p<<" ";
    }
    cout<<endl;
    cout<<pta<<" "<<ptb<<endl;
    //*/


    //cout<<"hoge"<<endl;
    if(ptb%2==1){
        if(pta==-1){
            pta++;
            ptb++;
        }else if(ptb==B.size()|| pta==A.size()-1){
            pta--;
            ptb--;
        }else{
            long long aa=A[pta+1]*A[pta];
            long long bb=B[ptb-1]*B[ptb];
            if(aa>bb){
                pta--;
                ptb--;
            }else{
                pta++;
                ptb++;
            }
        }
    }

    for(int i=0;i<ptb;i++){
        ans*=B[i];
        ans%=mod;
    }
    for(int i=A.size()-1;i>pta;i--){
        ans*=A[i];
        ans%=mod;
    }
    if(ans<0){
        ans+=mod;
    }


    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5636
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <tuple>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define INF 1000000007

using namespace std;
using llng = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

int main() {
    llng N, A, B; cin >> N >> A >> B;
    cout << (((B-A)*(N-2)+1 > 0) ? (B-A)*(N-2)+1 : 0) << endl;

    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ll n,k;cin>>n>>k;
  vector<ll> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  sort(h.rbegin(), h.rend());
  ll res=0;
  for(int i=k;i<n;i++){
    res += h[i];
  }
  cout<<res<<endl;
  
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    if(s.length() >= 6)
    {
        if(s[2] == s[3] && s[4] == s[5])
        {
            cout << "Yes";
            return 0;
        }
    } 
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp::min;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<u64> = procon_read();
	let n = v[0];
	let a:Vec<u64> = procon_read();
	let mut mini = 1000000000;
	let mut cnt = 0;
	for i in a {
		let mut check = i;
		while check%2 == 0 {
			check = check/2;
			cnt += 1;
		}
		mini = min(mini, cnt);
		cnt = 0;
	}
	println!("{}", mini);
}

Measured memory_bytes: 4352