akhauriyash/Code-Regression huggingface dataset:
use std::collections::VecDeque;

struct Bridge {
    a: usize,
    b: usize,
}

#[derive(Clone)]
struct UnionFindValue {
    root: i64,
    size: usize,
}

struct UnionFind {
    tree: Vec<UnionFindValue>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind{tree: vec![UnionFindValue{root: -1, size: 1}; n]}
    }

    fn root(&self, n: usize) -> usize {
        if self.tree[n].root < 0 {
            n as usize
        }
        else {
            self.root(self.tree[n].root as usize)
        }
    }

    fn connect(&mut self, n: usize, m: usize) -> u64 {
        let (root, leaf) = if self.size(n) > self.size(m) {
            (self.root(n), self.root(m))
        }
        else {
            (self.root(m), self.root(n))
        };

        let size = self.size(root) + self.size(leaf);
        self.tree[leaf].root = root as i64;
        self.tree[root].size = size as usize;
        size
    }

    fn size(&self, n: usize) -> u64 {
        self.tree[self.root(n)].size as u64
    }
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    let mut bridges = VecDeque::new();
    for _ in 0..m {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let ai: usize = iter.next().unwrap().parse().unwrap();
        let bi: usize = iter.next().unwrap().parse().unwrap();
        bridges.push_back(Bridge{a: ai, b: bi});
    }

    let mut unreachability = (n * (n-1) / 2) as u64;
    let mut unreachabilities = Vec::new();
    let mut reachability: u64 = 0;
    let mut uf = UnionFind::new(n);
    for bridge in bridges.iter().rev() {
        unreachability -= reachability;
        unreachabilities.push(unreachability);

        let a = bridge.a - 1;
        let b = bridge.b - 1;
        reachability = if uf.root(a) != uf.root(b) {
            let reachability = uf.size(a) * uf.size(b);
            uf.connect(a, b);
            reachability
        }
        else {
            0
        };
    }

    for unreachability in unreachabilities.iter().rev() {
        println!("{}", unreachability);
    }
}


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

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
typedef pair<LL, int> pli;
LL d[33][33], c[555][555];
// i + j = k の 場合に, 色X から 色Y に 塗り替えた場合の違和感を保存.
// -> k と 色Y に塗り替えた場合の違和感 を 保存.
LL discomfort[1111][33];
// k を 3で割った余りが, 0, 1, 2 の パターン に 集約.
LL dp[3][33]; 

int main() {

    // 1. 入力情報取得.
    int N, C;
    scanf("%d %d", &N, &C);
    for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) scanf("%lld", &d[i][j]);
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) scanf("%lld", &c[i][j]);
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) c[i][j]--;
    
    // 2. 違和感を集計.
    // マス(i, j) (但し, i + j = k とする) を, 色y に塗り替えた場合の違和感を調査.
    for(int k = 0; k < N; k++){
        for(int i = 0; i <= k && i < N; i++){
            int j = k - i;
            for(int y = 0; y < C; y++) discomfort[k][y] += d[c[i][j]][y];
        }
    }
    for(int k = N; k < 2 * N - 1; k++){
        for(int i = k - (N - 1); i < N; i++){
            int j = k - i;
            for(int y = 0; y < C; y++) discomfort[k][y] += d[c[i][j]][y];
        }
    }
    // for(int k = 0; k < 2 * N - 1; k++){
    //     for(int y = 0; y < C; y++) printf("discomfort[%d][%d]=%lld ", k, y, discomfort[k][y]);
    //     printf("\n");
    // }
    
    // 3. 違和感の和を集計(k を 3 で割ったときの余りで分類).
    // 各 k ごとに, 色y に塗り替えた場合の違和感の最小値を選択.
    for(int k = 0; k < 2 * N - 1; k++){
        for(int y = 0; y <= 32; y++){
            int kmod = k % 3;
            if(kmod == 0) dp[kmod][y] += discomfort[k][y];
            if(kmod == 1) dp[kmod][y] += discomfort[k][y];
            if(kmod == 2) dp[kmod][y] += discomfort[k][y];
        }
    }
    // for(int k = 0; k < C; k++){
    //     for(int y = 0; y < C; y++) printf("dp[%d][%d]=%lld ", k, y, dp[k][y]);
    //     printf("\n");
    // }
    
    // 4. 最小値を計算.
    // 以下の条件で, 色を変更したと仮定して, 全探索で確認.
    // kmod == 0: 色 y0
    // kmod == 1: 色 y1
    // kmod == 2: 色 y2
    LL ans = 1e9;
    for(int y0 = 0; y0 < C; y0++){
        for(int y1 = 0; y1 < C; y1++){
            for(int y2 = 0; y2 < C; y2++){
                if(y0 != y1 && y1 != y2 && y2 != y0){
                    ans = min(ans, dp[0][y0] + dp[1][y1] + dp[2][y2]);
                }
            }
        }
    }
    
    // 5. 出力 ～ 後処理.
    printf("%d\n", ans);
    return 0;

}

