akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN], B[MAXN], AA[MAXN], BB[MAXN];
int par[MAXN], mark[MAXN];

int get(int x){
	return (par[x]==x?x:par[x]=get(par[x]));
}
int join(int x, int y){
	x=get(x);
	y=get(y);
	par[x]=y;
	return x!=y;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i], A[0]^=A[i];
	for (int i=1; i<=n; i++) cin>>B[i], B[0]^=B[i];
	for (int i=0; i<=n; i++) AA[i]=A[i], BB[i]=B[i];
	sort(AA, AA+n+1);
	sort(BB, BB+n+1);
	for (int i=0; i<=n; i++) if (AA[i]!=BB[i]) kill(-1)
	m=unique(AA, AA+n+1)-AA;
	//debug(m)
	for (int i=0; i<=n; i++){
		A[i]=lower_bound(AA, AA+m, A[i])-AA;
		B[i]=lower_bound(AA, AA+m, B[i])-AA;
		if (A[i]==B[i] && i) continue ;
		mark[A[i]]=mark[B[i]]=1;
	}
	for (int i=0; i<m; i++) if (mark[i]) ans++, par[i]=i;
	for (int i=1; i<=n; i++) if (A[i]!=B[i]){
		ans++;
		ans-=join(A[i], B[i]);
	}
	ans--;
	cout<<ans<<'\n';
	
	
	return 0;
}


Measured memory_bytes: 4224
# AGC002 B Box and Ball

n, m = map(int, input().split())

b_list = [0] * (n+1)
b_list[1] = 1
c_list = [1] * (n+1)

for i in range(m):
    _x, _y = map(int, input().split())
    c_list[_x] -= 1
    c_list[_y] += 1 
    if b_list[_x] == 1:
        b_list[_y] = 1
        if c_list[_x] == 0:
            b_list[_x] = 0

print(sum(b_list))

