akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <limits>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

template <typename T = lnt, T INF = std::numeric_limits<T>::max()>
struct Dinic
{
	struct Edge
	{
		int a,b; T c,f;
		Edge(int a, int b, T c) : a(a),b(b),c(c),f(0) {}
	};
	int n,m;
	std::vector<Edge> E;
	std::vector<std::vector<int> > G,Gf;
	Dinic(int n) : n(n),m(0),G(n) {}
	void add_edge(int i, int j, int c) {
		E.emplace_back(i,j,c);
		E.emplace_back(j,i,0);
		G[i].emplace_back(m);
		G[j].emplace_back(m|1);
		m+=2;
	}
	bool bfs(int s, int t) {
		Gf.assign(n,std::vector<int>());
		std::queue<int> que; que.emplace(s);
		std::vector<int> dist(n,-1); dist[s]=0;
		while(!que.empty()) {
			int i=que.front(); que.pop();
			for(int to:G[i]) {
				if(dist[E[to].b]!=-1 || E[to].c==E[to].f) continue;
				dist[E[to].b]=dist[E[to].a]+1;
				que.emplace(E[to].b);
			}
		}
		if(dist[t]==-1) return false;
		for(int i=0;i<m;i++) {
			if(dist[E[i].a]+1!=dist[E[i].b] || E[i].c==E[i].f || dist[E[i].a]>=dist[t]) continue;
			Gf[E[i].a].emplace_back(i);
		}
		return true;
	}
	T dfs(int i, T a_f, const int& t) {
		if(i==t || a_f==0) {
			return a_f;
		}
		T v_f=0;
		for(int to:Gf[i]) {
			T f=dfs(E[to].b,std::min(a_f-v_f,E[to].c-E[to].f),t);
			E[to].f+=f; E[to^1].f-=f;
			v_f+=f;
			if(a_f==v_f) break;
		}
		return v_f;
	}
	T flow(int s, int t) {
		T max_flow=0;
		while(bfs(s,t)) {
			T f = dfs(s,INF,t);
			if(f==0) break;
			max_flow+=f;
		}
		return max_flow;
	}
};

int main() {
	int h,w;
	std::cin >> h >> w;
	std::vector<std::string> g(h);
	rep(i,h) std::cin >> g[i];
	std::vector<std::vector<int> > X(h),Y(w);
	int sx,sy,tx,ty;
	rep(i,h) {
		rep(j,w) {
			if(g[i][j]=='o'||g[i][j]=='S'||g[i][j]=='T') {
				if(g[i][j]=='S') {
					sx=i; sy=j;
				}
				if(g[i][j]=='T') {
					tx=i; ty=j;
				}
				X[i].emplace_back(j);
				Y[j].emplace_back(i);
			}
		}
	}
	if(sx==tx||sy==ty) {
		print(-1);
		return 0;
	}
	auto enc = [&] (int i, int j) {
		return i*w+j;
	};
	debug(sx,sy,tx,ty);
	Dinic<int> flow(2*h*w);
	rep(i,h) {
		for(auto y1:X[i]) for(auto y2:X[i]) {
			if(y1==y2) continue;
			flow.add_edge(enc(i,y1),h*w+enc(i,y2),1);
		}
	}
	rep(i,w) {
		for(auto x1:Y[i]) for(auto x2:Y[i]) {
			if(x1==x2) continue;
			flow.add_edge(enc(x1,i),h*w+enc(x2,i),1);
		}
	}
	rep(i,h) rep(j,w) flow.add_edge(enc(i,j)+h*w,enc(i,j),1);
	print(flow.flow(enc(sx,sy),enc(tx,ty)+h*w));
}


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

UL N;
using Card = pair<UL,char>;
Card A[100000];
Card B[100000];

UL partition(Card* pA,UL p,UL r){
 UL x = pA[r].first;
 UL i = p-1;
 for(UL j=p; j<r; j++)
  if(pA[j].first <= x){ i++; swap(pA[i],pA[j]); }
 swap(pA[i+1],pA[r]);
 return i+1;
}

void quicksort(Card* pA,UL p,UL r){
 if(p<r){
  UL q=partition(pA,p,r);
  quicksort(pA,p,q-1);
  quicksort(pA,q+1,r);
 }
}

void margesort(Card* pA,UL p,UL r){
 if(r-p<=1) return;
 UL m=(p+r)>>1;
 margesort(pA,p,m);
 margesort(pA,m,r);
 vector<Card> L(m-p+1); rep(i,m-p) L[i]=pA[p+i]; L[m-p]={~0u,' '};
 vector<Card> R(r-m+1); rep(i,r-m) R[i]=pA[m+i]; R[r-m]={~0u,' '};
 UL i=0, j=0;
 rep(k,r-p){
  if(L[i].first<=R[j].first) {pA[p+k]=L[i];i++;}
  else {pA[p+k]=R[j];j++;}
 }
}

