akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<iterator>
#include <algorithm>

using namespace std;

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
    }
    vector<pair<int, int> > AB(N);

    for (int i = 0; i < N; i++){
        AB[i] = make_pair(A[i], B[i]);
    }
    sort(AB.begin(), AB.end());
    long long ans = 0;
    for  (int i = 0; i < N; i++){
        int buy = min(M, AB[i].second);
        ans += (long long)buy * AB[i].first;
        M -= buy;
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int a,b,t,ans=0;
	cin >> a >> b >> t;
	for(int i=a; i<=t; i=i+a){
		ans+=b;
	}
	cout << ans;
	return(0);
}

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

int main(){
int D;
  cin >> D;
  
  if(D == 22) cout << "Christmas Eve Eve Eve" << endl;
  else if(D == 23) cout << "Christmas Eve Eve" << endl;
  else if(D == 24) cout << "Christmas Eve" << endl;
  else if(D == 25) cout << "Christmas" << endl;

return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    if(n>=30) cout << "Yes" << endl;
    else  cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3548
// AtCoder Regular Contest 068
// D - Card Eater

#include <cstdio>
#include <algorithm>
#define MAX_N 100000
using namespace std;
typedef long long int ll;


int N;
int A[MAX_N];
int ans;

int main() {

  int a;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  sort(A, A + N);

  a = A[0];
  ans = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] != a) {
      a = A[i];
      ans += 1;
    }
  }
  ans += (ans % 2) - 1;

  printf("%d\n", ans);

  return 0;

}




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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a;
  int n;
  cin >> n;
  long long k;
  cin >> k;
  int q;
  cin >> q;
  vector<int> vec(n);
  int tmp = k;
  for (int i = 0; i < q; i++) {
    cin >> a;
    if (a != 1) {
      tmp--;
    }
    // cout << "i: " << i << "  tmp: " << tmp << '\n';
    (++vec[a-1]);
  }

  int dif = tmp - vec[0];
  for (int i = 0; i < n; i++) {
    if (vec[i] + dif <= 0) {
      cout << "No" << '\n';
    } else {
      cout << "Yes" << '\n';
    }
  }

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int h,w;cin>>h>>w;
    char c[h][w];
    rep(i,h)rep(j,w) cin>>c[i][j];
    vector<vector<int>> a(h,vector<int>(w,0));
    int roty[8]={1,1,0,-1,-1,-1,0,1},rotx[8]={0,1,1,1,0,-1,-1,-1};
    rep(i,h)rep(j,w){
        if(c[i][j]=='#'){
            a[i][j]=-1;
            continue;
        }
        rep(k,8){
            int ny=i+roty[k],nx=j+rotx[k];
            if(0>ny||ny>=h||0>nx||nx>=w)continue;
            if(c[ny][nx]=='#')a[i][j]++;
        }
    }
    rep(i,h){
        rep(j,w){
            if(a[i][j]==-1)cout<<"#";
            else cout<<a[i][j];
        }
        cout<<endl;
    }
}

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