Measured memory_bytes: 4596
N, K = map(int, input().split())
P = [int(i) - 1 for i in input().split()]
Q = [int(i) for i in input().split()]
ans = - float('inf')
for i in range(N):
    now = i
    cnt = 0
    span = 0
    while True:
        span += 1
        cnt += Q[now]
        now = P[now]
        if now == i:
            break
    point = 0
    now = i
    for j in range(1, span + 1):
        point += Q[now]
        now = P[now]       
        if j > K:
            break
        value = point + (max(cnt, 0) * ((K - j) // span))
        ans = max(ans, value)
print(ans)

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

using namespace std;
const int N = 100010;
int _w;

int n, m, r[N], w[N];

int main() {
	_w = scanf( "%d%d", &n, &m );
	r[1] = 1;
	for( int i = 1; i <= n; ++i ) w[i] = 1;
	while( m-- ) {
		int x, y;
		_w = scanf( "%d%d", &x, &y );
		if( r[x] ) r[y] = 1;
		--w[x], ++w[y];
		if( !w[x] ) r[x] = 0;
	}
	int cnt = 0;
	for( int i = 1; i <= n; ++i )
		cnt += r[i];
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
def main():
    n, m = map(int, input().split())
    a = ['' for i in range(n)]
    b = ['' for i in range(m)]
    for i in range(n):
        a[i] = input()
    for i in range(m):
        b[i] = input()
    for i1 in range(n - m + 1):
        for i2 in range(n - m + 1):
            fl = True
            for j in range(m):
                for k in range(m):
                    if a[i1 + j][i2 + k] != b[j][k]:
                        fl = False
            if fl:
                print("Yes")
                exit(0)
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
using System;
using System.Collections.Generic;
using System.Linq;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());

            var l = new List<long>();
            var count = long.MaxValue;
            for(var i = 1; i < Math.Sqrt(n) + 1; i++){
                if(n % i == 0){
                    count = Math.Min(n / i + i - 2, count);
                }
            }
    
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<math.h>
int main(){
int n,i;
double a[110],b[110];
long double ans=0,k,x;
x=1.000000/3.000000;
scanf("%d\n",&n);
for(i=0;i<n;i++){
scanf("%lf\n",&a[i]);
}
for(i=0;i<n;i++){
scanf("%lf\n",&b[i]);
}
for(i=0;i<n;i++){
if(a[i]>b[i]){
ans=ans+(a[i]-b[i]);
}
else{
ans=ans+(b[i]-a[i]);
}
}
printf("%Lf\n",ans);
ans=0;
for(i=0;i<n;i++){
if(a[i]>b[i]){
ans=ans+(a[i]-b[i])*(a[i]-b[i]);
}
else{
ans=ans+(b[i]-a[i])*(b[i]-a[i]);
}
}
printf("%lf\n",sqrt(ans));
ans=0;
for(i=0;i<n;i++){
if(a[i]>b[i]){
ans=ans+(a[i]-b[i])*(a[i]-b[i])*(a[i]-b[i]);
}
else{
ans=ans+(b[i]-a[i])*(b[i]-a[i])*(b[i]-a[i]);
}
}
printf("%Lf\n",powl(ans,x));
ans=0;
for(i=0;i<n;i++){
if(a[i]>b[i]){
k=a[i]-b[i];
}
else{
k=b[i]-a[i];
}
if(k>ans){
ans=k;
}
}
printf("%Lf\n",ans);
return 0;
}


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

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

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

    int count = 0;
    rep(i, s.size() - 1){
        if(s[i] == s[i+1]){
            if(s[i] == '0')
                s[i+1] = '1';
            else
                s[i+1] = '0';
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


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

int main() {

  int A,B;
  cin >> A >> B;
  int X = 0;
  
  for (int i = A; i <= B; i++) {
    if (i/10000 == i%10 && i%10000/1000 == i%100/10) {
      X++;
    }  
  }
  cout << X << endl;
}


Measured memory_bytes: 3568
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

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

int arr[10000005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	rep(x,1,10000005){
		for (int y=x;y<10000005;y+=x){
			arr[y]++;
		}
	}
	
	int n;
	cin>>n;
	
	ll ans=0;
	rep(x,1,n+1){
		ans+=(ll)x*arr[x];
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 42712
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
using namespace std;
const int mod = 1000000007;


int main() {
 
  int64_t N;
  cin>>N;
  
  //vector<int> A(N);
  //for(int i=0; i<N; i++){cin>>A[i];}
  //vector<vector<int>> A(N,vector<int>(M));
  for(int64_t i=-1000; i<1000; i++){
    for(int64_t j=-1000; j<1000; j++){
      if(pow(i,5)-pow(j,5)==N){cout<<i<<" "<<j<<endl;return 0;}
    }
  }
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  //cout << N << endl;
}

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

using namespace std;


int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    vector<int> v;
    for(int i = 26; i >= 1; i--) {
        v.push_back(i);
    }
    v[0] = 0;
    for(int i = 0; i < n; i++) {
        int x = v[s[i]-'a'];
        if(x <= k) {
            s[i] = 'a';
            k -= x;
        } else {
            continue;
        }
    }
    k %= 26;
    s[n-1] = char(s[n-1]+k);
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> A;
  for(int i=0; i<N; ++i){
    int a;
    cin>>a;
    A.push_back(a);
  }
  
  sort(A.begin(),A.end());
  
  int ans=0;
  for(int i=A[1]; i>0; --i){
    int count=0;
    if((A[0]%i==0)||(A[1]%i==0)){
      for(int j=0; j<N; ++j){
        if(A[j]%i==0) count++;
      }
      if(count>=N-1){
        ans=i;
        break;
      }
    }
  }
  
  cout<<ans<<endl;
}


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

int main() {
    int H, W, d;
    cin >> H >> W >> d;
    if (d%2 == 1) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << (((i+j)%2) ? 'R' : 'B');
            }
            cout << "\n";
        }
        return 0;
    }
    else {
        int inf = d*1000;
        int e = d/2;
        vector<vector<char>> ans(H, vector<char>(W));
        for (int i = -d*2; i < H+d*2; i++) {
            for (int j = -d*2; j < W+d*2; j++) {
                if (i%e != 0 || j%e != 0) continue;
                if ((i/e + j/e)%2 != 0) continue;
                char c;
                if (i%d == 0) {
                    if ((j+inf)%(2*d) == (i+inf)%(2*d)) c = 'R';
                    else c = 'Y';
                }else {
                    if ((j+inf)%(2*d) == (i+inf)%(2*d)) c = 'B';
                    else c = 'G';
                }
                
                for (int k = i-e; k <= i+e; k++) {
                    for (int l = j-e; l <= j+e; l++) {
                        if ((k+l-i-j+inf)%2 != e%2 && abs(k-i)+abs(l-j)<e) {
                            if (k < 0 || k >= H) continue;
                            if (l >= 0 && l <= W-1) ans[k][l] = c;
                            if (l+1 >= 0 && l+1 <= W-1) ans[k][l+1] = c;
                        }
                    }
                }
            }
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << ans[i][j];
            }
            cout << "\n";
        }
        return 0;
    }
    return 0;
}

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

using namespace std;

int main(void){
  long long A, B, K;
  cin >> A >> B >> K;
  if(K <= A) A -= K;
  else{
    K -= A;
    A = 0;
    B = max(B - K, 0LL);
  }
  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
     int a,b,temp;
     while(scanf("%d%d",&a,&b)==2)
     {
         if(a==0&&b==0)
         {
             break;
         }
         if(a>b)
         {
             temp=a;
             a=b;
             b=temp;
         }
         printf("%d %d\n",a,b);
     }
     return 0;
}



Measured memory_bytes: 2020
n = int(input())
map_ans = []
ans = 0
for i in range(10):
    map_ans.append([0] * 10)
for i in range(1, n + 1):
    pre = str(i)[0]
    suf = str(i)[-1]
    map_ans[int(pre)][int(suf)] += 1
for i in range(1, 10):
    for j in range(1, 10):
        ans += map_ans[i][j] * map_ans[j][i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, k;
    cin>>n>>k;
    vector<long long> p(n);
    for(int i = 0; i < n; i++){
        cin>>p.at(i);
    }
    vector<long long> l(n+1,0),r(n+1,0);
    l.at(1) = p.at(0);
    r.at(n-1)= p.at( n-1 );
    for(int i=1; i<n; i++){
        l.at(i+1)= l.at(i)+p.at(i);
        r.at(n-1-i) = r.at(n-i) + p.at(n-1-i);
    }
    long long ma =0;
    long long su= l.at(n);
    for(int i=0; i<n-k+1; i++){
        ma =max(ma, su-l.at(i)-r.at(i+k));
    }
    long double two = 2.0;
    long double ans = (ma+k)/two;
  cout<<setprecision(10)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int X, n, m;cin >> X;
	n = X / 500;m = (X % 500) / 5;
	cout << 1000 * n + m * 5 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,S=0;
  long long int D;
  scanf("%d %lld\n",&N,&D);
  long long int X,Y;
  for(int i=1;i<=N;i++){
    scanf("%lld %lld\n",&X,&Y);
    if(X*X+Y*Y<=D*D) S++;
  }
  printf("%d\n",S);
  return 0;
}

Measured memory_bytes: 1728
mp=gets.split(' ').map(&:to_i)
l=mp[2]-mp[4]
r=mp[2]+mp[4]
t=mp[3]+mp[4]
b=mp[3]-mp[4]

if l<0 || r>mp[0] || b<0 || t>mp[1] then
   print "No\n"
else
   print "Yes\n"
end

Measured memory_bytes: 8632
#include <iostream>
#include <algorithm>
#include <array>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <random>

#include <atcoder/all>

using namespace atcoder;
using namespace std;
typedef long long ll;

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

    int N, M;
    cin >> N >> M;

    vector<string> grid(N);

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

    mcf_graph<int, int> g(N * M + 2);
    int s = N * M;
    int t = N * M + 1;
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            int v1 = i * M + j;
            if (grid[i][j] == 'o') {
                g.add_edge(s, v1, 1, 0);
                ans += (N + M - 2) - i - j;
            }
            if (grid[i][j] != '#'){
                g.add_edge(v1, t, 1, (N + M - 2) - i - j);
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if (grid[i][j] == 'o') {
                vector<vector<int>> cost(N, vector<int>(M));
                for (int k = 0; k < N; ++k) {
                    for (int l = 0; l < M; ++l) {
                        cost[k][l] = -1;
                    }
                }
                cost[i][j] = 0;
                queue<pair<int, int>> que;
                pair<int, int> p0 = make_pair(i, j);
                que.push(p0);
                while (!que.empty()) {
                    auto cur = que.front();
                    int cost_cur = cost[cur.first][cur.second];
                    que.pop();
                    if (cur.first + 1 < N && grid[cur.first + 1][cur.second] != '#' &&
                        cost[cur.first + 1][cur.second] == -1) {
                        pair<int, int> p1 = make_pair(cur.first + 1, cur.second);
                        cost[cur.first + 1][cur.second] = cost_cur + 1;
                        que.push(p1);
                    }
                    if (cur.second + 1 < M && grid[cur.first][cur.second + 1] != '#' &&
                        cost[cur.first][cur.second + 1] == -1) {
                        pair<int, int> p1 = make_pair(cur.first, cur.second + 1);
                        cost[cur.first][cur.second + 1] = cost_cur + 1;
                        que.push(p1);
                    }
                }
                int v0 = i * M + j;
                for (int k = 0; k < N; ++k) {
                    for (int l = 0; l < M; ++l) {
                        int v1 = k * M + l;
                        if (cost[k][l] >= 0 && grid[k][l] != '#') {
                            g.add_edge(v0, v1, 1, 0);

                        }
                    }
                }
            }
        }
    }

    auto f = g.flow(s, t);

    cout << (ans - f.second) << endl;

    return 0;
}


