akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

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

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

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

const long long kMAX = 1000000000;

using namespace std;
using ll = long long;

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

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, int n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

struct Food {
  long f0;
  long prod;

  Food(long f0, long prod): f0(f0), prod(prod) {}
};

ll kM = 998244353;
// ll p_ow(long x, long y) {
//   if (y == 1) return x;
//   return (p_ow(x, y / 2) * p_ow(x, y - y / 2)) % kM;
// }

int main(int argc, char const *argv[]) {
  long n, m, a, b;
  ll ans = 1;
  long x[kMax5];
  bool isD1 = true;
  mmst(x);
  cin >> n;
  rep(i, 1, n) {
    long d;
    cin >> d;
    ++x[d];
    if (i == 1 && d != 0) {
      isD1 = false;
      break;
    }
    if (i != 1 && d == 0) {
      isD1 = false;
      break;
    }
  }
  if (isD1) {
    per(i, n, 2) {
      rep(j, 1, x[i]) {
        ans = (ans * x[i - 1]) % kM;
      }
      // ans = (ans * p_ow(x[i - 1], x[i])) % kM;
    }
  } else {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
a, b, c =list(map(int, input().split()))

if (a+b+c)/2 == a or (a+b+c)/2 == b or (a+b+c)/2 == c:
  print("Yes")
elif (a+b+c)/2 == a+b or (a+b+c)/2 == b+c or (a+b+c)/2 == c+a:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import Data.List
import Data.Bits

toInt :: (String -> Int)
toInt x = read x ::Int

getInts :: IO [Int]
getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y



solve :: Integer -> Integer
solve 0 = 0
solve h = 1 + shiftL(solve(shiftR h 1)) 1



main = do
  h <- readLn :: IO Integer
  putStrLn $ show (solve h)


Measured memory_bytes: 508
#include<iostream>

using namespace std;

int main()
{
    int p,q,r;
    int max;
    int x;
    cin>>p>>q>>r;

    max=1;
    if(p>max)
    {
        max=p;
    }
    if(q>max)
    {
        max=q;
    }
    if(r>max)
    {
        max=r;
    }

    x=p+q+r;
    cout<<x-max;
    cout<<endl;
}

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

#define ll long long
int dp[200005];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin>>n>>k;
    int stones[n];
    for(int i=0; i<n; i++){
        cin>>stones[i];
    }
    for(int i=0; i<n; i++){
        if(i==0){
            dp[0] = 0;
        }
        else{
            int m=INT_MAX;
            for(int x=1; x<=k && i-x>=0; x++){
                m = min(m, dp[i-x]+abs(stones[i]-stones[i-x]));
            }
            dp[i] = m;
        }
    }
    cout<<dp[n-1];
}



Measured memory_bytes: 4328
#include<stdio.h>
int main(void)
{
	int a,b,c,x;
	
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	x=3;
	if(a==b) {
		x=x-1;
	}
	if(a==c) {
		x=x-1;
	}
	if(c==b) {
		x=x-1;
	}
	if(x==0) {
		x=x+1;
	}
	printf("%d\n",x);
	return 0;
}
	

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <cmath>
#include <math.h>
using namespace std;

int isprime(int x){
  if (x<2) return 0;
  if (x==2) return 1;
  if (x%2==0) return 0;
  for (int i=3;i<=sqrt(x);i+=2){
    if (x%i==0) return 0;
  }
  return 1;
}

int main(){
  int n,a,max=-1000000000,min;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(i==0) {
      min = a;
      continue;
    }
    if (a-min>max) max = a - min;
    if (a<min) min = a;
  }
  cout << max <<endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
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 PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

map<int, bool> mp;
int cnt4;

int main() {
    int n;
    cin >> n;
    REP(i,n) {
        int j;
        cin >> j;
        mp[j] = true;
    }
    
    int m;
    cin >> m;
    REP(i,m) {
        int j;
        cin >> j;
        if (mp[j]) cnt4++;
    }

    cout << cnt4 << endl;
    
    return 0;
}

Measured memory_bytes: 1260
// https://atcoder.jp/contests/dp/tasks/dp_c
// AC 26ms 4992KB

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for (int (i) = a; (i) < b; ++(i))
#define maxi(a, b) ((a) = max((a), (b)))

int N;
int arr[100005][3];
int dp[100005][3];

void read() {
	cin >> N;
	rep(i,1,N+1) rep(j,0,3)
		cin >> arr[i][j];
}

void solve() {
	rep(i,0,3) dp[0][i]=0;

	rep(i,1,N+1) {
		rep(p,0,3) dp[i][p]=INT_MIN;
		rep(j,0,3) rep(k,0,3)
			if (k != j) maxi(dp[i][j], arr[i][j] + dp[i-1][k]);
	}

	int ans = INT_MIN;
	rep(i,0,3) maxi(ans, dp[N][i]);
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	read();
	solve();
	return 0;
}



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

using namespace std;


int main()
{
    long long min = 100000000000000;
    long long n;
    cin >> n;
    for(long long i=1;i<=(int)sqrt(n);i++){
        if(n%i == 0){
            if(i + (n/i) < min){
                min = i+ n/i;
            }
        }
    }
    cout << min-2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s;cin>>s;
    int n=s.size();
    int ans=0;
    rep(i,0,(n+1)/2){
        if(s[i]=='p')ans--;
    }
    rep(i,(n+1)/2,n){
        if(s[i]=='g')ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=3e5+5;
const ll mod=1e9+7;
vector<string> ve;
map<string,int> ma;
int main()
{
    int i,j;
    int n;
    scanf("%d",&n);
    int max1=0;
    for(i=1;i<=n;i++)
    {
        string a;
        cin>>a;
        ma[a]++;
        if(ma[a]>max1)
        {
            max1=ma[a];
            ve.clear();
            ve.push_back(a);
        }
        else if(ma[a]==max1)
            ve.push_back(a);
    }
    sort(ve.begin(),ve.end());
    for(i=0;i<ve.size();i++)
        cout<<ve[i]<<endl;
    return 0;
}


Measured memory_bytes: 26736
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n;
        int ans;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        if (n % 2 == 0) ans = n;
        else ans = n * 2;

        System.out.println(ans);
    }

}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1000], b[1000];
int main(){
	int n, m, t, p, ans;
	while(1){
		scanf("%d%d", &n, &m);
		if(!n && !m)break;p = 0;
		rep(i,n)scanf("%d", &a[i]);
		rep(i,m)scanf("%d", &b[i]);
		for(int i = 0;i < m;i++){
			p += b[i];
			if(p >= n-1){ans = i+1;break;}
			p += a[p];
			if(p >= n-1){ans = i+1;break;}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3128
H,W=map(int,input().split())
P=[]

for i in range(H):
  S=list(input())
  P.append(S)


dx=[-1,-1,-1,0,1,1,1,0]
dy=[-1,0,1,1,1,0,-1,-1]

for i in range(H):
  for j in range(W):
    if P[i][j]=='.':
      count=0
      for k in range(8):
        x=i+dx[k]
        y=j+dy[k]
        if x<H and x>=0 and y<W and y>=0 and P[x][y]=='#':
          count+=1
        P[i][j]=count
          
for i in range(H):
  answer=""
  for j in range(W):
    if P[i][j]=='#':
      answer+="#"
    else:
      answer+=str(P[i][j])
  print(answer)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	/** 処理結果 奇数 */
	static final String ODD = "Odd";
	/** 処理結果 偶数 */
	static final String EVEN = "Even";

	public static void main(String[] args) {
		new Main().execute();
	}

	private void execute() {

		List<Integer> arrInitString = getParameter();

		long resultCalc = arrInitString.get(0);

		for (int i = 1; i < arrInitString.size(); i++) {
			resultCalc *= arrInitString.get(i);
		}

		if (resultCalc % 2 == 0) {
			// 偶数
			outputAnswer(Main.EVEN);
		} else {
			// 奇数
			outputAnswer(Main.ODD);
		}
	}

	private List<Integer> getParameter() {

		Scanner scan = new Scanner(System.in);
		List<Integer> listInput = new ArrayList<Integer>();
		listInput.add(scan.nextInt());
		listInput.add(scan.nextInt());
		scan.close();

		return listInput;
	}

	private void outputAnswer(String answer) {
		System.out.println(answer);
	}
}


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

x=[0]+[True]*10**6

for i in range(len(a)):
  cnt=a[i]
  if x[a[i]]==True and (i==0 or a[i]!=a[i-1]) and (i==(n-1) or a[i]!=a[i+1]):
        ans+=1
        while cnt<=10**6:
          x[cnt]=False
          cnt+=a[i]
          
  elif x[a[i]]==True and ((i!=0 and a[i]==a[i-1]) or (i!=(n-1) and a[i]==a[i+1])):
        while cnt<=10**6:
          x[cnt]=False
          cnt+=a[i]
print(ans)


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    string s;cin>>s;

    if(s[0]==s[1] && s[1]==s[2])cout<<"No\n";
    else cout<<"Yes\n";

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;

    int count=0;

    for (int i=a;i<=b;i++) {
        if(i/10000==i%10&&(i/1000)%10==(i/10)%10){
            count++;
        }
    }

    cout<<count<<endl;

}

Measured memory_bytes: 256
-- AOJ: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2006
import Data.Char
import Data.List.Split
import Control.Monad.Cont
import Control.Applicative

solve :: String -> String
solve s = let ws = splitOn "0" s
              wss = filter (\x -> x /= "") ws
           in map (\x -> keyToChar x) wss

keyToChar :: []Char -> Char
keyToChar all@(x:xs) = toChar x $ length all

preset :: []String
preset = [".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]

toChar :: Char -> Int -> Char
toChar x n = solveEx (n - 1) $ preset !! (ord x - ord '0' - 1)

solveEx :: Int -> [Char] -> Char
solveEx n xs = xs !! (n `mod` length xs)

main = do
    ns <- (map read . words) <$> getLine
    let n = ns !! 0
     in forM_ [0..(n-1)] $ \i ->  do
         ss <- getLine
         putStrLn $ solve ss

Measured memory_bytes: 4032
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(void){
    int n,c;
    while(cin>>n,n!=0){
        c=1;
        vector<vector<int> >d(n,vector<int>(n));
        for(int i=-n/2; i<=n/2; i++){
			for(int j=0; j<n; j++){
				d[(j-i+n)%n][(j+i+n)%n]=c;
                c++;
            }
        }
        
		for(int i=0; i<n-1; i++){
			for(int j=i; j<n-1; j++){
				swap(d[i][j+1], d[j+1][i]);
			}
		}
        
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++)printf("%4d", d[i][j]);
            cout<<"\n";
		}
	}
	return 0;
}

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

