akhauriyash/Code-Regression huggingface dataset:
from typing import List


class Dice:

    sur = [i for i in range(6)]

    def __init__(self, s: List[int]):
        self.s = s  # surfaceリスト

        # indexが面の番号。リストの値は、それに接する面の番号。
        self.sur[0] = [1, 2, 4, 3]
        self.sur[1] = [0, 3, 5, 2]
        self.sur[2] = [1, 5, 4, 0]
        self.sur[3] = [1, 0, 4, 5]
        self.sur[4] = [0, 2, 5, 3]
        self.sur[5] = [1, 3, 4, 2]

    def get_right_face_index(self, upper: int, front: int) -> int:
        for i, num in enumerate(self.sur[upper]):
            if num == front:
                return self.sur[upper][(i + 1) % 4]
        else:
            raise ValueError('get_right_faceの来てはいけない箇所')

    def get_num(self, index) -> int:
        return self.s[index]

    def get_sur_index(self, num) -> int:
        for i in range(len(self.s)):
            if num == self.s[i]:
                return i
        else:
            raise ValueError('get_sur_indexの来てはいけない箇所')


# 提出用
data = [int(i) for i in input().split()]
N = int(input())
dice = Dice(data)
for _i in range(N):
    upper_num, right_num = map(int, input().split())
    upper_index = dice.get_sur_index(upper_num)
    right_index = dice.get_sur_index(right_num)
    ans_index = dice.get_right_face_index(upper_index, right_index)
    print(dice.get_num(ans_index))

# # 動作確認用
# with open('input_itp1_11_a_1.txt', mode='r', encoding='utf8') as fin:
#     data = [int(i) for i in next(fin).split()]
#     N = int(next(fin))
#     dice = Dice(data)
#     for _i in range(N):
#         upper_num, right_num = map(int, next(fin).split())
#         upper_index = dice.get_sur_index(upper_num)
#         right_index = dice.get_sur_index(right_num)
#         ans_index = dice.get_right_face_index(upper_index, right_index)
#         print(dice.get_num(ans_index))



Measured memory_bytes: 7164
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int s;
	while (scanf("%d", &s), s)
	{
		for (int i = 0; i < 9; ++i)
		{
			int t;
			scanf("%d", &t);
			s -= t;
		}
		printf("%d\n", s);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	long h,ans,tmp,now;
	int i;

	ans = 1;
	tmp = 1;
	now = 0;

	cin >> n;
	cin >> now;
	for (i = 1; i < n; i++) {
		cin >> h;
		if (h <= now) {
			tmp++;
			ans = max(tmp, ans);
			now = h;
		}
		else {
			tmp = 1;
			now = h;
		}
	}
	cout << ans-1 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextInt();

		long ans = solve(n, a);

		cout.println(ans);
	}

	private static long solve(int n, long[] a) {
		long ans = Long.MAX_VALUE;
		long sum = Arrays.stream(a).sum();
		long x = 0;
		long y = sum;
		for (int i = 0; i < a.length - 1; i++) {
			x += a[i];
			y -= a[i];
			ans = Math.min(ans, Math.abs(x - y));
		}
		return ans;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
	}

}


