akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b; cin >> b >> a;
	int h = 100, w = 100;
	vector<string> v(h, string(w, '.'));
	rep(i, h / 2) v[i] = string(w, '#');
	
	a--; b--;
	for(int i = h - 1; a; i-= 2) for(int j = 0; a && j < w; j += 2){
		v[i][j] = '#';
		a--;
	}
	for(int i = 0; b; i += 2) for(int j = 0; b && j < w; j += 2){
		v[i][j] = '.';
		b--;
	}
	cout << h << "  " << w << endl;
	rep(i, h) cout << v[i] << endl;
	
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

Graph E;
vector<bool> seen;  // 訪問済みの点
map<pair<int,int>,int> I;

// BFSのための再帰関数
void bfs(const Graph &G, int v, int color, int k) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        I[make_pair(v, next_v)] = color;
        I[make_pair(next_v, v)] = color;
        color = (color + 1) % k;
        bfs(G, next_v, color, k);
    }
}

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

    // グラフ
    Graph G(N);

    vector<int> A(N-1);
    vector<int> B(N-1);

    seen.assign(N, false);

    vector<pair<int,int>> vp;

    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
        A[i] = a-1;
        B[i] = b-1;
        vp.emplace_back(a-1,b-1);
    }
    int K = 0;
    int index = 0;

    // 次数が最も高い頂点を探索
    REP(i, N){
        int size;
        size = G[i].size();
        if(size >= K){
            K = size;
            index = i;
        }
    }

    bfs(G, index, 0, K);

    cout << K << endl;
    for(auto p:vp) cout << I[p]+1 << endl;
    return 0;
}

Measured memory_bytes: 20856
#include<stdio.h>
#define MAX 200000
#define INFTY  2000000000

typedef long long llong;

int L[MAX/2+2], R[MAX/2+2];

llong merge(int A[], int left, int mid, int right){
  int i, j, k, n1, n2;
  llong cnt = 0;

  n1 = mid - left;
  n2 = right - mid;
  for( i = 0 ; i < n1 ; i++ ){
    L[i] = A[left+i];
  }
  for( i = 0 ; i < n2 ; i++ ){
    R[i] = A[mid+i];
  }
  L[n1] = R[n2] = INFTY;
  i = j = 0;
  for( k = left ; k < right ; k++ ){
    if( L[i] <= R[j] ){
      A[k] = L[i++];
    }
    else {
      A[k] = R[j++];
      cnt += n1 - i;
    }
  }
  return cnt;
}

llong mergeSort(int A[], int left, int right){
  int mid;
  llong v1, v2, v3;
  
  if( left + 1 < right ){
    mid = ( left + right ) / 2;
    v1 = mergeSort(A, left, mid);
    v2 = mergeSort(A, mid, right);
    v3 = merge(A, left, mid, right);
    return v1+v2+v3;
  }
  else return 0;
}