Measured memory_bytes: 2688
<?php
fscanf(STDIN, "%s", $s);
$s_1 = substr($s, 0, 1);
$s_2 = substr($s, 1, 1);
$s_3 = substr($s, 2, 1);
$s_4 = substr($s, 3, 1);

if ($s_1 === $s_2 && (substr_count($s, $s_1) === 2) && substr_count($s, $s_3) === 2) {
    echo 'Yes';
} elseif ($s_1 === $s_3 && (substr_count($s, $s_1) === 2) && substr_count($s, $s_2) === 2) {
    echo 'Yes';
} elseif ($s_1 === $s_4 && (substr_count($s, $s_1) === 2) && substr_count($s, $s_3) === 2) {
    echo 'Yes';
} elseif ($s_3 === $s_2 && (substr_count($s, $s_3) === 2 && substr_count($s, $s_1) === 2)) {
    echo 'Yes';
} else {
    echo 'No';
}


Measured memory_bytes: 16212
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
    // printElems(&a[0], &a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 1LL<<60;


int cslist[3005][3005];

int main(){
	string s,t;
	cin >> s >> t;
	rep(i,s.size())rep(j,t.size()){
		cslist[i+1][j+1] = max(cslist[i][j+1],cslist[i+1][j]);
		if(s[i] == t[j]) cslist[i+1][j+1] = cslist[i][j]+1;
	}

	stack<char> v;
	int n,m;
	n = s.size();
	m = t.size();
	while(cslist[n][m]!=0){
		if(cslist[n-1][m] == cslist[n][m]) {n--;continue;}
		elif(cslist[n][m-1] == cslist[n][m]){m--;continue;}
		else{
			v.push(s[n-1]);
			n--;m--;
		}
	}

	while(!v.empty()){
		cout << v.top();
		v.pop();
	}
	prints();

	return 0;
}



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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	auto l = load<int>();
	auto xs = vector<int>();
	for (auto i=1; i<=n; ++i)
		xs.push_back(l + i - 1);
	xs.erase(min_element(xs.begin(), xs.end(), [&](int x1, int x2){ return abs(x1) < abs(x2); }));
	cout << accumulate(xs.begin(), xs.end(), 0) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