Measured memory_bytes: 46240
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct UF{
  std::vector<int> par, dep, sz;
  UF(int n){
    par.resize(n+1), dep.resize(n+1), sz.resize(n+1);
    init(n);
  }
  void init(int nu) {
    for(int iu=0;iu<=nu;iu++){
      par[iu] = iu;
      dep[iu] = 0;
      sz[iu] = 1;
    }
  }
  int find(int xu){
    if(par[xu] == xu) return xu;
    return par[xu] = find(par[xu]);
  }
  void unite(int xu, int yu){
    xu=find(xu);
    yu=find(yu);
    if(xu == yu) return;
    if(dep[xu] < dep[yu]){
      sz[yu] += sz[xu];
      par[xu] = yu;
    }else{
      par[yu] = xu;
      sz[xu] += sz[yu];
      if(dep[xu] == dep[yu]) dep[xu]++;
    }
  }
  bool same(int xu, int yu){ return find(xu) == find(yu);}
  int get_size(int x){return sz[find(x)];}
};
int main(int argc, char const *argv[]) {
  ll n, m, k, a, b;std::cin >> n >> m >> k;
  UF uf(n+1);
  vll blfl(n+1, 0);
  for(int i=0;i<m;i++){
    scanf("%lld %lld", &a, &b);
    uf.unite(a, b);
    blfl[a]++;
    blfl[b]++;
  }
  for(int i=0;i<k;i++){
    scanf("%lld %lld", &a, &b);
    if(!uf.same(a, b)) continue;
    blfl[a]++;
    blfl[b]++;
  }
  for(int i=1;i<=n;i++){
    ll num = uf.get_size(i);
    std::cout << num - 1 - blfl[i] << (i==n?"\n":" ");
  }
  return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s; cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	else if(s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
	return 0;
}


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

typedef pair<int, int> P;

int p[10][10], visited[10][10];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int h, w, c;

int dfs(int count) {
    if(count == 5) {
        int ret = 0;
        if(p[0][0] != c) return 0;
        rep(i, 10) rep(j, 10) visited[i][j] = 0;
        queue<P> que;
        que.push(P(0, 0));
        while(!que.empty()) {
            P point = que.front(); que.pop();
            if(visited[point.first][point.second] == 0) {
               visited[point.first][point.second] = 1;
               ret++;
                rep(i, 4) {
                    int ny = point.first + dy[i];
                    int nx = point.second + dx[i];
                    if(nx >= 0 && nx < w && ny >= 0 && ny < h &&
                       visited[ny][nx] == 0 && p[ny][nx] == c) {
                        que.push(P(ny, nx));
                    }
                }
            }
        }
        return ret;
    }
    int org[10][10];
    int ret = 0;
    rep(i, h) rep(j, w) org[i][j] = p[i][j];
    rep(color, 6) {
        int org_c = p[0][0];
        rep(i, 10) rep(j, 10) visited[i][j] = 0;
        queue<P> que;
        que.push(P(0, 0));
        while(!que.empty()) {
            P point = que.front(); que.pop();
            p[point.first][point.second] = color+1;
            visited[point.first][point.second] = 1;
            rep(i, 4) {
                int ny = point.first + dy[i];
                int nx = point.second + dx[i];
                if(nx >= 0 && nx < w && ny >= 0 && ny < h &&
                   visited[ny][nx] == 0 && p[ny][nx] == org_c) {
                    que.push(P(ny, nx));
                }
            }
        }
        ret = max(ret, dfs(count+1));
        rep(i, 10) rep(j, 10) p[i][j] = org[i][j];
    }
    return ret;
}

int main(void){
    while(cin >> h >> w >> c && h) {
        rep(i, h) rep(j, w) cin >> p[i][j];
        cout << dfs(0) << endl;
    }
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, x, t; cin >> n >> x >> t;
  cout << t * ((n-1) / x + 1) << endl;

  return 0;
}








Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
using namespace std;

int main(void){
    int A,B; cin>>A>>B;
    if(A<9&&B<9)cout<<"Yay!";
    else cout<<":(";
    return 0;
}



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

using namespace std;

int main(){
    
    int N,M;
    cin >> N >> M;
    long int A[N];
    int B[N];
    
    pair<long int, int> dri[N];
    
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        dri[i].first = A[i];
        dri[i].second = B[i];
    
    }
    
    long int ans = 0;
    
    sort(dri, dri+N);
    
    int k = 0;
    while (M > 0) {
        if (dri[k].second < M) {
            M -= dri[k].second;
            ans += dri[k].first * dri[k].second;
            k += 1;
        }else{
            ans += dri[k].first * M;
            M = 0;
            
        }
    }

    cout << ans << endl;
    
    
    
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

// End of Template //

int main() {

    int N;
    cin >> N;

    string s;
    cin >> s;
    vector<char> a(N / 2);
    vector<char> b(N / 2);

    if (N % 2 == 1) {
        n();
    }

    else {
        rep(i, N / 2) {
            a[i] = s[i];
            b[i] = s[i + N / 2];
        }
        a == b ? y() : n();
    }
}

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

int main() {
    int N;
    cin >> N;
    map<pair<int, int>, ll> mp;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        ll t = 0;
        ll x = 0;
        for (int j = 0; j < (int)S.size(); j++) {
            if (S[j] == '.') {
                t = (int)S.size()-j-1;
            }else {
                x = x * 10 + (int)(S[j]-'0');
            }
        }
        ll pow2 = -t, pow5 = -t;
        while (x%2 == 0){
            x /= 2;
            pow2++;
        }
        while (x%5 == 0){
            x /= 5;
            pow5++;
        }
        for (auto p : mp) {
            int m2 = p.first.first, m5 = p.first.second;
            if (m2+pow2 >= 0 && pow5+m5 >= 0) ans += p.second;
        }
        mp[{pow2, pow5}]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
n = int(input())
w = [input() for i in range(n)]
wset = set(w)
flag = True
if len(wset) != n:
  flag = False

for i in range(1,n):
  if w[i-1][-1] != w[i][0]:
    flag = False

if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%d", $n);
$format = join(' ', array_fill(0, $n, '%d'));
$nums = array_map('intval', fscanf(STDIN, $format));
$count = bubble_sort($nums);
echo join(' ', $nums)."\n";
echo "$count\n";
function bubble_sort(&$nums){
    $count=0;
    $n=true;
 
    while ($n) {
        $n=false;
        for ($i=count($nums)-1; $i>0;$i--) {
            if ($nums[$i-1]<=$nums[$i]) {
                continue;
            }
            $temp = $nums[$i];
            $nums[$i]=$nums[$i-1];
            $nums[$i-1]=$temp;
            $n=true;
            $count++;
        }
    }
    return $count;
}

Measured memory_bytes: 15560
A, B, C, X, Y = map(int, input().split())

ret = A * X + B * Y
X -= 1
Y -= 1
Z = 2
while X >= 0 or Y >= 0:
    ret = min(ret, max(0, A * X) + max(0, B * Y) + C * Z)
    X -= 1
    Y -= 1
    Z += 2

print(ret)


Measured memory_bytes: 3060
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 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 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)

	k := scanInt()
	r := scanInt()

	fmt.Fprintln(wr, r+max(0,100*(10-k)))
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	int N, K, S;
	cin >> N >> K >> S;
	rep(i, K) {
		cout << S << " ";
	}
	int num = S;
	if (S == 1)num = 2;
	else num--;
	rep(i, N - K) {
		cout << num << " ";
	}
}

