akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

string dp[10004];
int dig[10], cost[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string get_best(string a, string b){

    if(a.size() > b.size())
        return a;
    if(a.size() < b.size())
        return b;

    for(int i = 0; i < a.size(); ++i){
        if(a[i] < b[i]){
            return b;
        } else if(a[i] > b[i]){
            return a;
        }
    }
    return a;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    dp[0] = "";

    int n, m; cin >> n >> m;

    for(int i = 0; i < m; ++i)
        cin >> dig[i];

    for(int i = 1; i <= n; ++i){
        for(int j = 0; j < m; ++j){
            if(i < cost[dig[j]]) continue;
            if(i - cost[dig[j]] > 0 && dp[i - cost[dig[j]]].empty()) continue;
            //cout << dp[i] << " " << dp[i - cost[dig[j]]] << " " << i - cost[dig[j]] << " " << dig[j] << endl;
            dp[i] = get_best(dp[i], dp[i - cost[dig[j]]] + to_string(dig[j]));
        }
        //cout << dp[i] << "\n";
    }

    cout << dp[n] << "\n";

    return 0;
}


Measured memory_bytes: 29568
n, m = map(int, input().split())
a, b = [], []
for i in range(n):
    te, mp = map(int, input().split())
    a.append(te)
    b.append(mp)

e, f = [], []
for i, j in sorted(zip(a, b)):
    e.append(i)
    f.append(j)

ans = 0
for i in range(n):
    if m - f[i] <= 0:
        ans += e[i] * m
        print(ans)
        exit()
    else:
        ans += f[i] * e[i]
        m -= f[i]
print(ans)


Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
typedef pair<int,int> P;
int cost1[25][25];
int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(i != j) cost1[i][j] = INF;
      else cost1[i][j] = 0;
    }
  }
  
  int a,b,c,d;
  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    cost1[a][b] = c;
    cost1[b][a] = d;
  }
  
  scanf("%d,%d,%d,%d",&a,&b,&c,&d);
  for(int k=1;k<=n;k++){ //経由するノード
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	cost1[i][j] = min(cost1[i][j],cost1[i][k]+cost1[k][j]);
      }
    }
  }
  c-= cost1[a][b];
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	cost1[j][i] = min(cost1[j][i],cost1[j][k]+cost1[k][i]);
      }
    }
  }
  
  cout << c-d-cost1[b][a] << endl;
  
  return 0;
}

Measured memory_bytes: 3192
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << min(a, b) + min(c, d) << endl;

	return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const n = lines[0] - 0;
  const f = (l) => l.split(" ").map(Number);
  const xs = f(lines[1]);
  const ys = f(lines[2]);
  let sum = 0;
  let sum2 = 0;
  let sum3 = 0;
  let max = 0;
  for (let i = 0; i < n; i++) {
    const xy = Math.abs(xs[i] - ys[i]);
    max = Math.max(max, xy);
    sum += xy;
    sum2 += xy * xy;
    sum3 += Math.pow(xy, 3);
  }
  console.log(sum);
  console.log(Math.sqrt(sum2).toFixed(5));
  console.log(Math.pow(sum3, 1 / 3).toFixed(5));
  console.log(max);
});



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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

