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

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin >> n;
    vector<long long> divs;
    for(long long i = 1; i*i <= n; i++) {
        if(n%i == 0) {
            divs.push_back(i);
            if(i != n/i) divs.push_back(n/i);
        }
    }
    long long ans = 0;
    for(long long x : divs) {
        if(x > 1) {
            long long m = x - 1;
            if((n/m)*(m+1) == n) ans += m;
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();

		scan.close();

		char[] c =s.toCharArray();

		int check=0;

		for(int i=0;i<s.length();i++) {
			if(i%2==0&&c[i]=='L'||i%2==1&&c[i]=='R') {
				check=1;
				break;
			}
		}
		if(check==1)System.out.println("No");
		else System.out.println("Yes");
	}

}

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

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

  if (((a+c)%2 == 0) && ((a+c)/2 == b)) {
    cout << "YES" << "\n";
  } else { cout << "NO" << "\n"; }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int[] a = new int[4];
		for(int i = 0; i < 4; i++) {
			a[i] = stdin.nextInt();
		}
		
		if(a[0] == a[1] && a[2] == a[3]) {
			System.out.println("yes");
		} else if(a[0] == a[2] && a[1] == a[3]) {
			System.out.println("yes");
		} else if(a[0] == a[3] && a[1] == a[2]) {
			System.out.println("yes");
		} else {
			System.out.println("no");
		}

	}
}

Measured memory_bytes: 26172
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n;cin>>n;
  vector<ll> T(n),V(n),M(n);
  rep(i,n){
    cin>>T[i];
  }
  rep(i,n){
    cin>>V[i];
  }
  V.push_back(0);
  REP(i,n){
    chmin(V[i], V[i+1] + T[i]);
  }
  double ans = 0;
  ll v = 0;
  rep(i,n){
    ll v0 = v;
    ll v1 = V[i], v2 = V[i+1];

    double best = 0;
    rep(t_, 2*T[i]+1){
      double t = t_ / 2.0;
      double sum = 0;
      sum += (v0 + (v0 + t)) * t / 2.0;
      if(v0 + t >= v1){
        sum -= (v0 + t - v1) * (v0 + t - v1);
      }
      sum += ((v0 + t) + (v0 + t - (T[i] - t))) * (T[i] - t) / 2.0;

      if(v0 + t_ - T[i] > v2) continue;
      chmax(best, sum);
    }
    ans += best;
    v = min({v + T[i], V[i], V[i+1]});
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N, M, Q = gets.split.map(&:to_i)

csum = Array.new(N + 1) { Array.new(N + 1, 0) }

M.times do
  l, r = gets.split.map(&:to_i)

  csum[l][r] += 1
end

(1..N).each do |i|
  (1..N).each do |j|
    csum[i][j] += csum[i][j - 1]
  end
end

(1..N).each do |i|
  (1..N).each do |j|
    csum[i][j] += csum[i - 1][j]
  end
end

Q.times do
  from, to = gets.split.map(&:to_i)

  puts csum[to][to] + csum[from - 1][from - 1] - csum[from - 1][to] - csum[to][from - 1]
end


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

int main() {
    int n;
    cin >> n;
    
    set<string>  items;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        items.insert(s);
    }
    cout << items.size();
    return 0;
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n, a, b, c, x, y[100];
  while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x) && (n||a||b||c||x)){
    rep(i, n) scanf("%d", y+i);
    int i = 0, res = 0;
    if(y[i] == x) i++;
    while(i < n){
      //      fprintf(stderr, "%d %d %d %d \n", a, b, c, x);
      x = (a * x + b) % c;
      if(y[i] == x) i++;
      res++;
      if(res > 10000) break;
    }

    if(res <= 10000) printf("%d\n", res);
    else puts("-1");
  }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int n, m, a[1005][1005];
pair<int,int> Q[1000005];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int maxim = 1, in, sf;

void bordare()
{
    for (int i=0;i<=n+1;i++)
        a[i][0] = a[i][m+1] = 1;
    for (int i=0;i<=m+1;i++)
        a[0][i] = a[n+1][i] = 1;
}