int main() {
 scanf("%u",&N);
 rep(i,N) scanf(" %c%u",&A[i].second,&A[i].first);
 rep(i,N) B[i]=A[i];
 quicksort(A,0,N-1);
 margesort(B,0,N);
 bool stable=true;
 rep(i,N) if(A[i]!=B[i]) stable=false;
 printf(stable?"Stable\n":"Not stable\n");
 rep(i,N) printf("%c %d\n",A[i].second,A[i].first);
 return 0;
}



Measured memory_bytes: 5100
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
struct node{
	int son[3],tag,id;
}g[531444*13];
int n,pw[531444],cnt,ans[531444];
char s[531444]; 
void build(int &rt,int D,int x){
	rt=++cnt;
	if (D==n) return (void)(g[rt].id=x);
	build(g[rt].son[0],D+1,x);
	build(g[rt].son[1],D+1,x+pw[D]);
	build(g[rt].son[2],D+1,x+pw[D]*2);
}
inline void pushdown(int rt){
	if (g[rt].tag){
		g[g[rt].son[0]].tag^=1;
		g[g[rt].son[1]].tag^=1;
		g[g[rt].son[2]].tag^=1;
		g[rt].tag=0;
		swap(g[rt].son[1],g[rt].son[2]);
	}
}
void addone(int rt,int D){
	if (D==n) return;
	pushdown(rt);
	swap(g[rt].son[0],g[rt].son[1]);
	swap(g[rt].son[0],g[rt].son[2]);
	addone(g[rt].son[0],D+1);
}
void release(int rt,int D,int x){
	if (D==n) return (void)(ans[g[rt].id]=x);
	pushdown(rt);
	release(g[rt].son[0],D+1,x);
	release(g[rt].son[1],D+1,x+pw[D]);
	release(g[rt].son[2],D+1,x+pw[D]*2);
}
signed main(){
	n=read();
	pw[0]=1;
	for (int i=1;i<=n;i++) pw[i]=pw[i-1]*3;
	int ROOT;
	build(ROOT,0,0);
	scanf("%s",s+1);
	int T=strlen(s+1);
	for (int i=1;i<=T;i++){
		if (s[i]=='S'){
			g[1].tag^=1;
		}else{
			addone(1,0);
		}
	}
	release(1,0,0);
	for (int i=0;i<pw[n];i++){
		printf("%d ",ans[i]);
	}
    return 0;
}


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

int main(){
    string S;
    cin >> S;
    int N = S.length();
    if(N < 5){
        cout << "NO" << endl;
        return 0;
    }
    if(S[0] != 'A')S = "A" + S;
    if(S[4] != 'A')S = S.substr(0, 4) + "A" + S.substr(4);
    if(S[6] != 'A')S = S.substr(0, 6) + "A" + S.substr(6);
    if(S[8] != 'A')S = S + "A";
    if(S == "AKIHABARA")cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in range(n):
  a, b = list(map(int, input().split()))
  d[a] += b
for ele in sorted(d.items()):
  k -= ele[1]
  if k<=0:
    print(ele[0])
    break

Measured memory_bytes: 14948
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int r,g,b,a;
  cin>>r>>g>>b;
  a=r*100+g*10+b;
  if(a%4==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
a=input().split()
b=0
for i in a:
  if i in ['5','7']:
    b=b+int(i)
    re='Yes'
  else:
    b=b+int(i)
    re='No'
    break
    
if b==17 and re!='No':
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

typedef vector<int> V;
typedef vector<V> MATRIX;

int N,M,A,B,C,T;
int S_0[50],ans[50];

MATRIX calc(MATRIX left,MATRIX right){

	MATRIX ret(N,V(N));

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)ret[i][k] = 0;
	}

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			for(int a = 0; a < N; a++){
				ret[row][col] += left[row][a]*right[a][col]%M;
			}
		}
	}

	return ret;

}

MATRIX pow(MATRIX MULT,int count){

	MATRIX ret(N,V(N));

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			if(row == col)ret[row][col] = 1;
			else{
				ret[row][col] = 0;
			}
		}
	}

	while(count > 0){
		if(count%2 == 1)ret = calc(ret,MULT);
		MULT = calc(MULT,MULT);
		count /= 2;
	}

	return ret;
}