Measured memory_bytes: 1280
import std.functional,
       std.algorithm,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv,
       std.math;

T read_num(T)() { return readln.chomp.to!T; }
T[] read_nums(T)() { return readln.chomp.split.to!(T[]); }

enum INF = 1L << 30;

T max(T)(T a, T b) { return a < b ? b : a; }
T abs(T)(T x) { return x < 0 ? -x : x; }
bool chmax(T)(ref T a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
bool chmin(T)(ref T a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
void main() {
  long N = read_num!long;
  long[] A = read_nums!long;
  long[] negs, poss;
  long ans;

  A.sort!"a<b";
  foreach (a; A) {
    if (a < 0) {
      negs ~= a;
    } else {
      poss ~= a;
    }
  }

  if (negs.length & 1) {
    long l = -INF;
    long r = INF;
    foreach (x; negs) {
      chmax(l, x);
    }
    foreach (x; poss) {
      chmin(r, x);
    }
    ans -= min(abs(l), abs(r)) * 2;
  }
    foreach (a; A) {
      ans += abs(a);
    }

  writeln(ans);
}

Measured memory_bytes: 4520
a, b = map(int, input().split())
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]
if a in g1  and b in g1:
  print("Yes")
elif a in g2  and b in g2:
  print("Yes")
elif a in g3  and b in g3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int a[2];
    int i;

    cin >> a[0] >> a[1];
    for (i = 1; i <= 3; i++) {
        if (a[0] != i && a[1] != i) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int l,m,n,i,j,k=0,A[200][200],B[200][200];
	long C[200][100]={0};
	scanf("%d %d %d",&l,&m,&n);
	for(i=0;i<l;i++){
		for(j=0;j<m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
		scanf("%d",&B[i][j]);
		}
	}
	for(i=0;i<l;i++){
		for(j=0;j<n;j++){
			for(k=0;k<m;k++){
				C[i][j]+=A[i][k]*B[k][j];
			}
		}
	}
	for(i=0;i<l;i++){
		for(j=0;j<n;j++){
			printf("%ld",C[i][j]);
			if(j!=n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 928
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int r = Integer.parseInt(in.readLine());
    int g = Integer.parseInt(in.readLine());
    System.out.println((g*2)-r);
  }
}

Measured memory_bytes: 32664
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    string S;
    cin>>S;
    //inputend;
    int size=S.length();
    vector<ll> C(size+1,0);
    vector<ll> D(size+1,0);
    C[0]=S[size-1]-'0';
    D[0]=10-S[size-1]+'0';
    REPi(i,1,size){
        C[i]=min(C[i-1]+S[size-1-i]-'0',D[i-1]+S[size-1-i]-'0'+1);
        D[i]=min(C[i-1]+10-S[size-1-i]+'0',D[i-1]+10-S[size-1-i]+'0'-1);
    }
    cout<<min(C[size-1],D[size-1]+1)<<endl;
}

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

using namespace std;



int main()
{
    int n;
    scanf("%d",&n);
    vector<int> tab(2*n);
    for(int i=0;i<2*n;i++)
    {
        scanf("%d",&tab[i]);
    }
    sort(tab.begin(),tab.end());
    int sum=0;
    for(int i=0;i<2*n;i+=2)
    {
        sum+=tab[i];
    }
    printf("%d",sum);

}


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

const ll mod = 998244353;
class SegmentTree {
private:
    int n;
    vector<ll> node, lazy;
    vector<bool> flag_lazy;
public:
    SegmentTree(int N) {
        n = 1;
        while (n < N) n *= 2;
        node.resize(2 * n - 1, 0);
        lazy.resize(2 * n - 1, 0);
        flag_lazy.resize(2 * n - 1, false);
    }

    void update(int i, int l, int r) {
        if (!flag_lazy[i]) return;
        node[i] += lazy[i];
        node[i] %= mod;
        if (r - l > 1) {
            lazy[2 * i + 1] += lazy[i] / 2;
            lazy[2 * i + 2] += lazy[i] / 2;
            flag_lazy[2 * i + 1] = true;
            flag_lazy[2 * i + 2] = true;
        }
        flag_lazy[i] = false;
        lazy[i] = 0;
    }

    void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        update(k, l, r);
        if (b <= l || r <= a) return;
        
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            flag_lazy[k] = true;
            update(k, l, r);
        } else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = (node[2 * k + 1] + node[2 * k + 2]) % mod;
        }
    }

    ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        update(k, l, r);
        if (b <= l || r <= a) return 0;        
        if (a <= l && r <= b) return node[k] % mod;

        ll sum_l = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll sum_r = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return (sum_l + sum_r) % mod;
    }

    void disp() {
        for (int i : node) {
            cout << i << " ";
        }
        cout << "\n";
    }

};