int main() {
 int N,H,W;
 cin >> N >> H >> W;
 vector<int>A(N);
 vector<int>B(N);
 for(int i=0;i<N;i++){
    cin >> A.at(i) >> B.at(i);
 }

  int count =0;
  for(int i=0;i<N;i++){
   if((A.at(i)>=H)&&(B.at(i)>=W)){
     count++;
   }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
using namespace std;

int main(){
    string a[100];
    int H, W;
    cin >> H >> W;
    int i = 0;
    int nrow = H;
    while (H--){
        cin >> a[i];
        if (a[i].find("#") == -1){
            nrow--;
        }
        else{
            i++;
        }
    }
    int j = 0;
    while (W--){
        bool is_white = true;
        for (i = 0; i < nrow; i++){
            if (a[i][j] == '#'){
                is_white = false;
            }
        }
        if (is_white) {
            for (i = 0; i < nrow; i++){
                a[i].erase(a[i].begin() + j);
            }
        }
        else{
            j++;
        }
    }
    for (i = 0; i < nrow; i++){
        cout << a[i] << endl;
    }
    return 0;
}


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

typedef long long ll;
ll mod = 1e9 + 7;

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

    vector<ll> v(4, 0);
    v[0] = 1;

    for(int i = 0; i < s.length(); i++){
        vector<ll> next = v;
        if(s[i] == 'A' || s[i] == '?') next[1] += v[0];
        if(s[i] == 'B' || s[i] == '?') next[2] += v[1];
        if(s[i] == 'C' || s[i] == '?') next[3] += v[2];
        if(s[i] == '?'){
            for(int j = 0; j < 4; j++){
                next[j] += 2*v[j];
            }
        }
        for(int j = 0; j < 4; j++){
            next[j] %= mod;
        }
        v = next;
    }

    cout << v[3] << endl;

    return 0;
}

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

int main(){
	int H,W;
	char a[10][10] = {};
	scanf("%d%d",&H,&W);
	for(int i = 0 ; i < H ; i ++){
		scanf("\n");
		for(int j = 0 ; j < W ; j ++){
			scanf("%c",&a[i][j]);
		}
	}
	
	int cnt = 0;
	for(int i = 0 ; i < H ; i ++){
		for(int j = 0 ; j < W ; j ++){
			if(a[i][j] == '#')cnt ++;
		}
	}
	if(cnt != H+W-1){
		puts("Impossible");
		return 0;
	}
	int x = 0, y = 0;
	while(x != H-1 || y != W-1){
		if(a[x+1][y] == '#')x ++;
		else if(a[x][y+1] == '#')y ++;
		else {
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, M, Ans = 0;cin >> N >> M;
vector<ll> a(N);
map<ll, ll> P;

rep(i, 0, N){

    cin >> a[i];

    Ans += a[i];

    P[a[i]]++;

}

rep(i, 0, M){

    ll b, c;cin >> b >> c;

    for(auto p : P ){
    
        if(p.first >= c)break;

        if(b <= p.second){

            Ans += b*c - p.first*b;P[c] += b;
          
            P[p.first] -= b;
                    
            b = 0;          

            if(p.second == 0)P.erase(p.first);break;

        }

        else{

            Ans += p.second*c - p.first*p.second;
          
            P[c] += p.second;
          
            b -= p.second;
          
            P.erase(p.first);
           
        }

    }
  
  //for(auto p : P )cout << p.first << " " << p.second << endl;

}
cout << Ans;
}

Measured memory_bytes: 10328
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read;
            if (S == "Sunny")
                WriteLine("Cloudy");
            else if (S == "Cloudy")
                WriteLine("Rainy");
            else if (S == "Rainy")
                WriteLine("Sunny");
        }

        static long GcdArray(long[] array)
        {
            var ans = array[0];
            for(var i=1; i<array.Length; i++)
            {
                ans = Gcd(ans, array[i]);
            }
            return ans;
        }

        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

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

    string s;
    cin >> s;
    int l = 0, n = s.size(), i = 0;
    while (i < n)
    {
        while (s[i] == 'B' && i < n)
            --l, ++i;
        if (l < 0) l = 0;
        if (s[i] == '0' || s[i] == '1')
            s[l] = s[i], ++l, ++i;
    }
    for (int i = 0; i < l; ++i)
        cout << s[i];
}

Measured memory_bytes: 3632
N = 5
a = [int(input()) for i in range(N)]
b = [i % 10 for i in a]
c = []
for i in b:
    c.append((10 - i)%10)
d = [i // 10 for i in a]
e = len([i for i in c if i > 0])

ans = (10-max(c)) + (sum(d)+e-1)*10
print(ans)


Measured memory_bytes: 3060
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10;

int main() {
	int n, ind; ll l;
	cin >> n >> l;
	ll prv, cur;
	cin >> prv;
	bool ans = false;
	for (int i = 2; i <= n; ++i) {
		cin >> cur;
		if (prv + cur >= l) {
			ans = true;
			ind = i;
		}
		prv = cur;
	}
	if (ans) {
		cout << "Possible\n";
		for (int i = 1; i < ind - 1; ++i) {
			cout << i << endl;
		}
		for (int i = n - 1; i >= ind; --i) {
			cout << i << endl;
		}
		cout << ind - 1 << endl;
	} else {
		cout << "Impossible\n";
	}
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  double l;
  cin >> l;
  printf("%.10f\n", pow(l / 3, 3));
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
string func(string S){
    int temp[26]={};
    int now=0;
    for(int i=0;i<S.length();i++){
        int c=S[i]-'a';
        if(!temp[c]){
            now++;
            temp[c]=now;
        }
    }
    string ret;
    for(int i=0;i<S.length();i++){
        ret+=char('a'+temp[S[i]-'a']-1);
    }
    return ret;
}
signed main(){

    int N;
    cin>>N;
    set<string> tes[2];
    tes[0].insert("a");
    for(int i=0;i<N-1;i++){
        int now=i%2, next=(i+1)%2;
        for(string S:tes[now]){
            for(int i=0;i<13;i++){
                string T=S+char('a'+i);
                tes[next].insert(func(T));
            }
        }
        tes[now].clear();
    }
    for(string S:tes[(N+1)%2])
        cout<<S<<endl;
    return 0;
}


Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    
    int n;
    cin >> n;
    
    vector<int> a(n, 0);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    
    int m = a[n - 1] / 2;
    int s = m;
    int now = a[0];
    
    for (int i = 0; i < n; ++i)
    {
        int tmp = abs(m - a[i]);
        if (tmp < s)
        {
            s = tmp;
            now = a[i];
        }
        
        if (a[n - 1] % 2)
        {
            int tt = abs(m + 1 - a[i]);
            if (tt < s)
            {
                s = tt;
                now = a[i];
            }
        }
    }
    
    cout << a[n - 1] << " " << now << endl;
    
    
    return 0;
}


Measured memory_bytes: 640
import collections
import fractions
import itertools
import functools
import bisect
import heapq
import math

def solve():
    a, b, c, d = map(int, input().split())
    ans = [
        a*c,
        a*d,
        b*c,
        b*d
    ]
    print(max(ans))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 10480
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}
int main() {
    int N, M; cin >> N >> M;
    ll L; cin >> L;

    const ll INF = 1LL << 32;

    ll d[N][N];
    repp(i,0,N) {
        repp(j,0,N) {
            if (i == j) d[i][j] = 0;
            else d[i][j] = INF;
        }
    }

    repp(i, 0, M) {
        int A, B; cin >> A >> B;
        ll C; cin >> C;
        d[A-1][B-1] = C;
        d[B-1][A-1] = C;
    }

    repp(k,0,N) {
        repp(i,0,N) {
            repp(j,0,N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }

    ll e[N][N];
    repp(i,0,N) {
        repp(j,0,N) {
            if (i == j) e[i][j] = 0;
            else if (d[i][j] <= L) e[i][j] = 1;
            else e[i][j] = INF;
        }
    }

    repp(k,0,N) {
        repp(i,0,N) {
            repp(j,0,N) e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
        }
    }

    int Q; cin >> Q;
    repp(i,0,Q) {
        int s, t; cin >> s >> t;
        ll res = e[s-1][t-1] < INF? e[s-1][t-1] - 1 : -1;
        cout << res << endl;
    }
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> a(m), b(m), v(n);
  REP(i, m) cin >> a[i] >> b[i];
  REP(i, n) v[i] = i + 1;
  do {
    if (v[0] != 1) break;
    bool exist = true;
    int i;
    for (i = 0; exist && i < n - 1; ++i) {
      exist = false;
      REP(j, m) {
        if (v[i] == a[j] && v[i + 1] == b[j]) exist = true;
        if (v[i] == b[j] && v[i + 1] == a[j]) exist = true;
      }
    }
    if (exist && i >= n - 1) ++ans;
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a[3][3];
    for(int i=0;i<3;i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int b;
        cin >> b;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a[j][k] == b) a[j][k] = 0;
            }
        }
    }
    if(a[0][0] == 0 && a[0][1] == 0 &&a[0][2]==0) cout << "Yes" << endl;
    else if(a[1][0] ==0 && a[1][1] == 0 &&a[1][2] ==0) cout << "Yes" << endl;
    else if(a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0) cout << "Yes" << endl;
    else if(a[0][0] == 0 &&a[1][0] == 0 &&a[2][0]==0) cout << "Yes" << endl;
    else if(a[0][1] == 0 &&a[1][1] == 0&&a[2][1]==0) cout << "Yes" << endl;
    else if(a[0][2] == 0&&a[1][2] == 0 &&a[2][2]==0) cout << "Yes" << endl;
    else if(a[0][0] == 0 &&a[1][1] == 0 &&a[2][2]==0) cout << "Yes" << endl;
    else if(a[0][2] ==0 && a[1][1] == 0 &&a[2][0]==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

bool is_sucess(int n, int *p)
{
    int last = p[n-1];
    for(int i = n - 2; 0 <= i; i--){
	    if(last < p[i]){
	    	if(last+1 != p[i]){
	    		return false;
	    	}
	    }else{
			last = p[i];
	    }
    }
    
    return true;
}

int main()
{
    // 入力
    int n;
    cin >> n;
    
    int *p = new int[n];
    for(int i = 0; i < n; i++){
	    cin >> p[i];
    }
    
    // 出力
    cout << (is_sucess(n, p) ? "Yes" : "No") << endl;
    
    delete[] p;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<# x "="<<x<<endl

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

#define INF 1000000000
#define EPS 1e-10

double a[100], b[100], c[100], d[100];

#define EQ(x,y) fabs((x)-(y))<(EPS)

inline double dist(double x1,double y1,double x2,double y2){
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}


int main(){
  int n;
  int cnt=1;
  while(cin>>n, n){
    /*
    if(cnt==49){
      fprintf(stderr, "%d\n", n);
      rep(i,n){
	scanf("%lf %lf %lf %lf", &a[i], &b[i], &c[i], &d[i]);
	fprintf(stderr, "%lf %lf %lf %lf\n", a[i], b[i], c[i], d[i]);
      }
      
    } else {
    */
    rep(i,n){
      scanf("%lf %lf %lf %lf", &a[i], &b[i], &c[i], &d[i]);
    }
    /*
    }cnt++;
    */

    int res=1;
    rep(i,n){
      // new line idx=i
      vector<pair<double, double> > cross;
      int adds=1;
      rep(j,i){
        // check if i and j have intersection point
        // => not paralell and inner square

        // is paralell ?
        if(EQ((a[i]-c[i])*(b[j]-d[j]), (a[j]-c[j])*(b[i]-d[i]))) continue;

        // calc intersection point
        double nx;
        double ny;
        if( EQ(a[i],c[i]) ){
          double dj = (b[j]-d[j])/(a[j]-c[j]);
          nx = a[i];
          ny = dj*(nx-a[j])+b[j];
        } else if( EQ(a[j],c[j]) ){
          double di = (b[i]-d[i])/(a[i]-c[i]);
          nx = a[j];
          ny = di*(nx-a[i])+b[i];
        } else {
          double di = (b[i]-d[i])/(a[i]-c[i]);
          double dj = (b[j]-d[j])/(a[j]-c[j]);
          nx = (b[j]-dj*a[j]-(b[i]-di*a[i]))/(di-dj);
          ny = di*(nx-a[i])+b[i];
          assert(EQ(ny, dj*(nx-a[j])+b[j]));
        }
        //      dbg(nx);dbg(ny);

        if(fabs(nx)-100.0<=-EPS && fabs(ny)-100.0<=-EPS){
          int reps=cross.size();
          bool flg=true;
          rep(k,reps){
            // new point is already added or not
	    //if(EQ(cross[k].first, nx) && EQ(cross[k].second, ny)){
	    if( dist(cross[k].first,cross[k].second,nx,ny)<EPS ){
              flg=false; break;
            }
          }
          if(flg){
            cross.pb(mp(nx,ny));
            adds++;
          }
        }

      }// rep  j
      //      dbg(adds);
      res += adds;
    }//rep i

    cout<<res<<endl;

  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  if(s.size()%2)cout<<"No"<<endl;
  else{
    map<char,char>MP;
    MP['p']='q';
    MP['q']='p';
    MP['d']='b';
    MP['b']='d';
    bool fl=true;
    ll n=s.size();
    for(int i=0;i<n/2;i++){
      if(MP[s[n-i-1]]!=s[i])fl=false;
    }
    if(fl)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let (a, b) = (char(), char());
    println!(
        "{}",
        if a == b {
            "="
        } else {
            if a < b {
                "<"
            } else {
                ">"
            }
        }
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

int main() {
    int n; cin >> n;
    vector< vector<long long> > dp(n+1, vector<long long>((1 << n), 0));
    dp[0][0] = 1;
    int pair[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> pair[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int bit = 0; bit < (1 << n); bit++) {
            if (dp[i][bit] == 0) continue;
            for (int j = 0; j < n; j++) {
                if (pair[i][j] == 0) continue;
                if (bit & (1 << j)) continue;
                dp[i+1][bit|(1<<j)] += dp[i][bit];
                dp[i+1][bit|(1<<j)] %= mod;
            }
        }
    }
    cout << dp[n][(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 377216
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public class Main {
	
	public static void main(String[] args) throws Exception {
		List<Double> hList = new ArrayList<Double>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String var;
		while ((var = br.readLine()) != null) {
			double h = Double.parseDouble(var);
			hList.add(h);
		}
		Collections.sort(hList);
		double hMin = (Double) hList.get(0);
		double hMax = (Double) hList.get(hList.size() - 1);
		
		System.out.println(hMax - hMin);
	}
}

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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

typedef long long ll;

using std::cin;
using std::cout;
using std::endl;
using std::vector;

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

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    REP(int, i, 0, n) cin >> a[i];
    REP(int, i, 0, n) cin >> b[i];
    REP(int, i, 0, n-1) cin >> c[i];

    int score = 0;
    int prev_dish = -1;
    REP(int, i, 0, n) {
        int dish = a[i] - 1;
        score += b[dish];
        if (i >= 1 && dish - prev_dish == 1) {
            score += c[prev_dish];
        }
        prev_dish = dish;
    }
    cout << score << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001
#define MAX 10000
#define rad M_PI/3

int main()
{
    unsigned short *A,*B;
    int X[MAX+1],m,i,j;

    scanf("%d",&m);

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

    for (i = 0; i <= MAX; i++) {  X[i]=0;}
    for(i=0;i<m;i++){
        scanf("%hu",&A[i+1]);
        X[A[i+1]]++;
    }
    for(i=1;i<=MAX;i++){X[i]=X[i]+X[i-1];}
    for(j=1;j<=m;j++){
        B[X[A[j]]]=A[j];
        X[A[j]]--;
    }
    for(i=1;i<=m;i++){
        if(i>1)printf(" ");
        printf("%d",B[i]);
    }

    printf("\n");
  return 0;
}



Measured memory_bytes: 9632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "Draw" << endl;
        return 0;
    }
    if(a == 1){
        cout << "Alice" << endl;
        return 0;
    }
    if(b == 1){
        cout << "Bob" << endl;
        return 0;
    }
    if(a > b){
        cout << "Alice" << endl;
    }
    else{
        cout << "Bob" << endl;
    }
    return 0;
}

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

d = {}
ans = 0

for _ in range(n):
    a = int(input())
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

for k,v in d.items():
    if v % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 15072
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int digits = Integer.toString(a + b).length();
            System.out.println(digits);
        }
    }
}

Measured memory_bytes: 26420
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  int Maxp = -1;
  for(int i = 1; i <= 32; i++){
    for(int j = 2; j < 10; j++){
      if(pow(i, j)>n)continue;
      int a = pow(i, j);
      Maxp = max(Maxp, a);
    }
  }
  cout << Maxp << endl;
  return 0;
}



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

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

    long n;
    cin >> n;

    long dp[n];
    for (long i = 0; i <= n; ++i) {
        dp[i] = i;
    }

    for (long i = 1; i <= n; ++i) {
        for (long j = 1; j <= i; j *= 6) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
        for (long j = 1; j <= i; j *= 9) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }

    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
	"sort"
)

type Int64Slice []int64

func (p Int64Slice) Len() int           { return len(p) }
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func main() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)

	vals := make(Int64Slice, 0, n)
	for index := 0; index < n; index++ {
		var n int64
		fmt.Scan(&n)

		vals = append(vals, n)
	}

	take := Min(n, k)

	var max int64

	for i := 0; i <= take; i++ {
		lim := take - i
		for j := 0; j <= lim; j++ {
			var val int64
			tmpVals := make(Int64Slice, 0, take)
			drop := k - i - j
			tmpVals = append(tmpVals, vals[:j]...)
			tmpVals = append(tmpVals, vals[n-i:]...)

			// for idx := 0; idx < i; idx++ {
			// 	tmpVals = append(tmpVals, vals[idx])
			// }

			// for idx := 0; idx < j; idx++ {
			// 	tmpVals = append(tmpVals, vals[n-idx-1])
			// }

			// fmt.Printf("%#v %#v %#v %#v\n", i, j, drop, tmpVals)
			sort.Sort(tmpVals)
			// fmt.Printf("%#v %#v %#v %#v\n", i, j, drop, tmpVals)

			for _, item := range tmpVals {
				if drop > 0 && item < 0 {
					drop--
					continue
				}
				val += int64(item)
			}

			if val > max {
				max = val
			}
		}
	}

	fmt.Printf("%d\n", max)
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("function min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 1152
n = int(input())
a = list(map(int, input().split()))
a.sort()

max_val = a.pop()

max_dif = 10 ** 100
ret = 0

for item in a:
    dif = abs(max_val - item * 2)
    if max_dif > dif:
        ret = item
        max_dif = dif

print(max_val, ret)


Measured memory_bytes: 14432
// This file is in ~/.config/geany/templates/files
#include<bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair
typedef long long tint;
int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}
string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

tint ele(tint a, tint b){
	if(b==0)return 1;
	if(b%2==0){
		return ele((a*a), b/2);
	}else{
		return a*ele((a*a), b/2);
	}
}

tint mcd(tint a, tint b){
	if(a==0)return b;
	return mcd(b%a, a);
}

double d_abs(long a, long b){
	if(a>b){
		return a-b;
	}
	return b-a;
}

void solve(int caso){
	int n;
	cin>>n;
	int a[2][n];
	forn(i, 2){
		forn(j, n){
			cin>>a[i][j];
		}
	}
	int pre[n];
	pre[0]=a[0][0];
	forsn(i, 1, n){
		pre[i]=a[0][i]+pre[i-1];
	}
	
	int suf[n];
	suf[n-1]=a[1][n-1];
	forsn(i, 1, n){
		suf[n-1-i]=a[1][n-1-i]+suf[n-i];
	}
	int best=0;
	forn(i, n){
		int pos=pre[i]+suf[i];
		best=max(best, pos);
	}
	cout<<best<<endl;
}



int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	T=1;
	forn(i,T){
		solve(i);
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
	long long a,b,c,d,max;
	cin>>a>>b>>c>>d;
	max=b*d;
	if(max<a*c)
	max=a*c;
	if(max<a*d)
	max=a*d;
	if(max<b*c)
	max=b*c;
	cout<<max<<endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();

    if (d == 22) {
      System.out.println("Christmas Eve Eve Eve");
    }

    if (d == 23) {
      System.out.println("Christmas Eve Eve");
    }

    if (d == 24) {
      System.out.println("Christmas Eve");
    }

    if ((d == 25)) {
      System.out.println("Christmas");
    }
  }
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int kazu[10];
	ll tunagi[10][11]={};
	int N=S.size();
	rep(i,N){
		kazu[i]=S[i]-'0';
	}
	rep(i,N){
		tunagi[i][i+1]=kazu[i];
		for(int j=i+2;j<=N;j++){
			tunagi[i][j]=tunagi[i][j-1]*10+kazu[j-1];
		}
	}
	ll ans=0;
	rep(i,N){
		for(int j=i+1;j<=N;j++){
			ans+=tunagi[i][j]*(1<<max(0,i-1))*(1<<max(0,N-j-1));
		}
	}
	prin(ans);
	return 0;
}


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

#define pb push_back
#define sz(v) ((int)(v.size()))
#define all(v) v.begin(), v.end()
#define nie NULL
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef vector<pii> vpi;

const int inf(1e9);
const int maxN(3e5 + 10);
const ll mod(1e9 + 7);

template <typename T1>
inline void in(T1 &a1) { cin >> a1; }
template <typename T1, typename T2>
inline void in(T1 &a1, T2 &a2) { cin >> a1 >> a2; }
template <typename T1, typename T2, typename T3>
inline void in(T1 &a1, T2 &a2, T3 &a3) { cin >> a1 >> a2 >> a3; }

void _main();
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/*--------------------------------------*/
	_main(); return 0;
}

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

void _main() {
	int a, c; in(a, c);
	printf("%d\n", 2 * c - a);
}

Measured memory_bytes: 256
from sys import stdin

def main():

    input = stdin.readline

    S = input()[:-1]

    zenhan = S[0:int(len(S)/2)]
    kouhan = S[int(len(S)-((len(S)-1)/2)):]

    #1
    if zenhan == kouhan[::-1]:
        zenhan_z = zenhan[0:int(len(zenhan)/2)]
        zenhan_k = zenhan[int(len(zenhan)-((len(zenhan)-1)/2)):]
        if zenhan_z == zenhan_k[::-1]:
            kouhan_z = kouhan[0:int(len(kouhan)/2)]
            kouhan_k = kouhan[int(len(kouhan)-((len(kouhan)-1)/2)):]
            if kouhan_z == kouhan_k[::-1]:
                print("Yes")
                return
    
    print("No")

    
if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    ll a, b, k;
        cin >> a >> b >>k;
    if(a-k<0){
        k -= a;
        a = 0;
        b = max(0LL, b-k);
    }else{
        a -= k;
    }
    
    cout << a << ' ' << b << endl;
}

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