void func(){

	for(int i = 0; i < N; i++)scanf("%d",&S_0[i]);

	if(T == 0){
		printf("%d",S_0[0]);

		for(int i = 1; i <= N-1; i++)printf(" %d",S_0[i]);
		printf("\n");

		return;
	}

	MATRIX MULT(N,V(N));

	MULT[0][0] = B;
	MULT[0][1] = C;
	for(int col = 2; col <= N-1; col++)MULT[0][col] = 0;

	for(int row = 1; row <= N-2; row++){
		for(int col = 0; col < row-1;col++)MULT[row][col] = 0;
		MULT[row][row-1] = A;
		MULT[row][row] = B;
		MULT[row][row+1] = C;
		for(int col = row+2; col <= N-1; col++)MULT[row][col] = 0;
	}

	for(int col = 0; col <= N-3; col++)MULT[N-1][col] = 0;
	MULT[N-1][N-2] = A;
	MULT[N-1][N-1] = B;

	if(T > 1)MULT = pow(MULT,T);

	int tmp;

	for(int row = 0; row <= N-1; row++){
		tmp = 0;
		for(int col = 0; col <= N-1; col++){
			tmp += MULT[row][col]*S_0[col]%M;
		}
		ans[row] = tmp%M;
	}

	printf("%d",ans[0]%M);

	for(int i = 1; i <= N-1; i++)printf(" %d",ans[i]%M);
	printf("\n");

}


int main(){

	while(true){
		scanf("%d %d %d %d %d %d",&N,&M,&A,&B,&C,&T);
		if(N == 0 && M == 0 && A == 0 && B == 0 && C == 0 && T == 0)break;

		func();
	}

	return 0;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

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

    int a,b,c,d,x,y;
    cin >> a >> b >> c >> d;
    y=a/d+(a%d > 0);
    x=c/b+(c%b > 0);
    if(x <= y)cout << "Yes";
    else cout << "No";
    return 0;
}


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

int main()
{
    int A[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    int b;
    for (int i = 0; i < N; i++)
    {
        cin >> b;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (A[i][j] == b)
                {
                    A[i][j] = 0;
                }
            }
        }
    }
    bool judge = false;
    int sum[8] = {0};
    for (int i = 0; i < 3; i++)
    {
        sum[0] += A[0][i];
        sum[1] += A[1][i];
        sum[2] += A[2][i];
        sum[3] += A[i][0];
        sum[4] += A[i][1];
        sum[5] += A[i][2];
    }
    sum[6] = A[0][0] + A[1][1] + A[2][2];
    sum[7] = A[0][2] + A[1][1] + A[2][0];
    for (int i = 0; i < 8; i++)
    {
        if (sum[i] == 0)
        {
            judge = true;
            break;
        }
    }
    if (judge)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MAX_N = 2e5;
class UnionFind {
private:
    int rank[MAX_N];

public:
    int par[MAX_N];
    
    void init(int n)
    {
        for (int i=0; i<n; i++) {
            par[i]=i;
            rank[i]=0;
        }
    }
    
    // 木の根を求める
    int find(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    
    // xとyの属する集合を併合する
    void merge(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
    
    // xとyが同じ集合に属するか判定する
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

const int MAX_M = 1e5;
vector<int> can[MAX_M];

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    UnionFind UF;
    UF.init(N + M);

    rep(i, N) {
        int K; cin >> K;
        rep(j, K) {
            int L;
            cin >> L;
            L--;
            UF.merge(i, N + L);
        }
    }

    bool ok = true;
    rep(i, N) {
        if (!UF.same(i, 0)) ok = false;
    }
    cout << (ok ? "YES" : "NO") << endl;
}



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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,d;cin>>n>>d;

    cout<<(n+(2*d+1)-1)/(2*d+1)<<endl;

}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] sticks = new int[N];

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

            sticks[i] = Integer.parseInt(sc.next());
        }

        sc.close();
      
        Arrays.sort(sticks);

        int count = 0;

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

            for(int j = i+1; j < N-1; j++) {

                for(int k = j+1; k < N; k++) {

                    if(sticks[k] < sticks[i] + sticks[j]) {

                        count++;
                    }

                }
            }
        }

        System.out.println(count);
    }

}


Measured memory_bytes: 25340
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

#pragma region
LL powMod(LL num,LL n,LL mod=(LL)MOD){//(num**n)%mod
	num %= mod;//
	if( n == 0 ){
		return (LL)1;
	}
	LL mul = num;
	LL ans = (LL)1;
	while(n){
		if( n&1 ){
			ans = (ans*mul)%mod;
		}
		mul = (mul*mul)%mod;
		n >>= 1;
	}
	return ans;
}
LL mod_inverse(LL num,LL mod=MOD){
	return powMod(num,MOD-2,MOD);
}
#pragma endregion //繰り返し二乗法 powMod