int main() {
    int N, K;
    cin >> N >> K;
    int L[K], R[K];
    for (int i = 0; i < K; i++) {
        cin >> L[i] >> R[i];
    }

    SegmentTree st(N + 1);
    st.add(1, 2, 1);
    
    for (int i = 1; i < N; i++) {
        ll x = st.query(i, i + 1);
        for (int j = 0; j < K; j++) {
            int l = i + L[j];
            int r = i + R[j] + 1;
            st.add(min(l, N + 1), min(r, N + 1), x);
        }
    }

    cout << st.query(N, N + 1) << "\n";

    return 0;
}

Measured memory_bytes: 11424
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007

using namespace std;

int main(){
    int N; cin >> N;
    int X,Y; cin >> X >> Y;
    int d[N][N];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            d[i][j] = abs(j-i);
        }
        
    }
    d[X-1][Y-1] = d[Y-1][X-1] = 1;
    for (int i = 0; i < X-1; i++)
    {
        for (int j = X; j < Y; j++)
        {
            d[i][j] = d[i][X-1] + min(j-X+1,Y-j);
        }
        
    }
    for (int i = 0; i < X-1; i++)
    {
        for (int j = Y-1; j < N; j++)
        {
            d[i][j] = X-1-i + j-Y+1 + 1;
        }
        
    }
    for (int i = X-1; i < Y; i++)
    {
        for (int j = i; j < Y; j++)
        {
            d[i][j] = min(j-i,i-X+1+Y-1-j+1);
        }
        
    }
    for (int i = X-1; i < Y; i++)
    {
        for (int j = Y-1; j < N; j++)
        {
            d[i][j] = j-Y+1 + min(Y-1-i,i-X+1+1);
        }
        
    }
    int ans[N];
    for (int i = 0; i < N; i++)
    {
        ans[i] = 0;
    }
    
    for (int i = 0; i < N; i++)
    {
        for (int j = i; j < N; j++)
        {
            ans[d[i][j]] ++;
        }
    }
    for (int i = 1; i < N; i++)
    {
        cout << ans[i] << endl;
     }
    
    
}

Measured memory_bytes: 15872
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      A[++H] = 0;
      p = com+7;
      do {
        A[H] = A[H]*10+*p-'0';
        p++;
      } while (*p!='\n');

      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      n = A[1];
     for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      fputs(buf+i+1, stdout);
      A[1] = A[H];
      i = 1;
      do {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      } while (1);
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5540
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break

    score = list(map(int, sys.stdin.readline().split()))
    ave = sum(score) / len(score)

    s2 = 0
    for v in score:
        s2 += (v-ave) ** 2
    print(round((s2 / len(score)) ** 0.5, 6))



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

int main(){
    vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int num;
    cin >> num; num--;
    cout << A[num] << endl;
    return 0;
}

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

using namespace std;