int main(){
  int N, Q;
  while(scanf("%d%d", &N, &Q) && N+Q){
    int cnt[101] = {};
    int M, data;
    rep(i, N){
      scanf("%d", &M);
      rep(i, M){ 
	scanf("%d", &data);
	cnt[data]++;
      }
    }

    int res = 0;
    REP(i, 1, 101) if(cnt[res] < cnt[i]) res = i;

    printf("%d\n", cnt[res]<Q?0:res);
  }
  return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

int main()
{
    string S;
    cin >> S;
    vector<char> ans(S.size(), 'x');
    for (auto &ch : ans)
    {
        cout << ch;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  int count=0;
  for(int i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]) count++;
    else if(count >= 1){
      n = n - count;
      count = 0;
    }
    
    if(i==s.size()-2 && count >= 1) n = n - count;
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// // 整数の入力
		// int a = sc.nextInt();
		// // スペース区切りの整数の入力
		// int b = sc.nextInt();
		// int c = sc.nextInt();
		// // 文字列の入力
		// String s = sc.next();
		// // 出力
    // System.out.println((a+b+c) + " " + s);
		String up = sc.next();
		String down = sc.next();
		if (up.charAt(0) == down.charAt(2) && up.charAt(1) == down.charAt(1) && up.charAt(2) == down.charAt(0)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23892
#include<stdio.h>

#define MAX 100000

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= H)printf("left key = %d, ",A[left(i)]);
    if(right(i) <= H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
fun main(args: Array<String>) {
    var (n,m,c) = readLine()!!.split(" ").map { s -> s.toInt() }
    var b = readLine()!!.split(" ").map { s -> s.toInt() }
    var count=0
    for (i in 0 until n){
        if(readLine()!!.split(" ").mapIndexed{i,s->b[i]*s.toInt()}.sum()+c>0)count+=1
    }
    println(count)
}

Measured memory_bytes: 37996
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int gcd(int x,int y){
    if(x<y)swap(x,y);
    return y==0?x:gcd(y,x%y);
}

int main(){
    int n;
    cin>>n;
    int ret=0;
    rep(i,n){
        int x;
        cin>>x;
        ret=gcd(ret,x);
    }
    cout<<ret<<endl;
    return 0;
}

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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;



int main(void)
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int i,j,key,n;
  int A[100];

  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d",A+i);
  for(i=0 ; i<n-1 ; i++) printf("%d ",A[i]);
  printf("%d\n",A[i]);

  for(j=1 ; j<n ; j++){
    key = A[j];
    i = j-1;
    while(i>=0 && A[i]>key){
      A[i+1] = A[i];
      i--;
    }

    A[i+1] = key;
    for(i=0 ; i<n-1 ; i++) printf("%d ",A[i]);
    printf("%d\n",A[i]);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_N = 30200;
char S[MAX_N];
char num[4];

bool pin_to_s(int pin){
    for(int i = 2; i >= 0; --i) num[i] = pin%10 + '0', pin /= 10;
}

int main()
{
    int N;
    scanf("%d", &N);
    scanf("%s", S);
    int res = 0;
    bool flg = false;
    for(int pin = 0; pin < 1000; ++pin){
        pin_to_s(pin);
        for(int i = 0; i < N; ++i) if(S[i] == num[0]) {
            for(int j = i+1; j < N; ++j) if(S[j] == num[1]) {
                for(int k = j+1; k < N; ++k) if(S[k] == num[2]) {
                    ++res;
                    break;
                }
                break;
            }
            break;
        }
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const long long INF=1e16;
int beg[100100],nex[200100],tto[200100],e;
long long w[200100];
int siz[100100];
long long fv[100100];
int mxv[100100];
int n;
bool flag;
void putin(int s,int t,long long v){
	tto[++e]=t;
	nex[e]=beg[s];
	beg[s]=e;
	w[e]=v;
}
void dfs(int u,int fa){
	siz[u]=1;
	mxv[u]=1;
	for(int i=beg[u];i;i=nex[i])
	{
		if(tto[i]==fa)
			continue;
		fv[tto[i]]=w[i];
		dfs(tto[i],u);
		siz[u]+=siz[tto[i]];
		if(siz[tto[i]]>mxv[u])
			mxv[u]=siz[tto[i]];
	}
	if(siz[u]==n-siz[u])
		flag=1;
}
int main()
{
//	freopen("C.in","r",stdin);
	scanf("%d",&n);
	int s,t;
	long long v;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d%lld",&s,&t,&v);
		putin(s,t,v);
		putin(t,s,v);
	}
	dfs(1,-1);
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=ans+min(siz[i],n-siz[i])*fv[i];
		if(n-siz[i]>mxv[i])
			mxv[i]=n-siz[i];
	}
	ans=ans*2;
	long long mn=INF;
	if(!flag)
	{
		for(int i=1;i<=n;i++)
		{
			if(mxv[i]<=n/2)
			{
				for(int j=beg[i];j;j=nex[j])
					if(w[j]<mn)
						mn=w[j];
			}
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			if(mxv[i]==n/2)
			{
				for(int j=beg[i];j;j=nex[j])
					if(mxv[tto[j]]==n/2)
						mn=w[j];
			}
		}
	}
	ans-=mn;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 9344
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	string line;
	cin >> line;

	int result = 0;

	int l = 0;
	int r = N - 1;
	while (l + 1 < r)
	{
		while (l < N && line[l] != 'W') l++;
		while (r >= 0 && line[r] != 'R') r--;

		if (l < r)
		{
			swap(line[l], line[r]);
			result++;
		}
	}

	for (int i = 0; i < N - 1; i++)
	{
		if (line[i] == 'W' && line[i + 1] == 'R')
		{
			result++;
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <numeric>
#include <random>
#include <memory>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <cstring>
#include <cassert>
#include <bitset>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif
//#define int ll
//#pragma GCC optimize("Ofast")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define sz(x) int((x).size())

#ifndef LOCAL
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#else
	mt19937 rng(228);
#endif

const int N = 5e3 + 7;
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 3;
const int MOD = 998244353;
const ld eps = 1e-6;
const string cars[] = {"🚗", "🚕", "🚙"};



signed main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(9);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	ll ans = 0;

	ans += min(a, k);
	k -= min(a, k);

	k -= min(b, k);

	ans -= min(c, k);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>

using namespace std;
typedef long long LL;

int main()
{
    LL n,m;
    while(scanf("%lld%lld",&n,&m)==2){
        if(n>=2) n=n-2;
        if(m>=2) m=m-2;
        printf("%lld\n",n*m);
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
# nまでの素数のテーブルを作る
def prime_table(n):
  list = [True for _ in range(n + 1)]
  i = 2
  while i * i <= n:
    if list[i]:
      j = i + i
      while j <= n:
        list[j] = False
        j += i
    i += 1

  table = [i for i in range(n + 1) if list[i] and i >= 2]
  return table

prime_table = prime_table(n)
ans = 1

for p in prime_table:
    count = 0
    for i in range(2,n+1):
        while i%p == 0:
            i /= p
            count += 1
    ans *= count+1

print(ans%(10**9+7))

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

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A){
    if(A.size() == N+1){
        int now = 0;
        for(int i=0; i<Q; i++){
            if(A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)){
                now += d.at(i);
            }
        }
        ans = max(ans, now);
        return;
    }
    A.push_back(A.back());
    while(A.back() <= M){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> N >>M >> Q;
    a = b = c = d = vector<int>(Q);
    for (int i = 0; i < Q; i++){
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#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 n = 0;
	cin >> n;
	ll ans = 0;
	ll a_count, b_count, both_count;
	a_count = b_count = both_count = 0;
	string s;
	int pos = 0;
	rep(i, n) {
		cin >> s;
		pos = 0;
		while (1) {
			pos = s.find("AB", pos);
			if (pos != string::npos) {
				ans++;
				pos += 2;
			}
			else break;
		}
		if (s.back() == 'A' && s[0] == 'B')	both_count++;
		else if (s.back() == 'A')	a_count++;
		else if (s[0] == 'B')	b_count++;
	}
	ans += min(a_count, b_count) + both_count;
	if (a_count == 0 && b_count == 0 && both_count != 0)	ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    cnt = 1 if all(s.count(c) for c in '753') else 0
    
    for ss in '753':
        cnt += dfs(s+ss)
    #print(s,cnt)
    
    return cnt
    
print(dfs('0'))

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

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

    REP(i, b) {
        if (i*a % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
N, L = list(map(int, input().split()))
maxscore = N*(L-1) + N*(N+1)/2
minscore = float("inf")
for i in range(1, N+1):
    if minscore > abs(L - 1 + i):
        minscore = abs(L-1+i)
        keisanyou = L-1+i
print(int(maxscore - keisanyou))

Measured memory_bytes: 3060
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	fmt.Println(Min((2*N+M)/4, M/2))
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


Measured memory_bytes: 1840
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int x,y;
  cin>>x>>y;
  vector<int> v1={1,3,5,7,8,10,12};
  vector<int> v2={4,6,9,11};
  vector<int> v3={2};
  map<int,int> m;
  for(int i:v1)m[i]=1;
  for(int i:v2)m[i]=2;
  for(int i:v3)m[i]=3;
  cout<<((m[x]==m[y])?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if((b-a)&1)
		puts("Borys");
	else
		puts("Alice");
	return 0;
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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

ll calc(ll x,ll y){
  if(x<=y)  return abs(y-x);
  else  return 1e18;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll x,y;
  cin >> x >> y;

  ll ans=1e18;
  chmin(ans,0+calc(x,y));
  chmin(ans,1+calc(-x,y));
  chmin(ans,1+calc(x,-y));
  chmin(ans,2+calc(-x,-y));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    int cnt = 0;
    rep(i,n){
        int x;
        cin >> x;
        if(x!=i+1) cnt++;
    }
    if(cnt==2 || cnt==0) cout <<"YES" << endl;
    else cout <<"NO" << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
//$N = trim(fgets(STDIN));
list($m1,$d1) =  explode(" ",trim(fgets(STDIN)));
list($m2,$d2) =  explode(" ",trim(fgets(STDIN)));
//$A =  explode(" ",trim(fgets(STDIN)));

$ret=0;
if ($d2 == 1) {
  $ret=1;
}
printf("%d\n",$ret);


Measured memory_bytes: 4856
#include<stdio.h>
#include<math.h>
typedef struct point{
  double x,y;
}point;
void kock(int,point,point);
int main(){
  int n;
  point p1={0,0}, p2={100,0};
  scanf("%d",&n);
  printf("%lf %lf\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%lf %lf\n",p2.x,p2.y);
  return 0;
}
void kock(int n,point p1,point p2){
  point s,t,u;
  if(n == 0) return;
  s.x = (2 * p1.x + 1 * p2.x) / 3;
  s.y = (2 * p1.y + 1 * p2.y) / 3;
  t.x = (1 * p1.x + 2 * p2.x) / 3;
  t.y = (1 * p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * cos(M_PI/3) - (t.y - s.y) * sin(M_PI/3) + s.x;
  u.y = (t.x - s.x) * sin(M_PI/3) + (t.y - s.y) * cos(M_PI/3) + s.y;
  kock(n-1, p1, s);
  printf("%.8lf %.8lf\n",s.x,s.y);
  kock(n-1, s, u);
  printf("%.8lf %.8lf\n",u.x,u.y);
  kock(n-1, u, t);
  printf("%.8lf %.8lf\n",t.x,t.y);
  kock(n-1, t, p2);
}

Measured memory_bytes: 640
import math
N,K = map(int,input().split())
n = 0
if K==0:
    print(N*N)
else:
    for a in range(K+1,N):
        n += math.floor(N/a)*(a-K) + max(N%a-K+1,0)
    n+=N-K
    print(n) 

Measured memory_bytes: 3060
a,b=gets.split(" ").map(&:to_i)
c = []
gets.split(" ").map{|n| c << n.to_i}
m = 0
l = []
c.each{|n|
  m = m + n
  l << m
}
count = 1
l.each{|k| count += 1 if k <= b}
puts count

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

using namespace std;

// n の k 乗を mod で割った余りを計算
long long power_mod(long long n, long long k, long long mod) {
    long long result = 1;
    // k を右シフトしつつ n を 2 乗していく
    while (k > 0) {
        // k の最下ビットが 1 なら、今の n を答えに掛ける
        if ((k & 1) == 1) result = (result * n) % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return result;
}

// 階乗・組み合わせの mod 逆数
class FactorialMod {
    // 逆元を計算
    void calc_inverse() {
        inverse[0] = 0;
        inverse[1] = 1;
        for (int i = 2; i <= max_num; i++) {
            inverse[i] = mod - ((mod / i) * inverse[mod % i] % mod);
        }
    }

    // i! を mod で割った余りと逆元を計算
    void calc_factorial_inverse() {
        factorial[0] = factorial_inverse[0] = 1;
        for (int i = 1; i <= max_num; i++) {
            factorial[i] = (factorial[i - 1] * i) % mod;
            factorial_inverse[i] = (factorial_inverse[i - 1] * inverse[i]) % mod;
        }
    }

  public:
    int max_num;                         // 扱う最大の値
    int mod;                             // mod の法（素数）
    vector<long long> inverse;           // 逆元
    vector<long long> factorial;         // 階乗
    vector<long long> factorial_inverse; // 階乗の逆元

    FactorialMod(int _max_num, int _mod) {
        calc_inverse();
        max_num = _max_num;
        mod = _mod;
        inverse = vector<long long>(max_num + 1);
        factorial = vector<long long>(max_num + 1);
        factorial_inverse = vector<long long>(max_num + 1);
        calc_factorial_inverse();
    }

    // nCk を mod で割った余りを計算
    long long combination_mod(int n, int k) {
        return (((factorial[n] * factorial_inverse[k]) % mod) * factorial_inverse[n - k]) % mod;
    }

    // nHk を mod で割った余りを計算
    long long multi_choose_mod(int n, int k) {
        return combination_mod(n + k - 1, k);
    }
};

const int MOD = 1000000007;

int main(void) {
    int n, k;
    cin >> n >> k;
    cout << power_mod(k, n, MOD) << endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<pair<int,ll>> to[100000];
	rep(i,n-1) {
		int a,b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		to[a].push_back(pair<int, ll>(b,c));
		to[b].push_back(pair<int, ll>(a,c));
	}
	int q,k;
	cin >> q >> k;
	k--;

	// 各点から頂点Kまでの距離を計算
	queue<int> que;
	que.push(k);
	vector<bool> visited(n,false);
	visited[k] = true;
	vector<ll> dist(n,0);
	while(!que.empty()) {
		int now = que.front();
		que.pop();
		for (pair<int,ll> nei : to[now]) {
			int next = nei.first;
			ll d = nei.second;
			if (!visited[next]) {
				dist[next] = dist[now] + d;
				visited[next] = true;
				que.push(next);
			}
		}
	}
	//rep(i,n) printf("%lld, %lld\n", i, dist[i]);

	rep(i,q) {
		int x,y;
		cin >> x >> y;
		x--, y--;
		ll ans = 0;
		// 距離を計算
		ans = dist[x] + dist[y];
		cout << ans << endl;
	}
	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[3]) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 1; i < N/2; i++) ans++;
  if(N%2 == 1) ans++;
  if(N==1) ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
int T[105]={0};
int main(){
  int n;cin>>n;int sum=0;
  for(int i=0;i<n;i++){
    int k;cin>>k;
    sum+=k;
    T[i]=n*k;
  }
  int dif=1000000000;
  int ans=0;
  for(int i=0;i<n;i++){
    if(abs(sum-T[i])<dif){ans=i;dif=abs(sum-T[i]);}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


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

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			int num = (n * j - j * i) + (i * (m - j));
			if (num == k) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main() {
    int N, M; string S, T; cin >> N >> M >> S >> T;
    
    ll g = gcd(N, M);
    ll l = N / g * M;

    bool ok = true;
    N /= g; M /= g;
    REP(i, 0, g) {
        if (S[N * i] != T[M * i]) ok = false;
    }

    if (ok) cout << l << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    string s; cin >> s;
    int n = s.size();
    map<int,int> mp;
    mp[0] = 0;
    int now = 0;
    int dp;
    rep(i,n){
        now ^= (1<<(s[i]-'a'));
        dp = inf;
        rep(j,26){
            int nxt = now ^ (1<<j);
            if(mp.find(nxt) != mp.end()){
                chmin(dp, mp[nxt] + 1);
            }
        }
        if(mp.find(now) != mp.end()){
            chmin(dp, mp[now] + 1);
            chmin(mp[now], dp);
        }else{
            mp[now] = dp;
        }
    }
    cout << dp << "\n";
}

Measured memory_bytes: 12956
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <set>

size_t nya(intmax_t p, intmax_t q, std::vector<std::pair<intmax_t, intmax_t>> xy) {
  std::set<std::pair<intmax_t, intmax_t>> tsurai(xy.begin(), xy.end());
  size_t res = xy.size();
  for (auto it = tsurai.begin(); it != tsurai.end(); ++it) {
    intmax_t x = it->first + p;
    intmax_t y = it->second + q;
    std::pair<intmax_t, intmax_t> pp(x, y);
    if (tsurai.count(pp)) --res;
  }
  return res;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<std::pair<intmax_t, intmax_t>> xy(N);
  for (auto& p: xy)
    scanf("%ld %ld", &p.first, &p.second);

  size_t res = N;
  for (size_t i = 0; i < N; ++i)
    for (size_t j = 0; j < N; ++j) {
      if (i == j) continue;

      intmax_t p = xy[i].first - xy[j].first;
      intmax_t q = xy[i].second - xy[j].second;
      size_t cur = nya(p, q, xy);
      // fprintf(stderr, "(%jd, %jd): %zu\n", p, q, cur);
      res = std::min(res, cur);
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	int a[1000], b;
	int c[1000];
	int c2;
	int dp[1000][4096];
	for(int i = 0;i < 1000;i++){
		for(int j = 0;j < 4096;j++){
			dp[i][j] = 1000000;
		}
	}
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		c2 = 0;
		cin >> a[i] >> b;
		for(int j = 0;j < b;j++){
			cin >> c2;
			c[i] += (1 << (c2 - 1));
		}
	}
	dp[0][0] = 0;
	dp[0][c[0]] = a[0];
	for(int i = 1;i < m;i++){
		for(int j = 0;j < (1 << n);j++){
			if(dp[i - 1][j] != -1){
				dp[i][j | c[i]] = min(dp[i][j | c[i]], dp[i - 1][j] + a[i]);
				dp[i][j] = min(dp[i - 1][j], dp[i][j]);
			}
		}
	}
	if(dp[m - 1][(1 << n) - 1] == 1000000){
		cout << -1 << endl;
		return 0;
	}
	cout << dp[m - 1][(1 << n) - 1] << endl;
}


Measured memory_bytes: 16384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		HashSet<Integer> fromStart = new HashSet<>();
		HashSet<Integer> toEnd = new HashSet<>();
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a == 1) {
				fromStart.add(b);
			} else if (a == n) {
				toEnd.add(b);
			}
			if (b == 1) {
				fromStart.add(a);
			} else if (b == n) {
				toEnd.add(a);
			}
		}
		for (int x : fromStart) {
			if (toEnd.contains(x)) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
		
	}
}


Measured memory_bytes: 107168
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K, A, B;
    cin >> K >> A >> B;
    bool C = false;
    if(A != B){
    for(int i = 0; i < (B-A+1); i++){
        if((i+A)%K == 0){
            C = true;
            break;
        }
    }
    }
    else{
        if(A%K==0){C = true;}
    }
    if(C == true){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
}


Measured memory_bytes: 3436
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,cnt;
    cin >> A >> B >> C;
    cnt = 0;
    while(true){
        if(cnt >= C || B < A){
            break;
        }
        cnt++;
        B-=A;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll power(ll x, ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2,m)%m; 
    p = (p * p)%m; 
  
    return (y%2 == 0)? p : (x * p)%m ; 
} 

ll modInverse(ll a, ll m) 
{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
    return power(a, m-2,m); 
} 
  
// To compute x^y under modulo m 


int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    ll h[n+1];int a[n+1]={0};
    for(int i=0;i<n;i++)
    {
      cin>>h[i+1];
    }
    for(int i=0;i<m;i++)
    {
      int s,d;
      cin>>s>>d;
      if(h[s]>h[d])
      {
        a[s] = a[s]!=-1?1:-1;
        a[d] = -1;
      }
      else if(h[s]<h[d])
      {
        a[d] = a[d]!=-1?1:-1;
        a[s] = -1;
      }
      else
      {
        a[s] = -1;
        a[d] = -1;
      }
    }
    
    int g = 0;
    for(int i=1;i<=n;i++)
    {
      if(a[i]!=-1)
      {
        g++;
      }
    }
    cout<<g;
    
    
    return 0;
}

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

int main(){
    long long h; cin >> h;
    long long cnt; cnt=0;
    for(int i = 0; i < 60; i++) {
        cnt+=pow(2,i);
        if(h>1) h=h/2;
        else {
            cout << cnt << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		TreeSet<Integer> S = new TreeSet<Integer>();
		int q = sc.nextInt();
		for(int i = 0; i < q; i++){
			int com = sc.nextInt();
			if(com == 0){
				int x = sc.nextInt();
				S.add(x);
				System.out.println(S.size());
			}else if(com == 1){
				int x = sc.nextInt();
				if(S.contains(x)) System.out.println(1);
				else System.out.println(0);
			}else if(com == 2){
				int x = sc.nextInt();
				S.remove(x);
			}else{
				int L = sc.nextInt();
				int R = sc.nextInt();
				SortedSet SS = S.subSet(L, R + 1);
				for(Iterator j = SS.iterator(); j.hasNext();) System.out.println(j.next());
			}
		}
	}
}



Measured memory_bytes: 181116
package main

import "fmt"

func main() {
	var time = make([]int, 3)
	for i := range time {
		fmt.Scan(&time[i])
	}

	ans := 1000000
	for i := 0; i < len(time); i++ {
		for j := i + 1; j < len(time); j++ {
			if time[i]+time[j] < ans {
				ans = time[i] + time[j]
			}
		}
	}
	fmt.Println(ans)

}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <stdlib.h>



int main(){
  int n, m, max_val, val;
  
  std::cin >> n >> m;
  max_val = int(m/n);
  val = max_val;

  while(val > 1){
	//std::cout << n << m << val << std::endl;
	if(0 == m % val){
	  std::cout << val << std::endl;
	  exit(0);
	}
	val -= 1;
  }
  std::cout << 1 << std::endl;
  
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

ans=[0]
for i in range(n):
    ans_bkup=ans.copy()
    ans=list(map(lambda x: x+a[i],ans))
#    print(ans,ans_bkup)
    ans.extend(ans_bkup)
    ans=list(set(ans))

for i in range(q):
    if(m[i] in ans):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
  int s, w;
  cin >> s >> w;
  if (s<=w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3592
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from math import gcd
def reduction(x,y):
    g = gcd(x,y)
    return abs(x)//g,abs(y)//g

def solve():
    mod = 10**9+7
    dplus = defaultdict(lambda: 0)
    dminus = defaultdict(lambda: 0)
    N = int(input())
    xzero = 0
    yzero = 0
    xyzero = 0
    for i in range(N):
        x,y = map(int, input().split())
        if x==0:
            if y==0:
                xyzero += 1
            else:
                xzero += 1
        elif y==0:
            yzero += 1
        elif x*y>0:
            dplus[reduction(x,y)] += 1
        else:
            dminus[reduction(-y,x)] += 1
    pattern = pow(2,xzero,mod)+pow(2,yzero,mod)-1
    other = N-xzero-yzero-xyzero
    for k,v in dplus.items():
        pattern *= pow(2,dminus[k],mod)+pow(2,v,mod)-1
        other -= dminus[k]+v
    ans = pattern * pow(2,other,mod) - 1
    ans += xyzero
    ans %= mod
    return ans
print(solve())


Measured memory_bytes: 54884
#!/usr/bin/env python3
from collections import defaultdict
n,*a=map(int,open(0).read().split())
d = defaultdict(int)
s = 0
ans = 0
d[0] += 1
for i in a:
    s += i
    ans += d[s]
    d[s] += 1
print(ans)


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

class Dice {
public:
	void init(int num[6]) {
		t = num[0];
		b = num[5];
		n = num[4];
		s = num[1];
		w = num[3];
		e = num[2];
	}
	bool operator == (Dice& d) {
		for (int i = 0; i < 4; i++) {
			if (t == d.t) {
				if (compDice(d))return true;
			}
			roll_e();
		}
		for (int i = 0; i < 3; i++) {
			roll_n();
			if (t == d.t) {
				if (compDice(d))return true;
			}
		}
		return false;
	}
	bool compDice(Dice& d) {
		for (int i = 0; i < 4; i++) {
			if (t == d.t && b == d.b && n == d.n &&
				s == d.s && w == d.w && e == d.e) {
				return true;
			}
			spin_left();
		}
		return false;
	}

	void roll_e() {
		int temp = w;
		w = b;
		b = e;
		e = t;
		t = temp;
	}
	void roll_w() {
		for (int i = 0; i < 3; i++)roll_e();
	}
	void roll_n() {
		int temp = s;
		s = b;
		b = n;
		n = t;
		t = temp;
	}
	void roll_s() {
		for (int i = 0; i < 3; i++)roll_n();
	}
	void spin_left() {
		int temp = n;
		n = e;
		e = s;
		s = w;
		w = temp;
	}
	int getTop() {
		return t;
	}
private:
	int t, b;
	int n, s, w, e;
};

bool checkDice(Dice dice[], int n) {
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (dice[i] == dice[j])return false;
		}
	}
	return true;
}

int main() {
	int n;
	int d[6];
	Dice dice[100];
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> d[j];
		}
		dice[i].init(d);
	}

	if (checkDice(dice,n)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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




using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;

// B貪欲法で決定する．
int main(){
  int d;
  cin>>d;
  vector<int> c(26);
  vector<vector<int>> s(d,vector<int>(26));
  vector<int> last(26),last0(26);
  vector<int>c_inv(26); // iを選んだ際の1日での下がり幅
  

  ll c_tot=0;
  rep(i,26){
    cin>> c[i];
    c_tot+=c[i];
    last[i]=-1;
    last0[i]=-1;
  }
  rep(i,26){
    c_inv[i]=c_tot-c[i];
  }

  rep(i,d){//i日目
    rep(j,26){
      cin>>s[i][j];
    }
  }
  // ここまで入力．

  //貪欲法により，初期値t[i]を決める．
  vector<int> t(d);
  int maxloss, iml; // maxlossとその日付
  random_device rnd;
  maxloss=INF;
  rep(i,d){//i日目
   int maxs=-INF;
   int jm=0;

   rep(j,26){
     cin>>s[i][j];
     ll casej=s[i][j];
     rep(k,26){
       if(j!=k){
         casej-=c[k]*(i-last[k]);
       }
     }

     if(casej>maxs){
       maxs=casej;
       jm=j;
     }
   }

   if(maxs<maxloss){
     maxloss=maxs;
     iml=i;
   }
   
   last[jm]=i;
   t[i]=jm;
  }

int cicle=0;
int Ncicle=10000;
  ll sum;
 while(cicle<Ncicle){
   cicle++;
   t[iml]=rnd()%26;
   //cout<<t[iml]<<":";
   
   maxloss=INF;
   sum=0;

   rep(i,d){//i日目
     ll casei;
     last[t[i]]=i;
     casei= s[i][t[i]];
     rep(j,26){
       casei-=c[j]*(i-last[j]);
     }
     
     sum+= casei;
     
     if(casei<maxloss){
       maxloss=casei;
       iml=i;
     }
  }  

 }
  rep(i,d){
    cout<<t[i]+1<<endl;
  
   }
  //cout<<sum;
  // cout<<endl; 














}


Measured memory_bytes: 3688
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll N,M,Q;


int main() {
	set<ll>A;
	cin >> Q;
	rep(i, Q) {
		ll a, b,c;
		cin >> a ;
		if (a==0) {
			cin >> b;
			A.insert(b);
			cout << A.size() << endl;
		}
		else if(a==1){
			cin >> b;
			if (A.find(b)!=A.end()) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
		else if (a == 2) {
			cin >> b;
			A.erase(b);
		}
		else {
			cin >> b >> c;
			for (set<ll>::iterator j = A.lower_bound(b); j != A.upper_bound(c); ++j) {
				cout << *j << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 12368
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

struct Hen {
	int a;
	int b;
	int color;
	int dist;
};

std::vector<Hen> a;
std::vector<std::vector<Hen> > hen;
int n, q;

std::vector<std::vector<Hen> > child;
std::vector<int> parent;
std::vector<int64_t> dist;
std::vector<int> depth;
std::vector<std::vector<int> > up;
std::vector<std::map<int, std::pair<int, int> > > qpool;
void dfs1(int i, int par, int64_t _dist, int _depth) {
	if (i) {
		int cur = par;
		up[i].push_back(cur);
		for (int pos = 0; pos < up[cur].size(); pos++) up[i].push_back(cur = up[cur][pos]);
	}
	parent[i] = par;
	dist[i] = _dist;
	depth[i] = _depth;
	for (auto j : hen[i]) {
		if (j.b == par) continue;
		child[i].push_back(j);
		dfs1(j.b, i, _dist + j.dist, _depth + 1);
	}
}
int lca(int i, int j) {
	if (i == j) return i;
	if (depth[i] > depth[j]) std::swap(i, j);
	if (!i) return 0;
	int change = depth[j] - depth[i];
	int beki = 0;
	while (change) {
		if (change & 1 << beki) {
			assert((int) up[j].size() > beki);
			j = up[j][beki];
			change -= 1 << beki;
		}
		beki++;
	}
	assert(up[i].size() == up[j].size());
	assert(depth[i] == depth[j]);
	if (i == j) return i;
	beki = 20;
	while (beki) {
		assert(up[i].size() == up[j].size());
		beki--;
		if (beki >= (int) up[i].size()) continue;
		if (up[i][beki] == up[j][beki]) continue;
		i = up[i][beki];
		j = up[j][beki];
	}
	assert(i != j);
	assert(parent[i] == parent[j]);
	return parent[i];
}
void dfs2(int i, std::vector<std::pair<int, int> > &cur) {
	// qpool[i]
	for (auto &j : qpool[i]) j.second = cur[j.first];
	for (auto &j : child[i]) {
		cur[j.color].second += j.dist;
		cur[j.color].first++;
		dfs2(j.b, cur);
		cur[j.color].first--;
		cur[j.color].second -= j.dist;
	}
}


int main() {
	n = ri(), q = ri();
	a.resize(n - 1);
	hen.resize(n);
	for (int i = 0; i + 1 < n; i++) {
		int aa = ri() - 1;
		int b = ri() - 1;
		int c = ri() - 1;
		int d = ri();
		a[i] = {aa, b, c, d};
		hen[aa].push_back(a[i]);
		hen[b].push_back({b, aa, c, d});
	}
	parent.resize(n);
	child.resize(n);
	dist.resize(n);
	depth.resize(n);
	up.resize(n);
	dfs1(0, -1, 0, 0);
	std::cerr << "dfs1 finished" << std::endl;
	qpool.resize(n);
	std::vector<int> c(q), l(q), lc(q);
	std::vector<std::pair<int, int> > v(q);
	for (int i = 0; i < q; i++) {
		c[i] = ri() - 1, l[i] = ri();
		v[i] = {ri() - 1, ri() - 1};
		lc[i] = lca(v[i].first, v[i].second);
		qpool[v[i].first][c[i]] = {0, 0};
		qpool[v[i].second][c[i]] = {0, 0};
		qpool[lc[i]][c[i]] = {0, 0};
	}
	std::vector<std::pair<int, int> > cur(n);
	dfs2(0, cur);
	for (int i = 0; i < q; i++) {
		int res = dist[v[i].first] + dist[v[i].second] - 2 * dist[lc[i]];
		res += qpool[v[i].first][c[i]].first * l[i] - qpool[v[i].first][c[i]].second;
		res += qpool[v[i].second][c[i]].first * l[i] - qpool[v[i].second][c[i]].second;
		res -= 2 * (qpool[lc[i]][c[i]].first * l[i] - qpool[lc[i]][c[i]].second);
		std::cout << res << std::endl;
	}
	
	return 0;
}


Measured memory_bytes: 52736
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll N, A[5], Min = (ll)1e15;

	cin >> N;
	rep(i, 5) {
		cin >> A[i];
		Min = min(A[i], Min);
	}

	cout << 5 + (N - 1) / Min << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
  int r,c,sum;
  int a[101][101]={0};

  cin >> r >> c;
  for (int i=0;i<r;i++){
    for (int j=0;j<c;j++){
      cin >> a[i][j];
      cout << a[i][j] << " ";
      a[i][c]+=a[i][j];
      a[r][j]+=a[i][j];
    }
    cout << a[i][c] << endl;
  }
  for (int i=0;i<c;i++){
    cout << a[r][i] << " ";
    sum += a[r][i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 3116
x, n = map(int, input().split())
list_P = list(map(int, input().split()))
list_P = set(list_P)
ans = pow(10, 10)

for i in range(-110, 111):
    if abs(i-x) < abs(x-ans):
        if i not in list_P:
            ans = i

print(ans)

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

using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;
  ll a=0, b=0;
  ll a_m=S.size()/2;
  ll b_m=S.size()/2;
  if(S.size()%2==1)
    a_m++;
  for (int i = 0; i < S.size(); ++i) {
    if(S[i]=='1') {
      if (i % 2 == 0) {
        a++;
      }else{
        b++;
      }
    }
  }
  ll c = a_m-a + b;
  ll d = a + b_m-b;
  cout << min(c, d) << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void)
{
	int K;

	cin >> K;

	if (K % 2 == 0)
	{
		int num = K / 2;
		cout << num * num;
	}

	else
	{
		int num = K / 2;
		cout << num * (num + 1);
	}


	return 0;
}

Measured memory_bytes: 256