void lee();

int main()
{
    int i, j;
    char c;

    cin >> n >> m;
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
        {
            cin >> c;
            if (c == '#')
                a[i][j] = 1;
        }
    bordare();
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
            if (a[i][j] == 1)
                Q[sf++] = {i,j};
    lee();
    cout << maxim-1;
    return 0;
}

void lee()
{
    while (in < sf)
    {
        auto aux = Q[in++];
        for (int i=0;i<4;i++)
        {
            int l9 = aux.first+dx[i];
            int c9 = aux.second+dy[i];
            if (!a[l9][c9])
            {
                a[l9][c9] = a[aux.first][aux.second]+1;
                Q[sf++] = {l9,c9};
                if (a[l9][c9] > maxim)
                    maxim = a[l9][c9];
            }
        }
    }
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define fi first
#define sc second
const ll mod = 1000000007;
#define repn(i,n) for(int i=1;i<=n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back

int n,a[105];
ll modpow(ll a,ll n){
    ll ret = 1;
    while(n){
        if(n&1) ret = ret*a%mod;
        a = a*a%mod;
        n >>= 1;
    }
    return ret;
}
P rec(int l,int r,int dep){
	int mn = mod;
	for(int i=l;i<=r;i++) mn = min(mn,a[i]);
	int cnt = 0;
	vector<P>ret;
	int sum = 0;
	for(int i=l;i<=r;i++){
		if(a[i] == mn){
			if(cnt) ret.pb(rec(i-cnt,i-1,mn));
			cnt = 0;
			sum++;
		}
		else cnt++;
	}
	if(cnt) ret.pb(rec(r-cnt+1,r,mn));
	
	//01010101....
	ll val = 1;
	rep(i,ret.size()) val = val * ret[i].fi % mod * 2LL % mod;
	
	//all
	ll val2 = modpow(2LL,sum);
	rep(i,ret.size()) val2 = val2 * (ret[i].fi*4LL%mod+ret[i].sc) % mod;
	val2 = (val2-2LL*val)%mod;
	if(val2 < 0) val2 += mod;
	
	val = val * modpow(2LL,mn-dep-1) % mod;
	return mp(val,val2);
}
int main(){
	cin >> n;
	repn(i,n) cin >> a[i];
	
	P ret = rec(1,n,0);
	ll ans = ret.fi*2LL+ret.sc;
	cout << (ans%mod+mod)%mod << endl;
}

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


int main(void){
    long n,i,sum=0;
    scanf("%ld",&n);
    long b[n-1];
    for(i=0;i<n-1;i++){
        scanf("%ld",&b[i]);
    }
    long a[i];
    for(i=0;i<n-1;i++){
        if(i==0) a[i]=b[i];
        if(b[i]>b[i+1]){
            a[i+1]=b[i+1];
        }else{
            a[i+1]=b[i];
        }
    }
    for(i=0;i<n;i++){
        sum+=a[i];
    }
    printf("%ld\n",sum);
    return 0;
}


Measured memory_bytes: 128
/**
 * @file A-Entrance-Examination.cpp
 * @author murnana
 * @brief A - B +/- A
 *   https://atcoder.jp/contests/abc118/tasks/abc118_a
 * @date 2019-02-16
 * 
 * @copyright Copyright (c) 2019
 * 
 */

#include <ios>
#include <iostream>
#include <iomanip>
using namespace std;

/**
 * @brief Entry point
 * 
 * @return int 
 */
int main()
{
    // A, Bを受け取る
    int A, B;
    cin >> A >> B;

    if (B <= 0 || A <= 0)
    {
        // 0で割らないで・・・！
        // 問題の条件分的にそんな数字出ないけど
    }
    else if (B % A)
    {
        cout << (B - A) << endl;
    }
    else
    {
        cout << (A + B) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

ll f(ll h,ll w){//hを3で割る
    ll ans1=max({h/3*w, (h-h/3)*(w/2), (h-h/3)*((w+1)/2)}) - min({h/3*w, (h-h/3)*(w/2), (h-h/3)*((w+1)/2)});
    ll ans2=max({(h+2)/3*w, (h-(h+2)/3)*(w/2), (h-(h+2)/3)*((w+1)/2)}) - min({(h+2)/3*w, (h-(h+2)/3)*(w/2), (h-(h+2)/3)*((w+1)/2)});
    ll ans3=max({h/3*w,(h-h/3)/2*w,(h-h/3+1)/2*w})-min({h/3*w,(h-h/3)/2*w,(h-h/3+1)/2*w});
    ll ans4=max({(h+1)/3*w,(h-(1+h)/3)/2*w,(h-(1+h)/3+1)/2*w})-min({(h+1)/3*w,(h-(1+h)/3)/2*w,(h-(1+h)/3+1)/2*w});
    return min({ans1,ans2,ans3,ans4});
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    ll h,w;cin >> h >> w;
    cout << min(f(h,w),f(w,h)) << endl;
}

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

using namespace std;

using int64 = long long;

const int64 INF = 1LL << 58;

struct edge
{
  int u, v;
  int64 cost;

  bool operator<(const edge &e) const
  {
    return (cost < e.cost);
  }
};

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

  int64 G[300][300], F[300][300], g[300][300];

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      cin >> G[i][j];
      F[i][j] = G[i][j];
    }
  }

  for(int k = 0; k < N; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  vector< edge > edges;
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      if(G[i][j] != F[i][j]) {
        cout << -1 << endl;
        return (0);
      }
      edges.emplace_back((edge) {i, j, G[i][j]});
    }
  }

  int64 ret = 0;
  fill_n(*g, 300 * 300, INF);
  for(int i = 0; i < N; i++) g[i][i] = 0;
  sort(begin(edges), end(edges));

  for(auto &e : edges) {

    const int64 s = e.v, t = e.u, cost = e.cost;
    if(g[s][t] <= cost) continue;
    ret += cost;
    g[s][t] = g[t][s] = min(g[s][t], cost);
    for(int k : {s, t}) {
      for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
      }
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 3188
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int ar[n];
    for(int i = 0;i < n;i++)scanf("%d",&ar[i]);
    long long cntbx[n+1];
    for(int i = 0;i <= n;i++)cntbx[i]=0;
    for(int i = 0;i < n;i++)cntbx[ar[i]]++;
    long long nbx[n+1];
    long long nbx1[n+1];
    for(int i = 1;i <= n;i++)nbx[i] = cntbx[i]*(cntbx[i]-1l)/2l;
    for(int i = 1;i <= n;i++)nbx1[i] = (cntbx[i]?(cntbx[i]-1l)*(cntbx[i]-2l)/2l:0);
    unsigned long long tmpans = 0;
    for(int i = 1;i <= n;i++)tmpans += nbx[i];
    for(int i = 0;i < n;i++)printf("%llu\n",tmpans-((unsigned long long)nbx[ar[i]]-nbx1[ar[i]]));
    return 0;
}