#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int a[N];
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    int res = 0;
    sort(a + 1, a + n + 1);
    for(int i = 3; i <= n; i ++){
        for(int j = i - 1; j >= 2; j --){
            int l = 0, r = j - 1;
            while(l < r){
                int m = (l + r) / 2;
                if(a[i] < a[j] + a[j - (m + 1)]){
                    l = m + 1;
                }
                else{
                    r = m;
                }
            }
            res += l;
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
)

func main() {

  var n int
  fmt.Scanln(&n)
  d := scanNums(n)
  
  sort.Ints(d)

  fmt.Print(d[n/2] - d[n/2 -1])
}

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

Measured memory_bytes: 5504
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (N, M) = (input[0], input[1])
var student = [[Int]]()
var checkpoint = [[Int]]()
for _ in 0..<N {
    student += [readIntSplit(by: " ")]
}
for _ in 0..<M {
    checkpoint += [readIntSplit(by: " ")]
}
for i in 0..<N {
    var ans = 0
    var minDist = 400000001
    for j in 0..<M {
        let dist = abs(student[i][0] - checkpoint[j][0]) + abs(student[i][1] - checkpoint[j][1])
        if dist < minDist {
            minDist = dist
            ans = j + 1
        }
    }
    print(ans)
}


Measured memory_bytes: 1152
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] alphabet = new int[26];
        
        while(scanner.hasNext()){
            String str = scanner.nextLine();
            char ch[] = str.toCharArray();
    
            for(int i=0; i<str.length(); i++){
                int cnt = Character.toLowerCase(ch[i])-'a';
                if(0 <= cnt && cnt <= 26){
                    alphabet[cnt] += 1;;
                }
            }
        }
        
        for(int i=0; i < 26; i++){
            System.out.println((char)('a' + i ) + " : " + Integer.toString(alphabet[i]));
        }
    }
}