Measured memory_bytes: 7084
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

string s;
int n;

bool ok(int k){
	bool one=1,zero=1;
	for(int i=0;i<n;i++){
		if(i>=k||i+k<n)continue;
		if(s[i]=='0')one=0;
		else zero=0;
	}
	return one || zero;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> s;
	n=s.size();
	int left=1,right=n+1;
	while(right-left>1){
		int mid=(left+right)/2;
		if(ok(mid)){
			left=mid;
		}else{
			right=mid;
		}
	}
	cout << left << endl;
}

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

using namespace std;

#define uf_type long long

class unionfind{
public:
    vector<uf_type> parent;
    vector<uf_type> siz;

    unionfind(){};
    unionfind(uf_type n){
        //0オリジンとノードの数の混同を避けるためn+1をする
        for(uf_type i = 0; i < n + 1; i++) parent.push_back(i);
        for(uf_type i = 0; i < n + 1; i++) siz.push_back(1);
    }

    uf_type find(uf_type a){
        vector<uf_type> v;
        while(a != parent[a]){
            v.push_back(a);
            a = parent[a];
        }

        for(long i = 0; i < v.size(); i++) parent[v[i]] = parent[a];
        return parent[a];
    }

    bool same(uf_type a, uf_type b){
        return (find(a) == find(b));
    }