int main () {

    long N, M;
    scanf("%ld %ld", &N, &M);

    vector<pair<long, long>> drink(N);

    for (int i = 0; i < N; i++) {
        scanf("%ld %ld", &drink[i].first, &drink[i].second);
    }

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

    long cost = 0;

    for (int i = 0; i < N; i++) {
        long buy_drinks = min(drink[i].second, M);
        cost += buy_drinks * drink[i].first;
        M -= buy_drinks;
        if (M <= 0) break;
    }
    cout << cost << endl;

    return 0;
}


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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int a,b,c;
	cin >> a >> b >> c;
	if(b-a == c-b)P("YES");
	else P("NO");
}

int main() {
    solve();
    return 0;
}


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

int main(void) {
    string s;
    cin >> s;
    for (int ans = (s.size() % 2 ? s.size() / 2 : s.size() / 2 - 1); ans > 0; ans--) {
        bool flag = true;
        for (int i = 0; i < ans; i++) {
            if (s[i] != s[ans + i]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << ans * 2 << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}
	
int main(){
	init();
	string a,b,c;
	cin>>a>>b>>c;
	if(*(a.end()-1)==*(b.
	begin()) && *(b.end()-1)==*(c.begin())){
		cout<<"YES"<<endl;
	}else cout<<"NO"<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#define mod(a,b) ((a-b)>0? a-b : b-a)
#define min(a,b) (a<b? a : b)

int main(){
	int n, pedra[100000], custo[100000], t1, t2;
	
	scanf("%d", &n);
	for(int i=0; i<n; i++)
		scanf("%d", &pedra[i]);
	
	custo[0] = 0;
	custo[1] = mod(pedra[0], pedra[1]);
	for(int i=2; i<n; i++){
		t1 = custo[i-1] + mod(pedra[i-1], pedra[i]);
		t2 = custo[i-2] + mod(pedra[i-2], pedra[i]);
		custo[i] = min(t1,t2);
	}

	printf("%d\n", custo[n-1]);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <map>
#include <queue>
using namespace std;

unsigned int swapPos( unsigned int s, int a, int b )
{
	unsigned int x, y, ret;
	x = ( s >> ( ( 7 - a ) * 4 ) ) & ( ( 1 << 4 ) - 1 );
	y = ( s >> ( ( 7 - b ) * 4 ) ) & ( ( 1 << 4 ) - 1 );
	unsigned long long int mask;
	mask = ( ( ( 1 << 4 ) - 1 ) << ( ( 7 - a ) * 4 ) ) | ( ( ( 1 << 4 ) - 1 ) << ( ( 7 - b ) * 4 ) );
	ret = s & ~( mask );
	ret += ( x << ( ( 7 - b ) * 4 ) ) + ( y << ( ( 7 - a ) * 4 ) );
	return ret;
}

int main()
{
	map< unsigned int, int > ans;
	queue< unsigned int > q;


	unsigned int s = 0;
	for( unsigned int i = 0; i < 8; ++i ){
		s <<= 4;
		s += i;
	}
	ans.insert( make_pair( s, 0 ) );
	q.push( s );

	int cnt = 0;
	while( !q.empty() ){
		++cnt;
		int size = q.size();
		for( int i = 0; i < size; ++i ){
			unsigned int s = q.front();
			q.pop();
			unsigned int pos = 0;
			unsigned int t = s;
			for( unsigned int j = 0; j < 8; ++j ){
				if( ( ( t & ( ( 1 << 4 ) - 1 ) ) ) == 0 ){
					pos = 7 - j;
					break;
				}
				t >>= 4;
			}
			bool right, left;
			right = left = false;
			if( pos != 3 && pos != 7 ) right = true;
			if( pos != 0 && pos != 4 ) left = true;
			t = swapPos( s, pos, ( pos + 4 ) % 8 );
			if( ans.find( t ) == ans.end() ){
				ans.insert( make_pair( t, cnt ) );
				q.push( t );
			}
			if( right ){
				t = swapPos( s, pos, pos + 1 );
				if( ans.find( t ) == ans.end() ){
					ans.insert( make_pair( t, cnt ) );
					q.push( t );
				}
			}
			if( left ){
				t = swapPos( s, pos, pos - 1 );
				if( ans.find( t ) == ans.end() ){
					ans.insert( make_pair( t, cnt ) );
					q.push( t );
				}
			}
		}
	}

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

		s = 0;
		for( unsigned int i = 0; i < 8; ++i ){
			s <<= 4;
			s += a[ i ];
		}
		cout << ans[ s ] << endl;
	}

	return 0;
}

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

int main(){
    int n; cin >> n;
    int able;
    vector<ll> x(n), y(n), h(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0){
            able = i;
        }
    }
    int flag = 1;
    for(int i = 0; i <= 100; i++){
        for(int l = 0; l <= 100; l++){
            flag = 1;
            ll H = h[able] + abs(x[able] - i) + abs(y[able] - l);
            for(int k = 0; k < n; k++){
                ll a = max(H - abs(x[k] - i) - abs(y[k] - l), 0LL);
                if(h[k] != a){
                    flag = 0;
                    break;
                } 
            }
            if(flag == 1){
                if(H == 0){continue;}
                cout << i << ' ' <<l << ' ' <<H << endl;
                return 0;
            }
        }
    }
}

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<pair<ll,int>> dt(N);
  for(int i=0;i<N;i++){
    cin>>dt.at(i).second>>dt.at(i).first;
  }
  sort(dt.begin(),dt.end());
  reverse(dt.begin(),dt.end());

  set<int> other;
  set<int> l_index;
  set<int> neta;

  ll sum=0;
  for(int i=0;i<K;i++){
    if(neta.count(dt.at(i).second)==0){
      neta.insert(dt.at(i).second);
      l_index.insert(i);
      sum+=dt.at(i).first;
    }else{
      other.insert(i);
      sum+=dt.at(i).first;
    }
  }
  ll ans=sum+(ll)neta.size()*(ll)neta.size();
  for(int i=K;i<N;i++){
    if(other.size()==0){
      break;
    }
    if(neta.count(dt.at(i).second)==0){
      l_index.insert(i);
      neta.insert(dt.at(i).second);
      sum+=dt.at(i).first;
      int k=*rbegin(other);
      sum-=dt.at(k).first;
      other.erase(k);
      ans=max<ll>(ans,sum+(ll)neta.size()*(ll)neta.size());
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define int long long int
#define ld long double
#define ar array
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1e5 + 7;

int a[maxN];

void solve()
{

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

    int q;
    cin>>q;
    for(int i = 0; i < q; i ++) {
        int b, c;
        cin>>b>>c;
        ans -= b * a[b];
        a[c] += a[b];
        ans += c * a[b];
        a[b] = 0;
        cout<<ans<<'\n';
    }
    cout<<"\n";
    return ;
}

/*
*/

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

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



Measured memory_bytes: 4328
import fractions

N, X = map(int, input().split(" "))
X = [X]
X.extend(map(int, input().split(" ")))
X.sort()
ans = X[1] - X[0]
for i in range(1, len(X) - 1):
    ans = fractions.gcd(ans, X[i + 1] - X[i])
print(ans)

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

signed main(){
	int A, B;
	scanf("%d%d", &A, &B);
	for(int i = 1; i <= 3; i++){
		if(i != A && i != B){
			printf("%d\n", i);
		}
	}
	return 0;
}

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

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i=0; i<N; ++i) cin >> v[i] >> w[i];

    vector<int> dp(W+1, 0);
    for (int i=0; i<N; ++i) {
        for (int j=0; j<=W; ++j) {
            if (j > 0) dp[j] = max(dp[j], dp[j-1]);
            if (j+w[i] <= W) dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
        }
    }
    cout << dp[W] << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <cstdio>
#include <cstdint>

intmax_t cubic(intmax_t n) {
  return n*n*n;
}

int main() {
  intmax_t N, K;
  scanf("%jd %jd", &N, &K);

  intmax_t res = cubic(N/K);

  if (K % 2 == 0)
    res += cubic((N+K/2)/K);

  printf("%jd\n", res);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {                                                                
    int i, n;                                                                   
    int money = 100000;                                                         
                                                                                
    scanf("%d", &n);                                                            
    for (i = 0; i < n; i++) {                                                   
        money = money * 1.05;                                                   
        if (money % 1000 != 0) {                                                
            money = ((money / 1000) + 1) * 1000;                                
        }                                                                       
    }                                                                           
    printf("%d\n", money);                                                      
                                                                                
    return 0;                                                                   
}

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

int main(){
    string S;
    int N, ans;
    char c = '1';

    std::cin >> N >> S;
    ans = N;

    for(int i = 0; i < N; i++){
        if(S[i] == c){
            ans--;
        }
        c = S[i];
    }

    std::cout << ans;
}


Measured memory_bytes: 3764