Measured memory_bytes: 7936
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = []
ord = [-1 for x in range(n+1)]
c = 1
l = 1

v = 1
while(ord[v] == -1):
    ord[v] = len(b)
    b.append(v)
    v = a[v-1]
c = len(b) - ord[v]
l = ord[v]

if (k < l):
    print(b[k])
else:
    k -= l
    k %= c
    print(b[l+k])


Measured memory_bytes: 32384
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

bool check(int x, int y, string s) {
	for(int i = x; i < y; ++i) {
		if( s.substr(i, 2) == "##" ) return false;
	}
	
	return true;
}

int main(void) {
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	
	a--; b--; c--; d--;
	
	if( !check(a, c, s) || !check(b, d, s) ) {
		cout << "No" << endl;
		return 0; 
	}
	
	if( c < d ) {
		cout << "Yes" << endl;
	} else if( c > d ) {
		for(int i = b; i <= d; ++i) {
			if( s.substr(i - 1, 3) == "..." ) {
				cout << "Yes" << endl;
				return 0;
			}				
		}
		
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
vector<string> input(int N) {
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  cin >> n;
  vector<string> s=input(n);
  sort(s.begin(),s.end());
  int ans=1;
  rep(i,n){
    if(s[i-1]!=s[i]){
      ans++;
    }
  }
  cout << ans << endl;
}

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

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

struct mobile {
  long long lm,rm;
  long long lc,rc,ll,rl;
  mobile(long long lc,long long rc,long long ll,long long rl)
  : lc(lc), rc(rc), ll(ll), rl(rl) {
    lm = rm = -1;
  }
};

int gcd(int a,int b) {
  return b != 0 ? gcd(b, a%b) : a;
}

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

int dfs(int pos,vector<mobile> &vm) {
  mobile now = vm[pos];
  now.lm = (now.lc == -1) ? 1 : dfs(now.lc,vm);
  now.rm = (now.rc == -1) ? 1 : dfs(now.rc,vm);
  int g = lcm(now.ll*now.lm, now.rl*now.rm);
  now.rm = g / now.rl;
  now.lm = g / now.ll;
  return now.rm+now.lm;
}

int main() {
  int n,i,p,q,r,b,root;
  while(cin>>n, n) {
    vector<mobile> vm;
    vector<bool> isroot(n+1,true);
    root = -1;
    rep(i,n) {
      cin>>p>>q>>r>>b;
      r--,b--;
      if(r >= 0) isroot[r] = false;
      if(b >= 0) isroot[b] = false;
      vm.push_back(mobile(r,b,p,q));
    }

    rep(i,n) if(isroot[i] == true) root = i;
    cout<<dfs(root,vm)<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N; 
	vector<pair<int,int>>vec(N);
	rep(i, 0, N) {
		int a, b; cin >> a >> b;
		vec[i] = make_pair(a + b, a - b);
	}
	sort(all(vec));
	int ans = 0, t = -2 * INF - 2;
	rep(i, 0, N) {
		if (t <= vec[i].second) {
			ans++;
			t = vec[i].first;
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = NextInt()
ans = 0
for i in range(n):
    ans += (n-i)*(i+1)
for i in range(n-1):
    u,v = NextInts()
    if u > v:
        u,v = v,u
    ans -= u*(n-v+1)
print(ans)

Measured memory_bytes: 9448
from itertools import product
n = int(input())
a = ['7','5','3']

x =[]
for i in range(3,11):
    x += list(product(a, repeat = i))
y = []
for j in x:
    if '7' in j and '5' in j and '3' in j:
        y.append(j)
z = []
for k in range(len(y)):
    z.append(''.join(y[k]))
z = [int(_) for _ in z]

b = 0
for p in z:
    if p <= n:
        b += 1

print(b)


Measured memory_bytes: 25004
import sys
import re


def resolve(in_):
    N = int(next(in_))
    S = next(in_).strip()

    answer = sum(1 for _ in re.finditer('ABC', S))
    return answer


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9952
#ABC147-D Xor Sum 4
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7

"""
ビット演算は桁ごとに独立しているので、何桁目かというループを外側において
桁ごとに計算して、最後に全部の値を足す。
↓何が良いか？
XORの性質として、0を1個、1を1個選ぶことで1になるので、そうなる選び方の総数を求めることで
高速に計算が可能となる。
"""

ans = 0

for i in range(60): #桁ごとのループ
    x = 0 #i桁における1の個数
    for j in range(n):
        if lst1[j]>>i &1: #要素Ajのi桁目がiならばxに1を足す
            x += 1
    y = n-x #i桁における0の個数
    now = x*y %mod #XORが1になる回数※コード下部に証明有り

    now *= 2**i #nowを2**iまで持ってく1

    ans += now
    ans %= mod

print(ans)

"""
その桁のXORが１になる回数が
(1の出現回数)*(0の出現回数)であることの証明

その桁の全ループに対して、愚直に1の出現回数を数えてみる
今回は、[0,1,0,1,0,0,1]について考える。X = 3,Y = 4でXOR=12となることを証明する。

[0] 1 0 1 0 0 1 → 3回(0より右に1は3回ある)
0 [1] 0 1 0 0 1 → 3回
0 1 [0] 1 0 0 1 → 2回
0 1 0 [1] 0 0 1 → 2回
0 1 0 1 [0] 0 1 → 1回
0 1 0 1 0 [0] 1 → 1回
---------------------
計：              12回

よって、その桁の全ループにおいて
XORが1になる回数は、(1の出現回数)*(0の出現回数)であることが分かる。
"""

Measured memory_bytes: 125624
N = int(input())
H = list(map(int, input().split()))
C = [0 for i in range(N)]
for i in range(N):
  if i == 0:
    C[i] = 0
  elif i == 1:
    C[i] = abs(H[i-1]-H[i])
  else:
    C[i] = min(C[i-1] + abs(H[i-1]-H[i]), C[i-2] + abs(H[i-2]-H[i]))
print(C[N-1])

Measured memory_bytes: 13980
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    print(N**3)



if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    unsigned long long N = 0;
    cin>>N;
    unsigned long long sum = (1+N)*N/2;
    unsigned long long div_3 = N/3;
    unsigned long long sum_3 = (3+div_3*3)*div_3/2;
    unsigned long long div_5 = N/5;
    unsigned long long sum_5 = (5+div_5*5)*div_5/2;
    unsigned long long div_15 = N/15;
    unsigned long long sum_15 = (15+div_15*15)*div_15/2;
    sum = sum-sum_5-sum_3+sum_15;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=9000000000000000000;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll popcount(ll n){
    ll ret=0;
    while(n>0){
        ret+=n%2;
        n/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    ll s[n];
    rep(i,0,n)cin>>s[i];
    bool dp[n+1][10001];
    memset(dp,0,sizeof dp);
    dp[0][0]=true;
    rep(i,0,n){
        rep(j,0,10001){
            if(dp[i][j]==false)continue;
            dp[i+1][j]=true;
            dp[i+1][j+s[i]]=true;
        }
    }
    rrep(i,10000,0){
        if(i%10==0)continue;
        if(dp[n][i]){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}




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

int main() {
  int N;
  int d[110];
  cin >> N;
  rep(i, N) cin >> d[i];

  set<int> values;
  rep(i, N) values.insert(d[i]);

  cout << values.size() << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>>x;
    REP(i, n){
        int a, b;
        cin >> a >> b;
        x.push_back(make_pair(a, b));
    }
    sort(x.begin(), x.end());
    vector<pair<int, int>> v;

     for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            v.push_back(make_pair(x[i].first - x[j].first, x[i].second - x[j].second));
        }
    }

    int cnt = 0;
    sort(v.begin(), v.end());
    bool flag = false;
    int ans = 0;
   /*   for (int i = 0; i < v.size(); i++)
    {
        cerr << v[i].first << " " << v[i].second << endl;
    }*/
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    for (size_t i = 0; i < v.size()-1; i++)
    {
        flag = false;
        cnt = 0;
        while (v[i] == v[i + 1])
        {
            flag = true;
            cnt++;
            if(i==v.size()-2){
                break;
            }
            i++;
        }
        if(flag){
            ans = max(ans, cnt);
        }
    }
    cout << n - ans-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string N;
  cin >> N;
  int D = N.size();
  int sum = 0;
  for (int i = 0; i < D; i++){
    sum += N[i] - '0';
  }
  if (sum % 3 == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

    vector<int> v1(N);
    vector<int> v2(N);
    vector<int> v(N);

    for (int i = 0; i < N; ++i) cin >> v1[i];
    for (int i = 0; i < N; ++i) cin >> v2[i];
    copy(v1.begin(), v1.end(), v.begin());
    sort(v.begin(), v.end());

    int cnt1 = 0, cnt2 = 0;
    int ans1 = 0, ans2 = 0;
    do {
        ++cnt1;
        ++cnt2;
        if (v == v1) ans1 = cnt1;
        if (v == v2) ans2 = cnt2;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ans1 - ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
using namespace std;

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
//if(s.find(s1) != std::string::npos)
//mp :: cpp_int a=0;


ll _gcd(ll a, ll b)
{
    if(b==0)return a;
    a=a%b;
    return _gcd(b-a,a);
}
long long f(long long a) {
     long long res[] = {a,1,a+1,0};
     return res[a%4];
}

long long getXor(long long a, long long b) {
     return f(b)^f(a-1);
}

int solve( ){


int a,b,c,d;
mi m;m[1]=0;m[9]=0;m[7]=0;m[4]=0;
cin>>a>>b>>c>>d;
m[a]++;m[b]++;m[c]++;m[d]++;
if(m[1]==1&&m[9]==1&&m[7]==1&&m[4]==1)cout<<"YES";
else cout<<"NO";

}

int main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  /*
    #ifndef ONLINE_JUDGE
    freopen("test.in", "r" , stdin);
    freopen("test.out", "w", stdout);
    #endif
  */
  clock_t time_req;

    // Without using pow function
    time_req = clock();


//cin>>t;
//cin.ignore();
   while(t--)
     {solve();
     }

         time_req = clock() - time_req;
   // cout << "Processor time taken in pow function: "
     //  << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N, L;
VI A;
int main() {
    std::cin >> N >> L;
    A.resize(N);

    int lp = -1;
    REP(i, N) {
        std::cin >> A[i];
        if(i > 0 && A[i-1] + A[i] >= L) {
            lp = i;
        }
    }
    if(lp == -1) {
        std::cout << "Impossible" << std::endl;
        return 0;
    }
    std::cout << "Possible" << std::endl;

    int i = 1, cnt = 0;
    while(i < lp) {
        std::cout << (i++) << std::endl;;
    }
    i = N-1;
    while(i > lp) {
        std::cout << (i--) << std::endl;
    }
    std::cout << lp << std::endl;
    return 0;
}

Measured memory_bytes: 1152
# https://atcoder.jp/contests/abc133/tasks/abc133_e

# あー解説あたまいい
# そのノードで塗れる色の候補を持つのではなくて、
# そのノードの子で塗れる通りの数を持っておく
# あるノードの子で塗れる通りの数は、親とそのノードで塗る色の通りも確定してると考えると、(K-2)P(子の数)となる。(自身が根のときは自身の色の通りも考慮して、(K)P(子の数+1)となる)
# これをdfsで実装すれば良い

import sys
from collections import defaultdict

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


MOD = 10**9 + 7

N, K = read_ints()
tree = defaultdict(lambda: [])
for _ in range(N - 1):
    a, b = read_ints()
    a, b = mina(a, b)
    tree[a].append(b)
    tree[b].append(a)


def perm_mod(n, r, mod=MOD):
    if n < r:  # そんな通りはありえない
        return 0

    ret = 1
    for _ in range(r):
        ret *= n
        ret %= mod
        n -= 1
    return ret


def dfs(u, p):  # 現在のuと親のp
    if len(tree[u]) == 1 and tree[u][0] == p:
        # 葉なので終了
        return 1
    ret = 1  # その地点までの通りの数
    for to in tree[u]:
        if to == p:
            continue
        ret *= dfs(to, u)
        ret %= MOD
    if p == -1:
        ret *= perm_mod(K, len(tree[u]) + 1)
    else:
        ret *= perm_mod(K - 2, len(tree[u]) - 1)

    return ret % MOD


print(dfs(0, -1))


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    vector<P> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i].F >> v[i].S;

    }

    set<P> p;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(i == j) continue;
            p.insert(MP(v[i].F - v[j].F, v[i].S - v[j].S));

        }
    }

    int mx = 0;
    for(auto pi = p.begin(); pi != p.end(); ++pi) {
        int cnt = 0;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(i == j) continue;
                P tmp = *pi;
                if(v[i].F - v[j].F == tmp.F && v[i].S - v[j].S == tmp.S) {
                    ++cnt;

                }
            }
         }
        mx = max(mx, cnt);
    }
    cout << n - mx << endl;
    return 0;
}



Measured memory_bytes: 384
#include <cstring>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    int cnt = 0;
    for (int i = 0; i < 3; i++)
        if (s1[i] == s2[i])
            cnt++;
    cout << cnt << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9 + 7

ans = 0
for b in range(60):
    c = 0
    for a in A:
        if (a >> b) & 1:
            c += 1
    ans += 2**b*c*(N-c)
    ans %= mod
print(ans)


Measured memory_bytes: 122808
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int m, i, j, k, sum = 0;
    cin>>k;
    for(i=1;i<=k;++i)
    {
        for(j=1;j<=k;++j)
        {
            for(m=1;m<=k;++m)
            {
                sum += gcd(i,gcd(j,m));
            }
        }
    }
    cout<<sum;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    for (char i : s) {
        if (i == 'a') a++;
        else if (i == 'b') b++;
        else c++;
    }
    cout << (abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<i64>();
    let mut b = read_vec::<i64>();
    let mut ans = 0;
    for i in 0..n {
        let consumed = min(a[i], b[i]);
        b[i] -= consumed;
        ans += consumed;
        let consumed = min(a[i + 1], b[i]);
        a[i + 1] -= consumed;
        ans += consumed;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4836
#include <iostream>
#include <vector>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    vector<int> p;
    int tmp;
    int num = 0;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp;
        p.push_back(tmp);
    }

    for(int i=1; i<n-1; i++){
        if(((p[i]>p[i-1]) && (p[i+1]>=p[i])) || ((p[i]>p[i+1]) && (p[i-1]>=p[i]))){
            num++;
            //cout << i << " " << endl;
        }
    }
    cout << num << endl;
}

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

struct Dice {
  int faces[6+1];
  Dice() : faces{0, 1, 2, 3, 4, 5, 6} {}
  void order(char cmd) {
    switch (cmd) {
      case 'E':
        swap(faces[1], faces[4]);
        swap(faces[4], faces[6]);
        swap(faces[6], faces[3]);
        break;
      case 'N':
        swap(faces[1], faces[2]);
        swap(faces[2], faces[6]);
        swap(faces[6], faces[5]);
        break;
      case 'S':
        swap(faces[1], faces[5]);
        swap(faces[5], faces[6]);
        swap(faces[6], faces[2]);
        break;
      case 'W':
        swap(faces[1], faces[3]);
        swap(faces[3], faces[6]);
        swap(faces[6], faces[4]);
        break;
      case 'L':
        swap(faces[2], faces[4]);
        swap(faces[4], faces[5]);
        swap(faces[5], faces[3]);
        break;
      case 'R':
        swap(faces[2], faces[3]);
        swap(faces[3], faces[5]);
        swap(faces[5], faces[4]);
        break;
    }
  }
};

enum Faces {Top = 1, Front = 2, Right = 3};

int main() {
  int labels[6+1];
  for (int i{1}; i <= 6; ++i)
    cin >> labels[i];
  int q;
  cin >> q;
  Dice d;
  for (int i{}; i < q; ++i) {
    int top, front;
    cin >> top >> front;
    // topがあるならS(N)方向に3回まわすまでにでてくる。
    for (int j{}; j < 3 && labels[d.faces[Top]] != top; ++j) {
      d.order('S');
    }
    // なかったらW(E)方向に3回まわすまでにでてくる。
    for (int j{}; j < 3 && labels[d.faces[Top]] != top; ++j) {
      d.order('W');
    }
    // frontはL(R)方向に3回まわすまでにでてくる。
    for (int j{}; j < 3 && labels[d.faces[Front]] != front; ++j) {
      d.order('L');
    }
    cout << labels[d.faces[Right]] << endl;
  }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    int A, B;
    cin >> A >> B;
    for (int i = 1; i < 4; i++) {
        if((i != A) && (i != B)) cout << i << endl;
    }
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,ar[105][2]; ll dp[105][2];
ll maxval(ll i,ll r){
	if(i==n+1) return 0;
	if(dp[i][r]!=-1){
		return dp[i][r];
	}
	if(r==0){
		ll a,b;
		a=maxval(i+1,0)+ar[i][0];
		b=maxval(i,1)+ar[i][0];
		return max(a,b);
	}
	else{
		return maxval(i+1,1)+ar[i][1];
	}
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	ll i,j,k,l;
	cin>>n;

	for(i=1;i<=n;i++){
		cin>>ar[i][0];
	}
	for(i=1;i<=n;i++){
		cin>>ar[i][1];
	}
	
	ll an=maxval(1,0);
	cout<<an;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int n, k, INIT=1e8;
P p[100000];
vector<int> e[100000];
P f(int x, int y, int z){
    int a=-1e7, b=1e7, q=z;
    if(p[x].first<INIT){
        a=max(a, p[x].first);
        b=min(b, p[x].second);
    }
    if(q==-1){
        q=a%2;
    }else{
        if((q+a+INIT)%2==1)a++;
        if((q+b+INIT)%2==1)b--;
    }
    for(int i=0;i<e[x].size();i++){
        int v=e[x][i];
        if(v!=y){
            P u=f(v, x, (q+1)%2);
            if(u.first>u.second){
                return P(INIT, -INIT);
            }
            a=max(a, u.first-1);
            b=min(b, u.second+1);
            if((q+a+INIT)%2==1)a++;
            if((q+b+INIT)%2==1)b--;
        }
    }
    //cout<<x<<" : "<<a<<" - "<<b<<endl;
    return p[x]=P(a, b);
}

void g(int x, int y){
    int q=p[x].first;
    for(int i=0;i<e[x].size();i++){
        int w=e[x][i];
        if(w!=y){
            if(q-1>=p[w].first){
                p[w]=P(q-1, q-1);
            }else{
                p[w]=P(q+1, q+1);
            }
            g(w, x);
        }
    }
}

int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a, b;
        cin>>a>>b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    fill(p, p+n, P(INIT, INIT));
    cin>>k;
    for(int i=0;i<k;i++){
        int v, w;
        cin>>v>>w;
        v--;
        p[v]=P(w, w);
        if(i==k-1){
            p[v]=f(v, -1, -1);
            if(p[v].first>p[v].second){
                cout<<"No"<<endl;
                return 0;
            }
            g(v, -1);
        }
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        cout<<p[i].first<<endl;
    }
}


Measured memory_bytes: 16512
n=int(input())
a=list(map(int,input().split()))
c=1
d=0
for i in range(1,n):
    if d==0:
        if a[i-1]<a[i]:
            d=1
        elif a[i-1]>a[i]:
            d=-1
    elif d==1 and a[i-1]>a[i]:
        c+=1
        d=0
    elif d==-1 and a[i-1]<a[i]:
        c+=1
        d=0
print(c)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 3e3;
int n, t, a, b, DP1[N], DP2[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> t;
  FOR(i, 0, n){
    int a, b;
    cin >> a >> b;
    FORR(j, t-a-1, 0) maxs(DP1[j+a], DP1[j]+b);
    FOR(j, 0, t) maxs(DP1[j], DP2[j]+b);
    FORR(j, t-a-1, 0) maxs(DP2[j+a], DP2[j]+b);
  }
  cout << DP1[t-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解説写し
const int INF=1001001001;
int a[12][12];

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[i][j];
  }
  int ans =INF;
  rep(s,1<<n){
    int cost=0;
    vector<int>d(m);
    rep(i,n){
   if (s&(1<<i)) {
        cost+=c[i];
        rep(j,m)d[j]+=a[i][j];
      }
    }
    bool ok=true;
    rep(j,m)if(d[j]<x)ok=false;
    if(ok)ans=min(ans,cost);
  }
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}
          


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);


    i64 ans = infll, cnt;
    string s; cin >> s;
    set<char> chs;
    for(auto c : s) chs.insert(c);
    for(auto ch : chs) {
        cnt = 0;
        string tmp = s;
        while(1) {
            bool can = 1;
            for(auto c : tmp) if(c != ch) can = 0;
            if(can) break;
            ++cnt;
            string tmp2;
            for(i32 j = 0; j < tmp.size()-1; ++j) {
                if(tmp[j] == ch) tmp2.push_back(tmp[j]);
                else tmp2.push_back(tmp[j+1]);
            }
            tmp = tmp2;
        }
        chmin(ans, cnt);
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 384