akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

vector<p> st = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

int BFS(int x, int y, int x1, int y1, vector<vector<char>> &a, int k){
    vector<vector<int>> dist(a.size(), vector<int>(a[0].size(), INF));
    queue<p> s;
    s.push({x, y});
    dist[x][y] = 0;
    while (!s.empty()){
        p q = s.front();
        if (q.first == x1 && q.second == y1){
            return dist[x1][y1];
        }
        int q1 = q.first, q2 = q.second, t = 0;
        s.pop();
        for (p q3: st){
            q1 = q.first+q3.first, q2 = q.second+q3.second, t = 0;
            while (t < k && q1 > -1 && q1 < a.size() && q2 > -1 && q2 < a[0].size()){
                if (dist[q1][q2] <= dist[q.first][q.second] || a[q1][q2] == '@'){
                    break;
                }
                if (dist[q1][q2] == INF) {
                    s.push({q1, q2});
                }
                dist[q1][q2] = dist[q.first][q.second]+1;
                q1 += q3.first, q2 += q3.second, t++;
            }
        }
    }
    return -1;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    int x, y, x1, y1;
    cin >> x >> y >> x1 >> y1;
    x--, y--, x1--, y1--;
    vector<vector<char>> a(n, vector<char>(m));
    for (int q = 0; q < n; q++){
        for (int q1 = 0; q1 < m; q1++){
            cin >> a[q][q1];
        }
    }
    cout << BFS(x, y, x1, y1, a, k) << endl;
    return 0;
}


Measured memory_bytes: 19920
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

pii dfs(int v, int p, const vector<vi>& g) {
  pii ans(v, 1);

  for(int u : g[v]) {
    if (u == p) continue;
    pii tmp = dfs(u, v, g);
    tmp.sc++;
    if (tmp.sc > ans.sc) {
      ans = tmp;
    }
  }

  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<vi> g(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].eb(b);
    g[b].eb(a);
  }

  pii p = dfs(0, -1, g);
  pii q = dfs(p.fs, -1, g);
  
  cerr << q.sc << endl;
  cout << (q.sc % 3 == 2 ? "Second" : "First") << endl;
    
}


Measured memory_bytes: 26752
#include <stdio.h>

int selectionSort(int A[], int N) {
	int i, j, t, sw = 0, minj;
	for (i = 0; i < N - 1; i++) {
		minj = i;
		for (j = i; j < N; j++) {
			if (A[j] < A[minj]) minj = j;
		}
		t = A[i];
		A[i] = A[minj];
		A[minj] = t;
		if (i != minj) sw++;
	}
	return sw;
}

int main() {
	int A[100], N, i, sw;

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

	sw = selectionSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n", sw);

	return 0;
}


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

#define ll long long
using namespace std;

ll binarySearchLowerBound(ll target, ll *arr, ll end) {
    ll low = 1, high = end; ll ans =-1;
    while(low <= high){
        ll mid = (low + high)/2;
        if(arr[mid] <= target){
            ans = mid;
            low = mid + 1;
        }
        else
            high = mid - 1;
    }
    return ans;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll A[n];
    ll B[m];
    ll preA[n + 1];
    ll preB[m + 1];
    preA[0] = 0;
    preB[0] = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> A[i];
        preA[i + 1] = preA[i] + A[i];
    }
    for (ll i = 0; i < m; ++i) {
        cin >> B[i];
        preB[i + 1] = preB[i] + B[i];
    }
    ll max = 0;
    for (ll i = 0; i <= n; ++i) {
        ll totalLeft = k - preA[i];
        if (totalLeft < 0) {
            break;
        }
        ll index = binarySearchLowerBound(totalLeft, preB, m);
        if (index == -1) {
            index = 0;
        }
        if (index + i > max) {
            max = index + i;
        }
    }
    cout << max;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M;
int WA[100100];

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

  std::cin >> N >> M;

  int ac = 0, penalty = 0;

  for(int i=0;i<M;++i){
      int p;
      std::string S;
      std::cin >> p >> S;

      if(S == "AC"){
          if(WA[p] != -1){
              ac += 1;
              penalty += WA[p];
              WA[p] = -1;
          }
      }else{
          if(WA[p] != -1){
              WA[p] += 1;
          }
      }
  }

  std::cout << ac << " " << penalty << std::endl;
}


Measured memory_bytes: 640
n = int(input())
a = [int(x) for x in input().split()]
b = [0]*n
c = []

for i in range(n):
    if sum(b[n-i-1:n:n-i]) % 2 != a[n-i-1]:
        b[n-i-1] += 1
        c.append(n-i)
print(len(c))
print(' '.join(map(str, c[::-1])))

Measured memory_bytes: 19960
#include <bits/stdc++.h>
using namespace std;
signed main(void)
{
    string s, t;
    int ans = 0;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++)
        if (s[i] != t[i])
            ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