    uf_type size(uf_type a){
        return siz[find(a)];
    }

    void unite(uf_type a, uf_type b){
        if(!same(a,b)){
            if(size(a) > size(b)){
                siz[find(a)] = siz[find(a)] + siz[find(b)];
                parent[find(b)] = parent[find(a)];
            }else{
                siz[find(b)] = siz[find(a)] + siz[find(b)];
                parent[find(a)] = parent[find(b)];
            }
        }
    }
};

int main(){

    long n,m;
    unionfind uf;
    vector<long> a;
    vector<long> b;

    vector<long long> ans;

    cin >> n >> m;

    ans.push_back(n * (n - 1) / 2);

    uf = unionfind(n);

    for(long i = 0; i < m; i++){
        long ta,tb;
        cin >> ta >> tb;
        a.push_back(ta);
        b.push_back(tb);
    }
  
  	long len = a.size();

    for(long i = 0; i < len; i++){
        if(uf.same(a.back(),b.back())){
            ans.push_back(ans.back());
        }else{
            long as = uf.size(a.back());
            long bs = uf.size(b.back());
            ans.push_back(ans.back() - as * bs);
            uf.unite(a.back(),b.back());
        }
        a.pop_back();
        b.pop_back();
    }

    for(long i = 0; i < m; i++) cout << ans[m - 1 - i] << endl;
    
    return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int >sunukes(N);
  for(int i=0;i<N;i++){
    sunukes[i] = 0;
  }
  for(int i=0; i<K; i++){
    int d;
    cin >> d;
    for(int j=0; j<d; j++){
      int A;
      cin >> A;
      sunukes[A-1] = 1;
    }
  }
  int count =0;
  for(int i=0; i<N; i++){
    if(sunukes[i]==0)count+=1;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
  int n=0,a,b,p1=0,p2=0,p3=0;
  cin>>n>>a>>b;
  int P[n];
  for(int i=0;i<n;i++)cin>>P[i];
  for(int i=0;i<n;i++){
    if(P[i]<=a)p1++;
    else if(P[i]>b)p3++;
    else p2++;
  }
  cout<<min({p1,p2,p3});
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	var s, t string
	fmt.Scan(&n)
	fmt.Scan(&s, &t)

	sSlice := strings.Split(s, "")
	tSlice := strings.Split(t, "")

	var ret string

	for i := 0; i < n; i++ {
		ret += sSlice[i] + tSlice[i]
	}

	fmt.Println(ret)
}


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

int main() {
  int N;
  cin >> N;
  long long A[N];
  int minusCount = 0;
  long long minA = 1000000000;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] < 0) {
      minusCount++;
      A[i] = abs(A[i]);
    }
    minA = min(A[i], minA);
    ans += A[i];
  }

  if (minusCount % 2 == 1) {
    ans -= minA * 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
pair<lli, lli> move(lli x, pair<lli, lli> p)
{
    if (p.first <= x and x <= p.second)
        return make_pair(0, x);
    if (p.first > x)
        return make_pair(p.first - x, p.first);
    if (p.second < x)
        return make_pair(x - p.second, p.second);
}
lli calc(vector<pair<lli, lli>> v, vector<int> id)
{
    int n = v.size();
    vector<bool> used(n);
    lli pos = 0;
    lli ans = 0;
    for (auto s : id) {
        // cout << s << " ";
        if (used[s])
            continue;
        auto piyo = move(pos, v[s]);
        used[s] = true;
        ans += piyo.first;
        pos = piyo.second;
    }

    return ans + abs(pos);
}
int main()
{
    int n;
    cin >> n;
    vector<pair<pair<lli, lli>, lli>> x(n);
    vector<pair<lli, lli>> h;
    rep(i, n) cin >> x[i].first.first >> x[i].first.second;
    rep(i, n) x[i].second = i;
    rep(i, n) h.push_back(x[i].first);
    auto y = x;
    //    rep(i, n) x[i].first.second *= -1;
    sort(x.begin(), x.end());
    //    rep(i, n) x[i].first.second *= -1;


    reverse(x.begin(), x.end());
    rep(i, n) swap(y[i].first.first, y[i].first.second);
    //   rep(i, n) y[i].first.second *= -1;
    sort(y.begin(), y.end());
    //   rep(i, n) y[i].first.second *= -1;
    rep(i, n) swap(y[i].first.first, y[i].first.second);
    vector<bool> used(n);
    int yi = 0;
    int xi = n - 1;
    lli pos = 0;
    lli ans = 0;
    vector<int> in1, in2;
    rep(i, n)
    {
        in1.push_back(x[i].second);
        in1.push_back(y[i].second);
        in2.push_back(y[i].second);
        in2.push_back(x[i].second);
    }
    cout << max(calc(h, in1), calc(h, in2)) << endl;
    ///    rep(i, n)

    // {
    //     pair<lli, lli> xx, yy;
    //     while (yi < n and used[y[yi].second])
    //         yi++;
    //     while (xi >= 0 and used[x[xi].second])
    //         xi--;
    //     if (xi >= 0)
    //         xx = move(pos, x[xi].first);
    //     if (yi < n)
    //         yy = move(pos, y[yi].first);
    //     if (yi == n or xx.first > yy.first) {
    //         ans += xx.first;
    //         pos = xx.second;
    //         used[x[xi].second] = true;
    //     } else {
    //         ans += yy.first;
    //         pos = yy.second;
    //         used[y[yi].second] = true;
    //     }
    //     //cout << ans << " " << pos << endl;
    // }
    // cout << ans + abs(pos) << endl;
}


Measured memory_bytes: 13296
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).