void solve(){
	LL N;
	cin >> N;
	vector<LL> A(N);
	vector<int> v(N,0);//0,N-1の個数
	for(int i=0;i<N;++i){
		cin >> A[i];//[0,N-1]
		v[ A[i] ]++;
	}
	/////
	bool flag = true;
	if( N%2 == 0 ){
		for(int i=0;i<N;++i){
			if( i%2 ){
				if( v[i] != 2 ){
					flag = false;
					break;
				}
			}else{
				if( v[i] != 0 ){
					flag = false;
					break;
				}
			}
		}
	}else{//Nが奇数
		for(int i=0;i<N;++i){
			if( i%2 == 0 ){
				if( i== 0 ){
					if( v[i] != 1 ){
						flag = false;
						break;
					}
				}else{
					if( v[i] != 2 ){
						flag = false;
						break;
					}
				}
			}else{
				if( v[i] != 0 ){
					flag = false;
					break;
				}
			}
		}
	}
	if( flag ){
		cout << powMod(2,N/2) << endl;
	}else{
		cout << 0 << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1408
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AA=sorted(A)
BB=sorted(B)
ans=AA[0]+BB[0]
for i in range(m):
  x,y,c=map(int,input().split())
  d=A[x-1]+B[y-1]-c
  if d<ans:
    ans=d
print(ans)

Measured memory_bytes: 18736
import java.util.Scanner;

public class Main {

    private static long sum(int g, int l) {
        return (long) g * (g + 1) / 2 + l * (l - 1) / 2;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int i = 0;
        int j = 0;
        long ans = 0;
        for (int k = 0; k < s.length(); k++) {
            if ('>' == s.charAt(k)) {
                j++;
                continue;
            }
            if (j == 0) {
                i++;
                continue;
            }
            ans += sum(Math.max(i, j), Math.min(i, j));
            i = 1;
            j = 0;
        }
        ans += sum(Math.max(i, j), Math.min(i, j));
        System.out.println(ans);
    }

}


Measured memory_bytes: 28824
n, k = map(int, input().split())
step = list(map(int, input().split()))

ans = [float('inf')]*(10**6)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

print(dp(n))

Measured memory_bytes: 84064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

int n;
set<pair<string,int>> s;

int main(void){
	cin>>n;
	s.insert({"a",1});
	rep(i,n-1){
		set<pair<string,int>> t;
		for(auto itr=s.begin();itr!=s.end();itr++){
			auto p = *itr;
			rep(j,p.second)t.insert({p.first+(char)('a'+j), p.second});
			t.insert({p.first+(char)('a'+p.second), p.second+1});
			// t.insert({p.first, p.second});
		}
		s=t;
	}
	for(auto itr=s.begin();itr!=s.end();itr++){
		auto p = *itr;
		cout<<p.first<<endl;
	}
	cerr<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 21504
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

ll pow(ll b, ll p, ll m) {
    b = b%m;
    ll ans = 1;
    while(p) {
        if(p & 1) {
            ans = (ans*b)%m;
        }
        p >>= 1;
        b = (b*b)%m;
    }
    return ans;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    const ll m = 1e9+7;

    ans += pow(10, n, m);
    ans %= m;
    ans += pow(8, n, m);
    ans %= m;
    ans -= 2*pow(9, n, m);
    ans %= m;

    while(ans < 0) {
        ans += m;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int dp[108000];
Int dp2[108000];
Int x[108000];
Int l, n, e, t;
int main(){
  cin >> n >> e >> t;
  fill(dp, dp + 108000, LINF);
  x[n] = e;
  for(int i = 0;i < n;i++)cin >> x[i];
  dp[0] = -x[0] * 2;
  dp2[0] = dp[0];
  for(int i = 1;i <= n;i++){
    while((x[i-1] - x[l+1])*2>=t)l++;
    
    if((x[i-1] - x[l]) * 2 >= t){
      dp[i] = dp2[l] + 2 * (x[i-1] - x[i]);
      dp[i] = min(dp[i], dp[l+1] + 2*x[l+1] + t - 2*x[i]);
    }
    else{
      dp[i] = dp[l] + 2*x[l] + t - 2 * x[i];
    }
    //    cout << i << " " << dp[i] + x[i] * 2 << " " << dp2[i] << endl;
    dp2[i] = min(dp[i], dp2[i-1]);
  }
  cout << e + dp[n] + x[n]*2 << endl;
  return 0;
}

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

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;

	int ans = 1;
	for (int i = 0; i < n - 1; i++) {
		if (s.at(i) != s.at(i + 1)) {
			ans++;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;

int calc(){

}

vector<int> makeArray(int cur, int n, vector<int>& ar){
    if(ar.size() == n){

    }

}

int main(){
    int n, m, q;    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    auto calc = [&](vector<int>& x){
        int res = 0;
        for(int i = 0; i < q; i++){
            if(x[b[i]] - x[a[i]] == c[i]){
                res += d[i];
            }
        }
        return res;
    };

    int res = 0;
    function<void(int, vector<int>&)> dfs =
            [&](int cur, vector<int>& ar){
                if(ar.size() == n){
//                    for(auto p: ar){
//                        cout << p << " ";
//                    }
//                    cout << endl;
                    res = max(res, calc(ar));
                }
                else{
                    for(int i = cur; i <= m; i++){
                        ar.push_back(i);
                        dfs(i, ar);
                        ar.pop_back();
                    }
                }
            };

    vector<int> tmp;
    dfs(1, tmp);

    cout << res << endl;


    return 0;
}


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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;

const ll INF = 1e18, MOD = 1e9 + 7;

const int MAX = 1e6;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    string a, b;
    cin >> a >> b;
    const int n = a.size(), m = b.size();
    vec<set<int> > v(26);
    for (int i = 0; i < n; i++) {
        v[a[i] - 'a'].insert(i);
    }
    ll res = 0;
    for (int i = 0, cur = 0; i < m;) {
        const int c = b[i] - 'a';
        if (v[c].empty()) {
            cout << "-1\n";
            return 0;
        }
        auto it = v[c].lower_bound(cur);
        if (it == v[c].end()) {
            res += n - cur;
            cur = 0;
        }
        else {
            res += *it - cur + 1;
            cur = *it + 1;
            i++;
        }
    }
    cout << res << '\n';
}

Measured memory_bytes: 5200
#include<stdio.h>
#include<math.h>

int main(){
  long long i,j,k,l,N,K,max=0,ans=0;
  
  scanf("%lld %lld",&K,&N);
  
  long long A[N],B[N];
  
  for(i=0;i<N;i++){
    scanf("%lld ",&A[i]);
    if(i != 0){
      B[i-1]=A[i]-A[i-1];
      if(max < B[i-1])
        max = B[i-1];
      ans+=B[i-1];
    }
  }
  B[N-1]=abs(K-A[N-1])+A[0];
  if(max < B[N-1])
    max = B[N-1];
  ans+=B[N-1];
  
  printf("%lld\n",ans-max);
  return 0;
}



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

using namespace std;
using ll = long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10LL * TEN(n-1); }

int main() {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cout << "lst" << " " << i << endl;
        int k;
        cin >> k;
        ans += k * (k-1);
        for (int i = 0; i < k; i++) {
            int unuse;
            cin >> unuse;
        }
    }
    cout << "ans " << ans << endl;
    return 0;
}

Measured memory_bytes: 3108
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int A[3][111];
int B[3][111];
int main(void){
  int n;
  cin>>n;

  int a;
  for(int i=1;i<=2;i++){
    for(int j=1;j<=n;j++){
      cin>>a;
      A[i][j]=a;
    }
  }
  for(int i=1;i<=n;i++){
    B[1][i]+=B[1][i-1]+A[1][i];
    B[2][n-i+1]+=B[2][n-i+2]+A[2][n-i+1];
  }
  
  int ans=0;
  for(int i=1;i<=n;i++){
    ans=max(ans,B[1][i]+B[2][i]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
//abc139_d.cpp
//Sun Sep  1 20:53:31 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n;
	cin >> n;

	ll ans = (n-1)*n/2;

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;

vector<vector<vector<ll>>> dp(10010, vector<vector<ll>>(2,vector<ll>(110,-1)));
//ll dp[10010][2][110];//dp[i][j][k]:uekara i keta j=ok? k= ketawa mod d
string s;
int d;

ll rec(int idx, int f, int x){
  if(dp[idx][f][x]!=-1){ return dp[idx][f][x]; }
  if(idx==s.size()){ return x==0; }
  ll ret=0;
  if(f){
    rep(i,10){ ret+=rec(idx+1, f, (x+i)%d); }
  } else {
    int m=s[idx]-'0';
    rep(i,m){ ret+=rec(idx+1, 1, (x+i)%d); }
    ret+=rec(idx+1, 0, (x+m)%d);
  }
  return dp[idx][f][x]=ret%mod;
}

int main(){
  cin >> s >> d;
  ll ans = (rec(0,0,0)+mod-1)%mod;  //-1 : including 0
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 19456
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
const int M=1e6+5;
int n,f[N],b[N],a[N][N];
#define fi first
#define se second
typedef pair<int,int>P;
priority_queue<P,vector<P>,greater<P> >que;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<n;j++)
			scanf("%d",&a[i][j]),b[i]=1;
	for(int i=1;i<=n;i++)
		if(i==a[a[i][1]][1])
			que.push(P(1,i)),++b[i];
	int ans=0,res=0;
	while(!que.empty()){
		P x=que.top();	que.pop();
		++res,ans=max(ans,f[x.se]);
		int k=a[x.se][b[x.se]];
		x.fi=max(x.fi,f[x.se]);
		if(x.se==a[k][b[k]]){
			++b[k],++b[x.se];
			x.fi=max(x.fi,f[k])+1;
			f[k]=x.fi,que.push(P(f[k],k));
			f[x.se]=x.fi,que.push(P(f[k],x.se));
		}
	}
	if(res!=n*(n-1))	cout<<-1<<endl;
	else	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8432
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <iostream>
#include <string>
#include <functional>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pci pair<char,int>
#define pdd pair<double,double>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pdi pair<double,int>
#define pdd pair<double,double>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 987564231
#define MAX 2000001
long double PI = 3.141592653589793238462643383279502884197;
using namespace std;

/* 🐣🐥 */
char b[1001][1001];
int rgo[4] = { 1, 0, -1, 0 }, cgo[4] = { 0, 1, 0, -1 };
int dist[1001][1001];
queue<pii> q;
int main() {
	memset(dist, -1, sizeof(dist));
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf("%s", b[i]);
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (b[i][j] == '#') {
				q.push({ i, j });
				dist[i][j] = 0;
			}
		}
	}
	int ans = 0;
	while (!q.empty()){
		pii cur = q.front();
		q.pop();
		ans = dist[cur.first][cur.second];
		for (int i = 0; i < 4; i++){
			int nr = rgo[i] + cur.first, nc = cgo[i] + cur.second;
			if (nr < 0 || nc < 0 || nr >= n || nc >= m || dist[nr][nc]!=-1) continue;
			dist[nr][nc] = dist[cur.first][cur.second] + 1;
			q.push({ nr, nc });
		}
	}
	printf("%d", ans);

	return 0;
}

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

using namespace std;
typedef long long ll;

ll simu(ll x, ll k, ll d){
    if(k==0){
        //cout<<x<<endl;
        return x;
    }
    if(x>0){
        if(x-d<0){
            if(k%2==0)return x;
            else return x-d;
        }
        //cout<<x<<" "<<k<<" "<<endl;
        ll n=min(x/d,k);
        return simu(x-d*n, k-n, d);
    }else {
        if(x+d>0){
            if(k%2==0)return x;
            else return x+d;
        }
        ll n=min(abs(x)/d,k);
        return simu(x+d*n, k-n, d);
    }


}

int main(){
    ll X,K,D;
    cin>>X>>K>>D;
    cout<<abs(simu(X,K,D));
    return 0;
}



Measured memory_bytes: 3684
#include <bits/stdc++.h>  // ver1.9.1
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(15);
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int now=0,nowb=0;
  rep(i,0,n){
    if(s[i]=='c') {
      cNo;
      continue;
    }
    if(s[i]=='a' && now<a+b){
      cYes;
      now++;
      continue;
    }
    if(s[i]=='b' && now<a+b && nowb<b){
      cYes;
      now++;
      nowb++;
      continue;
    }
    cNo;
  }
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
#define ll long long

int main(){
    ll N,M;
    cin >> N >> M;
    ll i,j;
    ll k[M];
    vector <ll> s[M];
    ll p[M];
    ll t;
    for(i=0;i<M;i++){
        cin >> k[i];
        for(j=0;j<k[i];j++){
            cin >> t;
            s[i].push_back(t);
        }
    }
    ll a[M];
    for(i=0;i<M;i++){
        cin >> p[i];
    }
    ll ans=0;
    bool flag;
    for(i=0; i < (1<<N);i++){
        for(j=0;j<M;j++){
            a[j]=p[j];
        }
        flag=1;
        for(j=0;j<M;j++){
                for(auto itr=s[j].begin();itr!=s[j].end();++itr){
                   if(i & (1<<(*itr-1)))a[j]=(a[j]+1)%2; 
                }
            }
        for(j=0;j<M;j++){
            if(a[j]==1)flag=0;
        }
        if(flag==1)ans++;
    }
    cout << ans <<endl ;
    return 0;
}


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

int main() {
	int A[3];
	for (int i = 0;i < 3;++ i) cin >> A[i];
	sort(A, A+3);
	cout << A[2] - A[0];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

タスクはAが昇順になるようにこなすと効率が良い
この時、A[2]-A[1] + A[1]-A[0] = A[2] - A[0]のコストがかかる
*/

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222





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

  cin >> n;
  ll a, t, x, d = inf;
  cin >> t >> a;
  t *= 1000;
  a *= 1000;
  FOR(i, 1, n + 1) {
    cin >> tmp;
    x = t - 6 * tmp;
    if (abs(d - a) > abs(x - a)) {
      d = x;
      ans = i;
    }
  }

  cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

ll canonical(const vector<int> &c){
	ll x = 1LL<<62;
	for(int i=0; i<4; i++){
		ll t = 0;
		for(int j=0; j<4; j++){
			t = (t<<10) + c[(i+j)%4];
		}
		x = min(x, t);
	}
	return x;
}

int count_greater(const vector<int> &v, int n, int m){
	auto it = lower_bound(v.begin(), v.end(), n);
	int x = v.end()-it;
	if(x>0&&*it==n) x--;
	if(binary_search(v.begin(), v.end(), m)) x--;
	return x;
}

int mul(ll x){
	ll c0 = (x>>30)&((1<<10)-1);
	ll c1 = (x>>20)&((1<<10)-1);
	ll c2 = (x>>10)&((1<<10)-1);
	ll c3 = (x>>0)&((1<<10)-1);
	if(c0==c1&&c1==c2&&c2==c3) return 4;
	if(c0==c2&&c1==c3) return 2;
	else return 1;
}

int main(){
	int N;
	cin >> N;
	vector<vector<int>> C(N, vector<int>(4));
	for(int i=0; i<N; i++) for(int k=0; k<4; k++) cin >> C[i][k];

	map<ll, vector<int>> faces;
	for(int i=0; i<N; i++){
		faces[canonical(C[i])].push_back(i);
	}

	ll ans = 0;
	for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) for(int k=0; k<4; k++){
		ll side[4];
		for(int l=0; l<4; l++){
			side[l] = canonical({C[i][l], C[j][(k+3-l+1)%4], C[j][(k+3-l)%4], C[i][(l+1)%4]});
		}
		sort(side, side+4);
		ll x[4];
		ll a = 1;
		for(int l=0; l<4; l++){
			x[l] = count_greater(faces[side[l]], i, j);
			a *= mul(side[l]);
		}
		if(side[0]==side[1]&&side[1]==side[2]&&side[2]==side[3]){
			a *= x[0]*(x[0]-1)*(x[0]-2)*(x[0]-3);
		} else if(side[0]==side[1]&&side[1]==side[2]){
			a *= x[0]*(x[0]-1)*(x[0]-2)*x[3];
		} else if(side[1]==side[2]&&side[2]==side[3]){
			a *= x[0]*x[1]*(x[1]-1)*(x[1]-2);
		} else if(side[0]==side[1]&&side[2]==side[3]){
			a *= x[0]*(x[0]-1)*x[2]*(x[2]-1);
		} else if(side[0]==side[1]){
			a *= x[0]*(x[0]-1)*x[2]*x[3];
		} else if(side[1]==side[2]){
			a *= x[0]*x[1]*(x[1]-1)*x[3];
		} else if(side[2]==side[3]){
			a *= x[0]*x[1]*x[2]*(x[2]-1);
		} else {
			a *= x[0]*x[1]*x[2]*x[3];
		}
		debug(any{i, j, k, a, x[0], x[1], x[2], x[3]});
		ans += a;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int button = 1;
    

    int count = 0;

    while(1){
        button = a[button];
        count++;
        if(button == 2){
            break;
        }
        if(count >= n){
            break;
        }
            
    }

    if(button == 2){
        printf("%d\n", count);
    }
    else if(count >= n){
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 768
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
P = []
for i in range(min(3000, X)):
    for j in range(min(3000//(i+1) + 1, X)):
        for z in range(min(3000//(i+1)//(j+1) +1, X) ):
            P.append(A[i]+B[j]+C[z])
P.sort(reverse=True)
for i in range(K):
    print(P[i])

Measured memory_bytes: 81164
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

int main() {
    long long n,i,k,j;
    cin >> n >>k;
    k=min(k,n);
    long long a[n];
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    long long dp[n+1];
    dp[0]=0;
    for(i=1;i<n;i++){
        dp[i]=INT_MAX;
    }
    for(i=0;i<k;i++){
        for(j=0;j<i;j++){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    for(i=k;i<n;i++){
        for(j=i-k;j<i;j++){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout << dp[n-1];
}

Measured memory_bytes: 5192
import collections
N = int(input())
a = [int(x) for x in input().split()]
aa = collections.Counter(a)
A = list(aa.items())
Alisted = [0]*(10**5+1)
for i in range(len(A)):
  Alisted[A[i][0]] = A[i][1]
Q = int(input())
BC = [[int(x) for x in input().split()]for i in range(Q)]

Sum = sum(a)
for i in range(Q):
  b = BC[i][0]
  c = BC[i][1]
  num = Alisted[b]
  Sum += (c-b)*num
  print(Sum)
  Alisted[b]=0
  Alisted[c]+=num


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

int main(){

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

    int n,m;
    n = ceil((float)(c) / b);
    m = ceil((float)(a) / d);

    if(n <= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}



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

int D[100][6];
void spin(int n,char c)
{
  if(c=='E'){
    swap(D[n][0],D[n][3]);swap(D[n][3],D[n][5]);swap(D[n][5],D[n][2]);
  }
  else if(c=='W'){
    swap(D[n][0],D[n][2]);swap(D[n][2],D[n][5]);swap(D[n][5],D[n][3]);
  }
  else if(c=='S'){
    swap(D[n][0],D[n][1]);swap(D[n][0],D[n][4]);swap(D[n][4],D[n][5]);
  } 
  else if(c=='N'){
    swap(D[n][0],D[n][1]);swap(D[n][1],D[n][5]);swap(D[n][5],D[n][4]);
  }
}
int main()
{
  int n,an[100];
  char SWS[10]={"SSSSWSSSS"};
  cin>>n;
  for(int i=0;i<6;i++)cin>>D[0][i];
  for(int j=1;j<n;j++){
    for(int i=0;i<6;i++)cin>>D[j][i];
    for(int i=0;i<10;i++){
      if(D[0][1]==D[j][1])break;
      spin(j,SWS[i]);
    }
    if(D[0][1]!=D[j][1] || D[0][4]!=D[j][4])an[j]=0;
    else{
      for(int i=0;i<4;i++){
	if(D[0][0]==D[j][0] &&D[0][2]==D[j][2] &&D[0][3]==D[j][3] &&D[0][5]==D[j][5]){
	  an[j]=1;
	  break;
	}
	spin(j,'W');
	if(i==3)an[j]=0;
      }
    }
  }
  for(int i=1;i<n;i++){
    if(an[i]==1){
      cout<<"No"<<endl;
      break;
    }
    if(i==n-1)cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N, M;
	cin >> N >> M;
	int A[M];
	rep(i,M) {
		cin >> A[i];
		N -= A[i];
	}
	if(N < 0) cout << -1 << endl;
	else cout << N << endl;



}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int a, b;
  cin >> a >> b;
  cout << (a <= b?a:a-1) << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

int main()
{
  ll n;
  string s;
  cin >> n >> s;
  int ans = 0;
  reps(i, 0, 1000)
  {
    int idx = 0;
    char v[4];
    sprintf(v, "%03d", i);
    rep(j, 3)
    {
      char x = v[j];
      bool isFind = false;
      while(idx < n)
      {
        if(x == s[idx])
        {
          idx++;
          isFind = true;
          break;
        }
        idx++;
      }
      if(!isFind)
      {
        break;
      }
      else if(j == 2)
      {
        ans++;
      }
      
    }
  }

  cout << fixed << ans << endl;

  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

//最大公約数
ll GCD(ll a, ll b)
{
    if (a == b || b == 0) {
        return a;
    } else if (a < b) {
        return GCD(b, a);
    } else {
        return GCD(b, a % b);
    }
}

vector<ll> a;
vector<ll> l, r;

int main()
{
    int n;
    ll ans = 0;
    cin>>n;
    a.push_back(0);
    REP(i,n) {
        ll ta;
        cin>>ta;
        a.push_back(ta);
    }
    l.resize(n+2);
    r.resize(n+2);
    l[0] = 0;
    r[0] = 0;
    l[n+1] = 0;
    r[n+1] = 0;
    FOR(i,1,n+1) {
        l[i] = GCD(l[i-1], a[i]);
    }
    RFOR(i,n+1,1) {
        r[i] = GCD(r[i+1], a[i]);
    }
    FOR(i,1,n+1) {
        ans = max(GCD(l[i-1], r[i+1]), ans);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2676