char t, start[100005];
bool flag = false;
int Q, t1, t2;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> start;
	list<char> L(start, start + strlen(start));
	cin >> Q;
	while (Q--){
		cin >> t1;
		if (t1 == 1){
			flag = !flag;
		}
		else{
			cin >> t2 >> t;
			if (flag){
				if (t2 == 1)
					L.push_back(t);				
				else
					L.push_front(t);
			}
			else{
				if (t2 == 1)
					L.push_front(t);
				else
					L.push_back(t);
			}
		}
	}
	if (flag){
		for (list<char>::reverse_iterator rit = L.rbegin(); rit != L.rend(); ++rit)
			cout << *rit;
		cout << '\n';
	}
	else{
		for (list<char>::iterator it = L.begin(); it != L.end(); ++it)
			cout << *it;
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    
    /* 文字列sのABC数を「sのうち３文字に丸をつけ、
       丸をつけた文字を左から読むとABCとなるようにする方法」と言い換える*/
    
    vvl dp(n+1, vl(4));  /* dp[i+1][j] : i文字目(iは0-index)までの処理(?の置換と丸つけ)をすでに行っていて
                                         これまでにj個丸をつけているときのsの残りの部分に対する処理を行う方法の数 */
    
    dp[n][3] = 1;
    for(ll i = n-1; i >= 0; i--) {
        for(ll j = 3; j >= 0; j--) {

            ll m1 = 1;
            if(s[i] == '?') {
                m1 = 3;
            }
            
            ll m2 = 0;
            if(s[i] == '?' || (j < 3 && s[i] == "ABC"[j])) {
                m2 = 1;
            }

            if(j == 3) {
                dp[i][j] = m1*dp[i+1][j];
            }
            else {
                // 右辺の第1項はs[i]に丸をつけない場合で、第2項はs[i]に丸をつける場合
                dp[i][j] = m1*dp[i+1][j] + m2*dp[i+1][j+1];
            }

            dp[i][j] %= mod;
        }
    }
    
    out(dp[0][0]);
    re0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ll N=ii(),K=ii();
    oie(min(N%K,K-N%K));
    return 0;
}


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

int main() {
    int n, ans, tmp, hmin, sum;
    ans = 0, sum = 0, hmin = 101, tmp = 101;
    scanf("%d", &n);
    int h[n+1] = {};
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
        if (h[i] >= 1) hmin = min(hmin, h[i]);
        sum += h[i];
    }

    while (sum > 0) {
        for (int i = 0; i < n; i++) {
            if (h[i] >= 1) {
                if (h[i+1] == 0) ans += hmin;
                h[i] -= hmin;
                if (h[i] >= 1) tmp = min(h[i], tmp);
                sum -= hmin;
            }
        }
        hmin = tmp;
        tmp = 101;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3832
#include <stdio.h>
int main(void)
{	
	int a,b,count=0;
	scanf("%d",&a);
	b=a;
	while(a>0){
		count=count+a%10;
		a=a/10;
	}
	if(b%count==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int64_t> v(2);
	v.at(0) = 2;
	v.at(1) = 1;
	for (int i = 2; i <= N; i++) {
		v.push_back(v.at(i - 1) + v.at(i - 2));
	}

	cout << v.at(N) << endl;
}

Measured memory_bytes: 3632
module Main where

import Data.List as List
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS
import Control.Monad as M
import Data.Maybe as Maybe

main :: IO ()
main =
    (\v -> solve v (v V.! 2) 10) =<< getInts

getInt :: IO Int
getInt = read <$> BS.unpack <$> BS.getLine

splitLine :: IO [BS.ByteString]
splitLine = BS.words <$> BS.getLine

getInts :: IO (V.Vector Int)
getInts = V.fromList <$> List.map fst <$> Maybe.mapMaybe BS.readInt <$> splitLine

{-
getInts :: IO (V.Vector Int)
getInts = V.fromList <$> List.map fst <$> Maybe.mapMaybe BS.readInt <$> replicateM 3 BS.getLine
-}

solve :: V.Vector Int -> Int -> Int -> IO ()
solve _ _ 0 = return ()
solve v x n = print nx >>= (\_ -> solve v nx (n - 1))
    where
        nx = x * (v V.! 0) - (v V.! 1)


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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,maxo=0,maxe=0,oo,ee;
int v[200000];
map<int,int>odd,even;
vector<int>o,e;
signed main(){
    cin>>n;
    if(n==2){
        if(v[0]==v[1])cout<<1<<endl;
        else cout<<0<<endl;
        return 0;
    }
    else if(n==3){
        int ans;
        if(v[0]==v[2]){
            if(v[0]==v[1])ans=1;
            else ans=0;
        }
        else{
            ans=1;
        }
    }
    rep(i,n){
        cin>>v[i];
        if(i%2)even[v[i]]++;
        else odd[v[i]]++;
    }
    rep(i,n){
        if(i%2){
            if(even[v[i]]>maxe){
                maxe=even[v[i]];
                ee=v[i];
            }
        }
        else{
            if(odd[v[i]]>maxo){
                maxo=odd[v[i]];
                oo=v[i];
            }
        }
    }
    rep(i,n){
        if(i%2){
            e.push_back(even[v[i]]);
            even[v[i]]=0;
        }
        else{
            o.push_back(odd[v[i]]);
            odd[v[i]]=0;
        }
    }
    sort(e.begin(),e.end());
    reverse(e.begin(),e.end());
    sort(o.begin(),o.end());
    reverse(o.begin(),o.end());
    if(ee!=oo){
        int ans=n-(e[0]+o[0]);
        cout<<ans<<endl;
    }
    else{
        int x=e[0]+o[1],y=e[1]+o[0];
        int ans=n-max(x,y);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 8316
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITH = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITH;
  }

  d[0] = 0;

  while (1) {
    minv = INFTY;
    u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != INFTY) {
        if (d[v] > M[u][v]) {
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] != -1 ) sum += M[i][p[i]];
  }

  return sum;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int e; cin >> e;
      M[i][j] = (e == -1 ) ? INFTY : e;
    }
  }
  cout << prim() << endl;

  return 0;
}