get_number(Number) :-
  get_string(String),
  number_string(Number, String).

main :-
  get_number(A),
  Ans is A + A * A + A * A * A,
  write(Ans).
:- main.

Measured memory_bytes: 8140
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define ld long double
using namespace std;

//Constants
const int maxn = 2e5+100;
const int mod = 1e9+7;
const int INF = 3e18+315;
set<string>st;
int n;
string l;
bool b = false;
int32_t main()
{
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  cin >> n;
  cin >> l;
  st.insert(l);
  for(int i = 2; i <= n; i++){
    string s; cin >> s;
    if(st.find(s) != st.end()) b = true;
    if(s[0] != l[l.size()-1]) b = true;
    st.insert(s);
    l = s;
  }
  if(b == true)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  
  return 0;
}

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

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

	int sum = 0;
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		sum += a[i];
	}

	if (n < sum) {
		cout << "-1" << endl;
	} else {
		cout << n - sum << endl;
	}

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef tuple<double, int, int> T;

double sq(double x) { return x * x; }
const double EPS = 1e-8;

vector<double> quadratic(double a, double b, double c){
    if(abs(a) < EPS){
        // bx + c = 0
        if(abs(b) < EPS){
            // c = 0 のとき任意のxが解．c != 0 のとき解なし．
            return vector<double>();
        }
        return vector<double>(1, -c / b);
    }
    double D = b*b - 4*a*c;
    if(D < 0) return vector<double>();
    if(D == 0) return vector<double>(1, -b/(2.0 * a));

    // |b| >> |ac|の時の桁落ちを避けるために
    // x_1 = (-b-sign(b)*sqrt(D))/(2*a), x_2 = c / (a*x_1)を利用する
    vector<double> res;
    int sign = (b >= 0) ? 1 : -1;
    double x1 = (-b - sign * sqrt(D))/(2.0 * a);
    double x2 = c / (a * x1);
    res.push_back(x1);
    res.push_back(x2);
    return res;
}