void R_YESNO(bool p){cout<<(p?"YES":"NO")<<endl;}
void R_YesNo(bool p){cout<<(p?"Yes":"No")<<endl;}
int main() {
    const i64 INF = 1e16;
    int N;
    cin >> N;
    vector<int> A(N);
    for(int &a : A) cin >> a;
    int X = N - 2 * (N / 2) + 1;
    vector2d<i64> dp(X + 1, vector<i64>(N, -INF));
    for(int i = X; i >= 0; i--) {
        dp[X - i][i] = A[i];
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= X; j++) {
            for(int k = 0; k <= j; k++) {
                int l = i + 2 + (j - k);
                if(l >= N) continue;
                dp[k][l] = max(dp[k][l], A[l] + dp[j][i]);
            }
        }
    }
    i64 ans = -INF;
    for(int i = 0; i <= X; i++) {
        ans = max(ans, dp[i][N - 1 - i]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 10296
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin>>n;
  ll a,ans=0;
  for(ll i=0;i<n;i++){
    cin>>a;
    if(a%2==1&&(i+1)%2==1){ans++;}
  }
  cout << ans<<endl;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		
		int ans=0;
		for(int i=0;i<4;i++) {
			ans=(s.charAt(i)=='+')?ans+1:ans-1;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<set>

using namespace std;

typedef long long ll;
 
ll n,w,dp[100100],a,b;

int main() {
	
	scanf("%lld %lld", &n, &w);
	
	for(int i = 0; i < n; i++) {
		
		scanf("%lld %lld", &a, &b);
		
		for(int j = w - a;j >= 0; j--) {
			dp[j + a] = max(dp[j + a],dp[j] + b);
		}
	}
	printf("%lld",dp[w]);
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int ans;
    int a, b;
    cin >> a >> b;
    for (ans=0; 1 + ans*(a - 1) < b;ans++)
        ;
    cout << ans << endl;
}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define clean(used) memset(used,false,sizeof(used))
using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c,tmp;
    scanf("%d %d %d",&a,&b,&c);
    if ( a > b )
    {
        tmp = a;
        a = b;
        b = tmp;
    }
    if ( b > c )
    {
        tmp = b;
        b = c;
        c = tmp;
    }
    if ( a > b )
    {
        tmp = a;
        a = b;
        b = tmp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2056
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cstdlib>
#include <iomanip>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)
typedef unsigned long long ULL;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=998244353;
const LL maxn=1e6+7;
const double eps=0.00000001;
const double pi=acos(-1.0);
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a,T b){T ret=1;for (;b;b>>=1ll,a=a*a%M) if (b&1) ret=1ll*ret*a%M;return ret;}

typedef pair<int,int> pii;
int T;
int n,m;
int i,j,k;
pair<pii,int> A[1000];
int mark[maxn];
int ans;
int main(){
    scanf("%d",&n);
    REP(i,n){
        int x,y;
        scanf("%d%d",&x,&y);
        A[i]=make_pair(make_pair(x,y),0);
    }REP(i,n){
        int x,y;
        scanf("%d%d",&x,&y);
        A[i+n]=make_pair(make_pair(x,y),1);
    }sort(A,A+n+n);
    REP(i,n*2){
        auto now=A[i].first;
        if (A[i].second==0){
            mark[now.second]=1;
            continue;
        }rREP(j,now.second) if (mark[j]) break;
        if (j>=0){
            ans++;mark[j]=0;
        }
    }printf("%d\n",ans);
}
/*
*/


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

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };

int main()
{
	fast();
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<< " "<<b<<" "<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

char island[13][13];

void bfs(int x,int y){
  island[y][x]='0';
  queue<pi> que;
  que.push(mp(x,y));
  while(que.size()){
    pi d=que.front();que.pop();
    rep(i,4){
      int xx=d.first+dx[i],yy=d.second+dy[i];
      if(0<=xx&&xx<=12&&0<=yy&&yy<=12&&island[yy][xx]=='1'){
	que.push(mp(xx,yy));
	island[yy][xx]='0';
      }
    }
  }
}

int solve(){
  int ret=0;
  rep(i,12){
    rep(j,12){
      if(island[i][j]=='1'){
	ret++;
	bfs(j, i);
      }
    }
  }
  return ret;
}

int main(){
  char a;
  while(cin>>a){
    island[0][0]=a;
    // cout<<"in"<<endl;
    rep(i,12){
      rep(j,12){
	if(i==0&&j==0)continue;
	// cout<<i<<" "<<j<<endl;
	cin>>island[i][j];
      }
    }
    cout<<solve()<<endl;
  }
}




Measured memory_bytes: 3032
#include <iostream>
int main(int argc, char *argv[]) {
	unsigned int a, b;
	std::cin >> a >> b;
	const unsigned int sum = a + b;
	const bool odd = (sum % 2 == 1);
	const unsigned int x = sum / 2 + ((odd) ? 1 : 0);
	std::cout << x << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int N;
  scanf("%d",&N);

  char S[N];
  scanf("%s",S);

  int sum[N+1];
  sum[0] = 0;
  for (int i = 0; i < N; i++) {
    sum[i+1] = sum[i];
    if(S[i] == 'W') sum[i+1]++;
  }

  int ans = N;
  for (int i = 0; i < N; i++) {
    ans = min(ans,sum[i]+N-i-1-(sum[N]-sum[i+1]));
  }

  printf("%d\n",ans);

  return 0;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> rotate(vector<int>& vec, int i) {
  vector<int> ret = {vec[(0+i)%4], vec[(1+i)%4], vec[(2+i)%4], vec[(3+i)%4]};
  return ret;
}

vector<int> getfirst(vector<int>& v) {
  vector<vector<int>> ret(4, vector<int>(4));
  rep(p, 4) {
    ret[p] = rotate(v, p);
  }
  sort(ret.begin(), ret.end());
  return ret[0];
}

int getdup(const vector<int>& vec) {
  if (vec[0] == vec[1] && vec[1] == vec[2] && vec[2] == vec[3]) {
    return 4;
  } else if (vec[0] == vec[2] && vec[1] == vec[3]) {
    return 2;
  } else {
    return 1;
  }
}

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

  int n; cin >> n;
  vector<vector<int>> tiles(n, vector<int>(4));
  map<vector<int>, int> mp, mp2;
  rep(i, n) {
    int a, b, c, d; cin >> a >> b >> c >> d;
    tiles[i] = {a, b, c, d};
    tiles[i] = getfirst(tiles[i]);
    mp[tiles[i]]++;
  }

  ll ans = 0;
  rep(i, n-5) {
    vector<int> ti = tiles[i];
    mp[ti]--;
    for(int j=i+1; j<n; j++) {
      mp[tiles[j]]--;
      rep(k, 4) {
        vector<int> tj = rotate(tiles[j], k);
        vector<vector<int>> dice(4, vector<int>(4));
        dice[0] = {ti[0], tj[1], tj[0], ti[1]};
        dice[1] = {ti[1], tj[0], tj[3], ti[2]};
        dice[2] = {ti[2], tj[3], tj[2], ti[3]};
        dice[3] = {ti[3], tj[2], tj[1], ti[0]};
        rep(l, 4) {
          mp2[getfirst(dice[l])]++;
        }
        ll now = 1;
        for(auto& e: mp2) {
          int cnt = mp[e.first];
          int num = e.second;
          int dup = getdup(e.first);
          for(int p=1; p<=num; p++) {
            now *= cnt*dup;
            cnt--;
          }
        }
        mp2.clear();
        ans += now;
      }
      mp[tiles[j]]++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
	int n=0;
	int a[40]={0};
	while(cin>>a[n++]);n--;
	
	int maxn=1000000;
	bool p[maxn];
	for(int i=0;i<maxn;i++)
	{
		p[i]=1;
	}
	for(int i=2;i<maxn;i++)
	{
		for(int j=i+i;j<maxn;j+=i)
		{
			p[j]=0;
		}
	}
	
	for(int i=0,cnt=0;i<n;i++)
	{
		for(int j=2;j<=a[i];j++)
		{
			cnt+=p[j];
		}
		cout<<cnt<<endl;cnt=0;
	}
	return 0;
}

Measured memory_bytes: 4060
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
def fact(x):
  if x==0:
    return 1
  else:
    return x*fact(x-1)%mo
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
elif m==n:
  print((2*fact(m)*fact(n))%mo)
else:
  print((fact(m)*fact(n))%mo)


Measured memory_bytes: 83316
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let A = read![[i64]];

    let mut count = 0;

    for i in 0..N {
        let mut x = A[i];

        while x != 0 && x % 2 == 0 {
            x /= 2;
            count += 1;
        }
    }

    println!("{}", count)
}


Measured memory_bytes: 4352
r, c = map(int, input().split())
ans = []
for i in range(r) :
    col = list(map(int, input().split()))
    col_sum = sum(col)
    col.append(col_sum)
    ans.append(col)

col = []
for i in range(c + 1) :
    element = 0
    for j in range(r) :
        element += ans[j][i]
    col.append(element)

ans.append(col)

for col in ans :
    print(" ".join(map(str, col)))


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

int main() {
    string s;
    int k;
    cin >> s >> k;
    set <string> st;
    rep (i, s.size()) {
        string tmp = "";
        for (int j = 0; j < k && i + j < s.size(); j++) {
            tmp += s[i + j];
            st.insert(tmp);
        }
    }
    auto itr = st.begin();
    rep (i, k - 1) itr++;
    cout << *itr << endl;
    return 0;
}


Measured memory_bytes: 1664
D,G =(int(i) for i in input().split())
pc = [[int(j) for j in input().split()] for i in range(D)]
unuse = -1
point = total = 0
G /= 100
answer = 1000
for i in range(1 << len(pc)):
  point = 0
  total = 0
  unuse = -1
  for j in range(len(pc)):
    if ((i >> j) & 1) == 1:
      point += pc[j][0] * (j+1) + (pc[j][1] / 100)
      total += pc[j][0]
    else:
      unuse = max(unuse,j)
    if(point >= G):
      answer = min(answer,total)
    elif(unuse > -1 and point + (pc[unuse][0] - 1) * (unuse + 1) >= G):
      if((G - point) % (unuse + 1) == 0):
        answer = min(answer, total+int((G - point) // (unuse + 1)))
      else:
        answer = min(answer, total+int((G - point) // (unuse + 1))+1)     
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
long long int A,B,C,D,E,F,G; 
cin >> A >> B >> C >> D >> E >> F >> G; 
if(A >= 1 && D >= 1 && E >= 1){
int K = A % 2 + D % 2 + E % 2; 
cout << A + B + D + E - min(K, 3-K) << endl; 
}
else{
cout << A + B + D + E - A % 2 - D % 2 - E % 2 << endl; 
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[109];
int dp[100009];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<=k;i++){
		for(int j=0;j<n;j++){
			if(i-a[j]<0){
				continue;
			}
			if(dp[i-a[j]]==0){
				dp[i]=1;
				break;
			}
		}
	}
	if(dp[k]==1) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <stdio.h>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
    int A, B, C, D;
    scanf(" %d %d %d %d", &A, &B, &C, &D);

    int minTrain = A < B ? A : B;
    int minBus = C < D ? C : D;

    printf("%d\n", minTrain + minBus);
    return 0;
}

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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = tolower(s[k-1]);
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
if a > 0:
  a -= 1
if a % 4 == 0:
  ans = a
elif a % 4 == 1:
  ans = 1
elif a % 4 == 2:
  ans = a + 1
else:
  ans = 0
if b % 4 == 0:
  print(ans^b)
elif b % 4 == 1:
  print(ans^1)
elif b % 4 == 2:
  print(ans^b^1)
else:
  print(ans)

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


using namespace std;


int n, k;
vector < vector<int> > g;
vector<int> mt;
vector<char> used;

bool try_kuhn(int v) {
    if (used[v])  return false;
    used[v] = true;
    for (size_t i = 0; i<g[v].size(); ++i) {
        int to = g[v][i];
        if (mt[to] == -1 || try_kuhn(mt[to])) {
            mt[to] = v;
            return true;
        }
    }
    return false;
}

int main() {
    cin >> n;
    k = n;

    g.resize(k);
    vector<pair<int, int>> rd(k), bd(k);
    for (int i = 0; i < k; ++i) {
        cin >> rd[i].first >> rd[i].second;
    }

    for (int i = 0; i < k; ++i) {
        cin >> bd[i].first >> bd[i].second;
    }

    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
            if (rd[i].first < bd[j].first && rd[i].second < bd[j].second) {
                g[i].push_back(j);
            }
        }
    }

    mt.assign(k, -1);
    for (int v = 0; v < n; ++v) {
        used.assign(n, false);
        try_kuhn(v);
    }

    int cnt = 0;
    for (int i = 0; i<k; ++i) {
        if (mt[i] != -1) {
            ++cnt;
        }
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 256
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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


    //start from here

    readb(s, w);
    if(w >= s) cout << "unsafe";
    else cout << "safe";

    return 0;
}


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

int main() {
  int n;
  string s, t;
  vector<char> A(0);
  cin >> n >> s >> t;
  for(int i = 0; i < n; i++) {
    A.push_back(s[i]);
    A.push_back(t[i]);
  }
  for(char a: A) {
    cout << a;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    capacity: usize,
    things: [(usize, i64); n]
  }
  let mut dp = vec![vec![0; capacity + 1]; 2];
  for item in 0..n {
    for cap in 0..capacity+1 {
      dp[(item+1) % 2][cap] = dp[item % 2][cap];
      if things[item].0 <= cap {
        dp[(item+1) % 2][cap] = cmp::max(dp[(item+1) % 2][cap], dp[item % 2][cap - things[item].0] + things[item].1);
      }
    }
  }
  let ans = dp[n % 2].iter().fold(0, |current, val| cmp::max(current, *val));
  println!("{}", ans);
}


Measured memory_bytes: 6396
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[]) {
int N;
cin>>N;
vector<vector<int>> F;
vector<vector<long long int>> P;
for(int i=0;i<N;i++){
  vector<int> temp(10);
  for(int j=0;j<10;j++){
    cin>>temp[j];
  }
  F.push_back(temp);
}
int res=-(1<<30);
for(int i=0;i<N;i++){
  vector<long long int> temp(11);
  for(int j=0;j<11;j++){
    cin>>temp[j];
  }
  P.push_back(temp);
}

for(int b=1;b<1024;b++){
  int largest=0;
  for(int i=0;i<N;i++){
    int c=0;
    for(int j=0;j<10;j++){
      if((b>>j&1)&&F[i][j]) c++;
    }
    largest+=P[i][c];
  }
  if(res<largest)res=largest;

}

cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
N, K = [eval(v) for v in input().strip().split(" ")]
Snuke = [0] * N
for i in range(K):
    d = eval(input())
    A = [eval(v) for v in input().strip().split(" ")]
    for a in A:
        Snuke[a-1] += 1

victim_num = 0
for i in range(len(Snuke)):
    if Snuke[i] == 0:
        victim_num += 1
print(victim_num)

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

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define len(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>


signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int x; cin >> x;
  if(x>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
  ret;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<int>adj[MAX];
int v[MAX],d[MAX],nxt[MAX];
void dfs(int src)
{
    v[src]=1;
    for(int i=0; i<adj[src].size(); i++)
    {
        int c=adj[src][i];
        if(v[c]==0)
        {
            d[c]=d[src]+1;
            dfs(c);
        }
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int a;
        cin>>a;
        nxt[i]=a;

    }
    int cnt=0,cur=1,f=0;
    while(!v[cur])
    {
        cnt++;
        v[cur]=1;
        cur=nxt[cur];
        if(cur==2){
         f=1;
            break;
        }
    }
    if(!f)
        cout<<"-1"<<endl;
    else
        cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 27844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1000000000
int i,j,k,p;
int main(){
    bool ok=true;
    int n;cin>>n;
    vector<int> a(n);
    for(i=0;i<n;i++){cin>>a[i];}

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

    for(i=0;i<n-1;i++){
        if(a[i]==a[i+1]){ok=false;break;}
    }

    if(ok){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
using namespace std;
int div(int n){
	int tot = 0;
	for(int i = 1;i <= n;++i)if(n % i == 0)tot++;
	return tot;
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 1;i <= n;++i)if((i & 1)&& div(i) == 8)cnt++;
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
class diceroll{
    public:
    int num[6],new_num[6];
    void refresh();
    void turn_N();
    void turn_S();
    void turn_E();
    void turn_W();
};
    
void diceroll::refresh(){
    for(int i=0;i<6;i++){
        num[i]=new_num[i];
    }    
}
void diceroll::turn_N(){
    new_num[0]=num[1];
    new_num[1]=num[5];
    new_num[5]=num[4];
    new_num[4]=num[0];
    new_num[2]=num[2];
    new_num[3]=num[3];
}

void diceroll::turn_S(){
    new_num[0]=num[4];
    new_num[4]=num[5];
    new_num[5]=num[1];
    new_num[1]=num[0];
    new_num[2]=num[2];
    new_num[3]=num[3];
}

void diceroll::turn_E(){
    new_num[0]=num[3];
    new_num[3]=num[5];
    new_num[5]=num[2];
    new_num[2]=num[0];
    new_num[1]=num[1];
    new_num[4]=num[4];
}

void diceroll::turn_W(){
    new_num[0]=num[2];
    new_num[2]=num[5];
    new_num[5]=num[3];
    new_num[3]=num[0];
    new_num[1]=num[1];
    new_num[4]=num[4];
}

int main(){
    int n;
    bool c=false;
    cin >> n;
    diceroll a[n];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<6;j++){
        cin >> a[i].num[j];
    }
    
    }
    for(int l=0;l<n-1;l++){
        for(int m=l+1;m<n;m++){
            for(int k=0;k<4;k++){
                for(int i=0;i<4;i++){
                    for(int j=0;j<4;j++){
                        if(a[l].num[0]==a[m].num[0]&&a[l].num[1]==a[m].num[1]&&a[l].num[2]==a[m].num[2]&&a[l].num[3]==a[m].num[3]&&a[l].num[4]==a[m].num[4]&&a[l].num[5]==a[m].num[5]){
                            c=true;
                        }
                        a[l].turn_W();
                        a[l].refresh();
                    }
                    a[l].turn_S();
                    a[l].refresh();
                }
                a[l].turn_W();
                a[l].refresh();
            }
        }
    }
    
    if(c){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    
}


Measured memory_bytes: 3100
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# def sub(kouho, target):
#     l = len(kouho)
#     best = None
#     for b in range(1<<l):
#         v = 0
#         for i in range(l.bit_length()):
#             if b>>i&1:
#                 v += 1<<i
#         if 
                

n = int(input())
a = list(map(int, input().split()))

val = 0
for num in a[2:]:
    val ^= num
k = a[0] + a[1]
if (k-val)%2!=0 or k<val:
    ans = -1
else:
    tmp = (k-val)//2
    if tmp<0 or 2*tmp>k:
        ans = -1
    else:
        v1 = tmp
        v2 = tmp
        kouho = []
        ans = None
        if tmp>a[0]:
            ans = -1
        diff = k - 2*tmp
        for i in range(diff.bit_length()):
            if (diff&1<<i) & tmp:
                ans = -1
                break
            elif diff&1<<i:
                kouho.append(1<<i)
        s = sum(kouho)
        if ans is None:
            for num in kouho[::-1]:
                s -= num
                if v2+s<a[1]:
                    v2 += num
                elif v1+num<=a[0]:
                    v1 += num
                else:
                    v2 += num
            if v1==0:
                ans = -1
            else:
                ans = a[0]-v1
        else:
            ans = -1
        
print(ans)

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

using namespace std;
const int MAXN = 100100;

#define p(args...) fprintf(stderr, args)
typedef pair<int, int> pii;
vector<pii> ed[MAXN]; // ed[i] = pii(j, e)
map<int, int> mp;
int B[MAXN];
int C[MAXN];

bool vis[MAXN];
vector<int> ans;
bool dfs(int cur, int prv = -1) {
  if (vis[cur]) return false;
  vis[cur] = true;
  bool ret = C[cur];
  p("DFS %d %d init: %d\n", cur, prv, ret);
  for (auto p: ed[cur]) {
    if (p.second == prv) continue;
    if (dfs(p.second, cur)) {
      ans.push_back(p.first);
      ret = !ret;
    }
  }
  p("DFS %d %d fin: %d\n", cur, prv, ret);
  return ret;
}

bool go() {
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    mp[a] = b;
  }
  int c = 0;
  for (auto p: mp) {
    int b = p.second;
    B[c] = b;
    mp[p.first] = c++;
  }
  C[0] = B[0];
  for (int i = 1; i <= n; ++i) {
    C[i] = B[i] != B[i - 1];
  }
  mp[1E9 + 1] = n;
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    ++b;
    p("N: %d -> %d\n", a, mp.lower_bound(a)->second);
    a = mp.lower_bound(a)->second;
    b = mp.lower_bound(b)->second;
    p("(%d, %d)\n", a, b);
    ed[a].push_back(pii(i, b));
    ed[b].push_back(pii(i, a));
  }

  for(int i = 0; i <= n; ++i) {
    if (dfs(i)) {
      return false;
    }
  }
  return true;
}

int main() {
  if (go()) {
    cout << ans.size() << "\n";
    sort(ans.begin(), ans.end());
    for (auto i: ans) {
      cout << i << " ";
    }
    cout << "\n";
  } else {
    cout << "-1\n";
  }
}


Measured memory_bytes: 20608
// Name: Kanisht Agarwal Copyright Think before u copy //
//Connect with me at LinkedIn

#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1)
#define nui 100
#define INF 100000000000

#define F(i,a,n) for(ll i=a;i<n;i++)
#define B(i,a,n) for(ll i=n-1;i>=a;i--)
#define tc int t;cin>>t;while(t--)
#define tcf int t;cin>>t;for(int w=1;w<=t;w++)



using namespace std;


ull binpow(ll a, ll b)
{
    ull res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}

ll fermat_inv(ll y) {return binpow(y, mod - 2);}


int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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

    //Problem A:

    string s,t;
    cin>>s>>t;
    int ct=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            ct++;
    }
    cout<<ct<<"\n";

    return 0;

}







Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) cin >> w[i];

  map<string, bool> used;
  rep(i, n) {
    if (used[w[i]]) {
      cout << "No" << endl;
      return 0;
    }
    used[w[i]] = true;
  }

  rep(i, n - 1) {
    int m = w[i].size();
    if (w[i][m - 1] != w[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n); i >= 0; i--)
#define revrepr(i, a, b) for (int i = (a); i >= b; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

int main() {
    string s, t;
    cin >> s >> t;
    vector<char> change_to(26, '#'), change_from(26, '#');
    bool ok = true;
    rep(i, s.size()) {
        int si = s.at(i) - 'a', ti = t.at(i) - 'a';
        
        if (change_to.at(ti) == '#') change_to.at(ti) = s.at(i);
        else if (change_to.at(ti) != s.at(i)) ok = false;
        
        if (change_from.at(si) == '#') change_from.at(si) = t.at(i);
        else if (change_from.at(si) != t.at(i)) ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 776
// B - NarrowRectanglesEasy
#include <bits/stdc++.h>
using namespace std;

int main(){
	int w,a,b;
	cin>>w>>a>>b;
	int min_i = min(a,b);
	int max_i = max(a,b);
	int ans = max_i-(min_i+w);
	cout<< max(0,ans) <<endl;
}

Measured memory_bytes: 384
N = int(input())
counts = [[0 for j in range(19)] for i in range(19)]

for _ in range(N):
    a = float(input())
    a = int(round(a*10**9))

    i, j = 0, 0
    while a % 2 == 0:
        i += 1
        a //= 2
    while a % 5 == 0:
        j += 1
        a //= 5

    i = min(i, 18)
    j = min(j, 18)
    counts[i][j] += 1


ans = 0
for i in range(19):
    for j in range(19):
        for k in range(19):
            for l in range(19):
                if i+k >= 18 and j+l >= 18:
                    ans += counts[i][j]*counts[k][l]

for i in range(9, 19):
    for j in range(9, 19):
        ans -= counts[i][j]

print(ans//2)


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

int main() {
    vector<string> name(9);
    vector<int> a(9);
    vector<int> b(9);
    
    rep(i, 9) {
        int tmpa, tmpb;
        cin >> name.at(i) >> tmpa >> tmpb;
        a.at(i) = tmpa + tmpb;
        b.at(i) = tmpa * 200 + tmpb * 300;
    }
    rep(i, 9) {
        cout << name.at(i) << " " << a.at(i) << " " << b.at(i) << endl;
    }
}


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

#define inf 1e9

int minCost(int n, int k, int* height) {
	int* dp = new int[n + 1];
	dp[1] = 0;
	for (int i = 2; i <= n ; ++i)
	{	dp[i] = inf;
		for (int j = i - 1; j >= i - k and j >= 1; j--) {
			dp[i] = min(dp[i], dp[j] + abs(height[j] - height[i]));
		}
	}
	return dp[n];
}


int main() {
	int n, k;
	cin >> n >> k;
	int* height = new int[n + 1];
	for (int i = 1; i <= n ; ++i)
	{
		cin >> height[i];
	}
	cout << minCost(n, k, height) << endl;

}

Measured memory_bytes: 3924