Measured memory_bytes: 3124
import java.util.Scanner;

public class Main{
 public static void main(String[] args){

   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int str[] = new int[N];
   boolean flag = true;
   for(int i=0; i<N; i++) {
	   str[i] = sc.nextInt();
      }

   for(int i=0; i<N; i++) {
	if(str[i] % 2 == 0) {
		boolean flag1 = false;
		if(str[i] % 3 == 0) {
			flag1 = true;
		}
			if(str[i] % 5 == 0) {
			flag1 = true;
			}

			if(flag1 == false) {
				flag = false;
				break;
			}

			}
		}

   if(flag == true) {
   System.out.print("APPROVED");
   }else {
   System.out.print("DENIED");

   }




   }

   }



Measured memory_bytes: 22996
def main():
    N = int(input())
    L = list(map(int, input().split(" ")))
    L.sort()
    sum_except_max = sum(L[:-1])
    if sum_except_max > L[-1]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

class Card{
public:
	int value;
	char mark;
};

int main(){
	int n;
	cin >> n;
	Card c1[100],c2[100];
	for(int i = 0; i < n; i++){
		cin >> c1[i].mark >> c1[i].value;
		c2[i] = c1[i];
	}

	//BubbleSort
	for(int i = 0; i < n; i++){
		for(int j = n - 1; j > i; j--){
			if(c1[j].value < c1[j-1].value){
				swap(c1[j].value,c1[j-1].value);
				swap(c1[j].mark,c1[j-1].mark);
			}
		}
	}
	for(int i = 0; i < n; i++){
		if(i!=0) cout << " ";
		cout << c1[i].mark << c1[i].value;
	}
	cout << endl;
	cout << "Stable" << endl;

	//SelectionSort
	for(int i = 0; i < n; i++){
		int mini = i;
		for(int j = i; j < n; j++){
			if(c2[j].value < c2[mini].value) mini = j;
		}
		if( i != mini ){
			swap(c2[i].value,c2[mini].value);
			swap(c2[i].mark,c2[mini].mark);
		}
	}
	bool flag = true;
	for(int i = 0; i < n; i++){
		if(c1[i].value != c2[i].value or c1[i].mark != c2[i].mark) flag = false;
	}
	for(int i = 0; i < n; i++){
		if(i!=0) cout << " ";
		cout << c2[i].mark << c2[i].value;
	}
	cout << endl;
	cout << (flag ? "Stable" : "Not stable") << endl;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N, vl(3));
  rep(i,N) rep(j,3) cin >> G[i][j];

  ll ans = 0;
  rep(i,1<<3) {
    bitset<3> s(i);
    vi sign(3, 1);
    rep(j,3) if (s.test(j)) sign[j] = -1;

    priority_queue<ll> pq;
    rep(j,N) {
      ll tmp = 0;
      rep(k,3) tmp += sign[k] * G[j][k];
      pq.push(tmp);
    }

    ll sum = 0;
    rep(j,M) {
      sum += pq.top();
      pq.pop();
    }

    ans = max(ans, sum);
  }

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


Measured memory_bytes: 256
n, a, b = map(int, input().split())
monsters = [int(input()) for _ in range(n)]

i = 10 ** 9
left, mid, right = 0, i // 2, i + 1

def attack(x):
    global n, a, b
    d = a - b
    remain = x
    for j in monsters:
        temp = j - b * x
        if temp > 0:
            remain -= (temp + d - 1) // d
    return remain >= 0

while right - left > 1:
    if attack(mid):
        right = mid
    else:
        left = mid
    mid = (left + right + 1) // 2

print(mid)

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