int main(){
    int n;
    double p[222][3];
    double v[222][3];
    double r[222];
    double vr[222];
    while(cin >> n) {
        REP(i, n) {
            REP(j, 3) cin >> p[i][j];
            REP(j, 3) cin >> v[i][j];
            cin >> r[i] >> vr[i];
        }

        vector<T> events;
        REP(i, n) {
            double t = r[i] / vr[i];
            events.push_back(T(t, i, i));
        }
        REP(i, n) REP(j, n) if(i < j) {
            double p1[3];
            REP(k, 3) p1[k] = p[i][k];
            double p2[3];
            REP(k, 3) p2[k] = p[j][k];
            double v1[3];
            REP(k, 3) v1[k] = v[i][k];
            double v2[3];
            REP(k, 3) v2[k] = v[j][k];
            double r1 = r[i];
            double r2 = r[j];
            double vr1 = vr[i];
            double vr2 = vr[j];


            double A = sq(vr1 + vr2);
            double B = -2.0 * (vr1 + vr2) * (r1 + r2);
            double C = sq(r1 + r2);

            REP(k, 3) A -= sq(v2[k] - v1[k]);
            REP(k, 3) B -= 2.0 * (v2[k] - v1[k]) * (p2[k] - p1[k]);
            REP(k, 3) C -= sq(p2[k] - p1[k]);

            vector<double> res = quadratic(A, B, C);
            /*
            cout << i << " " << j << " : ";
            for(double t : res) cout << t << " "; cout << endl;
            */
            for(double t : res) if(t > EPS) events.emplace_back(t, i, j);
        }

        sort(events.begin(), events.end());
        vector<double> ans(n, -1);
        for(T ev : events) {
            double t;
            int a, b;
            tie(t, a, b) = ev;
            if(ans[a] != -1) continue;
            if(ans[b] != -1) continue;
            ans[a] = ans[b] = t;
        }
        REP(i, n) {
            printf("%.12f\n", ans[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 1928
program preparing_boxes
  implicit none
  integer :: n, a(200000) = 0, b(200000) = 0, c(200000) = 1, m = 0, s, i
  read(*,*) n
  read(*,*) a(1:n)
  do i = n, 1, -1
    s = sum(c(i:n:i))
    if (mod(s,2) /= a(i)) c(i) = 0
  end do
  do i = 1, n
    if (c(i) == 1) then
      m = m+1
      b(m) = i
    end if
  end do
  write(*,'(i0)') m
  if (m > 0) then
    write(*,'(i0)',advance='no') b(1)
    do i = 2, m
      write(*,'(x,i0)',advance='no') b(i)
    end do
    write(*,*)
  end if
  stop
end program preparing_boxes

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
//#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    stack<int> s;
    long long int N;
    cin >> N;
    while(N > 0)
    {
        int num;
        num = N % 26;
        if(num == 0)
            num +=26;
        N -= num;
        s.push(num);
        N = N/26;
    }
    while(s.size()){
        cout << char(s.top()+96);
        s.pop();
        //+96
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {
    
    lli a,b,n;
    cin>>a>>b>>n;

    lli x;
    a-=n;
    if(a<0) {
        x=-a;
        a=0;
        b-=x;
    }
    
    if(b<0)
    {
        b=0;
    }

    cout<<a<<" "<<b<<endl;


    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
#define REP(i,n) for(long long (i)=0;(i)<(long long)(n);(i)++)
#define RREP(i,n) for(long long (i)=(long long)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
int main() {
 
    int N; cin >> N;
    vector< int > A(N);
    REP(i,N) cin >> A[i];
 
    ll ans = 1;
    ll minus = 1;
    REP(i,N) {
    	if (A[i] % 2 == 0) {
    		ans *= 3;
    		minus *= 2;
    	} else {
    		ans *= 3;
    	}
    }
 
    cout << ans - minus << endl;
 
    return 0;
}

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

int main() {
int k,x;
cin >> k >> x;
int a = x - k + 1;
int b = x + k - 1;
if(a < -1000000) a = -1000000;
if(b > 1000000) b = 1000000;
for(int i = a; i <= b; i++) cout << i << " ";
cout << endl;

}
  


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


int main(){
  int N;
  ll A,B;
  cin >> N >> A >> B;
  vector<ll> x(N);
  rep(i,N) {
    cin >> x[i];
  }
  ll res = 0;
  rep(i,N-1) {
    res += min( (x[i+1] - x[i] ) * A , B);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#define maxn 200010
int head[maxn],tot,n,m,d[maxn],pre[maxn],q[maxn*10],vis[maxn];
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
void init(){
	int i,u,v;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
}
void spfa(){
	int h,t,i,u,v,b;
	for(i=1;i<=n;i++)d[i]=maxn;
	d[1]=0,h=t=1,q[t]=1,t++,vis[1]=1;//以1点为起始点
	while(h<t){
		u=q[h];
		for(b=head[u];b;b=e[b].next){
			v=e[b].to;
			if(d[v]>d[u]+1){
				pre[v]=u;//记录到达v的前一个点
				d[v]=d[u]+1;
				if(!vis[v])vis[v]=1,q[t]=v,t++;
			}
		}
		h++;
		vis[u]=0;
	}
	for(i=1;i<=n;i++)
		if(d[i]==maxn){printf("No\n");return;}//若有点到不了1
	printf("Yes\n");
	for(i=2;i<=n;i++)printf("%d\n",pre[i]);
}
int main(){
	init();
	spfa();
	return 0;
}
 

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

#define ll long long
#define f first
#define s second
#define inf 1e15

#define N 200005

string s;
ll n,m,x,y,d,k;
ll a[N];

int siz[N];
int parent[N];

int find(int g)
{
    if(parent[g]!=g)
    parent[g]=find(parent[g]);
    return parent[g];
}
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--){
	    
	    
	    cin>>n>>m;
	    
	   for(int i=0;i<n;i++)
	   {
		parent[i]=i;
		siz[i]=1;
	   }
	   for(int i=0;i<m;i++)
	   {
		int x,y;
		cin>>x>>y;
		x--;y--;
		x=find(x);
		y=find(y);
		if(x==y)
			continue;
		parent[x]=y;
		siz[y]+=siz[x];
	    }
	    int ans=0;
	    for(int i=0;i<n;i++)
	    {
	        ans=max(ans,siz[find(i)]);
		// cout<<size[find(i)]-1<<" ";
	    }
	    
	    
	    
	    
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 11344
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    int x;
    cin >> x;
    int mx = 0;
    rep(i,21) rep(j,21) rep(k,21) rep(l, 21) rep(m, 21) rep(n,21){
        int mon = 100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n;
        if (mon == x){
            cout << 1 << endl;
            return 0;
        }
        chmax(mx, mon);
    }

    if (x < mx){
        cout << 0 << endl; 
    }else{
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  ll n = s.size();
  ll g = n / 2 + n % 2;
  ll ans = 0;
  rep(i, n) {
    if (i < g) {
      if (s.at(i) == 'p')
        --ans;
    } else {
      if (s.at(i) == 'g')
      ++ans;

    }

  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
 
int main()
{
  int i,j,n,count=0;
  int G[101][101],color[101],d[101],pi[101],mincost,ii;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  for(i=0;i<n;i++){
    color[i]=0;
    pi[i]=-1;
    d[i]=2001;
  }
  d[0]=0;
 
  while(1){
    mincost=2001;
    for(i=0;i<n;i++){
      if(color[i]!=2 && d[i]<mincost){
        mincost=d[i];
        ii=i;
      }
    }
    if(mincost==2001)break;
    color[ii]=2;
    for(i=0;i<n;i++){
      if(G[ii][i]!=-1 && color[i]!=2 && G[ii][i]<d[i]){
    pi[i]=ii;
    d[i]=G[ii][i];
    color[i]=1;
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i]!=-1)count+=G[i][pi[i]];
    }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2108
import numpy as np

n, k = map(int, input().split())
a = np.array(input().split(), np.int64)
f = np.array(input().split(), np.int64)
a.sort()
f.sort()
a = a[::-1]
left = -1
right = np.max(a * f)
while left + 1 < right:
    mid = (left + right) // 2
    if np.sum(np.maximum(a - mid // f, 0)) <= k:
        right = mid
    else:
        left = mid

print(right)


Measured memory_bytes: 37204
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	string S; cin >> S;
	int mi = INF, ma = -1;

	REP(i, S.size()) {
		if (S[i] == 'Z')chmax(ma, i);
		if (S[i] == 'A')chmin(mi, i);
	}

	cout << ma - mi + 1 << endl;
	return 0;
}



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

int main() {
    int N;
    cin >> N;
    int i = 0;
    int j = 0;
    bool frag = true;
    while (i * 4 + j * 7<= N) {
        while (i * 4 + j * 7<= N) {
            if (i * 4 + j * 7 == N) {
                cout << "Yes" << endl;
                frag = false;
                break;
            }
            j++;
        }
        if (not frag) {
            break;
        }
        j = 0;
        i++;
    }
    if (frag) {
        cout << "No" << endl;
    }
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    if (n < 105){
        cout << 0 << endl;
    }
    else if (n < 135){
        cout << 1 << endl;
    }
    else if (n < 165){
        cout << 2 << endl;
    }
    else if (n < 189){
        cout << 3 << endl;
    }
    else if (n < 195){
        cout << 4 << endl;
    }
    else{
        cout << 5 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int fn(0);
for(int i=0; i<n; ++i)
{
int a;
cin>>a;
if(a%2==0)
{
if(a%3!=0&&a%5!=0)
fn=1;
}
}
if(fn)
cout<<"DENIED";
else
cout<<"APPROVED";
}


Measured memory_bytes: 256
dice = [
	[1, 2, 4, 3, 5],
	[5, 2, 0, 3, 4],
	[1, 5, 4, 0, 3],
	[1, 0, 4, 5, 2],
	[0, 2, 5, 3, 1],
	[1, 3, 4, 2, 0]
]

def getRound(D, top):
	result = []
	for index in dice[top]:
		result.append(D[index])
	return result

def compareRound(l1, l2):
	if l1[4] != l2[4]:
		return False
	elif l1[0] not in l2:
		return False
	offset = l2.index(l1[0])
	
	for i in range(4):
		if l1[i] != l2[(i+offset)%4]:
			return False
	return True

def compare(D1, D2, i1):
	if D1[i1] not in D2:
		return False
	i2 = D2.index(D1[i1])
	return compareRound(getRound(D1, i1), getRound(D2, i2))

def isSame(D1, D2):
	for i in range(6):
		if compare(D1, D2, i):
			return True
	return False

def isAllDifferent(DList, n):
	for i in range(n-1):
		for j in range(i+1, n):
			if isSame(DList[i], DList[j]):
				return False
	return True

n = int(input())
DList = []
for i in range(n):
	DList.append(input().split(" "))


if isAllDifferent(DList, n):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 5608
#include <stdio.h>
int main()
{
    int i,j,J,I,h,w;
    int a[52][52]={0};
    char tmp;
    scanf("%d %d",&h,&w);
    //input
    for(j=1;j<=h;j++)
    {
        for(i=1;i<=w;i++)
        {
            scanf("%c",&tmp);
            if(tmp=='\n')
            {
                i--;
                continue;
            }
            if(tmp=='#')
            {
                a[j][i]= -1024;
            }
        }
    }
    
    //count
    for(j=1;j<=h;j++)
    {
        for(i=1;i<=w;i++)
        {
            for(J=-1;J<=1;J++)
            {
                for(I=-1;I<=1;I++)
                {
                    if(a[j+I][i+J] < 0)
                    {
                        a[j][i]+=1;
                    }
                }
            }
        }
    }

    //display
    for(j=1;j<=h;j++)
    {
        for(i=1;i<=w;i++)
        {
            if(a[j][i] < 0)
            {
                printf("#");
            }
            else
            {
                printf("%d",a[j][i]);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
    return os << "(" << P.fi << "," << P.se << ")";
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
    os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
template <typename T>
T power_mod(T base, int exp, int mod = MOD) {
    T res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
template <typename T>
T power(T base, int exp) {
    T res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, MOD - 2);
}

/******************************** template ********************************/
#define N 100010
ll k;
ll a[N];

int main() {
    cin >> k;
    for (int i = 0; i < k; ++i) {
        scanf("%lld", a + i);
    }
    ll l = 2, r = 2;
    for (int i = k - 1; i >= 0; --i) {
        l = (l + a[i] - 1) / a[i] * a[i];
        r = r / a[i] * a[i];
        if (l > r) {
            cout << -1;
            return 0;
        }
        r += a[i] - 1;
    }
    cout << l << " " << r;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

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

    int targetNumber = b;
    do {
        a *= 10;
    } while ((b /= 10) != 0);

    targetNumber += a;
    for (long i = 0; i < sqrt(targetNumber + 1); ++i) {
        if (i * i == targetNumber) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384