Measured memory_bytes: 26188
import java.util.*;
class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      String str = "";
      
      for(int i = 0; i < K; i++) {
          str += "ACL";
      }
      
      System.out.print(str);
    }
}

Measured memory_bytes: 38424
#include"bits/stdc++.h"
using namespace std;
int main(){
	long long n,a,b;
	cin>>n>>a>>b;
	long long ans=0;
	ans+=n/(a+b)*a;
	long long temp=n%(a+b);
	if(temp>a&&temp<a+b)ans+=a;
	else if(temp<=a)ans+=temp;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, n int
	fmt.Scanf("%d %d %d", &a, &b, &n)

	if n < (b - 1) {
		fmt.Println((a * n / b) - a*(n/b))
	} else {
		fmt.Println((a * (b - 1) / b) - a*((b-1)/b))
	}

}


Measured memory_bytes: 1816
class dice:
    def __init__(self, f0, f1, f2, f3, f4, f5):
        self.dice_num = [f0, f1, f2, f3, f4, f5]

    def roll_dice(self, command):
        for i in command:
            if i == 'N':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[1]
                self.dice_num[1] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[4]
                self.dice_num[4] = tmp

            if i == 'S':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[4]
                self.dice_num[4] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[1]
                self.dice_num[1] = tmp

            if i == 'E':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[3]
                self.dice_num[3] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[2]
                self.dice_num[2] = tmp

            if i == 'W':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[2]
                self.dice_num[2] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[3]
                self.dice_num[3] = tmp

    def print_topface(self):
        print(self.dice_num[0])

    def turn_clockwise(self):
        tmp = self.dice_num[1]
        self.dice_num[1] = self.dice_num[2]
        self.dice_num[2] = self.dice_num[4]
        self.dice_num[4] = self.dice_num[3]
        self.dice_num[3] = tmp

    def check_same_dice(self, dice2):
        for i in range(4):
            self.roll_dice('W')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        for i in range(4):
            self.roll_dice('N')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        return False

    def check_all_same_dice(self, dice_list):
        for i in dice_list:
            if self.check_same_dice(i):
                return False
        return True