int main() {
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nq = Input.ar;
        var uf = new UnionFind(nq[0] + 1);
        var res = new List<int>();
        while (nq[1]-- > 0)
        {
            var cxy = Input.ar;
            if (cxy[0] == 0) uf.Union(cxy[1], cxy[2]);
            else res.Add(uf.IsSame(cxy[1], cxy[2]) ? 1 : 0);
        }
        if (res.Count != 0)
            WriteLine(string.Join("\n", res));
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

public class UnionFind
{
    private int _num;
    private int[] _parent, _size, _rank;
    public UnionFind(int num)
    {
        _num = num;
        _parent = new int[num];_size = new int[num];_rank = new int[num];
        for(var i = 0; i < num; i++) { _parent[i] = i;_size[i] = 1;}
    }
    private int Find(int i)
        => i == _parent[i] ? i : (_parent[i] = Find(_parent[i]));
    public int Parent(int i)
        => Find(i);
    public int Size(int i)
        => _size[Find(i)];
    public bool Union(int v1,int v2)
    {
        v1 = Find(v1);v2 = Find(v2);
        if (IsSame(v1, v2)) return false;
        _num--;
        if (_rank[v1] > _rank[v2])
        {
            _parent[v2] = v1;
            _size[v1] += _size[v2];
        }
        else
        {
            _parent[v1] = v2;
            _size[v2] += _size[v1];
            if (_rank[v1] == _rank[v2])
                _rank[v2]++;
        }
        return true;
    }
    public bool IsSame(int v1, int v2)
        => Find(v1) == Find(v2);
}


Measured memory_bytes: 25172
import java.util.Scanner; 
 public class Main {
   public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
            double r = sc.nextDouble();
            double d = r*r*Math.PI;
            double f = r*2*Math.PI;
             System.out.println(String.format("%.6f",d)+" "+String.format("%.6f",f));
   }
 }


Measured memory_bytes: 28336
#include <bits/stdc++.h> 
#define ll long long 
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    long long q(1);//cin>>q;
    while(q--){
        long long n,m,k,l,tot(0),p(0);
        string s;
        bool ok(0),okk(1);
        cin>>n>>m>>k>>l;
        if(m<=0 and l<=0){cout<<n*k;}
        else if(m<=0 and k<=0){cout<<n*k;}
        else if(m<=0){cout<<m*k;}
        else if(l<=0 and n<=0){cout<<n*k;}
        else if(l<=0){cout<<n*l;}
        else cout<<max(m*l,k*n);
    }
}

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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n; cin>>n;
	int ans = (n*n*n);
	cout<<ans;
	return 0;
}

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

double n = 0 ;
int k = 0 ;
int x = 0 ;
int y = 0 ;
int half = 0 ;
int col = 0 ;

int main ()
{
    cin >> n >> k ;
    half = ceil( n / 2 ) ;

    for (int i = 0 ;i < k ;i++ )
    {
        cin >> x >> y ;

        if ( x > half )
        {
            if ( ( (int)n % 2) == 0 )
            {
                x = half - ( x - half ) + 1 ;
            }
            else
            {
                x = half - ( x - half ) ;
            }
        }

        if ( y > half )
        {
            if ( ( (int)n % 2) == 0 )
            {
                y = half - ( y - half ) + 1 ;
            }
            else
            {
                y = half - ( y - half ) ;

            }
        }

        col = min( x , y ) % 3 ;
        if ( col == 0 ) col = col + 3 ;

        cout << col << endl ;
    }

    return 0 ;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 505;

char s[maxn][maxn], b[maxn][maxn], r[maxn][maxn];
int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%s", s[i]);
	for (int i = 1; i < n - 1; i++)
	{
		for (int j = 0; j < m; j++)
		{
			b[i][j] = '.';
			r[i][j] = '.';
			if (j % 2 == 0 || s[i][j] == '#') b[i][j] = '#';
			if (j % 2 == 1 || s[i][j] == '#') r[i][j] = '#';
		}
		b[i][m] = '\0';
		r[i][m] = '\0';
	}
	for (int i = 0; i <m; i++)
	{
		r[0][i] = '#';
		b[0][i] = '.';
		b[n - 1][i] = '#';
		r[n - 1][i] = '.';
	}
	for (int i = 0; i < n; i++) printf("%s\n", b[i]);
	printf("\n");
	for (int i = 0; i < n; i++) printf("%s\n", r[i]);
	return 0;
}

Measured memory_bytes: 1536
/*   LazyBones
*
*/