int main() {
  char a;cin>>a;
  if(a-'A'<='Z'-'A')cout<<'A'<<endl;
  else cout<<'a'<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

int s;
   #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
pair<int, int>x[120000]; int n, dp[120000], a[120000];
int main() {
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	(a[1]==5&&a[2]==7)?puts("YES"):puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size(),ans=s.size();
    rep(i,n-1){
        if(s[i]==s[i+1]){
            ans--;
            i+=2;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3728
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key);
void init();
void printList();
void deleteNode(Node *t);
void deleteFirst();
void deleteLast();
void deleteKey(int key);
void insert(int key);

int main() {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ) {
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) insert(key);
    else if ( strlen(com) == 6 ) deleteKey(key);
    else if ( com[6] == 'F' ) deleteFirst();
    else deleteLast();
  }

  printList();

  return 0;
}

Node* listSearch(int key) {
  Node *cur = nil->next;
  while ( cur != nil && cur->key != key)
    cur = cur->next;
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while ( 1 ) {
    if ( cur == nil ) break;
    if ( isf++ > 0 ) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}


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

using namespace std;

int main()
{
    //ios::sync_with_stdio(false);
    int Q;
    long long A, B, a, b, bg, av, bv, L, R, t, g, I;
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        cin >> A >> B;
        L = -1;
        R = 20000000000;
        while (R - L > 1)
        {
            g = 1;
            t = (L+R) / 2;
            bg = t;
            if (B <= t)
            {
                bg++;
            }
            av = t/2;
            bv = t-av+1;
            if (A <= av)
            {
                av++;
            }
            if (B <= bv)
            {
                bv++;
            }
            a = av;
            b = bv;
            for (int y = 0; y < 5; y++)
            {
                if (a < 0)
                {
                    break;
                }
                if (a*b >= A*B)
                {
                    g = 0;
                }
                a--;
                if (a == A)
                {
                    a--;
                }
                b++;
                if (b == B)
                {
                    b++;
                }
            }
            a = av;
            b = bv;
            for (int y = 0; y < 5; y++)
            {
                if (b < 0)
                {
                    break;
                }
                if (a*b >= A*B)
                {
                    g = 0;
                }
                a++;
                if (a == A)
                {
                    a++;
                }
                b--;
                if (b == B)
                {
                    b--;
                }
            }
            if (g == 1)
            {
                L = t;
            }
            else
            {
                R = t;
            }
        }
        cout << L << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 30 16:38:31 2015

@author: hirose
"""

#Branch on Condition - Sorting Three Numbers

n = map(int, raw_input().split())

a = n[0]
b = n[1]
c = n[2]

for i in range(3):
    for i in range(2):
        if(n[i] > n[i+1]):
            temp = n[i]
            n[i] = n[i+1]
            n[i+1] = temp

print n[0], n[1], n[2]

Measured memory_bytes: 4228
n, p = map(int, input().split())
s = list(map(int, list(input())))


cnt = [0] * p
cnt[0] = 1
rem = 0
sum = 0

if p == 2 or p == 5:
    for i in range(n):
        if s[i] % p == 0:
            sum += i + 1

else:
    for i in range(n):
        rem = (int(s[-i - 1]) * pow(10, i, p) + rem) % p
        sum += cnt[rem]
        cnt[rem] += 1

print(sum)

Measured memory_bytes: 6432
s = [i for i in input()]
a = s[0]
b = ""
cnta = 0
cntb = 0
for i in range(1,4):
    if s[i] == a:
       cnta += 1
    elif b == "":
        b = s[i]
        continue
    if s[i] == b:
        cntb += 1

if cnta == 1 and cntb == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;


int32_t main(){IOS;
	int n ; cin >> n; 
	string s , t ; cin >> s >> t ; 
	for(int i=0;i<n;i++){
		cout << s[i] << t[i] ;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn main() {
    let in_n = {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut it = buf.split_whitespace();
        i64::from_str(it.next().unwrap()).unwrap()
    };
    let alphabets = (b'a'..=b'z').map(|c| c as char).collect::<Vec<_>>();
    const N: i64 = 26;
    let mut ans = Vec::new();
    let mut tmp = in_n;
    let mut idx;
    while tmp > 0 {
        tmp -= 1;
        idx = tmp % N;
        ans.push(&alphabets[idx as usize]);
        tmp = tmp / N;
    }
    ans.reverse();
    println!("{}", ans.into_iter().collect::<String>());
}


Measured memory_bytes: 2112
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
  
int main(){
 int A,B,C,D;
 cin>>A>>B>>C>>D;
 if(A<=B){
     if(C<=D){
         cout<<A+C<<endl;
     }
     else{
         cout<<A+D<<endl;
     }
 }
 else{
     if(C<=D){
         cout<<B+C<<endl;
     }
     else{
         cout<<B+D<<endl;
     }
 }
}

Measured memory_bytes: 256
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll r;
		cin>>r;
		double pi = 3.141592653589793238;
		printf("%0.9f",2.0*pi*r);
	}
	return 0;
}

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

int a[12]={1,3,5,7,9,11,15,17,19,21,23,25};

string affine(string x){
	string tmp=x;
	for(int i=0; i<12; i++){
		int A=0;
		while(a[i]*A%26!=1)A++;
		for(int b=0; b<26; b++){
			if(tmp.find("this")==-1&&tmp.find("that")==-1){
					for(int s=0; s<x.size(); s++){
						if(isalpha(x[s]))tmp[s]=((A*(x[s]-'a')+26-b)%26)+'a';
					}
			}else return tmp;
		}
	}
	return tmp;
}

int main(){
	int n;
	string str;
	cin>>n;
	cin.ignore();
	while(n--){
		getline(cin, str);
		cout<<affine(str)<<endl;	
	}
	return 0;
}

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

int main(){
    int a;
    cin>>a;
    int b;
    cin>>b;
    
    cout<<setprecision(6);
    
    cout<<a/b<<" "<<a%b<<" "<<fixed<<static_cast<double>(a)/b<<endl;
    
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 1000000000000000000 //14

int main(){
	ll n; cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	sort(a.begin(),a.end());
	ll b = a[0];
	FOR(i,1,n-1){
		if (b>(ld)INF/a[i]){
			b=-1;
			break;
		}
		else {
			b*=a[i];
		}
	}
	cout << b << endl;
}

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

using namespace std;

#define run_forrest_run ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define fi first
#define se second
#define si set <int>
#define all(x) (x).begin(),(x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);} 

const int inf = 1e9;	
const int mod = inf + 7;

const int N = 205000;
vector <int> g[N];
vector <bool> visited(N);
vector <int> color(N);

int main()
{
	run_forrest_run;
    ll n,w;
    cin>>n>>w;
    vector<ll> weight(n);
    vector<ll> value(n);
    for(ll i=0;i<n;i++)
    {
        cin >> weight[i] >> value[i];
    }
    vector<ll> dp(w+1,0);
    for(ll i = 0;i < n; i++)
    {
        for(ll j = w;j >= 0; j--)
        {
           if (j + weight[i] <= w)
           		dp[j + weight[i]] = max(dp[j+weight[i]], dp[j] + value[i]);
        }
    }
    ll ans = 0;
 	for (int i = 0; i <= w; i++)
 		ans = max(ans, dp[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int a,int b){
	if(a>b) swap(a,b);
	if(a==0) return b;
	else return gcd(b%a,a);
}

vector<int> ve,ve2;
int main(){
	int N;
	cin>>N;
	int a;
	for(int i=1;i<=N;i++){
		cin>>a;
		ve.push_back(a);
	}
	int sdk;
	if(ve.size()==1){
		sdk=ve[0];
	}
	else{
		sdk=gcd(ve[0],ve[1]);
		for(int i=2;i<ve.size();i++){
			sdk=gcd(sdk,ve[i]);
		}
	}
	for(int i=1;i*i<=sdk;i++){
		if(sdk%i==0){
			ve2.push_back(i);
			if(i*i!=sdk)ve2.push_back(sdk/i);
		}
	}
	sort(ve2.begin(),ve2.end());
	for(int i=0;i<ve2.size();i++){
		cout<<ve2[i]<<endl;
	}
	return 0;
}

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

int main()
{
    int n, m, lo, hi;
    cin >> n >> m;
    int a, b;
    cin >> a >> b;
    lo = a;
    hi = b;
    for (int i = 1; i < m; i++)
    {
        cin >> a >> b;
        lo = max(lo, a);
        hi = min(hi, b);
    }
    if (lo <= hi)cout << hi - lo + 1;
    else cout << 0;
  	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
string S;	
int main(){
	bool flg=true;
	cin>>S;
	if (S[0]!='A'){
		flg=false;
	}
	int c=0;
	FOR(i,2,S.size()-1){
		if (S[i]=='C') c++;
	}
	if (c!=1){
		flg=false;
	}
	c=0;
	FOR(i,1,S.size()){
		if ('A'<=S[i] && S[i]<='Z'){
			c++;
		}
	}
	if (c!=1){
		flg=false;
	}
	cout<<(flg ? "AC" : "WA")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll arr1[3010];
ll dp[3010][3010];
ll solve(ll idx1,ll idx2,ll move)
{
    if(dp[idx1][idx2]!=NEGINF)
    {
        return dp[idx1][idx2];
    }
    if(idx1>idx2)
    {
        return 0;
    }
    ll ans;
    if(!move)
    {
        ans=max(solve(idx1+1,idx2,1-move)+arr1[idx1],solve(idx1,idx2-1,1-move)+arr1[idx2]);
    }
    else
    {
        ans=min(solve(idx1+1,idx2,1-move)-arr1[idx1],solve(idx1,idx2-1,1-move)-arr1[idx2]);    
    }
    dp[idx1][idx2]=ans;
    return ans;
}

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

    for(ll i=0;i<3010;i++)
    {
        for(ll j=0;j<3010;j++)
        {
            dp[i][j]=NEGINF;
        }
    }
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>arr1[i];
    }
    cout<<solve(0,n-1,0);
    return 0;
}

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

	const int NN = 1000004;
	int primefactor[NN];
	int arr[NN];int n;
	// vector<pair<int,int>>prime;
	void seive(){

		for(int i=2;i<NN;i++){
			primefactor[i]=i;
		}
		primefactor[0]=1;
		primefactor[1]=1;
		for(int i=2;i*i<NN;i++){
				if(primefactor[i]==i){
					for(int j=2*i;j<NN;j+=i){

							if(primefactor[j]==j){
								primefactor[j]=i;
							}
					}
				}
		}

		// for(int i=2;i<NN;i++){
		// 	if(primefactor[i]==i){
		// 		prime.push_back(i);
		// 	}
		// }
	}
	
	int main() {

		#ifndef ONLINE_JUDGE
	        freopen("input.txt","r",stdin);
	        // freopen("output.txt","w",stdout);
	    #endif
	    ios::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);  
	  

		seive();
		cin>>n;

		
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		map<int,int> ss;
		for(int i=0;i<n;i++){
			int x= arr[i];
			while(x>1){
				int f= primefactor[x];
				// cout<<f<<" "<<x<< "        ";
				ss[f]++;
				x/=f;
				while(x%f==0 && x!=0){
					x=x/f;
				}

			}
			// cout<<endl;
		}
		int pairwise_coprime=1;
		int setwise_coprime=1;
		for(auto itr=ss.begin();itr!=ss.end();itr++){
			if(itr->second>1){
				pairwise_coprime=0;
			}
			if(itr->second==n){
				setwise_coprime=0;
			}
		}
		if(pairwise_coprime){
			cout<<"pairwise coprime"<<endl;
		}
		else if(setwise_coprime){
			cout<<"setwise coprime"<<endl;
		}
		else{
			cout<<"not coprime"<<endl;
		}
	}



	


Measured memory_bytes: 15028
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

class Dice
{
public:
	Dice( char c[ 6 ] )
	{
		for( int i = 0; i < 6; ++i ){
			face[ i ] = c[ i ];
		}
		face[ 6 ] = '\0';
	}
	void rotateVertical()
	{
		char t = face[ 0 ];
		face[ 0 ] = face[ 1 ];
		face[ 1 ] = face[ 5 ];
		face[ 5 ] = face[ 4 ];
		face[ 4 ] = t;
	}
	void rotateHorizontal()
	{
		char t = face[ 1 ];
		face[ 1 ] = face[ 2 ];
		face[ 2 ] = face[ 4 ];
		face[ 4 ] = face[ 3 ];
		face[ 3 ] = t;
	}
	char roundFace( int index )
	{
		static int a[] = { 1, 2, 4, 3 };
		return face[ a[ index ] ];
	}
	int getId()
	{
		static string pattern[] = {
			"RBMGCY", "RBMCGY", "RBGMCY", "RBGCMY", "RBCMGY", "RBCGMY",
			"RYMGCB", "RYMCGB", "RYGMCB", "RYGCMB", "RYCMGB", "RYCGMB",
			"RYBGCM", "RYBCGM", "RYGBCM", "RYGCBM", "RYCBGM", "RYCGBM",
			"RYBMCG", "RYBCMG", "RYMBCG", "RYMCBG", "RYCBMG", "RYCMBG",
			"RYBMGC", "RYBGMC", "RYMBGC", "RYMGBC", "RYGBMC", "RYGMBC",
		};
		if( face[ 2 ] == 'R' || face[ 3 ] == 'R' ){
			rotateHorizontal();
		}
		while( face[ 0 ] != 'R' ){
			rotateVertical();
		}
		if( face[ 5 ] == 'Y' ){
			while( face[ 1 ] != 'B' ){
				rotateHorizontal();
			}
		}else{
			while( face[ 1 ] != 'Y' ){
				rotateHorizontal();
			}
		}
		string diceStr( face );
		for( int i = 0; i < 30; ++i ){
			if( pattern[ i ] == diceStr ){
				return i;
			}
		}
		return -1;
	}

	char face[ 6 + 1 ];
};

int main()
{
	int n;
	while( cin >> n && n ){
		int id[ 30 ];
		memset( id, 0, sizeof(id) );

		for( int i = 0; i < n; ++i ){
			string s;
			char c[ 6 ];
			for( int i = 0; i < 6; ++i ){
				cin >> s;
				c[ i ] = s[ 0 ];
			}
			Dice dice( c );
			++id[ dice.getId() ];
		}

		int ans = 0;
		for( int i = 0; i < 30; ++i ){
			if( id[ i ] > 1 ){
				ans += ( id[ i ] - 1 );
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
using namespace std;

int main() {
	int N; cin >> N;
	vector<long long> vx(N), vy(N), vh(N);
	int si = -1;
	for (int i = 0; i < N; ++i) {
		cin >> vx[i] >> vy[i] >> vh[i];
		if (vh[i] > 0) si = i;
	}

	long long resx = -1, resy = -1, resh = -1;
	for (long long x = 0; x <= 100; ++x) {
		for (long long y = 0; y <= 100; ++y) {
			long long h = vh[si] + abs(x - vx[si]) + abs(y - vy[si]);
			bool ok = true;
			for (int i = 0; i < N; ++i) {
				if (vh[i] > 0 && h - vh[i] != abs(x - vx[i]) + abs(y - vy[i])) ok = false;
				if (vh[i] == 0 && h > abs(x-vx[i]) + abs(y-vy[i])) ok = false;
			}
			if (ok) resx = x, resy = y, resh = h;
		}
	}
	cout << resx << " " << resy << " " << resh << endl;
}

Measured memory_bytes: 764
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int funk (long long N){
  int i = 1;
  int  count = 0;
 while (N >= 0) {
   N -= i;
   count ++;
   i++;
 }
  return count-1;
}
int main() {
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
   
   int counter = 0;
    for (auto p : res) {
       counter += funk(p.second);
    }
    cout <<counter<< endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();

    while(true){
        ll a, b, ret;
        string c;
        cin >> a >> c >> b;
        if (c == "?") break;

        if (c == "+") ret = a + b;
        else if(c=="-")
            ret = a - b;
        else if(c=="*")
            ret = a * b;
        else
            ret = a / b;
        cout << ret << endl;
    }
}


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

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

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

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

/* Permutation <-> ID */
// {0,1,2} <=> 0, {0,2,1} <=> 1, {2, 1, 0} <=> 5

namespace PermutationConverter {
  const int MAX_DATASIZE = 20;

  ll encode(int N, int *data) {
    bool used[MAX_DATASIZE] = {};
    ll id = 0, t = 1;

    for (int i = 1; i <= N; i++) t *= i;

    for (int i = 0; i < N; i++) {
      t /= (N - i);
      used[data[i]] = true;
      id += count(used, used + data[i], false) * t;
    }

    return id;
  }

  void decode(int N, ll id, int *data) {
    bool used[MAX_DATASIZE] = {};
    ll t = 1;

    for (int i = 1; i <= N; i++) t *= i;

    for (int i = 0; i < N; i++) {
      t /= (N - i);

      int s = id / t;
      for (int j = 0;; j++) {
        if (!used[j] && s == 0) {
          data[i] = j;
          used[j] = true;
          break;
        }
        s -= !used[j];
      }

      id %= t;
    }
  }
};


int main() {
  int N, A[SIZE], B[SIZE];

  cin >> N;

  for (int i=0; i<N; i++) cin >> A[i];
  for (int i=0; i<N; i++) cin >> B[i];

  int a = PermutationConverter::encode(N, A);
  int b = PermutationConverter::encode(N, B);

  cout << abs(a - b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

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

string s[410];
bool seen[410][410];
int h, w;
ll cnt_w, cnt_b;

void bfs(int sx, int sy){
    queue<pair<int,int>> que;
    que.push({sx,sy});
    while(!que.empty()){
        pair<int,int> p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;

        if (s[y][x] == '#') cnt_b++;
        else if (s[y][x] == '.') cnt_w++;
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
            else if (seen[ny][nx]) continue;
            else if (s[ny][nx] != s[y][x]) {
                seen[ny][nx] = true;
                que.push({nx,ny});
            }
        }
    }
}

int main(){
    cin >> h >> w;
    rep(i, h) cin >> s[i];
    ll ans = 0;

    rep(y, h) rep(x, w){
        cnt_w = 0, cnt_b = 0;
        if(seen[y][x]) continue;
        seen[y][x] = true;
        bfs(x, y);
        ans += cnt_w * cnt_b;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640