if __name__ == "__main__":
    dice_list = []
    k = int(input())
    for i in range(k):
        num_list = list(map(int, input().split()))
        dice_list.append(dice(*num_list))
    same_dice = dice_list[0].check_all_same_dice(dice_list[1:])
    if same_dice:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
int n, W, w[105], v[105];
long long dp[105][100005];
long long f(int x, int y) {
  if (x==n) return 0;
  if (dp[x][y]!=-1) return dp[x][y];
  return dp[x][y] = max(f(x+1, y), y+w[x]<=W?f(x+1, y+w[x])+v[x]:0);
}
int main () {
  scanf("%d %d", &n, &W);
  memset(dp,-1,sizeof dp);
  for (int i=0; i<n; i++) {
    scanf("%d %d", &w[i], &v[i]);
  }
  printf("%lld\n", f(0, 0));
  return 0;
}

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

int main(){
    ll H,W,K;
    cin >> H >> W >> K;
    ll keki[H][W],itigo[H][W];
    char kigou;
    
    rep(i,H){
        rep(j,W){
            keki[i][j]=0;
            cin >> kigou;
            if(kigou=='#') itigo[i][j]=1;
            else itigo[i][j]=0;
        }
    }
    
    ll x,y=0;
    
    rep(i,H){
        rep(j,W){
            if(itigo[i][j]==1){
                x=i;
                y++;
                break;
            }
        }
        if(y) break;
    }
    
    ll count=0,count2=1;
    
    rep(j,W){
        if(itigo[x][j]==1) count++;
    }
    
    if(count==1){
        for(ll i=0;i<=x;i++){
            for(ll j=0;j<W;j++){
                keki[i][j]=count2;
            }
        }
        count2++;
    }else{
        rep(j,W){
            keki[x][j]=count2;
            if(itigo[x][j]==1){
                count--;
                if(count!=0) count2++;
            }
        }
        count2++;
        for(ll i=0;i<x;i++){
            for(ll j=0;j<W;j++){
                keki[i][j]=keki[x][j];
            }
        }
    }
    
    count=0;
    ll z=0;
    
    for(ll i=x+1;i<H;i++){
        rep(k,W){
            if(itigo[i][k]==1) count++;
        }
        if(count==0){
            rep(j,W){
                keki[i][j]=keki[i-1][j];
            }
        }else{
            if(z) count2++;
            z=1;
            rep(j,W){
                keki[i][j]=count2;
                if(itigo[i][j]==1){
                    count--;
                    if(count!=0) count2++;
                }
            }
        }
        count = 0;
    }
    
    rep(i,H){
        rep(j,W){
            if(j) cout << " " << keki[i][j] ;
            else cout << keki[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

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

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

  vector<int> num(4);

  num.at(0) = ABCD / 1000;
  num.at(1) = ABCD / 100 % 10;
  num.at(2) = ABCD / 10 % 10;
  num.at(3) = ABCD % 10;

  rep(i, (1 << 3)){
    bitset<3> b(i);
    int sum = num.at(0);

    rep(j, 3){
      if(b.test(j)) sum += num.at(j+1);
      else sum -= num.at(j+1);
    }
    if(sum == 7){
      cout << num.at(0);
      rep(j, 3){
        if(b.test(j)) cout << '+' << num.at(j+1);
        else cout << '-' << num.at(j+1);
      }
      cout << "=7" << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
# ABC119 Synthetic Kadomatsu

N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def kadomatsu(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = kadomatsu(cur + 1, a, b, c)
    ret1 = kadomatsu(cur + 1, a + l[cur], b, c) + 10
    ret2 = kadomatsu(cur + 1, a, b + l[cur], c) + 10
    ret3 = kadomatsu(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(kadomatsu(0, 0, 0, 0))

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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);  
  rep(i, 0, m) cin >> s[i] >> c[i];
  
  int left, right;
  if(n==1) {
    left = 0;
    right = 10;
  }
  if(n==2) {
    left = 10;
    right = 100;
  }
  if(n==3) {
    left = 100;
    right = 1000;
  }
  
  rep(i, left, right) {
    int ans = 0;
    string str = to_string(i);
    
    rep(j, 0, m) {
      if(str[s[j]-1] == c[j]) ans++;
    }
    
    if(ans == m) {
      cout << i << "\n";
      return 0;
    }
    
  }
    
  cout << -1 << "\n";

}

Measured memory_bytes: 256
N,M=map(int,input().split())
mod=(10**9)+7

ans=0

L=[i+1 for i in range(N+1)]
#print(L)

l=L[::-1]
#print(l)
RUI=[L[0]]
for i in range(1,len(L)):
    RUI.append(RUI[-1]+L[i])
#print(RUI)
rui=[l[0]]
for i in range(1,len(l)):
    rui.append(rui[-1]+l[i])
#print(rui)

ans=0
for i in range(N+1):
    I=N+1-i
    if I<M:
        break
    ans+=(rui[I-1]-RUI[I-1]+1)
    ans%=mod
print(ans)

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

using namespace std;

int		main(void)
{
	int r, D, x;

	cin >> r >> D >> x;
	int ans = r * x - D;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n;
    cin >> n;
    n++;
    vector<ll> z(n);
    ll t = 0;
    ll gt = 0;
    for (int i = 0; i < n; i++) {
        cin >> z.at(i);
        t += z.at(i);
        gt += z.at(i);
    }
    ll ans = 0;
    ll goni = 52;
    ll zf = 1;
    ll d = 100000000;
    for (int i = 0; i < n; i++) {
        zf -= z.at(i);
        t -= z.at(i);
        if (zf < 0) {
            ans = -1;
            break;
        }
        if (t <= zf) {
            ans += t+z.at(i);
            d = i;
            break;
        }
        ans += zf+z.at(i);
        zf *= 2;
    }
    for (int i = d + 1; i < n; i++) {
        ans += (i - d) * z.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
#define MAX 100000

ll n,m,a[MAX],b[MAX];
P ab[MAX] ;

int main(){

    cin>>n>>m;
    
    rep(i,m){
        cin>>a[i];
        cin>>b[i+1];
        ab[i].first=b[i+1];
        ab[i].second=a[i];
    }
    sort(ab,ab+m);
    rep(i,m){
        //cout<<ab[i].first<<" "<<ab[i].second<<endl;
    }
    int count=0;
    ll c=INT_MIN;
    rep(i,m){
        if(c<=ab[i].second){
            count++;
            c=ab[i].first;
            //cout<<ab[i].second<<endl;
        }
    }
    cout<<count; 
    
    return 0;
    
}



Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main()
{
    int n;
    int  i,j;
    float k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%2!=0)
            k++;
    }
    float res;
    res=(float)k/n;
    cout<<res;

    return 0;
}


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

int main()
{
  	long long n;
  	const long long MOD=1e9+7;
  	cin>>n;
  	long long ans=1;
  	for(long long i=2 ; i<=n ; ++i)
    {
    	ans=((ans%MOD)*(i%MOD))%MOD;
    }
  	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;

vector<P> v;
void solve(){
	//奇数の場合
	if(N % 2){
		reps(i, N){
			for(int j = i + 1; j <= N; j++){
				if(i + j != N){
					v.pub(P(i, j));
				}
			}
		}
	}
	else{
		reps(i, N){
			for(int j = i + 1; j <= N; j++){
				if(i + j != N + 1){
					v.pub(P(i, j));
				}
			}
		}
	}
	cout << v.size() << endl;
	rep(i, v.size()){
		cout <<v[i].first << " " << v[i].second << endl;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
		solve();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

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

    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;

int main() {

	int n, x;
	cin >> n >> x;

	vector<int> a(n);

	for (int i = 0; i < n;i++)
		cin >> a.at(i);

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

		int res = 0;
		for (int i = 0;i < n;i++) {
			x -= a.at(i);
			if (x < 0) {
				res = i;
				break;
			}
		}

		if (x == 0)
			cout << n;
		
		else if (x > 0)
			cout << n - 1;

		else
			cout << res;
	}


Measured memory_bytes: 256
fun bingo(sheet:List<List<Int>>, n:Int){
    var bingo = (0 until 3).map{IntArray(3)}

    for(i in 0 until n){
        var tmp = readLine()!!.toInt()
        for(y in 0..2){
            for(x in 0..2){
                if(sheet[y][x] == tmp){
                    bingo[y][x] = 1
                }
            }
        }
    }

    check_bingo(bingo)
}

fun check_bingo(bingo:List<IntArray>){
    var ans = "No"
    //horizon
    for(i in 0..2){
        if(bingo[i].sum() == 3){
            ans = "Yes"
        }
    }

    //vertical
    for(x in 0..2)
        if(bingo[0][x] + bingo[1][x] + bingo[2][x] == 3){
            ans = "Yes"
        }

    //cross
    if(bingo[0][0] + bingo[1][1] + bingo[2][2] == 3 || bingo[0][2] + bingo[1][1] + bingo[2][0] == 3){
        ans = "Yes"
    }

    println(ans)
}

fun main(){
    var sheet = (0 until 3).map{readLine()!!.split(' ').map{it.toInt()}}
    val n = readLine()!!.toInt()
    bingo(sheet,n)
}

Measured memory_bytes: 40400
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	ll n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	ll answer = p;
	ll have = 0;
	ll cnt = 1;
	for (int i = p; i < n; ++i) {
		ll left = p - 1 + (n - i);
		ll v2 = v;
		v2 -= left;
		v2 *= m;
		v2 -= have;
		v2 = max(v2, 0ll);
		ll plus = (v2 + cnt - 1) / cnt;
		if (a[i] + m >= a[p - 1] + plus) {
			++answer;
		}
		have += a[p - 1] - a[i];
		++cnt;
	}
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<int,ll> P;

int N;
vector<int> p[100000];
bool vtd[100000];
vector<int> path;
bool foundPath = false;

void findPath(int n){
  if(foundPath) return;
  //cout << n << endl;
  path.push_back(n);
  /*for(int i=0;i<(int)path.size();i++){
    cout << path[i];
  }
  cout << endl;*/
  if(n == N-1) foundPath = true;

  vtd[n] = true;
  for(int i=0;i<(int)p[n].size();i++){
    if(!vtd[p[n][i]]){
      findPath(p[n][i]);
    }
  }
  if(foundPath) return;
  path.pop_back();
  return;
}

int dfs(int n){
  vtd[n] = true;
  int cnt = 1;
  for(int i=0;i<(int)p[n].size();i++){
    if(!vtd[p[n][i]]){
      cnt += dfs(p[n][i]);
    }
  }
  return cnt;
}

//==============================================================
int main(){
  cin >> N;
  for(int i=0;i<N-1;i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }

  //0~N-1までのパスを見つける
  fill(vtd,vtd+100000,false);
  findPath(0);
  /*for(int i=0;i<(int)path.size();i++){
    cout << path[i];
  }
  cout << endl;*/

  int s,t;
  if(path.size()%2==0){
    s = path[path.size()/2 - 1];
    t = path[path.size()/2];
  } else {
    s = path[path.size()/2];
    t = path[path.size()/2 + 1];
  }

  //黒の点をdfsで数え上げ
  fill(vtd,vtd+100000,false);
  vtd[t] = true;
  int cnt = dfs(s);

  //cout << cnt << endl;
  if(cnt > N - cnt){
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
  return 0;
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    rep(i,3){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 3720
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
    double ax, ay, bx, by, cx, cy, dx, dy;
    while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &ax, &ay, &bx, &by, &cx,&cy,&dx,&dy)) {
        double dot = (ax - bx) * (cx - dx) + (ay - by) * (cy - dy);
        abs(dot) < 1e-10 ? puts("YES") : puts("NO");
    }
    return 0;
}

Measured memory_bytes: 1036
let partition (a : int array) p r =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let rec doit = function
    | (i, j) when j = r -> swap i r; i
    | (i, j) when a.(j) <= a.(r) -> swap i j; doit (i + 1, j + 1)
    | (i, j) -> doit (i, j + 1) in
  doit (p, p)

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let k = partition a 0 (n - 1) in
  Array.iteri (fun i e -> if i = 0 then print_int e else if i = k then (print_string " ["; print_int e; print_string "]") else (print_string " "; print_int e)) a;
  print_newline ()

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

int main(void){
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 1; i <= n; ++i){
		if(i%2==0) continue;
		int a = 0;
		for(int j = 1; j <= i; ++j){
			if(i % j == 0) a++;
		}
		if(a == 8) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 0X3f3f3f3f
#define M 1000000007
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back 
#define fi first
#define se second
#define endl "\n"
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false)
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 90;
ll lucas[N];
int n;

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

	lucas[0] = 2;
	lucas[1] = 1;

	for(int i = 2; i <= n; i++){
		lucas[i] = lucas[i-2] + lucas[i-1];
	}

	cout << lucas[n] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,p[25],f=0;
	cin >>n ;
	for(int i=0;i<n;i++)
		cin >> p[i] ;
	for(int i=1;i<n-1;i++)
		if((p[i]>p[i-1]&&p[i]<p[i+1] )|| (p[i]>p[i+1]&&p[i]<p[i-1]))
			f++;
	cout << f;		
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D;
    string S,T;
    ll X[100];
    ll gcd(ll a,ll b){
        if(b==0)return a;
        return gcd(b,a%b);
    }
int main(){
    cin>>A>>B;
    cout<<((A/gcd(A,B))%(B/gcd(A,B))==0?-1:A*A/gcd(A,B))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int a, b, tmp;
  scanf("%d%d", &a, &b);
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }

  while(b != 0){
    tmp = b;
    b = a % b;
    a = tmp;
  }
  printf("%d\n", a);

  return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UnionFind
{
    int i;
    vector<int> par;
    vector<int> size;
    UnionFind(int n): par(n),size(n,1){
        for(i = 0;i < n;++i){
            par.at(i) = i;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = root(par.at(x));
        }
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return;
        }else{
            if(size.at(rx) < size.at(ry)){
                swap(rx,ry);
            }
            par.at(ry) = rx;
            size.at(rx) += size.at(ry);
            return;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    vector<ll> b(m);
    for(i = 0;i < m;++i){
        cin >> a.at(i) >> b.at(i);
        --a.at(i);   --b.at(i);
    }
    vector<ll> ans(m+1);
    ans.at(0) = n*(n-1)/2;
    UnionFind uf(n);
    for(i = 0;i < m;++i){
        ll ti = i+1;
        ll c = a.at(m-1-i);
        ll d = b.at(m-1-i);
        if(uf.same(c,d)){
            ans.at(ti) = ans.at(i);
        }else{
            ll e = uf.get_size(c);
            ll f = uf.get_size(d);
            ans.at(ti) = ans.at(i) - e*f;
        }
        uf.unite(c,d);
    }
    for(i = m-1;i >= 0;--i){
        cout << ans.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
using namespace std;
signed main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++) {
        if (A.at(i) == 0) {
            cout << 0 << endl;
          return 0;
        }
    }
    Bint sum = 1;
    int ABC = 0;
    for (int i = 0; i < N; i++) {
        if (A.at(i) == 0) {
            break;
        }
        sum *= A.at(i);
        if (sum > 1000000000000000000) {
            ABC += 2;
            break;
        }
    }
    if (ABC == 2) {
        cout << "-1" << endl;
    }
    else {
        cout << sum << endl;
    }
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<std::string> s(n);
	std::vector<int> t(n);
	for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
	std::string x; cin >> x;

	int ans = 0;
	bool f = false;
	for(int i = 0; i < n; i++) {
		if(f) ans += t[i];
		if(s[i] == x) f = true;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());
  int a,b;cin>>a>>b;
  int count=0;
  for(int i=a; i<=b;i++){
    string st = to_string(i);
    if(st[0] == st[4] && st[1]==st[3]){
      count++;
    }
  }
  P(count);
  return 0;
}


Measured memory_bytes: 256
# 解説AC
A = list(input())
cnt = [0] * 26
for s in A:
    cnt[ord(s) - ord("a")] += 1

ans = len(A) * (len(A) - 1) // 2
ans -= sum(c * (c - 1) // 2 for c in cnt)
ans += 1

print(ans)

Measured memory_bytes: 4840
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 1e9;
const int MB = 30;
const int MOD = 1e9 + 7;
const int maxN = 2e5 + 1;

int fact[maxN], rev[maxN];

int mod_pow(int a, int b) {
    if (!b) return 1;
    if (b % 2) return a * mod_pow(a, b - 1) % MOD;
    int q = mod_pow(a, b / 2);
    return q * q % MOD;
}

int c(int n, int k) {
    return (fact[n] * rev[k] % MOD) * rev[n - k] % MOD;
}

void solve() {
    int n, k;
    cin >> n >> k;

    fact[0] = 1;
    for (int i = 1; i < maxN; i++){
        fact[i] = fact[i - 1] * i % MOD;
    }
    for (int i = 0; i < maxN; i++) {
        rev[i] = mod_pow(fact[i], MOD - 2);
    }

    int ans = 0;
    int mn = 0, mx = n;
    int now1 = 1, now2 = n - 1;
    for (int i = 1; i <= n + 1; i++) {
        if (i >= k) ans = (ans + mx - mn + 1) % MOD;
        mn += now1++;
        mx += now2--;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    //srand(time(0));
    cout.precision(12);
    cout << fixed;
    while (t--) solve();
}

Measured memory_bytes: 6816
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include <functional>

#define big ((long long)(1e9)+7)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int x = n%10;
    if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
    {
        cout << "hon" << endl;
    }
    else if(x == 0 || x == 1 || x == 6 || x == 8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "bon" << endl;
    }
}


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

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}

Measured memory_bytes: 1180