int main(){
  int A[MAX], n, i;

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

  llong ans = mergeSort(A, 0, n);
  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 3416
/*
Owner: dxxrk
Problem: Range Product
Date: 21/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	long long a, b; cin >> a >> b;
	
	if(a <= 0 && b >= 0){
		cout << "Zero";
	}
	else if(a > 0 && b > 0){
		cout << "Positive";
	}
	else {
		if(abs(a - b) % 2 == 0){
			cout << "Negative";
		}
		else {
			cout << "Positive";
		}
	}

	return 0;
}


Measured memory_bytes: 256
unittest
{

	assert( [ "6", "1 2 3 2 2 1" ].parse.expand.solve == 2 );
	assert( [ "9", "1 2 1 2 1 2 1 2 1" ].parse.expand.solve == 5 );
	assert( [ "7", "1 2 3 2 1 999999999 1000000000" ].parse.expand.solve == 3 );
	
	assert( [ "7", "1 2 2 3 3 2 1" ].parse.expand.solve == 2 );		// 追加ケース
	assert( [ "1", "100" ].parse.expand.solve == 1 );				// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 1L;
	auto d = 0L;
	for( auto i = 0L; i + 1 < as.length; i++ )
	{
		if( d == 0 )
		{
			if(      as[ i ]     <  as[ i + 1 ] ) d = 1;
			else if( as[ i + 1 ] <  as[ i ]     ) d = -1;
			continue;
		}
		if( 0 < d && as[ i ]     <= as[ i + 1 ] ) continue;
		if( d < 0 && as[ i + 1 ] <= as[ i ]     ) continue;
		d = 0;
		ans++;
	}
	return ans;
}


Measured memory_bytes: 6964
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 400003  //N idhar hai
#define inf 1e10
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a*b)/gcd(a,b))
#define bitcount( x ) __builtin_popcountll( x )
#define br "\n"
#define sp " "
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
void call(){dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1));}
ll n,m,k,h;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION(10) ;
    ll a,b,c,d,i,j,t,x,y,z;//,x1,y1,z1,e,f;
    db p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU  +  Graph Theory + Math + DP + Bitmasks + Geometry + Brute Force + Greedy + Implementation + Binary Search
    cin>>a>>b;
    for(i=1 ; i<=N ; i++)
    {
        c = (8*i)/100;
        d = (i)/10;
        if(c==a && d==b)
        {
            cout<<i;
            exit(0);
        }
    }
    cout<<"-1";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)




int main() {
	int n;
	cin >> n;
	vector<int> ps(n + 1,0);

	for(int i = 1; i <= n; i++) {

		for(int j = i; j <= n; j+= i) {
			ps[j] ++;
		}
	}	
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += ps[i] * i;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 41868
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn is_prime(n: usize) -> bool {
    if n == 1 {
        return false;
    }
    if n == 2 {
        return true;
    }
    for i in (2..).take_while(|i| i * i <= n) {
        if n % i == 0 {
            return false;
        }
    }
    true
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let X: usize = sc.get();
    for i in X..X+10000 {
        if is_prime(i) {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
#include<stack>
#include<ctime>
#include<set>
using namespace std ;

long long a , b ;
vector < long long > v ;
vector < long long > w ;

void input ( ) {
    cin >> a >> b ;
}

void solve ( ) {
    for ( long long i = 2 ; i * i <= a ; ++ i ) {
        if ( ( a % i ) == 0 ) {
            v.push_back ( i ) ;
            while ( ( a % i ) == 0 ) { a /= i ; }
        }
    }
    if ( a > 1 ) { v.push_back ( a ) ; }

    for ( long long i = 2 ; i * i <= b ; ++ i ) {
        if ( ( b % i ) == 0 ) {
            w.push_back ( i ) ;
            while ( ( b % i ) == 0 ) { b /= i ; }
        }
    }
    if ( b > 1 ) { w.push_back ( b ) ; }

    int p = v.size ( ) ;
    int q = w.size ( ) ;
    int ans = 1 ;
    for ( int i = 0 ; i < p ; ++ i ) {
        for ( int j = 0 ; j < q ; ++ j ) {
            if ( v[ i ] == w[ j ] ) { ++ ans ; }
        }
    }
    cout << ans << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


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

int main()
{
    int fx;
    long n, ncopy;
    bool flag = false;
    cin >> n;
    ncopy = n;
    
    // 各桁を足していくプログラム
    while(ncopy){
        fx += ncopy % 10;
        ncopy /= 10;
    }
    if (n % fx == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
import time
# stdin = open("sample.txt")


MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    D,T,S = [int(x) for x in stdin.readline().rstrip().split()]
    if T*S >= D:
        print("Yes")
    else:
        print("No")
main()

Measured memory_bytes: 27248
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		int[][] x = new int[n][d];
		for(int i = 0;i < n; i++) {
			for(int j = 0; j <d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k < 200; k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
n = int(input())
l = [int(x) for x in input().split()]
c = 0
for i in range(n):
    for j in range(i+1,n):
        if l[i] == l[j]:
            continue
        for k in range(j+1,n):
            if l[i] == l[k] or l[j] == l[k]:
                continue
            if l[i]+l[j] > l[k] and l[i]+l[k] > l[j] and l[j]+l[k] > l[i]:
                c += 1
print(c)

Measured memory_bytes: 9136
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int x1,x2,x3,x4,y1,y2,y3,y4;
	cin>>x1>>y1>>x2>>y2;
	int lx,ly;
	lx=x2-x1;
	ly=y2-y1;
	x4=x1-ly;
	y4=y1+lx;
	x3=x2-ly;
	y3=y2+lx;
	cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>

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

using namespace std;
using ll = long long int;

int main(void) {
    int n; cin >> n;
    vector<int> h(n);
    REP(i, n) cin >> h[n - 1 - i];
    for (int i = 1; i < n; i++) {
        if (h[i] > h[i - 1]) h[i]--;
    }
    bool t = true;
    for (int i = 1; i < n; i++) {
        if (h[i] > h[i - 1]) t = false;
    }
    t ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 640
import java.util.*;

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

    String[] strArray = sc.next().split("");

    Arrays.sort(strArray,new Comparator<String>() {
      @Override
      public int compare(String obj0, String obj1) {
        return obj0.compareTo(obj1);
      }
    });

    if (strArray[0].equals(strArray[1]) && !(strArray[1].equals(strArray[2])) && strArray[2].equals(strArray[3])) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23764
s = str(input())
p = str(input())
 
ans = False
 
for i in range(len(s)):
    a = True
    for k in range(len(p)):
        if s[(i+k)%(len(s))] != p[k]:
            a = False
            break
 
    if a == True:
        ans = True
        break
 
if ans == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5564
s = input()
i = 0
key = "keyence"
while i < 7:
    if s[i] == key[i]:
        i += 1
    else:
        break
    if i == 7:
        print("YES")
        exit()

if s[:i] + s[-7+i:] == key:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    h, w = map(int, input().split())
    c = [[int(i) for i in input().split()] for _ in range(10)]
    a = [[int(i) for i in input().split()] for _ in range(h)]

    # Warshall-Floyd
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if c[i][j] > c[i][k] + c[k][j]:
                    c[i][j] = c[i][k] + c[k][j]

    ans = 0
    for i in a:
        for j in i:
            if j == -1:
                continue
            else:
                ans += c[j][1]

    print(ans)

main()

Measured memory_bytes: 73780
#include <bits/stdc++.h>
 
using namespace std ;
 
const int MAX = 5010 ;
 
int dp[MAX][MAX] ;
int arr[MAX] ;
int n , k;
int idx2 ;

bool check(int mid)
{
	if(arr[mid] >= k)
		return 0 ;
	memset(dp , -1 , sizeof(dp)) ;
	bitset<MAX>bit[1] ;
	bit[0][0] = 1 ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i == mid || arr[i] >= k)
			continue ;
		bit[0] |= (bit[0] << arr[i]) ;
	}
	for(int i = k-arr[mid] ; i < k ; ++i)
		if(bit[0][i])
			return 0 ;
	return 1 ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>k ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	sort(arr , arr + n) ;
	int l = 0 , r = n-1 , ans = -1;
	while(l <= r)
	{
		int mid = (l + r) >> 1 ;
		if(check(mid))
			ans = mid , l = mid+1 ;
		else
			r = mid-1 ;
	}
	return cout<<ans+1<<"\n" , 0 ;
}

Measured memory_bytes: 98432
n = int(input())
x = list(map(int, input().split()))
sum_energy_list = []

for p in range(1, 100):
    sum_energy = 0
    for i in range(len(x)):
        sum_energy += (x[i] - p) ** 2
    sum_energy_list.append(sum_energy)

answer = min(sum_energy_list)

print(answer)


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

const int MAXN = 200005;

int n, u, v;

struct node {
	int to, next;
} edge[MAXN];
int head[MAXN], top = 0;
inline void push(int i, int j)
{ edge[++top] = (node) {j, head[i]}, head[i] = top; }

long long ans = 0;

struct point {
	int one, zero, pos;
	point()
	{}
	point(int c, int p)
	{ pos = p, one = (c == 1), zero = (c == 0); }
	inline void join(const point &pt)
	{
		ans += 1ll*one*pt.zero;
	        one += pt.one, zero += pt.zero;
	}
	friend bool operator < (const point &a, const point &b)
	{ return 1ll*b.one*a.zero == 1ll*a.one*b.zero ? a.pos > b.pos : 1ll*b.one*a.zero < 1ll*a.one*b.zero; }
	friend bool operator == (const point &a, const point &b)
	{ return a.one == b.one && a.zero == b.zero && a.pos == b.pos; }
} pt[MAXN];

priority_queue<point> st;
priority_queue<point> del;

int fa[MAXN];
inline int findf(int nd)
{ return fa[nd]?fa[nd]=findf(fa[nd]):nd; } 

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	static int p[MAXN];
	for (int i = 2; i <= n; i++) {
		cin >> p[i];
		push(p[i], i);
	}
	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		st.push(pt[i] = (point){a, i});
	}
	while (1) {
		while (!st.empty() && !del.empty() && st.top() == del.top()) 
			st.pop(), del.pop();
		if (st.empty()) break;
		int cur = findf(st.top().pos);
		del.push(st.top());
		if (cur == 1) continue;
		else {
			int par = findf(p[cur]);
			if (par != 1)
				del.push(pt[par]);
		        fa[cur] = par, pt[par].join(pt[cur]);
			st.push(pt[par]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 14960
#include<iostream>

using namespace std;

int a[100][100] = {};
int b[100] = {};
int ans[100] = {};

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int k = 0; k < m; k++)
	{
		cin >> b[k];
	}
	//
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			ans[i] = ans[i] + a[i][j] * b[j];
		}
	}
	//
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  ll k; cin >> k;
  ll ans = 0;
  int sz = s.size();
  char now = s[0];
  int cnt = 1;
  bool same = true;
  ll beg = 0, ed = 0;
  bool init = true;
  for(int i=1;i<sz;++i) {
    if(now == s[i]) {
      cnt++;
    } else {
      if(!init) ans += cnt/2;
      if(init) {
        beg = cnt;
        init = false;
      }
      cnt = 1;
      now = s[i];
      same = false;
    }
  }
  ed = cnt;
  if(same) {
    cout << sz * k / 2 << endl;
    return 0;
  }
  ans *= k;
  if(s[0] == s[sz-1]) {
    ans += (beg + ed) / 2 * (k-1);
    ans += beg / 2 + ed / 2;
  } else {
    ans += beg / 2 * k + ed / 2 * k;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int n,a[100002],b[100002],ans;
map<int,int>m;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
		m[b[i]]=i;
	for(int i=1;i<=n;i++)
		if(m[a[i]]%2!=i%2)ans++;
	printf("%d",ans/2);
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

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

    vector<int> h(n);
    rep(i, n) cin >> h[i];
    h.insert(h.begin(), 0);

    vector<vector<ll>> dp(305, vector<ll>(305, 0));
    rep(i, n + 1)rep(j, m + 1)dp[i][j] = INF;
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        rep(j, m) {
            ll now = INF;
            rep(ki, i) {
                cmin(now, dp[ki][j] + max(0, h[i] - h[ki]));
            }
            dp[i][j + 1] = now;
        }
    }

    ll ans = INF;
    rep(i, n + 1)cmin(ans, dp[i][m]);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int maxn = 5e3 + 1;
const ll inf = 1e18;
bool vis[maxn];
 
void solve() {
 
   ll n, k, ans = -inf;
   cin >> n >> k;
   vector <ll> a(n + 1), c(n + 1);
   for (int i = 1; i <= n; i++)
      cin >> a[i];
   for (int i = 1; i <= n; i++)
      cin >> c[i];
 
   for (int i = 1; i <= n; i++) {
      memset(vis, false, sizeof(vis));
      vector <ll> p;
      p.push_back(0ll);
      int x = i;
      while (!vis[x]) {
         vis[x] = true;
         p.push_back(c[x]);
         x = a[x];
      }
      ll m = p.size() - 1;
      for (int i = 1; i <= m; i++) {
         p[i] += p[i - 1];
      }
      for (int i = 1; i <= m; i++) {
         ll rem = k - i;
         if (rem < 0)
            break;
         ans = max({ans, p[i] + p[m] * (rem / m), p[i]});
      }
   }
   cout << ans << '\n';
 
}
 
int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
 
   solve();
 
   return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }






void solve() {
    ll n;
    string s;
    cin>>n>>s;
    ll a[4010]={},b[4010]={},c[4010]={};
    repr(i,n){
        a[i]=a[i+1];
        b[i]=b[i+1];
        c[i]=c[i+1];
        if(s[i]=='R') a[i]++;
        else if(s[i]=='G') b[i]++;
        else c[i]++;
    }

    ll ans = 0;

    rep(i,n){
        rep2(j,i+1,n){
            ll x = 0;
            if(s[i]==s[j]) continue;
            if(s[i]=='R'||s[j]=='R') x+=1;
            if(s[i]=='G'||s[j]=='G') x+=2;
            if(s[i]=='B'||s[j]=='B') x+=4;
            char now;
            ll cnt=0;
            if(x==6) now='R',cnt=a[j+1];
            else if(x==3) now='B',cnt=c[j+1];
            else now='G',cnt=b[j+1];

            if(j + (j-i) < n){
                if(s[j+(j-i)] == now){
                    cnt--;
                }
            }
            ans += cnt;
        }
    }
    cout<<ans<<endl;

}


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


    ll t=1;
    
    // cin>>t;

    rep(i,t){
        solve(); 
    }

    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<vector<int>,int>P;
vector<int>v[13],s(13),t(13);
map<vector<int>,int>m;
 
int has[14];
 
 
void init(){
 
    v[0].push_back(2);
 
    v[1].push_back(2);
    v[1].push_back(5);
 
    v[2].push_back(0);
    v[2].push_back(1);
    v[2].push_back(3);
    v[2].push_back(6);
 
    v[3].push_back(2);
    v[3].push_back(7);
 
    v[4].push_back(5);
 
    v[5].push_back(1);
    v[5].push_back(4);
    v[5].push_back(6);
    v[5].push_back(9);
 
    v[6].push_back(2);
    v[6].push_back(5);
    v[6].push_back(7);
    v[6].push_back(10);
 
    v[7].push_back(3);
    v[7].push_back(6);
    v[7].push_back(8);
    v[7].push_back(11);
 
    v[8].push_back(7);
 
    v[9].push_back(5);
    v[9].push_back(10);
 
    v[10].push_back(6);
    v[10].push_back(9);
    v[10].push_back(11);
    v[10].push_back(12);
 
    v[11].push_back(7);
    v[11].push_back(10);
 
    v[12].push_back(10);
 
    int a=20;
    int p=1;
 
    r(i,13){
        has[i]=p;
        p*=a;
    }
}
 
int ha(vector<int> &x){
 
    int re=0;
 
    r(i,13){
        re+=x[i]*has[i];
    }
 
    return re;
}
 
vector<int> ah(int x){
    vector<int>y(13);
    r(i,13){
        y[i]=x%20;
        x/=20;
    }
    return y;
}
 
void BFS1(){
    s[0]=0;
    s[12]=0;
    r(i,11)s[i+1]=i+1;
    set<vector<int> >st;
    st.insert(s);
    m[s]=0;
    queue<P>q;
    q.push(P(s,0));
    while(1){
        vector<int> now=q.front().first;
        int cost=q.front().second;
        q.pop();
        if(cost==12)break;
        //cout<<m.size()<<' '<<cost<<endl;
        r(i,13)if(now[i]==0){
            r(j,v[i].size()){
                swap(now[i],now[v[i][j]]);
                if(!st.count(now)){
                    st.insert(now);
                    m[now]=cost+1;
                    q.push(P(now,cost+1));
                }
                swap(now[i],now[v[i][j]]);
            }
        }
    }
}
 
void BFS2(){
    set<vector<int> >st;
    st.insert(t);
    queue<P>q;
    q.push(P(t,0));
    while(1){
        vector<int>now=q.front().first;
        int cost=q.front().second;
        q.pop();
        if(m.count(now)){
            cout<<m[now]+cost<<endl;
            return ;
        }
        if(cost==8)break;
        r(i,13)if(now[i]==0){
            r(j,v[i].size()){
                swap(now[i],now[v[i][j]]);
                if(!st.count(now)){
                    st.insert(now);
                    if(m.count(now)){
                        cout<<m[now]+cost+1<<endl;
                        return ;
                    }
                    q.push(P(now,cost+1));
                }
                swap(now[i],now[v[i][j]]);
            }
        }
    }
    cout<<"NA"<<endl;
}
 
 
signed main(){
    init();
    BFS1();
    while(cin>>t[0],t[0]!=-1){
        r(i,12)cin>>t[i+1];
        BFS2();
    }
}


Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
void pn(){
    puts("No");
}
void py(){
    puts("Yes");
}
const int M=1e3+3;
char s[M];
int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    if(n&1){
        int l=1,r=n;
        while(l<r&&s[l]==s[r])
            l++,r--;
        if(l<r)
            return pn(),0;
        l=1,r=(n-1)/2;
        while(l<r&&s[l]==s[r])
            l++,r--;
        if(l<r)
            return pn(),0;
        l=(n+3)/2,r=n;
        while(l<r&&s[l]==s[r])
            l++,r--;
        if(l<r)
            return pn(),0;
        py();
    }
    else{
         //   cout<<"!!"<<endl;
         pn();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

#define eps 1e-9
#define all(a)   a.begin(),a.end()
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define sz size()
#define sl(inp) scanf("%lld",&inp)
#define sd(inp) scanf("%d",&inp)

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int inf = 1e9;

ll fpow(ll base,ll power){
  ll result = 1;
  while (power > 0){
    if (power%2 == 1) result=(result*base);
  	base = (base*base);
  	power /= 2;
  }
	return result;
}

const ll maxn = 123456;

ll a[maxn];

int main(){
    ll n, l;
    scanf("%lld %lld", &n, &l);
    ll i;
    for ( i = 1 ; i <= n ; i ++ ){
    	scanf("%lld", &a[i]);
    }
    ll id = 0;
    bool flag = false;
    for ( i = 1 ; i < n ; i ++ ){
    	if ( a[i] + a[i+1] >= l ){
    		flag = true;
    		id = i;
    	}
    }
    if ( flag ){
    	printf("Possible\n");
    }
    else{
    	printf("Impossible\n");
    	return 0;
    }
    for ( i = 1 ; i <= id - 1 ; i ++ ){
    	printf("%lld\n", i);
    }
    for ( i = n - 1 ; i >= id + 1 ; i -- ){
    	printf("%lld\n", i);
    }
    printf("%lld\n", id);
    return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long LL;

int main()
{
	char a[5], b[5], c[5];
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);
	printf("%c%c%c\n",a[0],b[1],c[2]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 3000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000
const int MAX = 1000000;
const int MOD = 1000000007;
int dpf[N+1][N+1];
int dpb[N+1][N+1];
int main(){
	int n,t;
    cin>>n>>t;
    vector<int> a(n),b(n);
    REP(i,n){
        cin>>a[i]>>b[i];
    }
    REP(i,n){
        REP(j,t){
            if(j-a[i]<0) dpf[i+1][j]=dpf[i][j];
            else dpf[i+1][j]=max(dpf[i][j],dpf[i][j-a[i]]+b[i]);
        }
    }
    for(int i=n-1;i>=0;i--){
        REP(j,t){
            if(j-a[i]<0) dpb[i][j]=dpb[i+1][j]; 
            else dpb[i][j]=max(dpb[i+1][j],dpb[i+1][j-a[i]]+b[i]);
        }
    }
    int ans=0;
    REP(i,n){
        REP(j,t){
            int tmp=b[i]+dpf[i][j]+dpb[i+1][t-1-j];
            ans=max(ans,tmp);
        }
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 70656
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int x; cin >> x;
    cout << 10 - x / 200 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3652
local n = io.read()
local w = {}
local flag = true
for i=1,n do
	w[i] = io.read()
end

for i = 1, n-1 do
	if string.sub(w[i],-1,-1) ~= string.sub(w[i+1],1,1) then
	flag = false
	end
end

for i = 1,n-1 do
	for j=i+1,n do
		if w[i] == w[j] then
		    flag = false
		end
	end
end

if flag then
	print("Yes")
else
	print("No")
end

Measured memory_bytes: 760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main() {
	int n, max=0; cin >> n;
	vector<string>s(n);
	set<string>v;
	map<string, int>Map;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		Map[s[i]] += 1;
	}
	for (int i = 0; i < n; i++) {
		if (max < Map[s[i]])max = Map[s[i]];
	}
	for (int i = 0; i < n; i++) {
		if (max == Map[s[i]])v.insert(s[i]);
	}
	for (auto e : v) {
		cout << e << endl;
	}
}

Measured memory_bytes: 36096
#!/usr/bin/env ruby

require 'set'

class Dice
	attr_reader :top, :s, :e

    def initialize(top, s, e, w, n, bottom)
        @top    = top
        @s      = s
        @e      = e
        @w      = w
        @n      = n
        @bottom = bottom
	end

	def rotate!(dist)
		@top, @s, @e, @w, @n, @bottom = 
		case dist
		when 'N' then [@s, @bottom, @e, @w, @top, @n]
		when 'S' then [@n, @top, @e, @w, @bottom, @s]
		when 'E' then [@w, @s, @top, @bottom, @n, @e]
		when 'W' then [@e, @s, @bottom, @top, @n, @w]
		end
	end
end

if __FILE__ == $0 then
	srand(0)

	n = gets.chomp.to_i
	dice = ([0]*n).map { |x| Dice.new(*gets.split.map(&:to_i))}
	ref  = [*1..n].map { |x| Set.new()}

	1000.times do
		if ref[0].size > 23 then
			break
		end

		dist = 'NEWS'[rand(4)]
		n.times do |i|
			ref[i].add([dice[i].top, dice[i].s, dice[i].e])
			dice[i].rotate!(dist)
		end
	end

	puts ref.to_set.size == n ? 'Yes' : 'No'
end



Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    if (n & (n - 1)) {
        puts("Yes");
        printf("%d %d\n", 1, 2);
        printf("%d %d\n", 2, 3);
        printf("%d %d\n", 3, n + 1);
        printf("%d %d\n", n + 1, n + 2);
        printf("%d %d\n", n + 2, n + 3);
        for (int i = 4; i < n; i += 2) {
            printf("%d %d\n", 1, i);
            printf("%d %d\n", i, n + i + 1);
            printf("%d %d\n", 1, i + 1);
            printf("%d %d\n", i + 1, n + i);
        }
        if (n % 2 == 0) {
            for (int i = 2; i < n; i++) {
                int j = n ^ i ^ 1;
                if (j >= 2 && j < n) {
                    return printf("%d %d\n%d %d\n", i, n, j, n + n), 0;
                }
            }
        }
    }
    else puts("No");
}

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


int main()
{
	int a, b, c,differC = 0;
	cin >> a >> b >> c;
	if (a != b)differC++;
	if (b != c)differC++;
	if (c != a)differC++;
	if (differC == 0)differC++;
	cout << differC << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,0,0},dy[]={1,0,-1,0,0,0};
int dz[]={0,0,0,0,1,-1};

int n;
double sx[30],sy[30],sz[30];

double dist(double x,double y,double z,int id){
  double tx=x-sx[id];
  double ty=y-sy[id];
  double tz=z-sz[id];
  return sqrt(tx*tx+ty*ty+tz*tz);
}

double rad(double x,double y,double z){
  double ret=dist(x,y,z,n-1);
  rep(i,n-1)ret=max(ret,dist(x,y,z,i));
  return ret;
}

typedef struct _node{
  double x,y,z,r;
  int wh;
  _node(double x,double y,double z,int wh):
    x(x),y(y),z(z),wh(wh),r(rad(x,y,z)){};

  bool operator<(const _node& rn)const{
    if(rn.wh!=wh)return rn.wh<wh;
    return rn.r<r;
  }
}node;

int tx[]={1,1,1,1,-1,-1,-1,-1};
int ty[]={1,1,-1,-1,1,1,-1,-1};
int tz[]={1,-1,1,-1,1,-1,1,-1};
double len[1000];

void solve(){
  rep(i,n)scanf("%lf%lf%lf",sx+i,sy+i,sz+i);
  len[0]=100;
  for(int i=1;i<1000;++i)
    len[i]=len[i-1]/2;
  double ans=10000;
  rep(i,n)rep(j,i)
    ans=min(ans,rad((sx[i]+sx[j])/2,
                    (sy[i]+sy[j])/2,
                    (sz[i]+sz[j])/2));

  priority_queue<node> q;
  q.push(node(50,50,50,0));
  int cu=0;
  int bwh=-1;
  while(!q.empty()){
    node cur=q.top();
    q.pop();
    if(cu==500 && cur.wh==bwh)continue;
    if(cu==500)cu=0,bwh=cur.wh;
    ++cu;
    double rr=len[cur.wh];    
    if(ans<cur.r-rr*sqrt(3)*2+EPS)continue;
    ans=min(ans,cur.r);
    if(cur.wh>25)continue;
    //printf("%.5f %.5f %.5f %.5f %.7f %d\n",cur.x,cur.y,cur.z,cur.r,ans,cur.wh);

    rep(i,8)
      q.push(node(cur.x+rr*tx[i],cur.y+rr*ty[i],cur.z+rr*tz[i],cur.wh+1));
  }

  printf("%.5f\n",ans);
}

main(){
  while(cin>>n,n)
    solve();
}

Measured memory_bytes: 0
float c[8];j;
f(i){
	return c[i+1]*(c[(i+2)%6]-c[6])+c[(i+3)%6]*(c[6]-c[i])+c[7]*(c[i]-c[(i+2)%6]);
}
main(){for(;~scanf("%f",c+j++);j%8||puts(f(j=0)*f(2)>0&&f(2)*f(4)>0?"YES":"NO"));
	return 0;
}

Measured memory_bytes: 0
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <sstream>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;



namespace stdint_literal {
	constexpr uint64_t operator""_ui64(unsigned long long x)noexcept {
		return uint64_t(x);
	}
	constexpr int64_t operator""_i64(unsigned long long x)noexcept {
		return int64_t(x);
	}
	constexpr uint32_t operator""_ui32(unsigned long long x)noexcept {
		return uint32_t(x);
	}
	constexpr int32_t operator""_i32(unsigned long long x)noexcept {
		return int32_t(x);
	}
}
using namespace stdint_literal;

int64_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	if (N == 0) {
		out << 0 << endl;
		return 0;
	}

	if (N > 0) {
		int64_t add = 0b01010101'01010101'01010101'01010101_i64;
		std::stringstream ss;
		ss << std::bitset<32>(add ^ (add - N));
		out << ss.str().substr(ss.str().find('1')) << endl;
	}
	else {
		int64_t add = 0b1010101'01010101'01010101'010101010_i64;
		std::stringstream ss;
		ss << std::bitset<32>(add ^ (add - -N));
		out << ss.str().substr(ss.str().find('1')) << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;

signed main() 
{
	string n;
	cin >> n;
	for (int i = 1; i < 4; i++)
		if (n[i] == n[i - 1])
			{cout << "Bad"; return 0;}
	cout << "Good";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;
string s;

int main() {
  cin >> s;
  N = s.size();
  int a = 0;
  int b = 0;
  a = count(all(s), '0');
  b = count(all(s), '1');

  cout << min(a , b) * 2 << endl;
}


Measured memory_bytes: 512
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

TYPES = 26
history = [-1] * TYPES
satisfaction_level = [0] * (d+1)

def last(day, i):
    if history[i] == -1:
        return 0
    else:
        return history[i]

def satisfaction(day, typ):
    # コンテスト実施記録を更新
    history[typ] = day
    # 満足度の減少
    decrease = sum((c[i]*(day-last(day,i)) for i in range(TYPES)))
    value = s[day-1][typ] - decrease + satisfaction_level[day-1]
    satisfaction_level[day] = value
    return value

for day, typ in enumerate(t):
    print(satisfaction(day+1, typ-1))

Measured memory_bytes: 9528