#include <bits/stdc++.h>
#include<cctype>
#include <sstream>
#include<ctime>
using namespace std;
#define rep(i,b) for(int i=0;i<b;i++)
#define getarr(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define disparr(a,n) for(int i=0;i<n;i++){cout<<a[i];}cout<<"\n";
#define disparrs(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";
#define disparrl(a,n) for(int i=0;i<n;i++){cout<<a[i]<<"\n";}cout<<"\n";
#define mem0(a) memset(a,0,sizeof(a));
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define F first
#define S second
//#define nu 100001
#define M 1000000007
#define mul(x,y) ((ll)(x)*(y))%M
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 0x3f3f3f3f
int MOD(int a, int b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll max3(ll a,ll b,ll c)
{
    return max(c,max(a,b));
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll max(ll a,ll b)
{
    return (a>b)?a:b;
}
ll min(ll a,ll b)
{
    return (a<b)?a:b;
}
ll gcd(ll a,ll b)
{
    if(b==1)
    return 1;
    else if(a%b==0)
    return b;
    else
    return gcd(b,a%b);
}
ll mod(ll x){
    if(x>=0)
    return x;
    else
    return -x;
}
ll n,m;
int main()
{
    fastio;
    cin>>n;
	ll arr[n];
	rep(i,n){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	
    int res=arr[n-1];
    rep(i,n-1){
    	res=gcd(res,arr[i]);
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
char s[MAX+10];

int main(int argc, char ** argv) {
	scanf("%s", s);
	int sz = strlen(s);
	rep(i, 0, 5) s[sz+i] = 'A';
	for(char c = 'a'; c <= 'z'; c++) {
		rep(i, 0, sz) {
			if(s[i] == s[i+1] && s[i] == c) printf("%d %d\n", i+1, i+2), exit(0);
			if(s[i] == s[i+2] && s[i] == c) printf("%d %d\n", i+1, i+3), exit(0);
		}
	}
	puts("-1 -1");
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

const ll MOD = 1000000007;

class Combination{
    private:
    vector<ll>fact, inv;
    ll mod;
    
    public:
    // xのn乗
    ll modpow(ll x, ll n){
        ll res = 1;
        while(n > 0){
            if(n & 1)res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        return res;
    }
    // /x
    ll modinv(ll x){
        ll y = mod, u = 1, v = 0;
        while(y){
            ll t = x / y;
            x -= t * y; swap(x, y);
            u -= t * v; swap(u, v);
        }
        u %= mod;
        if(u < 0)u += mod;
        return u;
    }
    Combination(ll num, ll _mod = 1000000007){
        fact = vector<ll>(2 * num + 10);
        inv = vector<ll>(2 * num + 10);
        mod = _mod;
        fact[0] = 1;
        inv[0] = modinv(fact[0]);
        for(ll i = 1; i < fact.size(); i++){
            fact[i] = fact[i - 1] * i % mod;
            inv[i] = modinv(fact[i]);
        }
    }
    // n!(事前に設定した範囲)
    ll factrial(ll n){
        return fact[n];
    }
    ll nPk(ll n, ll k){
        return fact[n] * inv[n - k] % mod;
    }
    ll nCk(ll n, ll k){
        return nPk(n, k) * inv[k] % mod;
    }
    ll nHk(ll n, ll k){
        return nCk(n+k-1, k);
    }
};

int main(){

    Combination cmb(101010, MOD);
    ll N, K;
    cin >> N >> K;
    for(ll i = 1; i <= K; i++){
        ll B = i;
        ll b = K - B;
        ll R = i + 1;
        ll r = N - K - (i - 1);
        if(r < 0){
            cout << 0 << endl;
            continue;
        }
        ll ans = 1;
        ans = (ans * cmb.nHk(B, b)) % MOD;
        ans = (ans * cmb.nHk(R, r)) % MOD;
        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	ll x = 1;
	ll ans = 1;
	vector<int>prime;
	prime.push_back(2);
	reps(i, 2, N + 1) {
		bool flagp = true;
		rep(j, prime.size()) {
			if (i%prime[j] == 0) {
				flagp = false;
				break;
			}
		}
		if (flagp)prime.push_back(i);
	}
	vector<int>count(N+1);
		reps(i, 2, N + 1) {
			rep(j, prime.size()) {
				if (i%prime[j] == 0) {
					int x = i;
					while (x%prime[j] == 0) {
						count[prime[j]]++;
						x /= prime[j];
						if (x == 0)break;
					}
				}
			}
	}
	rep(i, prime.size()) {
		ans *= count[prime[i]] + 1;
		ans %= mod;
	}
	cout << ans << 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++)
#define pb push_back
#pragma GCC optimize("Ofast")
int N, cnt, t1 = -1, t2, f, p;
typedef pair<int, int> P;
set<P> g[100000];
int X[100000];

void dfs(int u){
	while(!g[u].empty()){
		P e = *g[u].begin();
		int v = e.first;
		if(e.second){ X[u]--; X[v]++; }
		else{
			if(u == t2) p++;
			if(v == t2) p--;
		}
		g[v].erase({u, e.second});
		g[u].erase(e);
		dfs(v);
	}
}

int main(){
	cin >> N;
	rep(i, 2*N){
		int v; cin >> v;
		v--;
		if(v != -2){
			g[i%N].insert({v, (i/N)});
			g[v].insert({i%N, (i/N)});
		}else{
			if(t1 == -1) t1 = i%N;
			else t2 = i%N;
		}
	}
	if(t1 == t2){
		rep(i, N){
			if(g[i].size() % 2 == 1) f = 1;
		}
	}else{
		rep(i, N){
			if(i==t1 || i==t2){
				if(g[i].size() % 2 == 0) f = 1;
			}else if(g[i].size() % 2 == 1) f = 1;
		}
	}
	if(f) cout << "IMPOSSIBLE" << "\n";
	else{
		dfs(t1);
		cout << "POSSIBLE" << "\n";
		if(t1 == t2) X[t1]++;
		else X[t2] = p;
		rep(i, N) cout << X[i] << " ";
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 49296
_n = int(raw_input())
_a = [int(x) for x in raw_input().split()]

for i in range(1, _n):
    print(" ".join([str(x) for x in _a]))
    key = _a[i]
    j = i - 1
    while j >= 0 and _a[j] > key:
        _a[j+1] = _a[j]
        j -= 1
    _a[j+1] = key
        
print(" ".join([str(x) for x in _a]))

Measured memory_bytes: 6384
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if (a+c-1)<(b-c+1):
  for i in range(c):
    print(a+i)
  for i in range(c):
    print(b-c+1+i)
else:
  for i in range(a,b+1):
    print(i)

Measured memory_bytes: 9116
import java.io.*;
 
class Main {
	
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
            int n = Integer.parseInt( kb.readLine() );
			String[] nums = kb.readLine().split( " " );
			int[] A = new int[n];
            int i, j;
            
            for( i=0; i<n; i++ ) {
            	A[i] = Integer.parseInt( nums[i] );
            }
            
            int cnt = 0;
			cnt = bubbleSort( A, n );
			
            StringBuilder output = new StringBuilder( 200+1 );
            for( i=0; i<n; i++ ) {
            	output.append( A[i]  );
            	output.append( " "  );
            }
            output.deleteCharAt( output.lastIndexOf( " " ) );

            System.out.println( output );
            System.out.println( cnt );
			 
            kb.close();
        } catch( IOException e ) {
            System.err.println( e );
        }        
    }
    
    static int bubbleSort( int[] A, int n ) 
    {
    	int tmp;
    	int i, j, cnt;
    	
    	cnt = 0;
   		for( i=0; i<n; i++ ) {
   			for( j=n-1; i<j; j-- ) {
   				if( A[j] < A[ j-1 ] ) {
   					tmp = A[ j-1 ];
   					A[ j-1 ] = A[ j ];
   					A[ j ] = tmp;
   					cnt++;
   				}
   			}
   		}
   		return cnt;
    }
}

Measured memory_bytes: 17072
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp> //__gnu_pbds::priority_queue
 
using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 200000;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

int n, m;
int b[N + 5];
vector<int> q[N + 5];
int f[N + 5], s[N + 5];

namespace Seg_T {
#define lc (u << 1)
#define rc (u << 1 | 1)
#define mid ((l + r) >> 1)

    const int SZ = N << 2;

    int Mn[SZ + 5];
    void clear() {
        memset(Mn, oo, sizeof Mn);
    }

    void modify(int u, int l, int r, int x, int y, int v) {
        if(x <= l && r <= y) {
            chkmin(Mn[u], v);
            return;
        }
        if(x <= mid) modify(lc, l, mid, x, y, v);
        if(mid < y) modify(rc, mid+1, r, x, y, v);
    }
    int query(int u, int l, int r, int p) {
        if(l == r) return Mn[u];
        int ans = Mn[u];
        if(p <= mid) chkmin(ans, query(lc, l, mid, p));
        else chkmin(ans, query(rc, mid+1, r, p));
        return ans;
    }
}

int main() {
    //freopen("hamming.in", "r", stdin);
    //freopen("hamming.out", "w", stdout);

    read(n);
    for(int i = 1; i <= n; ++i) {
        read(b[i]);
        s[i] = s[i-1] + (!b[i]);
    }

    read(m);
    for(int i = 1; i <= m; ++i) {
        int l, r;
        read(l), read(r); q[r].pb(l);
    }

    memset(f, oo, sizeof f);
    Seg_T::clear();

    f[0] = 0;
    Seg_T::modify(1, 0, n, 0, 0, 0);
    for(int i = 1; i <= n; ++i) {
        chkmin(f[i], f[i-1] + b[i]);
        Seg_T::modify(1, 0, n, i, i, f[i] - s[i]);

        for(int j = 0; j < (int) q[i].size(); ++j) {
            int l = q[i][j], tmp = Seg_T::query(1, 0, n, l-1) + s[i];
            chkmin(f[i], tmp);
            Seg_T::modify(1, 0, n, l, i, tmp - s[i]);
        }
    }
    printf("%d\n", f[n]);

    return 0;
}


Measured memory_bytes: 15232
tax = [int(n) for n in input().split()]

max_8tax = (tax[0]+1) / .08
min_8tax = tax[0] / .08
max_10tax = int((tax[1]+1) / .1) - 1
min_10tax = int(tax[1] / .1)

r = -1

for i in range(min_10tax, max_10tax):
    if min_8tax <= i and i < max_8tax:
        r = i
        break

print(r)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b){
	if(a>b){
		return true;
	}
	return false;
}
int main(){
	int n,k,s=0;
	int a[100];
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=k;i++){
		s+=a[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
As = list(map(int, input().split()))
As = sorted(As, reverse=True)
num = sum(As)
ans = 0
for a in As:
  if num / (4*m) <= a:
    ans += 1
if ans >= m:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 38384
import copy

S=list(input())
T=list(input())
# S=list("ab?c")
# T=list("abcd")
# print(T)
flag = False
#文字が入るかの確認
for i in range(len(S)+1-len(T)):
    if S[i]==T[0] or S[i]=="?":
        #文字列判定
        for j in range(len(T)):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                # print("不一致ij",i,j)
                break
        else:
            result=copy.copy(S)
            for j in range(len(T)):
                flag=True
                result[i+j]=T[j]
                

# print("=================")
if flag==True:
    print("".join(result).replace("?","a"))
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3444
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	k := scanInt()

	for k > 1 && s[0] == '1' {
		k--
		s = s[1:]
	}
	fmt.Fprintln(wr, s[0:1])
}


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

int N,W;
int w[105],v[105];
int cache[105][100005];

int dp(int n, int wt)
{
    if (wt>W)
        return -1e15;
    if (n==N)
        return 0;
    if (cache[n][wt]!=-1)
        return cache[n][wt];
    cache[n][wt]=max(dp(n+1,wt),v[n]+dp(n+1,wt+w[n]));
    return cache[n][wt];
}

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

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

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

    cout<<dp(0,0);

    return 0;
}

Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;
// 24ñÅ³ÉàÇé
/*
zñÆ_CXÌÊÌÖW
c0ÍRXgN^ÌøÅ^¦çêéxN^Ìvf
0 c4 0 0
c3 c0 c2 c5
0 c1 0 0
*/
class Dice{
private:
	int yoko;
	int tate;
	int round;
private:
	int face[3][4];
public:
	vector<int> colored;
	int getFace(const int idx)const{
		if(idx==0)return face[1][1];
		else if(idx==1)return face[2][1];
		else if(idx==2)return face[1][2];
		else if(idx==3)return face[1][0];
		else if(idx==4)return face[0][1];
		else if(idx==5)return face[1][3];
		return -1;
	}
	Dice(const vector<int> &v){
		init();
		for(int i=0;i<8;i++)colored.push_back(v[i]);
	}
private:
	// _CXÌú»
	void init(){
		for(int i=0;i<3;i++)for(int j=0;j<4;j++)face[i][j]=-1;
		yoko=0;
		tate=0;
		round=0;
	}
public:
	// _CXÌñ]
	void rotate(){
		if(round<4){
			round++;
			// z²ðSÉñ]
			int tp[8];
			for(int i=0;i<4;i++){
				tp[(i+1)%4]=colored[i];
				tp[(i+1)%4+4]=colored[i+4];
			}
			for(int i=0;i<8;i++)colored[i]=tp[i];
		}
		if(round>=4){
			round=0;
			// àÇÁÄ«½çA¡ÌXbgðñ]³¹é
			if(yoko<4){
//				int tmp = face[1][3];
//				for(int i = 2; i >= 0; i--)
//					face[1][i+1]=face[1][i];
//				face[1][0]=tmp;
				yoko++;
				int tp[8];
				tp[0]=colored[4];
				tp[1]=colored[5];
				tp[4]=colored[7];
				tp[5]=colored[6];
				tp[2]=colored[1];
				tp[3]=colored[0];
				tp[7]=colored[3];
				tp[6]=colored[2];
				for(int i=0;i<8;i++)colored[i]=tp[i];
			}
			// àÇÁÄ«½çAcÌXbgðñ]³¹é
			if(yoko>=4){
				if(tate<4){
					int loop=1;
					if(tate==1)loop=2;
					while(loop--){
						tate++;
						int tp[8];
						tp[7]=colored[3];
						tp[4]=colored[0];
						tp[6]=colored[7];
						tp[5]=colored[4];
						tp[2]=colored[6];
						tp[1]=colored[5];
						tp[3]=colored[2];
						tp[0]=colored[1];
						for(int i=0;i<8;i++)colored[i]=tp[i];
					}
				}
				if(tate>=4){
					round=0;
					tate=0;
					yoko=0;
				}
			}
		}
	};
};

int main() {
	int cs[8];
	string s;
	while (getline(cin, s)) {
		map<string,int> idxs;
		int idx=0;
		istringstream iss(s);
		for(int i=0;i<8;i++){
			string ts;
			iss>>ts;
			if(idxs.find(ts)==idxs.end())idxs[ts]=idx++;
			cs[i]=idxs[ts];
		}
		set<vector<int> > svs;
		int cnt=0;
		do{
			vector<int> init;
			for(int i=0;i<8;i++)init.push_back(cs[i]);
			Dice d(init);
			// ¡Ìhèûªp^[ÌÇê©Éêv·é©`FbN
			if(svs.find(d.colored)==svs.end()){
				cnt++;
				for(int i=0;i<24;i++){
					svs.insert(d.colored);
					d.rotate();
				}
			}
		}while(next_permutation(cs,cs+8));
		cout<<cnt<<endl;
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char p;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    int c4 = 0;
    while(cin >> p) {
        if (p == '1') ++c1;
        if (p == '2') ++c2;
        if (p == '3') ++c3;
        if (p == '4') ++c4;
    }
    if (c1 == 0 || c2 == 0 || c3 == 0 || c4 == 0) cout << "NO\n";
    else if (c1 >= 3 || c2 >= 3 || c3 >= 3 || c4 >= 3) cout << "NO\n";
    else cout << "YES\n";

    return 0;
}

Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

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



int main() {

	int n, m;
	vector<string> str;
	string v;

	cin >> n >> m;

	roop(i, 0, n) {
		cin >> v;
		str.push_back(v);
	}

	sort(str.begin(), str.end());
	roop(i, 0, n) {
		cout << str[i];
	}

	cout << endl;

	return 0;
}


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

using namespace std;

void WriteArray(const vector<int>& nums) {
    for (auto iterator = nums.begin(); iterator != nums.end(); ++iterator) {
        cout << *iterator << (iterator + 1 != nums.end() ? " " : "");
    }
    cout << endl;
}

int main() {
    int len;
    cin >> len;
    vector<int> nums(len);

    for (int i = 0; i < len; i++) cin >> nums[i];
    
    int count = 0;

    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = len - 1; j >= 1; j--) {
            if (nums[j] < nums[j - 1]) {
                swap(nums[j], nums[j - 1]);
                flag = true;
                count++;
            }
        }

    }

    WriteArray(nums);
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++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(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

void test(priority_queue<pair<ll,ll>> que){
  while(!que.empty()){
    cout<<que.top().first<<" "<<que.top().second<<endl;
    que.pop();
  }
}
int n,m,q;

vector<int> a,b,c,d;
vector<ll> e(10,0);
ll ma=0;

void dfs(int position,int num){
  e[position]=num;
  if(position>=n){
    ll alpha=0;
    for(int i=0;i<q;i++){
      int tmp;
      tmp=e[b[i]]-e[a[i]];
      if(tmp==c[i]){
        alpha+=d[i];
      }
    }
    if(alpha>ma){ma=alpha;}
    return;
  }
  for(int i=num;i<=m;i++){
    dfs(position+1,i);
  }
  return;
}

int main(){
  cin>>n>>m>>q;
  int a1,b1,c1,d1;
  REP(i,q){
    cin>>a1>>b1>>c1>>d1;
    a.push_back(a1);
    b.push_back(b1);
    c.push_back(c1);
    d.push_back(d1);
  }
  dfs(0,1);
  cout<<ma<<endl;
}

Measured memory_bytes: 3172
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
nsum=0
for i in range(n):
    b[a[i]]+=1
for k in range(n+1):
    nsum+=max(b[k]*(b[k]-1)//2,0)

for j in range(n):
    print((nsum+1-b[a[j]]))


Measured memory_bytes: 26140
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

  if(s=='A') cout<<"T";
  else if(s=='T') cout<<"A";
  else if(s=='G') cout<<"C";
  else cout<<"G";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a, b;
	scanf("%d %d",&a ,&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

class UnionFind {
    int cnt;
    vector<int> par, rank, size;
public:
    UnionFind() {}
    UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) {
        for (int i = 0; i<_n; ++i) par[i] = i;
    }
    int find(int k) {
        return (k == par[k]) ? k : (par[k] = find(par[k]));
    }
    int operator[](int k) {
        return find(k);
    }
    int getSize(int k) {
        return size[find(k)];
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        --cnt;
        if (rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if (rank[y] == rank[x]) ++rank[x];
        }
    }
    int count() {
        return cnt;
    }
};

bool A[100000 * 7][7];
int f(int h, int m, vi &col) {
    MEM(A, 0);
    UnionFind uf(7 * h);
    int cur = 0, black = 0;
    rep(y, h)rep(x, 7) {
        if (!col[cur%m]) {
            A[y][x] = 1;
            if (y > 0 && A[y - 1][x])uf.unite(cur, cur - 7);
            if (x > 0 && A[y][x - 1])uf.unite(cur, cur - 1);
        } else {
            black++;
        }
        cur++;
    }
    return uf.count() - black;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    int m, q;
    cin >> n >> m >> q;
    vi col(m);
    rep(i, q) {
        int a;
        cin >> a;
        col[a] = 1;
    }

    int H = m;
    if (H % 7 == 0)H /= 7;
    int b = f(H, m, col), a = f(H * 2, m, col) - b;
    cout << a*((n - H) / H) + b << endl;
}


Measured memory_bytes: 21872
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << (800 * n - 200 * (n / 15)) << endl;
}


Measured memory_bytes: 256